[cfe-dev] Compilation warning when compiling preprocessed file, but not when compiling original file?

Mikael Holmén via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 8 22:58:06 PST 2018


Hi,

On 11/8/18 6:23 PM, Reid Kleckner wrote:
> 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.

Ok, thanks for the explanation!
/Mikael

> 
> On Wed, Nov 7, 2018 at 11:39 PM Mikael Holmén via cfe-dev 
> <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> 
>     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)))
>                  ^~
>                  =
>     1 warning generated.
> 
>     ---
> 
>     Is this how it's supposed to be? Is it perhaps even a feature?
> 
>     It's not something I suffer from in any way, I just noticed it
>     yesterday
>     and thought it was odd since I thought compiling the original file or
>     the preprocessed output would behave the same way.
> 
>     Regards,
>     Mikael
>     _______________________________________________
>     cfe-dev mailing list
>     cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> 



More information about the cfe-dev mailing list