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

Implement C++26 union lifetime rules

GCC now supports C++26's adjusted union lifetime and constexpr rules for object initialization.

GCC and libstdc++ now implement the C++26 P3726R2 paper, adjusting union lifetime rules. This includes a new builtin for std::start_lifetime that operates on pointers, and improvements to reduced_constant_expression_p to correctly handle union-nested arrays and ignored holes. The changes ensure correct constant evaluation and object lifetime management in C++26, particularly for unions.

In Details

This commit implements C++26 P3726R2, focusing on union lifetime and constexpr evaluation. A new FE builtin, __builtin_start_lifetime, is introduced to handle pointer-based lifetime initialization, differentiating from reference-based standard functions. The cxx_eval_store_expression is adapted to support this builtin for MODOP_EXPR. Additionally, reduced_constant_expression_p is enhanced to ignore holes in union-nested arrays for C++26, and __cpp_trivial_union is predefined. This impacts constant evaluation and object lifetime management within the C++ frontend.

For Context
libstdc++
The standard C++ library implementation used by GCC. It provides fundamental C++ functionalities like containers, algorithms, and I/O streams.
constexpr
A C++ keyword that indicates a variable or function can be evaluated at compile time. This allows for more efficient execution by performing computations during compilation rather than at runtime.
union
A user-defined data type in C++ that can store different types of data in the same memory location. Only one member of the union can be active at any given time.
P3726R2
A C++ standardization proposal (number 3726, revision 2) addressing adjustments to union lifetime rules. It aims to clarify and standardize behavior related to object lifetimes within unions.
FE builtin
A built-in function provided by the compiler's frontend that is not part of the standard language but offers specific functionality, often for internal compiler use or to support language features.
GIMPLE
GNU Intermediate Representation, a three-address code form used by GCC after the initial parsing and before machine code generation. It's designed for easier optimization.
MODOP_EXPR
A specific expression type in GCC's GIMPLE intermediate representation, often used to represent modification operations.
Filed Under: c++standardizationcompiler