Why can a C++ toolchain building with -std=c++20 still reject correct C++20 code, and how do you find out what it really supports?
answer
- mode is a request
- papers ship one at a time
- missing, partial, gated
- compiler and library versioned apart
- status pages plus a CI probe
basics
~20 s-std=c++20 selects the language mode; it does not promise that the compiler and its standard library implement all of C++20. Vendors ship a revision paper by paper, some features stay behind extra flags, and the compiler and library are separate projects. Status pages and a build on every toolchain tell you what works.
solid answer
~40 sA `-std=` flag sets the **language mode**, but vendors implement each revision **paper by paper** over several releases. A feature can be **missing**: with Apple clang 21 and libc++, `std::atomic<std::shared_ptr<int>>` fails a static assertion in C++20 mode and `<generator>` is not found in C++23 mode. It can be **partial**: libc++ lists C++20 calendars and time zones as partial, and that libc++ has no `std::chrono::current_zone()`. It can be **gated**: GCC 16 needs `-fmodules` for C++20 modules and calls its C++23 mode experimental. And the **compiler and the standard library are versioned separately** (Clang can build against libstdc++ with `-stdlib=libstdc++`), so support belongs to the pair. Read both vendors' status pages and build a probe on every toolchain in CI.
code
cpp · 16 lines#include <cstdio> // pulls in the library's configuration header
int main() {
#if defined(__clang__)
std::printf("compiler: clang %d.%d\n", __clang_major__, __clang_minor__);
#elif defined(__GNUC__)
std::printf("compiler: gcc %d.%d\n", __GNUC__, __GNUC_MINOR__);
#elif defined(_MSC_VER)
std::printf("compiler: msvc %d\n", _MSC_VER);
#endif
#if defined(_LIBCPP_VERSION)
std::printf("library: libc++ %d\n", _LIBCPP_VERSION);
#elif defined(_GLIBCXX_RELEASE)
std::printf("library: libstdc++ %d\n", _GLIBCXX_RELEASE);
#endif
}go deeper
Know that -std picks the language mode and that some features of that standard may still be missing from a given toolchain.
Name the missing, partial and gated cases with an example of each, and explain that the compiler and the standard library are versioned separately.
Describe a real partial-support case you hit, how you confirmed it on every toolchain in CI, and what you used instead until it arrived.
Turn support questions into a per-feature record across the build matrix and keep experimental modes out of shipped binaries until vendors call them stable.
## The mode is a request, not a guarantee `-std=c++20` tells the compiler which grammar and which library declarations to use. It does not say how much of that revision the vendor has finished. WG21 votes a standard in as a list of papers, and each compiler and standard library implements those papers over several releases, often finishing the last ones years after publication. ## Three kinds of gap | Gap | Example | Source | |---|---|---| | **Missing** | `std::atomic<std::shared_ptr<T>>` (C++20) and `std::generator` (C++23) | libc++ status pages list both papers as not implemented | | **Partial** | C++20 calendars and time zones | libc++ lists the paper as partial; Apple clang 21's libc++ has no `std::chrono::current_zone()` | | **Gated** | C++20 modules; the whole C++23 mode | GCC 16 enables modules only with `-fmodules` and calls C++23 support experimental, liable to change in incompatible ways | On Apple clang 21 the missing case is easy to see. In C++20 mode `std::atomic<std::shared_ptr<int>>` falls through to the primary `std::atomic` template, and compilation stops at its static assertion that `T` be trivially copyable. In C++23 mode `#include <generator>` fails with *file not found*. Gated features move. libc++ implemented `std::jthread` in LLVM 18 but kept it behind `-fexperimental-library` until LLVM 20, where its status page marks it complete. ## Two projects, two schedules A C++ toolchain is a **compiler** plus a **standard library**, and they are versioned apart: - **Language features** (concepts, coroutines, `if consteval`) depend on the compiler. - **Library features** (`std::format`, `std::expected`, `std::jthread`) depend on the library headers and the runtime it links. GCC ships libstdc++, and Apple platforms pair Clang with libc++. Clang can also use libstdc++ (`-stdlib=libstdc++`) and its documentation supports releases back to libstdc++ 4.8.3, so a recent Clang on an older Linux distribution can accept C++20 syntax while the distribution's library still lacks a C++20 type. Upgrading the compiler alone does not upgrade the library. The probe below shows the split on one machine: Apple clang 21 reports clang 21.0, and its libc++ reports its own version number, 220106. ## Finding out what works 1. **Name the toolchains.** List every compiler and standard library release the product builds with, per platform. 2. **Read the status pages.** GCC and libstdc++, Clang and libc++, and Microsoft's compiler and STL each publish per-paper tables; cppreference collects them in one compiler-support table. 3. **Build a probe in CI.** A small program that uses the features you want, compiled on every toolchain, settles what the tables leave vague, such as a feature that exists but is behind a flag. 4. **Record the answer per feature.** "We support C++20" is rarely true; "std::format everywhere, time zones nowhere yet" is useful. Checking a single feature from inside the code, with `__cplusplus` or the standard's feature-test macros, is a preprocessor technique that belongs with macros and conditional compilation; this question is about why such checks are needed at all.
- Why can upgrading Clang on a Linux build server leave a C++20 library type still missing?Because the library comes from elsewhere. On many Linux distributions Clang compiles against the system's libstdc++, so a new compiler gains language features while the library stays at the distribution's release. Either upgrade the library too, or switch to libc++ with -stdlib=libc++ and ship it with the product.
- What does it mean for your project when GCC calls its C++23 mode experimental?GCC's manual warns that C++23 support could change in incompatible ways in future releases. Code that compiles today may need changes after a compiler upgrade, and binaries or libraries built in that mode by different GCC releases are not promised to stay compatible. Keep such builds on one pinned compiler, or treat the mode as a preview.
- If a compiler accepts -std=c++20, every C++20 feature works with it.
- Upgrading the compiler upgrades the standard library too.
- A feature listed in the standard is either fully implemented or absent; there is no partial state.
- A feature that needs an extra flag such as -fmodules is ready for production use.
- One status page answers what a toolchain supports.
Observations from Apple clang 21 with its libc++, the LLVM 23 libc++ status pages and the GCC 16.2 manual.