Compilation warning when compiling preprocessed file, but not when compiling original file?

Hi,

I get this with a clang built from trunk, but also old clang versions
behave like this.

If I compile foo.c like this I get no warnings at all:

  clang -Wall -o foo.o -c foo.c

But if I first preprocess it

  clang -Wall -o foo.pp.c -c foo.c -E

and then compile the preprocessed output:

  clang -Wall -o foo.o -c foo.pp.c

then clang warns:

foo.c:7:12: warning: equality comparison with extraneous parentheses
[-Wparentheses-equality]
   if (((i) == (j)))
        ~~~~^~~~~~
foo.c:7:12: note: remove extraneous parentheses around the comparison to
silence this warning
   if (((i) == (j)))
       ~ ^ ~
foo.c:7:12: note: use '=' to turn this equality comparison into an
assignment
   if (((i) == (j)))
            ^~

foo.c (108 Bytes)

This is a frequently asked question, and the solution is to use -frewrite-includes. We should consider adding it to http://clang.llvm.org/docs/FAQ.html.

Basically, yes, clang’s warnings look at macro definitions, so if you pre-process, you can expect to get different warnings. If you add -frewrite-includes, then clang should produce the same set of warnings when compiling the un-preprocessed source as the preprocessed source.

Hi,

This is a frequently asked question, and the solution is to use
-frewrite-includes. We should consider adding it to
Frequently Asked Questions (FAQ) — Clang 18.0.0git documentation.

Basically, yes, clang's warnings look at macro definitions, so if you
pre-process, you can expect to get different warnings. If you add
-frewrite-includes, then clang should produce the same set of warnings
when compiling the un-preprocessed source as the preprocessed source.

Ok, thanks for the explanation!
/Mikael