GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

c++: Fix up ICEs with some metafns with non-dependent args in templates [PR126036]

Compiler fix prevents ICEs when evaluating metafunctions with non-dependent arguments within templates.

This commit resolves an internal compiler error (ICE) occurring when evaluating C++ metafunctions with non-dependent arguments inside templates. The issue arose because cxx_eval_constant_expression did not handle certain CAST_EXPR forms that potential_constant_expression_1 did. The fix introduces logic to defer constant evaluation of such metafn calls when processing_template_decl is true, preventing the ICE and ensuring correct behavior for constructs like std::array and std::meta::exception objects within templates.

In Details

Fixes an ICE in reflect.cc related to cxx_eval_constant_expression not processing CAST_EXPR formed by finish_compound_literal when processing_template_decl is true. Normally, fold_non_dependent_expr_template removes these CAST_EXPRs during template instantiation, but this doesn't happen during constant evaluation. The patch modifies get_range_elts and process_metafunction to also avoid calling finish_compound_literal (by setting *non_constant_p and returning NULL_TREE) when processing_template_decl is active, deferring the evaluation. This is acceptable as the return…

For Context
ICE
Internal Compiler Error. A condition where the compiler encounters an unrecoverable state and terminates abnormally, typically due to a bug in the compiler itself.
metafunction
A function in C++ template metaprogramming that operates on types or values at compile time, often to perform computations or generate code.
non-dependent argument
In the context of C++ templates, an argument to a template whose type or value does not depend on the template parameters. This means its properties can be determined before template instantiation.
CAST_EXPR
An internal representation in GCC's Abstract Syntax Tree (AST) indicating a type cast operation.
processing_template_decl
A flag or context within the GCC compiler indicating that it is currently processing a template declaration or instantiation.
Filed Under: c++compiler-errortemplate-metaprogramming