Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2026-02-05 Jakub Jelinek <[email protected]> PR c++/123752 * pt.cc (tsubst_splice_expr): Return error_mark_node if splice returned it. * g++.dg/reflect/splice8.C: New test. --- gcc/cp/pt.cc.jj 2026-02-05 15:14:59.078531057 +0100 +++ gcc/cp/pt.cc 2026-02-05 19:27:49.528258536 +0100 @@ -16753,6 +16753,8 @@ tsubst_splice_expr (tree t, tree args, t 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)) --- gcc/testsuite/g++.dg/reflect/splice8.C.jj 2026-02-05 19:29:28.915578706 +0100 +++ gcc/testsuite/g++.dg/reflect/splice8.C 2026-02-05 19:28:59.850069966 +0100 @@ -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 <typename T> +consteval decltype (^^int) +foo () +{ + return ^^S::s; +} + +template <> +consteval decltype (^^int) +foo <U> () +{ + throw 1; +} + +template <typename T> +auto +bar (T x) +{ + return x.[: foo <T> () :]; // { dg-error "uncaught exception '1'" } +} + +auto +baz (U x) +{ + return bar (x); +} Jakub
