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

Handles constexpr nested empty objects correctly.

GCC now correctly handles nested empty objects in constexpr contexts, preventing errors during compile-time evaluation.

GCC’s handling of constexpr nested empty objects was corrected. The compiler did not always create a constructor for the outer object, leading to issues when the inner object needed a context for initialization. This commit ensures that both the constructor and the object can be null for an empty subobject in constexpr contexts. A new test case, g++.dg/cpp2a/no_unique_address16.C, was added.

In Details

The fix involves modifying constexpr.cc in GCC's C++ front end. Specifically, the init_subob_ctx function is updated to allow both the constructor and the object to be null when dealing with an empty subobject. This ensures correct handling of nested empty objects in constexpr contexts, preventing miscompilations.

For Context

Constexpr in C++ allows certain expressions and functions to be evaluated at compile time. Empty objects, which consume no memory, can be nested within other objects. Correctly handling these nested empty objects during compile-time evaluation is crucial for ensuring that constexpr code works as expected. This commit fixes a bug in GCC that could cause errors when dealing with such cases.

Filed Under: c++constexprbugfix