GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

c++: ICE with reflect_constant and std::allocator::allocate

Fixes ICE in `reflect_constant` when used with dynamically allocated memory.

This commit resolves an Internal Compiler Error (ICE) occurring in std::meta::reflect_constant when used with memory allocated by std::allocator. The issue stemmed from reflect_constant’s requirement that its argument must be a constexpr-representable object, which dynamically allocated memory from std::allocator is not. The fix involves refining checks in invalid_tparm_referent_p and related functions to correctly identify heap-allocated variables, ensuring reflect_constant throws an appropriate meta::exception rather than causing an ICE.

In Details

The fix in constexpr.cc and pt.cc addresses an ICE in eval_reflect_constant (called from invalid_tparm_referent_p) when std::meta::reflect_constant is invoked on a pointer obtained from std::allocator::allocate. This scenario violates [expr.const.init]/3 and /4 because the pointed-to object has dynamic storage duration and is thus not constexpr-referenceable. The patch introduces heap_var_p and updates invalid_tparm_referent_p to detect such heap variables, causing reflect_constant to throw meta::exception as required by [meta.reflection.result]/5, instead of asserting on…

For Context
ICE
Internal Compiler Error. An ICE indicates a bug within the compiler itself, where it encounters an unrecoverable state during translation.
constexpr-representable
An object is constexpr-representable if it can be evaluated in a constant expression context, typically implying it has static or automatic storage duration and its initialization is constant.
std::allocator::allocate
A member function of std::allocator that allocates raw, uninitialized storage for a specified number of objects.
std::meta::reflect_constant
A C++ reflection facility that attempts to reflect information about a constant expression. It requires its argument to be valid within a constant evaluation context.
Filed Under: c++constexprreflectionerror-handling