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

Fix ICE on template tree from metafunction in C++ reflection.

C++ reflection now correctly handles template trees from metafunctions, preventing an ICE during constant expression evaluation.

This commit addresses an Internal Compiler Error (ICE) in C++ reflection when processing a call to identifier_of within a generic lambda. The issue occurred because eval_identifier_of would call build_special_member_call, which in a template context creates a COMPONENT_REF that could not be evaluated by cxx_eval_constant_expression. The fix enforces a non-template context during process_metafunction when such calls are encountered, ensuring that the generated expression is evaluable as a constant expression and preventing the ICE.

In Details

The change in gcc/cp/reflect.cc introduces a processing_template_decl_sentinel in process_metafunction. This sentinel ensures that when eval_identifier_of is called within a generic lambda, the subsequent call to build_special_member_call does not create a COMPONENT_REF that is instantiation-dependent. This is crucial because cxx_eval_constant_expression is called on the result of process_metafunction in certain contexts (like finish_if_stmt_cond), and it cannot handle instantiation-dependent expressions. By forcing a non-template context via the sentinel, the generated expr…

For Context
metafunction
A function used in template metaprogramming that operates on types or compile-time values to compute other types or values.
generic lambda
A C++ lambda expression where the parameter types are deduced using auto, allowing it to operate on a variety of argument types.
identifier_of
A C++ reflection construct that obtains the identifier (name) of a type or entity.
cxx_eval_constant_expression
A GCC internal function that attempts to evaluate a C++ expression at compile time.
COMPONENT_REF
A GCC internal tree node representing a reference to a component (member) of a class or struct.
Filed Under: c++reflectionmetaprogrammingcompiler error