How do I find which standards my GCC compiler supports? I don't mean how do I find out at the compilation time what C++ standard is being used (checking defined constants), but before compiling, how can I check available standards to use (i.e. for flag -std=c++??
)?
The information is not present in man g++
.
I can check out my GCC version by g++ --version
besides manually trying the options?
Is it possible to find somewhere table of GCC versions and supported standards?
C++17 Support in GCCThis mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
C++14 is a version of the ISO/IEC 14882 standard for the C++ programming language. It is intended to be a small extension over C++11, featuring mainly bug fixes and small improvements, and was replaced by C++17. Its approval was announced on August 18, 2014. C++14 was published as ISO/IEC 14882:2014 in December 2014.
GCC has had complete support for C++17 language features since version 8. Clang 5 and later supports all C++17 language features.
GCC 7.1 Released with Full C++17 Support.
So, after a bit of a struggle trying to dust off my sed
skills, I was able to come up with this command:
gcc -v --help 2> /dev/null | sed -n '/^ *-std=\([^<][^ ]\+\).*/ {s//\1/p}'
It processes the output of g++ -v --help
(silencing the extra info it prints to stderr
), matches lines that start with -std=
then captures the values. The ^<
is to block the -std=<standard>
line of the help. Here is some example output for GCC 9:
f2003 f2008 f2008ts f2018 f95 gnu legacy c++03 c++0x c++11 c++14 c++17 c++1y c++1z c++2a c++98 c11 c17 c18 c1x c2x c89 c90 c99 c9x gnu++03 gnu++0x gnu++11 gnu++14 gnu++17 gnu++1y gnu++1z gnu++2a gnu++98 gnu11 gnu17 gnu18 gnu1x gnu2x gnu89 gnu90 gnu99 gnu9x iso9899:1990 iso9899:199409 iso9899:1999 iso9899:199x iso9899:2011 iso9899:2017 iso9899:2018
You can add a grep
in the middle to filter based on help description text, which is conveniently consistent in the help output. E.g. if you want to drop the deprecated ones:
gcc -v --help 2> /dev/null | grep -iv deprecated | sed -n '/^ *-std=\([^<][^ ]\+\).*/ {s//\1/p}'
If you want to list just non-deprecated C++:
gcc -v --help 2> /dev/null | grep -iv deprecated | grep "C++" | sed -n '/^ *-std=\([^<][^ ]\+\).*/ {s//\1/p}'
If you want to list just non-deprecated C:
gcc -v --help 2> /dev/null | grep -iv deprecated | grep "C " | sed -n '/^ *-std=\([^<][^ ]\+\).*/ {s//\1/p}'
Those are pretty hacky and rely on "deprecated", "C++" and/or "C" (note the space at the end of grep "C "
!) appearing in the help description for each standard name but they seem to work.
You could similarly filter out e.g. "same as" to get rid of synonymous ones, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With