llvm-project
82ce34d7 - [clang][constexpr] Allow IndirectGotoStmt in constexpr functions for C++23 (#213449)

Commit
21 days ago
[clang][constexpr] Allow IndirectGotoStmt in constexpr functions for C++23 (#213449) ### Summary P2242R3 relaxed `constexpr` function requirements in C++23 to allow jump statements such as `goto` and labels inside `constexpr` functions. In `CheckConstexprFunctionStmt`, `GotoStmtClass` and `LabelStmtClass` were added, but `IndirectGotoStmtClass` (GNU computed goto) was missed. This patch adds `case Stmt::IndirectGotoStmtClass:` alongside `GotoStmtClass` in `CheckConstexprFunctionStmt`. ### Details - Before this patch, writing `goto *p;` inside a `constexpr` function resulted in `error: statement not allowed in constexpr function` because `IndirectGotoStmtClass` fell through to the `default` case in `CheckConstexprFunctionStmt`. - With this patch, indirect gotos behave identically to standard gotos in `constexpr` function bodies: - Allowed in C++23 mode. - Issued as a C++23 extension warning in earlier modes (C++11 through C++20). - Executing an indirect goto during constant evaluation continues to produce an error during evaluation, while valid runtime paths (e.g. guarded by `if consteval`) succeed. ### Test Plan - Added test case covering indirect gotos (`goto *(&&x);`) to `clang/test/SemaCXX/gnu-constexpr-computed-goto.cpp`. - Verified test fails without the patch and passes with the patch across all standard modes (`-std=c++11` through C++23). ### AI Policy Used AI to format and improve the PR message.
Author
Parents
Loading