On 1/14/26 4:34 PM, Jakub Jelinek wrote:
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
2026-01-14 Jakub Jelinek <[email protected]>
PR c++/123551
* constexpr.cc (potential_constant_expression_1) <case GOTO_EXPR>:
Only test DECL_ARTIFICIAL on LABEL_DECLs.
* g++.dg/ext/goto2.C: New test.
--- gcc/cp/constexpr.cc.jj 2026-01-03 12:16:44.567863383 +0100
+++ gcc/cp/constexpr.cc 2026-01-13 15:50:01.041706699 +0100
@@ -12520,7 +12520,7 @@ potential_constant_expression_1 (tree t,
*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)
--- gcc/testsuite/g++.dg/ext/goto2.C.jj 2026-01-13 16:03:25.068940758 +0100
+++ gcc/testsuite/g++.dg/ext/goto2.C 2026-01-13 15:59:39.277806858 +0100
@@ -0,0 +1,13 @@
+// PR c++/123551
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+void
+foo ()
+{
+ [] () {
+ void *a = &&b;
+ goto *a;
+ b:;
+ };
+}
Jakub