GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++: Use specific feature test macros in <chrono>

Switches <chrono> header in libstdc++ to use feature test macros instead of __cplusplus checks.

The <chrono> header in libstdc++ has been updated to use specific C++ feature test macros, such as compiler-defined macros for Core C++ features and __glibcxx_chrono_cxx20 for C++20 chrono features, rather than relying solely on the __cplusplus macro. This provides a more precise way to control feature availability, although chrono::abs, chrono::floor, etc., still use __cplusplus for freestanding environments due to the __cpp_lib_chrono macro not being defined in that context.

In Details

This patch replaces most __cplusplus preprocessor checks in <bits/chrono.h> with feature test macros. For standard C++20 chrono features, it uses compiler-provided macros or __glibcxx_chrono_cxx20. The primary motivation is to correctly signal the availability of C++20 chrono features, especially for C++20 conformance. A known limitation is the continued use of __cplusplus for functions like chrono::abs and chrono::floor in freestanding environments, as __cpp_lib_chrono is not defined there; this is noted as a follow-up task.

For Context
__cplusplus
A predefined macro that indicates the C++ language standard version being used. For C++20, it is typically defined as 202002L or a higher value.
feature test macro
A macro used in C++ to conditionally compile code based on the availability of specific language or library features, as defined by C++ standards.
<chrono>
A C++ standard library header that provides types and functions for measuring, tracking, and manipulating time.
freestanding environment
A minimal C++ execution environment where only a subset of the standard library is available. This is common in embedded systems or operating system kernels.
Filed Under: libstdc++c++20chronostandards