简体   繁体   English

如何消除针对 c++17 功能的 gcc 警告?

[英]how to silence gcc warning against c++17 features?

I self built gcc 7 to try out some new c++17 features.我自己构建了 gcc 7 来尝试一些新的 c++17 功能。

When I built the code, I saw hundred lines of warnings, saying certain features are available only when -std=c++1z (I have already specified -std=c++1z in the build command line and I tried gnu++1z too)当我构建代码时,我看到了数百行警告,说某些功能仅在 -std=c++1z 时可用(我已经在构建命令行中指定了 -std=c++1z 并且我尝试了 gnu++ 1z也是)

I want to silence this warning.我想消除这个警告。 when using clang 4, there was an option -Wno-c++1z-extensions使用 clang 4 时,有一个选项 -Wno-c++1z-extensions

but this option is not recognized by gcc.但是这个选项不被 gcc 识别。

I have root caused the reason for my problem. 我有根导致我的问题的原因。

It's because I set -std=c++17 with cmake. 这是因为我用cmake设置了-std = c ++ 17。 and I also have included Qt5. 我也包括了Qt5。 Qt5 settings overwrote my -std=c++17. Qt5设置覆盖了我的-std = c ++ 17。 With make VERBOSE=1, I could see both -std=c++17 and -std=c++14. 使用make VERBOSE = 1,我可以看到-std = c ++ 17和-std = c ++ 14。

This confuses the compiler. 这会混淆编译器。

the problem is related to https://gitlab.kitware.com/cmake/cmake/issues/16468 该问题与https://gitlab.kitware.com/cmake/cmake/issues/16468有关

gcc 12 supports the option to suppress the warning of the specific c++ version gcc 12 支持抑制特定c++版本警告的选项

-Wno-c++17-extensions ( work well both on gcc12 and clang) -Wno-c++17-extensions (适用于 gcc12 和 clang)

ref gcc/clang compiling options:参考 gcc/clang 编译选项:

https://docs.adacore.com/live/wave/gcc-12.x/html/gcc/gcc.html#Warning-Options https://docs.adacore.com/live/wave/gcc-12.x/html/gcc/gcc.html#Warning-Options

https://releases.llvm.org/12.0.0/tools/clang/docs/DiagnosticsReference.html#diagnostic-flags https://releases.llvm.org/12.0.0/tools/clang/docs/DiagnosticsReference.html#diagnostic-flags

but it's better to support c++17 features through flag:但最好通过 flag 支持 c++17 特性:

  • -std=c++17
  • -std=gnu++17

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM