From: Jakub Jelinek Date: Wed, 14 Jan 2026 16:09:13 +0000 (+0100) Subject: c++: Don't ICE on computed goto in potential_constant_expression_1 [PR123551] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4c2d1952a6f0d00430f8cbed796524650211cc3;p=thirdparty%2Fgcc.git c++: Don't ICE on computed goto in potential_constant_expression_1 [PR123551] r16-968-g5c6364b09a6 has added if (DECL_ARTIFICIAL (*target)) return true; stmt for GOTO_EXPRs. This unfortunately ICEs if *target is not a decl, which is the case for computed gotos. For those we should always reject them, so the following patch additionally checks for LABEL_DECL before testing DECL_ARTIFICIAL on it. 2026-01-14 Jakub Jelinek PR c++/123551 * constexpr.cc (potential_constant_expression_1) : Only test DECL_ARTIFICIAL on LABEL_DECLs. * g++.dg/ext/goto2.C: New test. --- diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 4b362b1caba..54a50c4b6b0 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -12520,7 +12520,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, *jump_target = *target; return true; } - if (DECL_ARTIFICIAL (*target)) + if (TREE_CODE (*target) == LABEL_DECL && DECL_ARTIFICIAL (*target)) /* The user didn't write this goto, this isn't the problem. */ return true; if (flags & tf_error) diff --git a/gcc/testsuite/g++.dg/ext/goto2.C b/gcc/testsuite/g++.dg/ext/goto2.C new file mode 100644 index 00000000000..662c7efad03 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/goto2.C @@ -0,0 +1,13 @@ +// PR c++/123551 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +void +foo () +{ + [] () { + void *a = &&b; + goto *a; + b:; + }; +}