WEDNESDAY, JULY 29, 2026
libstdc++
Reject user-defined specializations for allocator_traits
User-defined specializations of `std::allocator_traits` are now rejected for C++23 and later, improving quality of implementation.
In C++23 and later, user-defined specializations of std::allocator_traits are now explicitly disallowed. This change aligns with a C++ standard proposal (P2652R2) and improves the quality of implementation by making such specializations ill-formed, with diagnostics provided when attempted.
In Details
The std::allocator_traits primary template in libstdc++ is now annotated with [[_Clang::__no_specializations]] for C++23 and later. This enforces P2652R2, which disallows user specializations of allocator_traits. Locally defined macros are used to manage warnings for the coroutine_handle and allocator_traits specializations.
For Context
- allocator_traits
- A C++ template that provides a uniform interface to access properties and operations of an allocator, used for memory management in containers.
- specialization
- In C++, a specific version of a class or function template created for a particular set of template arguments.
- C++23
- The next major revision of the C++ programming language standard, following C++20.
- ill-formed
- A programming construct that violates the rules of the C++ language, meaning it cannot be compiled, and may or may not produce a diagnostic message depending on the standard's requirements.