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

标签 c++ g++ compiler-warnings suppress-warnings

我有一个奇怪的 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/

相关文章:

c++ - 为什么 g++ 4.9.0 默认有 std::isnan?

c++ - 让 g++ 产生一个可以使用多核的程序?

c++ - 为 Capn Pronto 和 Snappy 链接 C++ 库

c++ - 如何判断头文件包含在哪里?

java - 为什么 ClassNotFoundException 会表现出这种行为?

actionscript-3 - "Warning: 1090: Migration issue"尽管显式注册了事件处理程序

c - 编译器警告消息

c++ - 找不到Dlib “' dlib/image_processing/frontal_face_detector.h'文件” Xcode C++控制台应用程序

具有 2 个键的 C++ 映射,因此可以使用任何 1 个键来获取值

c++ - 具有不同类型的CUDA每线程阵列