GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

Libstdc++ constexpr support for inplace_vector improved.

Libstdc++ enhances inplace_vector's constexpr support for union lifetime rules and error reporting.

Libstdc++ has improved inplace_vector’s constexpr support by implementing the remaining aspects of the P3726R2 standard, specifically concerning union lifetime rules. It now uses std::start_lifetime in _M_init and utilizes __builtin_constexpr_diag for better compile-time error messages. This change also removes an older optimization-hindering approach and ensures better compatibility with compiler behavior regarding union member writes.

In Details

This commit refines inplace_vector's constexpr capabilities by integrating std::start_lifetime into _M_init, aligning with P3726R2's union lifetime rules. It replaces std::start_lifetime_as with std::start_lifetime to avoid hindering optimizations, as GCC's treatment of union writes (any write may change the active member) obviates the need for the more restrictive _as variant. Compile-time diagnostics are enhanced using __builtin_constexpr_diag. Test cases are expanded to cover non-trivial types in constexpr contexts.

For Context
constexpr
A C++ keyword that indicates a variable or function can be evaluated at compile time. This allows for more efficient code by performing computations during compilation rather than at runtime.
inplace_vector
A C++ container that stores elements directly within its own memory, similar to std::vector, but without using dynamic allocation for the elements themselves. It's often used for small, fixed-size collections.
union lifetime rules
Rules in C++ that govern how objects stored within a union are managed, particularly concerning their construction, destruction, and lifetime, especially in constexpr contexts.
std::start_lifetime
A C++ standard library function used to establish the lifetime of an object at a specific memory location, particularly useful in scenarios involving unions or placement new.
__builtin_constexpr_diag
A GCC-specific built-in function that allows emitting diagnostic messages during compile time, useful for providing more informative errors in constexpr evaluations.
Filed Under: libstdc++constexprc++ standardunion