Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler standards support (c++11, c++14, c++17)

Tags:

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?

like image 928
Šimon Hrabec Avatar asked Jan 17 '16 09:01

Šimon Hrabec


People also ask

Does GCC 11 support C++17?

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.

What is C++14 and C++17?

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.

Does GCC 9 support C++17?

GCC has had complete support for C++17 language features since version 8. Clang 5 and later supports all C++17 language features.

Does GCC 7 support C++17?

GCC 7.1 Released with Full C++17 Support.


1 Answers

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.

like image 92
Jason C Avatar answered Sep 19 '22 19:09

Jason C