geh
geh

Reputation: 846

Using c++20 with gcc 10 is limited to c++17

When i try to set c++20 standard with gcc 10.3, it sets _cplusplus macro to 201709L

gcc -x c++ -std=c++20  -E -dM -< /dev/null | grep _cplusplus

outputs:

#define __cplusplus 201709

Getting gcc version

 gcc --version

outputs:

gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

Any ideas ?

Upvotes: 1

Views: 395

Answers (1)

Nimrod
Nimrod

Reputation: 3543

__cplusplus
This macro is defined when the C++ compiler is in use. You can use __cplusplus to test whether a header is compiled by a C compiler or a C++ compiler. This macro is similar to STDC_VERSION, in that it expands to a version number. Depending on the language standard selected, the value of the macro is 199711L for the 1998 C++ standard, 201103L for the 2011 C++ standard, 201402L for the 2014 C++ standard, 201703L for the 2017 C++ standard, or an unspecified value strictly larger than 201703L for the experimental languages enabled by -std=c++2a and -std=gnu++2a.

As quoted in the gcc 10.3 doc. Since C++20 is not complete in gcc 10.3 yet.

For who interested in the macro difference between -std=c++17 and std=c++20, see here

Upvotes: 3

Related Questions