How do I disable the GCC warning that the #warning directive is a GCC extension?

When using the #warning directive instead of one warning, I get two — the one I generate, plus an additional warning: #warning is a GCC extension [enabled by default] .

I can suppress the result of the #warning directive itself, with -Wno-cpp , but this is the opposite of what I want.

I can get around this using #pragma message() , but it seems that the #warning directive is pretty pointless - there is no way to suppress this warning?

+8
gcc compiler-warnings gcc-warning warnings
source share
3 answers

And, it seems, the -pedantic option enables this warning, and there is no specific override for it, as in most other GCC warnings. Removing -pedantic removes the warning warning.

+3
source share
 #ifdef __GNUC__ #warning "no warning here!" #endif 

will compile with or without gcc even with -pedantic , but it will still give a warning (and will not work if warnings are overloaded to errors).

UPDATE: According to this related question , there is no clean solution to selectively turn off gnu-specific warnings #pragma s

0
source share

Actually, the following should work. With this, you can suppress / ignore gcc warnings.

 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcpp" ... #pragma GCC diagnostic pop 
0
source share

All Articles