> cat warning.cpp
#pragma foobar
> cat no_warning.cpp
#pragma message "foobar"
> g++ -Wall -Wno-foobar -c warning.cpp
warning.cpp:1:0: warning: ignoring #pragma foobar [-Wunknown-pragmas]
cc1plus: warning: unrecognized command line option "-Wno-foobar" [enabled by default]
> g++ -Wall -Wno-foobar -c no_warning.cpp
no_warning.cpp:1:17: note: #pragma message: foobar
This is by design, explained here:
When an unrecognized warning option is requested (e.g., -Wunknown-warning),
GCC emits a diagnostic stating that the option is not recognized.
However, if the -Wno- form is used, the behavior is slightly different:
no diagnostic is produced for -Wno-unknown-warning unless other diagnostics
are being produced.
This allows the use of new -Wno- options with old compilers, but if something
goes wrong, the compiler warns that an unrecognized option is present.
In other words, suppose you have foo.cc
, and GCC-4.9 warns about something (let's call it foobar
) in it, but you believe that your use of foobar
is safe.
Since you want to treat all warnings as errors (with -Werror
), you dutifully add -Wno-foobar
to your Makefile
.
Now someone else tries to build your code with GCC-4.8. As stated above, this produces no warning and he succeeds.
If this did produce a warning, you'd be unable to both use the foobar
construct and have a single Makefile
that worked with both GCC-4.8 and GCC-4.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With