GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
middle-end

Fix C++26 uninitialized read behavior for P2795R5

Corrects C++26 handling of uninitialized reads to ensure consistent values and diagnostics.

This commit fixes an incorrect implementation of the C++26 P2795R5 standard concerning uninitialized reads. The standard requires that multiple reads of the same uninitialized variable yield a consistent (though unspecified) value and that such uses are diagnosed. The previous implementation incorrectly optimized these reads in the middle-end passes, violating the standard’s requirements. This fix ensures that uninitialized reads are treated more conservatively, preserving their value consistency and allowing for diagnostics.

In Details

The implementation of C++26 P2795R5 ('Erroneous behavior for uninitialized reads') had a flaw in the middle-end passes. While the front-end and initial gimplification handled the new AUTO_INIT_CXX26 mode, subsequent optimizations were treating .DEFERRED_INIT for C++26 as something that could be optimized away or treated as UNDEFINED too aggressively. This violated the standard's requirement for consistent, albeit unspecified, values from multiple reads and for diagnostics. This patch adjusts the middle-end's understanding of AUTO_INIT_CXX26 to prevent such aggressive optimizations.

For Context
C++26
The 2026 revision of the C++ programming language standard.
P2795R5
A revision of a C++ standardization proposal (likely related to uninitialized variables) that has been incorporated into the C++26 standard.
uninitialized read
Accessing the value of a variable that has not been explicitly assigned a value. In C++, this can lead to undefined or unspecified behavior.
middle-end
The part of a compiler that performs optimizations and transformations on an intermediate representation (IR) of the code, after the front-end has parsed the source code and before the back-end generates machine code.
gimplification
The process in GCC where the high-level intermediate representation (like GENERIC or GIMPLE) is transformed into a lower-level, simpler form (GIMPLE) suitable for optimization passes.
PHI node
In compiler theory, a PHI node is used in control flow graphs to represent a value that may have come from multiple different control flow paths. It's analogous to a merge point.
Filed Under: c++middle-endoptimizationstandard conformanceuninitialized reads