Skip to content

Instantly share code, notes, and snippets.

@ax3l
Last active April 8, 2024 18:19
Show Gist options
  • Save ax3l/53db9fa8a4f4c21ecc5c4100c0d93c94 to your computer and use it in GitHub Desktop.
Save ax3l/53db9fa8a4f4c21ecc5c4100c0d93c94 to your computer and use it in GitHub Desktop.
Compiler C++ Version Defaults

C++ -std=... default of various commonly used C++ compilers

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.

Meaning of __cplusplus

__cplusplus C++ Standard
199711L C++98
201103L C++11
201402L C++14
201703L C++17
202002L C++20
TBD C++23

Meaning of __STDC_VERSION__

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

Default of various commonly used C compilers

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

References

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__);
}
@zohaib2002
Copy link

Thanks

@MarekKnapek
Copy link

If you are compiling with Visual Studio 2015 Update 3 or newer (MSVC), you can use the _MSVC_LANG pre-defined macro. It has value of 201402L or 201703L or 202002L when compiling in C++14 or C++17 or C++20 mode. Beware, selecting C++20 mode in Visual Studio doesn't necessary mean enabling all C++20 features as described in the Standard.

@ax3l
Copy link
Author

ax3l commented Jun 12, 2023

@grisuthedragon interesting find on icpc classic. This is what Godbolt shows: https://godbolt.org/z/EvoEsqYrh

Maybe it depends on which stdlib and version it is installed? I think it does not ship its own libstdc++/libc++ but relies on GCC's libstdc++ on the system... Where did you see the old version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment