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

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 8 09:23:20 PST 2018


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.

On Wed, Nov 7, 2018 at 11:39 PM Mikael Holmén via cfe-dev <
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
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181108/86bcc3de/attachment.html>


More information about the cfe-dev mailing list