https://gcc.gnu.org/g:1124bb120dea57071537465033b38da914fc16da
commit r17-826-g1124bb120dea57071537465033b38da914fc16da Author: Jakub Jelinek <[email protected]> Date: Wed May 27 09:26:22 2026 +0200 c++: Don't ICE in eval_constant_of on vars with error_mark_node type [PR125412] The following testcase ICEs during error recovery, because we aren't prepared to handle error_mark_node type. Fixed thusly. 2026-05-27 Jakub Jelinek <[email protected]> PR c++/125412 * reflect.cc (process_metafunction): If ht is error_operand_p, set *non_constant_p and return NULL_TREE. * g++.dg/reflect/pr125412.C: New test. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/cp/reflect.cc | 5 +++++ gcc/testsuite/g++.dg/reflect/pr125412.C | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 5459c8dfbe18..34750f2aa25b 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -7887,6 +7887,11 @@ process_metafunction (const constexpr_ctx *ctx, tree fun, tree call, if (*jump_target || *non_constant_p) return NULL_TREE; ht = REFLECT_EXPR_HANDLE (info); + if (error_operand_p (ht)) + { + *non_constant_p = true; + return NULL_TREE; + } if (METAFN_KIND_ARG (minfo, argno) == METAFN_KIND_ARG_TINFO && eval_is_type (ht) != boolean_true_node) return throw_exception_nontype (loc, ctx, fun, non_constant_p, diff --git a/gcc/testsuite/g++.dg/reflect/pr125412.C b/gcc/testsuite/g++.dg/reflect/pr125412.C new file mode 100644 index 000000000000..4e54ce7c4310 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/pr125412.C @@ -0,0 +1,24 @@ +// PR c++/125412 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +#include <meta> + +void +foo () +{ +} + +auto bar (); + +template <typename T> +auto a = foo (); // { dg-error "variable or field 'a' declared void" } +template <typename T> +auto b = bar (); // { dg-error "use of 'auto bar\\\(\\\)' before deduction of 'auto'" } + +consteval { + auto c = substitute (^^a, { ^^int }); + std::meta::extract <int> (c); + auto d = substitute (^^b, { ^^int }); + std::meta::extract <int> (d); +}
