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

c++/reflection: Fix ICE with consteval-only variable [PR128941]

Fixes an internal compiler error in C++ reflection when handling consteval-only variables.

This commit resolves an internal compiler error (ICE) in the C++ reflection implementation that occurred when processing consteval-only variables. The error stemmed from mark_needed being called with a consteval_only_p declaration, which violated an assertion. The fix adds necessary guards to prevent this call in cp_finish_decl and setup_explicit_instantiation_definition_linkage, ensuring correct handling of these types of variables.

In Details

An ICE was occurring in cp_finish_decl and setup_explicit_instantiation_definition_linkage due to mark_needed being invoked with a consteval_only_p declaration. The fix adds a !consteval_only_p guard around these calls. The issue was exacerbated by the DECL_INLINE_VAR_P check in cp_finish_decl, which incorrectly returned true for certain constexpr static data members (I::value) that should have been consteval-only. New test cases value17.C and value18.C are added to cover these scenarios.

For Context
ICE
Internal Compiler Error. A crash within the compiler itself, typically indicating a bug in the compiler's logic.
consteval
A C++20 keyword that specifies a function or variable can only be evaluated at compile time.
reflection
In C++, reflection refers to the ability of a program to examine, introspect, and modify its own structure and behavior at compile time or runtime. C++20 introduced features for compile-time reflection.
mark_needed
An internal GCC function likely related to tracking entities that are required or used, possibly for template instantiation or other dependency management.
consteval_only_p
A flag or predicate indicating that a declaration is restricted to compile-time evaluation only.
Filed Under: c++reflectioncompiler-bug