The title is quite clear, is there a way to disable every single non-standard feature of gcc (extension) when compiling some C++ code. I've previously always used -pedantic-errors
alongside -Wall
and -Wextra
, the first according to the gcc man page does the following
Give an error whenever the base standard (see -Wpedantic) requires a diagnostic, in some equivalent to -Werror=pedantic, since there are errors enabled by this option and not particular library's limitations. However, if -Wpedantic is used with -Wformat, warnings made into an error by -pedantic-errors. -Wall or -Wpedantic.
As a result it disables practically all extensions that aren't standard conforming, however. I was rather shooked that the following code compiles with gcc
void foo(std::vector<auto>) { ... }
with the -std=c++20
flag, if we bump it down to -std=c++17
we receive an error message prompting the use of -std=c++20
as it's a "c++20 feature". However neither clang or msvc is willing to compile this. After some further research I was notified of the following
This is a GCC extension and accepted by design.
Which is rather upsetting as even the safe-guards of -pedantic-errors
, -Wall
and -Wextra
didn't pick this up, which leads me to question what other extensions might be silently passed through by gcc. Thus the question comes; is there any way to disable exactly every gcc extension?
Edit: From the comment section of How to disable GNU C extensions?
You cannot