Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for C++20 support? What is the value of __cplusplus for C++20? [duplicate]

Tags:

c++

macros

c++20

Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?

How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is, in principle, possible to inquire the C++ version by:

#if __cplusplus > ???   // C++20 code here #endif 

What should ??? be for C++20?

like image 978
user2296653 Avatar asked Nov 30 '18 12:11

user2296653


People also ask

Is C++20 supported?

You just have to manually enter c++20 to setting C++ Language Dialect . Visual Studio 2019 (latest version 16.10, on Windows) is the only IDE currently coming with a compiler that fully supports C++20.

How do I know if my GCC supports C++17?

C++17 Support in GCC C++17 features are available since GCC 5. This 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.

How do I know if GCC supports C++ 11?

To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.

Is C++20 released?

C++20 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++20 replaced the prior version of the C++ standard, called C++17. The standard was technically finalized by WG21 at the meeting in Prague in February 2020, approved on 4 September 2020, and published in December 2020.


1 Answers

It's too early for that.

Until the standard replaces it, use:

#if __cplusplus > 201703L   // C++20 code #endif 

since the predefined macro of C++20 is going to be larger than the one of C++17.

As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):

__cplusplus

The integer literal 201703L. [Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value.]


The macros used, as of Nov 2018, are:

  • GCC 9.0.0: 201709L for C++2a. Live demo
  • Clang 8.0.0: 201707L. Live demo
  • VC++ 15.9.3: 201704L (as @Acorn's answer mentions).

PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.

like image 158
gsamaras Avatar answered Sep 18 '22 09:09

gsamaras