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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

David Blaikie via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

foo.c (148 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

David Blaikie via cfe-dev
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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

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

David Blaikie via cfe-dev
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
> <[hidden email] <mailto:[hidden email]>> 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
>     [hidden email] <mailto:[hidden email]>
>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev