https://github.com/babadany2999 updated 
https://github.com/llvm/llvm-project/pull/213449

>From db3e8ab18e94e552c4e48dc128373c66b9551491 Mon Sep 17 00:00:00 2001
From: Baba Dan Constantin <[email protected]>
Date: Sat, 1 Aug 2026 17:09:50 +0300
Subject: [PATCH] [clang][constexpr] Allow IndirectGotoStmt in constexpr
 functions for C++23

P2242R3 ("More Relaxed Constexpr Functions") permitted jump statements such as 
`goto` and labels inside `constexpr` functions starting in C++23. When handling 
`GotoStmtClass` and `LabelStmtClass` in `CheckConstexprFunctionStmt`, 
`IndirectGotoStmtClass` (GNU computed goto) was inadvertently omitted.

As a result, any indirect goto inside a `constexpr` function body hit the 
default case in `CheckConstexprFunctionStmt` and triggered an unrecoverable 
hard error (`err_constexpr_body_invalid_stmt`), even when placed in unexecuted 
branches (e.g. behind `if consteval`).

This commit adds `case Stmt::IndirectGotoStmtClass:` alongside `GotoStmtClass` 
so that indirect gotos are treated consistently:
- Permitted in C++23 `constexpr` functions.
- Allowed in earlier standard dialects (C++11/14/17/20) as a C++23 extension 
warning.
- Evaluated properly by constant evaluation (which rejects actual compile-time 
execution of computed gotos if reached).

Regression test added to `clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp`.
---
 clang/lib/Sema/SemaDeclCXX.cpp                       | 1 +
 clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 47b01b913b428..76b3d8cca9701 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2343,6 +2343,7 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const 
FunctionDecl *Dcl, Stmt *S,
 
   case Stmt::LabelStmtClass:
   case Stmt::GotoStmtClass:
+  case Stmt::IndirectGotoStmtClass:
     if (Cxx2bLoc.isInvalid())
       Cxx2bLoc = S->getBeginLoc();
     for (Stmt *SubStmt : S->children()) {
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
index 51990ee4341d2..508941ae0429d 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -167,6 +167,14 @@ constexpr int DisallowedStmtsCXX14_7() {
   int n; // beforecxx20-warning {{uninitialized variable in a constexpr 
function}}
 }
 
+constexpr int DisallowedStmtsCXX14_8() {
+  return 0; // beforecxx14-note {{previous}}
+  //  - an indirect goto statement
+  goto *(&&x); // beforecxx23-warning {{use of this statement in a constexpr 
function is a C++23 extension}}
+  x:;
+    return 0; // beforecxx14-warning {{multiple return}}
+}
+
 constexpr int ForStmt() {
   for (int n = 0; n < 10; ++n) {} // beforecxx14-error {{statement not allowed 
in constexpr function}}
     return 0;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to