GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Make pointer_traits::pointer_to constexpr for main template.

The `pointer_traits::pointer_to` function in libstdc++ is now `constexpr` since C++20, allowing compile-time evaluation.

This commit makes pointer_traits::pointer_to constexpr for the main template in libstdc++, aligning with the resolution of LWG3454 from the C++ standard. This change enables compile-time evaluation of pointer_to when used with pointer types in C++20 and later. A new test case is added to verify the constexpr behavior with custom pointer-like types.

In Details

This patch implements LWG3454, making pointer_traits::pointer_to constexpr since C++20. The change affects the main template in bits/ptr_traits.h. A new test case, testsuite/20_util/pointer_traits/pointer_to_constexpr.cc, verifies the constexpr behavior with a custom pointer-like type.

For Context

pointer_traits is a C++ template that provides a way to obtain information about pointer types, such as the type they point to. The pointer_to member function constructs a pointer to an object. constexpr allows a function or variable to be evaluated at compile time, rather than at runtime. By making pointer_to constexpr, the compiler can perform optimizations and calculations related to pointers during compilation, potentially improving performance.

Filed Under: libstdc++constexprc++20templates