> 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
这是设计使然,在这里说明:
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.
换句话说,假设您有foo.cc
,并且GCC-4.9警告其中有某些东西(我们称它为foobar
),但是您相信使用foobar
可以安全。
由于您希望将所有警告都视为错误(带有-Werror
),因此请忠实地添加-Wno-foobar
到中Makefile
。
现在,其他人尝试使用GCC-4.8构建您的代码。如上所述,这不会产生任何警告,他会成功。
如果确实产生警告,则您将无法同时使用该foobar
构造,并且无法使用可同时用于Makefile
GCC-4.8和GCC-4.9的单个构造。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句