Skip to content

Instantly share code, notes, and snippets.

@WillianBR
Created August 26, 2026 12:42
Show Gist options
  • Select an option

  • Save WillianBR/d02d358ed14883e8088b75a2547a6e43 to your computer and use it in GitHub Desktop.

Select an option

Save WillianBR/d02d358ed14883e8088b75a2547a6e43 to your computer and use it in GitHub Desktop.
Checking C++ Standard Support — GCC and Microsoft MSVC
# Checking C++ Standard Support — GCC and Microsoft MSVC
Quick reference for identifying the compiler version, supported C++ language modes, active C++ standard, and compiler predefined macros.
Useful when working across different development machines, build servers, CI environments, Windows, Linux, GCC/MinGW, and Microsoft Visual C++.
---
## C++ Standard Values
The `__cplusplus` predefined macro can be used to identify the active C++ language standard.
| Standard | Typical `__cplusplus` value |
|---|---:|
| C++98 / C++03 | `199711L` |
| C++11 | `201103L` |
| C++14 | `201402L` |
| C++17 | `201703L` |
| C++20 | `202002L` |
| C++23 | `202302L` |
> **Note:** Compiler support for a language mode does not necessarily mean that every language and standard-library feature from that C++ standard has been implemented.
---
# GCC / G++
## 1. Compiler version
Short version:
```bash
g++ --version
```
Detailed compiler configuration:
```bash
g++ -v
```
Executable location:
### Bash / Git Bash
```bash
which g++
```
### Windows CMD
```cmd
where g++
```
---
## 2. List the C++ standards recognized by GCC
### Bash / Git Bash / GNU tools available
```bash
g++ --help=c++ | grep -- "-std="
```
To look specifically for C++23:
```bash
g++ --help=c++ | grep -- "-std=c++23"
```
Older GCC versions may use the draft name `c++2b`:
```bash
g++ --help=c++ | grep -- "-std=c++2b"
```
### Without `grep`
Simply display all C++ compiler options:
```cmd
g++ --help=c++
```
On Windows CMD, `findstr` can be used instead of `grep`:
```cmd
g++ --help=c++ | findstr /C:"-std="
```
Look specifically for C++23:
```cmd
g++ --help=c++ | findstr /C:"-std=c++23"
```
And for the older draft name:
```cmd
g++ --help=c++ | findstr /C:"-std=c++2b"
```
---
## 3. Test whether GCC accepts C++23
### Bash / Git Bash
No source file is necessary:
```bash
echo 'int main(){}' | g++ -x c++ -std=c++23 -fsyntax-only -
```
If the command terminates without an error, the compiler recognizes the C++23 language mode.
Older GCC releases may recognize the draft name:
```bash
echo 'int main(){}' | g++ -x c++ -std=c++2b -fsyntax-only -
```
### Windows CMD without GNU tools
Create a temporary source file:
```cmd
echo int main(){} > cpp-standard-test.cpp
g++ -std=c++23 -fsyntax-only cpp-standard-test.cpp
del cpp-standard-test.cpp
```
For an older GCC:
```cmd
echo int main(){} > cpp-standard-test.cpp
g++ -std=c++2b -fsyntax-only cpp-standard-test.cpp
del cpp-standard-test.cpp
```
---
## 4. Check `__cplusplus` directly using the GCC preprocessor
### Bash / Git Bash
Default compiler mode:
```bash
echo | g++ -dM -E -x c++ - | grep __cplusplus
```
C++17:
```bash
echo | g++ -std=c++17 -dM -E -x c++ - | grep __cplusplus
```
C++20:
```bash
echo | g++ -std=c++20 -dM -E -x c++ - | grep __cplusplus
```
C++23:
```bash
echo | g++ -std=c++23 -dM -E -x c++ - | grep __cplusplus
```
Expected for C++23:
```text
#define __cplusplus 202302L
```
### Windows CMD using `findstr`
```cmd
echo. | g++ -std=c++23 -dM -E -x c++ - | findstr __cplusplus
```
---
## 5. Show all predefined GCC macros
This is useful for diagnosing the exact compiler, platform, architecture, standard library, and enabled language features.
### Bash / Git Bash
```bash
echo | g++ -dM -E -x c++ -
```
For C++23:
```bash
echo | g++ -std=c++23 -dM -E -x c++ -
```
Filter C++ feature-test macros:
```bash
echo | g++ -std=c++23 -dM -E -x c++ - | grep "__cpp_"
```
Sort them:
```bash
echo | g++ -std=c++23 -dM -E -x c++ - | grep "__cpp_" | sort
```
---
## 6. Check GCC version macros
### Bash / Git Bash
```bash
echo | g++ -dM -E -x c++ - | grep "__GNUC__"
```
Relevant macros include:
```text
__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__
```
Without `grep`, dump everything:
```cmd
echo. | g++ -dM -E -x c++ -
```
Or use Windows `findstr`:
```cmd
echo. | g++ -dM -E -x c++ - | findstr "__GNUC__"
```
---
## 7. Strict ISO C++ compilation
Selecting `-std=c++23` disables GNU extensions that conflict with ISO C++, but GCC can still accept some extensions.
For stricter ISO conformance:
```bash
g++ -std=c++23 -pedantic source.cpp
```
Treat those diagnostics as errors:
```bash
g++ -std=c++23 -pedantic-errors source.cpp
```
A useful development configuration is:
```bash
g++ -std=c++23 -Wall -Wextra -Wpedantic source.cpp
```
---
## 8. ISO C++ versus GNU C++
Strict ISO C++23 mode:
```bash
g++ -std=c++23 source.cpp
```
C++23 plus GNU extensions:
```bash
g++ -std=gnu++23 source.cpp
```
Older GCC releases may call these modes:
```text
-std=c++2b
-std=gnu++2b
```
---
# Microsoft Visual C++ — CL.EXE
Run these commands from a **Developer Command Prompt for Visual Studio** or another environment where `cl.exe` is configured.
---
## 1. Locate the compiler
```cmd
where cl
```
---
## 2. Display the compiler version
```cmd
cl
```
For detailed build/toolchain information:
```cmd
cl /Bv
```
`/Bv` is particularly useful when multiple Visual Studio or Build Tools versions are installed.
---
## 3. Display compiler options
```cmd
cl /?
```
To find `/std` options using Windows tools:
```cmd
cl /? 2>&1 | findstr /C:"/std:"
```
With Git Bash / GNU `grep` available:
```bash
cl /? 2>&1 | grep "/std:"
```
---
## 4. Microsoft C++ language modes
Common MSVC language-mode options include:
```text
/std:c++14
/std:c++17
/std:c++20
/std:c++latest
```
For example:
```cmd
cl /std:c++20 /EHsc source.cpp
```
For the newest language features implemented by the installed MSVC:
```cmd
cl /std:c++latest /EHsc source.cpp
```
> **Important:** `/std:c++latest` means the newest C++ language and library features implemented by that MSVC release. It does not guarantee complete implementation of a particular future or recently published C++ standard.
---
# MSVC and `__cplusplus`
MSVC has an important historical compatibility behavior.
Without `/Zc:__cplusplus`, MSVC may report:
```text
199711L
```
even when compiling modern C++.
Enable standards-conforming reporting with:
```text
/Zc:__cplusplus
```
Therefore, when checking the language level with MSVC, use both the desired `/std` option and `/Zc:__cplusplus`.
Example:
```cmd
cl /std:c++20 /Zc:__cplusplus /EHsc source.cpp
```
Or:
```cmd
cl /std:c++latest /Zc:__cplusplus /EHsc source.cpp
```
---
# Portable `__cplusplus` Test Program
Create:
```cpp
#include <iostream>
int main()
{
std::cout << "__cplusplus = "
<< __cplusplus
<< '\n';
return 0;
}
```
Save it as:
```text
cpp-standard.cpp
```
---
## Compile with GCC
Compiler default:
```bash
g++ cpp-standard.cpp -o cpp-standard
```
C++17:
```bash
g++ -std=c++17 cpp-standard.cpp -o cpp-standard
```
C++20:
```bash
g++ -std=c++20 cpp-standard.cpp -o cpp-standard
```
C++23:
```bash
g++ -std=c++23 cpp-standard.cpp -o cpp-standard
```
Run on Linux / Bash:
```bash
./cpp-standard
```
Run on Windows:
```cmd
cpp-standard.exe
```
---
## Compile with MSVC
C++17:
```cmd
cl /std:c++17 /Zc:__cplusplus /EHsc cpp-standard.cpp
```
C++20:
```cmd
cl /std:c++20 /Zc:__cplusplus /EHsc cpp-standard.cpp
```
Latest features implemented by MSVC:
```cmd
cl /std:c++latest /Zc:__cplusplus /EHsc cpp-standard.cpp
```
Run:
```cmd
cpp-standard.exe
```
---
# MSVC-specific `_MSVC_LANG`
Microsoft also provides:
```cpp
_MSVC_LANG
```
It reports the C++ language mode selected by `/std`.
A useful diagnostic program for MSVC is:
```cpp
#include <iostream>
int main()
{
std::cout << "__cplusplus = " << __cplusplus << '\n';
#ifdef _MSVC_LANG
std::cout << "_MSVC_LANG = " << _MSVC_LANG << '\n';
#endif
#ifdef _MSC_VER
std::cout << "_MSC_VER = " << _MSC_VER << '\n';
#endif
#ifdef _MSC_FULL_VER
std::cout << "_MSC_FULL_VER = " << _MSC_FULL_VER << '\n';
#endif
return 0;
}
```
Compile:
```cmd
cl /std:c++latest /Zc:__cplusplus /EHsc cpp-standard.cpp
```
---
# Cross-Compiler Diagnostic Program
The following small program is useful when the same source tree is compiled using GCC and MSVC:
```cpp
#include <iostream>
int main()
{
std::cout << "__cplusplus: " << __cplusplus << '\n';
#if defined(__GNUC__)
std::cout << "GCC: "
<< __GNUC__ << '.'
<< __GNUC_MINOR__ << '.'
<< __GNUC_PATCHLEVEL__
<< '\n';
#endif
#if defined(_MSC_VER)
std::cout << "MSVC _MSC_VER: "
<< _MSC_VER
<< '\n';
std::cout << "MSVC _MSC_FULL_VER: "
<< _MSC_FULL_VER
<< '\n';
std::cout << "MSVC _MSVC_LANG: "
<< _MSVC_LANG
<< '\n';
#endif
return 0;
}
```
GCC:
```bash
g++ -std=c++23 cpp-standard.cpp -o cpp-standard
./cpp-standard
```
MSVC:
```cmd
cl /std:c++latest /Zc:__cplusplus /EHsc cpp-standard.cpp
cpp-standard.exe
```
---
# Quick Reference
## GCC + Bash / Git Bash
```bash
# Version
g++ --version
# Detailed configuration
g++ -v
# Location
which g++
# Supported -std options
g++ --help=c++ | grep -- "-std="
# Does the compiler recognize C++23?
echo 'int main(){}' | g++ -x c++ -std=c++23 -fsyntax-only -
# Active __cplusplus value
echo | g++ -std=c++23 -dM -E -x c++ - | grep __cplusplus
# GCC version macros
echo | g++ -dM -E -x c++ - | grep "__GNUC__"
# C++ feature-test macros
echo | g++ -std=c++23 -dM -E -x c++ - | grep "__cpp_" | sort
```
## GCC + Windows CMD, no GNU utilities
```cmd
g++ --version
g++ -v
where g++
g++ --help=c++
g++ --help=c++ | findstr /C:"-std="
echo int main(){} > cpp-standard-test.cpp
g++ -std=c++23 -fsyntax-only cpp-standard-test.cpp
del cpp-standard-test.cpp
echo. | g++ -std=c++23 -dM -E -x c++ - | findstr __cplusplus
echo. | g++ -dM -E -x c++ - | findstr "__GNUC__"
```
## Microsoft MSVC
```cmd
:: Location
where cl
:: Version
cl
:: Detailed version/toolchain information
cl /Bv
:: Compiler options
cl /?
:: C++ standard options
cl /? 2>&1 | findstr /C:"/std:"
:: C++20
cl /std:c++20 /Zc:__cplusplus /EHsc source.cpp
:: Newest features implemented by installed MSVC
cl /std:c++latest /Zc:__cplusplus /EHsc source.cpp
```
---
# Important Caveat
A compiler accepting:
```text
-std=c++23
```
does **not** prove that it implements every C++23 feature.
C++ support consists of at least two major parts:
1. **Language/compiler support**
2. **Standard-library support**
Individual features can be checked through the standardized C++ **feature-test macros**, such as:
```cpp
__cpp_constexpr
__cpp_concepts
__cpp_if_consteval
```
and library feature-test macros generally named:
```cpp
__cpp_lib_*
```
For serious portability work, check the specific feature required by the program instead of relying only on the compiler version.
---
## Official References
- GCC — C++ Standards Support:
https://gcc.gnu.org/projects/cxx-status.html
- GCC — Language Standards:
https://gcc.gnu.org/onlinedocs/gcc/Standards.html
- GCC — C++ Dialect Options:
https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
- Microsoft — `/std` language standard option:
https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version
- Microsoft — `/Zc:__cplusplus`:
https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment