gpt4 book ai didi

c++ - cc1plus : unrecognized command line option warning on any other warning

转载 作者:太空宇宙 更新时间:2023-11-04 13:13:05 31 4
gpt4 key购买 nike

我有一个奇怪的 g++ 行为,当显示任何其他警告时,它会显示有关无法识别的命令行选项的警告。

例子:

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()’ can be marked override [-Wsuggest-override]
struct Bar:public Foo{int bar() {return 0;} };
^
cc1plus: warning: unrecognized command line option ‘-Wno-c99-extensions’

补充:当我使用 g++-5 -Wno-c99-extensions a.cpp 编译时没有警告/错误因此该选项使用 CHECK_CXX_COMPILER_FLAG 通过 CMAKE 检查/p>

这让我很困扰,因为我们使用 Werror 但通过 Wno-error=... 异常(exception),当任何(非错误)警告显示为“无法识别的命令行选项”时,它就会退出

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

最佳答案

如果您不想收到有关无法识别的命令行选项的警告,请不要使用无法识别的命令行选项:-Wno-c99-extensions 从来都不是有效的 GCC 选项(我相信这是一个clangism)。只需将其从构建命令中删除即可。

至于为什么只有当您有另一个 警告时才发出警告,这种行为似乎违反直觉,但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.

事实上,在 Google 上有一些关于邮件列表线程的结果,其中软件开发人员遇到了这个“问题”,特别是 CMake,并对他们的构建脚本进行了微不足道的修复以“修复”它。

关于c++ - cc1plus : unrecognized command line option warning on any other warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38785168/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com