Compiler | Version | __cplusplus |
---|---|---|
g++ | 4.7.4 | 199711L |
5.5.0 | 199711L | |
6.1.0 | 201402L | |
10.2 | 201402L | |
11.1.0 | 201703L | |
clang++ | 3.4.2 | 199711L |
5.0.0 | 199711L | |
6.0.0 | 201402L | |
12.0.1 | 201402L | |
16.0.0 | 201703L | |
hipcc | 4.0.0 | 201103L |
4.1.0 | 201103L | |
icpc | 15.0.2 | 199711L |
17.0.2 | 199711L | |
18.0.1 | 201402L | |
21.1.1 | 201402L | |
icpc (classic/oneAPI) | 2021.1 Beta 20200602 | 201402L |
2021.6.0 | 201402L | |
2021.7.0 | 201703L | |
21.5.0 | 201402L | |
icpx (oneAPI) | 2021.1.2 | 201402L |
2022.2.1 | 201402L | |
dpcpp | 2021.1-beta07 (2020.5.0.0604) | 201703L |
2022.0.0 (2022.0.0.20211123) | 201703L | |
pgc++ | 16.1 | 199711L |
17.5 | 199711L | |
18.3 | 201402L | |
nvc++ | 22.7 | 201703L |
xlc++ | 14.1b2 | 199711L |
(XLClang) | 16.1.1 | 199711L |
crayc++ (classic) | 8.7.9 | 201402L |
crayc++ (LLVM) | 9.0.0 | 201402L |
msvc | 19.28 | 199711L |
19.28 | 199711L | |
19.35 | 199711L |
Note: MSVC __cplusplus
defines are unreliable.
Note: For Clang++, the -x hip|cuda
frontend default differs from -x c++
for older releases.
__cplusplus |
C++ Standard |
---|---|
199711L | C++98 |
201103L | C++11 |
201402L | C++14 |
201703L | C++17 |
202002L | C++20 |
TBD | C++23 |
Random fun fact:
The C standard for C-compilers defines a similar macro, __STDC_VERSION__
:
__STDC_VERSION__ |
C Standard |
---|---|
undefined | earlier |
199409L | C95 |
199901L | C99 |
201112L | C11 |
201710L | C18 |
TBD | C23 |
Compiler | Version | __STDC_VERSION__ |
---|---|---|
gcc | 4.9.4 | undefined |
5.1.0 | 201112L | |
8.1 | 201710L | |
clang | 3.0.0 | 199901L |
3.5.2 | 199901L | |
3.6 | 201112L | |
11.0 | 201710L | |
icc (classic/oneAPI) | 21.1.9 | 201112L |
icx (oneAPI) | 2021.1.2 | 201710L |
Inspired by https://stackoverflow.com/a/44735016/2719194
$CXX -dM -E -x c++ /dev/null | grep -F __cplusplus
or just check if this C++14 snippet compiles and read its assembly:
struct X {
static constexpr int value = __cplusplus;
};
int main() {
auto const x = X::value;
return 0;
}
Equivalently for C:
cc -dM -E -x c /dev/null | grep -F __STDC_VERSION__
or in code:
#include <stdio.h>
int main(){
printf("%ld", __STDC_VERSION__);
}
Thanks