This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pragma GCC diagnostic ignored "-Wundef"


"ml.lattuada@libero.it" <ml.lattuada@libero.it> writes:

> I have a problem with undef and diagnostic pragma and I am not sure if I am 
> doing something wrong or it's a GCC bug.
>
> The following code:
>
> #pragma GCC diagnostic ignored "-Wundef"
> #if FOO
> #endif
> int main (void) { return 42; }
>
> compiled in this way:
>
> gcc -o test test.c -Wundef -Werror
>
> does not give any error.
> On the contrary if I compile it with g++
>
> g++ -o test test.c -Wundef -Werror
>
> gives
>
> test.c:2:5: error: "FOO" is not defined [-Werror=undef]
> cc1plus: all warnings being treated as errors
>
> gcc version is:
> gcc (Debian 4.7.0-8) 4.7.0
>
> Why does preprocessor have this different behavior?

It's a bug.  The C++ parser lexes the entire file first, and then parses
it.  The #pragma processing is deferred until parsing, but the
preprocessor reports the warning during lexing.

The C parser lexes as it goes, so it processes the #pragma before the
preprocessor reports the warning.

Please open a bug report about this if there isn't one open already.
Thanks.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]