From: Jakub Jelinek Date: Sat, 7 Feb 2026 10:06:35 +0000 (+0100) Subject: c++: Fix error recovery of invalid splice during tsubst_splice_expr [PR123752] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6749b94438a1a47c34a390e2eee53546c6d33ea;p=thirdparty%2Fgcc.git c++: Fix error recovery of invalid splice during tsubst_splice_expr [PR123752] splice can return error_mark_node, e.g. if the evaluation of the constant expression throws without being caught, and the error_mark_node later on causes ICEs in various asserts. The following patch fixes it by returning early if error_mark_node is returned. 2026-02-07 Jakub Jelinek PR c++/123752 * pt.cc (tsubst_splice_expr): Return error_mark_node if splice returned it. * g++.dg/reflect/splice8.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 50966de76f8..049bbf07e01 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16753,6 +16753,8 @@ tsubst_splice_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (op == error_mark_node) return error_mark_node; op = splice (op); + if (op == error_mark_node) + return error_mark_node; if (dependent_splice_p (op)) { if (SPLICE_EXPR_EXPRESSION_P (t)) diff --git a/gcc/testsuite/g++.dg/reflect/splice8.C b/gcc/testsuite/g++.dg/reflect/splice8.C new file mode 100644 index 00000000000..5ca28466c08 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/splice8.C @@ -0,0 +1,33 @@ +// PR c++/123752 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +struct S { int s; }; +struct U { int u; }; + +template +consteval decltype (^^int) +foo () +{ + return ^^S::s; +} + +template <> +consteval decltype (^^int) +foo () +{ + throw 1; +} + +template +auto +bar (T x) +{ + return x.[: foo () :]; // { dg-error "uncaught exception '1'" } +} + +auto +baz (U x) +{ + return bar (x); +}