Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is "cc1plus: warning: unrecognized command line option" for "no-" options only flagged by g++ when there is another warning?

Tags:

c++

g++

> 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
like image 948
Mark Galeck Avatar asked Oct 21 '22 19:10

Mark Galeck


1 Answers

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.

like image 84
Employed Russian Avatar answered Oct 24 '22 13:10

Employed Russian