Question

When using the #warning directive, rather than 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 #warning directive's result itself, with -Wno-cpp, but that's the opposite of what I want.

I can work around this by instead using #pragma message() but that seems to render the #warning directive rather pointless - is there no way to suppress this warning warning?

Was it helpful?

Solution

Ah, it seems the -pedantic option enables this warning, and there does not seem to be a specific override for it, as there is with most other GCC warnings. Removing -pedantic gets rid of the warning about a warning.

OTHER TIPS

#ifdef __GNUC__
#warning "no warning here!"
#endif

will compile with or without gcc, even with -pedantic, but it will still give the warning, (and fail if warnings are escalated to errors).

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

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

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"

...

#pragma GCC diagnostic pop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top