简体   繁体   中英

how to silence gcc warning against c++17 features?

I self built gcc 7 to try out some new c++17 features.

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)

I want to silence this warning. when using clang 4, there was an option -Wno-c++1z-extensions

but this option is not recognized by gcc.

I have root caused the reason for my problem.

It's because I set -std=c++17 with cmake. and I also have included Qt5. Qt5 settings overwrote my -std=c++17. With make VERBOSE=1, I could see both -std=c++17 and -std=c++14.

This confuses the compiler.

the problem is related to https://gitlab.kitware.com/cmake/cmake/issues/16468

gcc 12 supports the option to suppress the warning of the specific c++ version

-Wno-c++17-extensions ( work well both on gcc12 and clang)

ref gcc/clang compiling 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

but it's better to support c++17 features through flag:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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