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.
How to disable GCC warning about the #warning directive being a GCC extension?
-
30-05-2022 - |
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?
Solution
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