cc1plus:无法识别的任何其他警告的命令行选项警告 [英] cc1plus: unrecognized command line option warning on any other warning

查看:1005
本文介绍了cc1plus:无法识别的任何其他警告的命令行选项警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例:

$ g ++有一个奇怪的g ++行为,它显示一个关于无法识别的命令行选项的警告。 b
$ b

  struct Foo {virtual int bar()= 0;}; 
struct Bar:public Foo {int bar(){return 0;}};

int main(){}

g ++ - 5 -Wsuggest-override -Wno-c99-extensions -std = c ++ 11 a.cpp 甚至 g ++ - 5 -Wsuggest-override -Wno-c99 -extensions a.cpp 显示:

  a.cpp:2:27:warning:'virtual int Bar :: bar()'可以被标记为override [-Wsuggest-override] 
struct bar:public Foo {int bar(){return 0;}};
^
cc1plus:warning:无法识别的命令行选项'-Wno-c99-extensions'

附加:使用 g ++ - 5 -Wno-c99-extensions a.cpp 进行编译时没有警告/错误,因此该选项通过使用<$的CMAKEs检查c $ c> CHECK_CXX_COMPILER_FLAG



这让我困惑不少,因为我们使用Werror,但通过Wno-error =然后在任何(非错误)警告显示为无法识别的命令行选项时退出。



这是已知的/预期的吗?如何防止它?

解决方案

如果您不希望发生无法识别的命令行选项的警告,请不要使用无法识别的命令行选项: -Wno-c99-extensions 从来都不是一个有效的GCC选项(我相信这是一种哗众取宠)。至于为什么只有当你有另外一个警告时才发出警告,这种行为似乎是反对的,直观,但它实际上是刻意记录的


警告无法识别的命令行选项不适用于-Wno-foo

从GCC 4.4开始,正如GCC手册中所解释的那样:当请求无法识别的警告选项时( -Wunknown-warning ),GCC发出一个诊断信息,指出选项不被识别。但是,如果使用 -Wno - 表单,则行为会稍有不同: -Wno-unknown-warning 除非正在生成其他诊断信息。这允许在旧编译器中使用新的 -Wno - 选项,但是如果出现问题,编译器会警告存在无法识别的选项。(请参阅PR28322对于这个改变的历史)

这可能会中断配置测试,检​​查 -Wno-foo 选项。解决方案是测试正面表单( -Wfoo )或者使用触发其他警告的测试用例进行测试。




实际上,Google在邮件列表线程中遇到了一些结果,软件开发人员遇到了这个问题,特别是CMake,并且对其构建脚本进行了微小的修复以修复它。


I have a strange behavior of g++ that it shows a warning about unrecognized command line option, when any other warning is shown.

Example:

struct Foo{virtual int bar() = 0;};
struct Bar:public Foo{int bar() {return 0;} };

int main(){}

Compiling with g++-5 -Wsuggest-override -Wno-c99-extensions -std=c++11 a.cpp or even g++-5 -Wsuggest-override -Wno-c99-extensions a.cpp shows:

a.cpp:2:27: warning: ‘virtual int Bar::bar()’ can be marked override [-Wsuggest-override]
 struct Bar:public Foo{int bar() {return 0;} };
                           ^
cc1plus: warning: unrecognized command line option ‘-Wno-c99-extensions’

ADDITION: There is no warning/error when I compile with g++-5 -Wno-c99-extensions a.cpp hence that option passes CMAKEs check using CHECK_CXX_COMPILER_FLAG

This bothers me quite a lot, as we use Werror but with exceptions via Wno-error=... It then bails out when any of the (non-error) warnings is shown with the "unrecognized command line option"

Is this known/expected? How can it be prevented?

解决方案

If you don't want warnings about unrecognised command-line options, don't use unrecognised command-line options: -Wno-c99-extensions has never been a valid GCC option (I believe it's a clangism). Simply remove it from your build command.

As for why the warning is only emitted when you have another warning present, this behaviour seems counter-intuitive but it is actually deliberate and documented:

The warning "unrecognized command-line option" is not given for -Wno-foo

Since GCC 4.4, and as explained in the GCC manual: when an unrecognized warning option is requested (-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. (See PR28322 for the history of this change)

This might break configure tests that check for -Wno-foo options. The solution is to either test for the positive form (-Wfoo) or test using a testcase that triggers some other warning.

There are in fact a few results on Google of mailing list threads where software developers have faced this "problem", specifically with CMake, and made trivial fixes to their build scripts to "fix" it.

这篇关于cc1plus:无法识别的任何其他警告的命令行选项警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆