简体   繁体   English

为什么“cc1plus:警告:无法识别的命令行选项”用于“no-”选项仅在有另一个警告时由g ++标记?

[英]why is “cc1plus: warning: unrecognized command line option” for “no-” options only flagged by g++ when there is another warning?

> 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. 换句话说,假设你有foo.cc ,并且GCC-4.9警告某些东西(让我们称之为foobar ),但你相信你使用foobar是安全的。

Since you want to treat all warnings as errors (with -Werror ), you dutifully add -Wno-foobar to your Makefile . 由于您希望将所有警告视为错误(使用-Werror ),因此请尽职地将-Wno-foobar添加到Makefile

Now someone else tries to build your code with GCC-4.8. 现在有人试图用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. 如果这确实产生了警告,那么你将无法同时使用foobar构造并拥有一个可与GCC-4.8和GCC-4.9一起使用的Makefile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cc1plus:对任何其他警告的无法识别的命令行选项警告 - cc1plus: unrecognized command line option warning on any other warning cc1plus:错误:无法识别的命令行选项“ -fsysroot = <path> ”和g ++ - cc1plus: error: unrecognized command line option “-fsysroot=<path>” with g++ cc1plus:错误:使用g ++无法识别的命令行选项“-std = c ++ 11” - cc1plus: error: unrecognized command line option “-std=c++11” with g++ cc1plus:警告:命令行选项“ -Wstrict-prototypes”对Ada / C / ObjC有效,但对C ++无效 - cc1plus: warning: command line option “-Wstrict-prototypes” is valid for Ada/C/ObjC but not for C++ 为什么我得到cc1plus:错误:无法识别的命令行选项“-arch”? - Why do I get cc1plus: error: unrecognized command line option “-arch”? cc1plus:错误:无法识别的命令行选项“-std=c++0x” - cc1plus: error: unrecognized command line option "-std=c++0x" cc1plus:错误:hxcpp无法识别的命令行选项“ -stdlib = libstdc ++” - cc1plus: error: unrecognized command line option “-stdlib=libstdc++” with hxcpp 无法解析cc1plus:错误:无法识别的命令行选项“ -std = c ++ 11” - Failed to resolve cc1plus: error: unrecognized command line option “-std=c++11” cc1plus:错误:无法识别的命令行选项“ -Wno-implicit-fallthrough” [-Werror] - cc1plus: error: unrecognized command line option “-Wno-implicit-fallthrough” [-Werror] cc1plus:错误:无法识别的命令行选项“ -std = gnu ++ 11” - cc1plus: error: unrecognized command line option “-std=gnu++11”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM