https://gcc.gnu.org/g:e4c2d1952a6f0d00430f8cbed796524650211cc3

commit r16-6777-ge4c2d1952a6f0d00430f8cbed796524650211cc3
Author: Jakub Jelinek <[email protected]>
Date:   Wed Jan 14 17:09:13 2026 +0100

    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  <[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.

Diff:
---
 gcc/cp/constexpr.cc              |  2 +-
 gcc/testsuite/g++.dg/ext/goto2.C | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 4b362b1caba3..54a50c4b6b04 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 000000000000..662c7efad038
--- /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:;
+  };
+}

Reply via email to