This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pragma GCC diagnostic ignored "-Wundef"
- From: Ian Lance Taylor <iant at google dot com>
- To: "ml dot lattuada\ at libero dot it" <ml dot lattuada at libero dot it>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 18 May 2012 06:55:44 -0700
- Subject: Re: pragma GCC diagnostic ignored "-Wundef"
- References: <17967411.2365241337333761651.JavaMail.defaultUser@defaultHost>
"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