[clang] [clang] Add break/continue stmts with missing lable to the AST (PR #168332)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 17 00:22:52 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/156801
We can't return a `RecoveryExpr` here since the functions returns a `StmtResult`. Just add those statements to the AST without the target.
I'm not entirely sure if we should do the same thing in `Sema::ActOnBreakStmt`, but I think so.
---
Full diff: https://github.com/llvm/llvm-project/pull/168332.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseStmt.cpp (+1-3)
- (modified) clang/test/SemaCXX/labeled-break-continue-constexpr.cpp (+9-1)
``````````diff
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 7e73d89c2a18c..f9141cabf0e6a 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2313,10 +2313,8 @@ StmtResult Parser::ParseBreakOrContinueStatement(bool IsContinue) {
// TODO: Make this a compatibility/extension warning instead once the
// syntax of this feature is finalised.
Diag(LabelLoc, diag::err_c2y_labeled_break_continue) << IsContinue;
- if (!Target) {
+ if (!Target)
Diag(LabelLoc, diag::err_break_continue_label_not_found) << IsContinue;
- return StmtError();
- }
}
if (IsContinue)
diff --git a/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp b/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
index d1b57adca91c1..cc45887ab3817 100644
--- a/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
+++ b/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -fnamed-loops -std=c++23 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fnamed-loops -std=c++23 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
-// expected-no-diagnostics
struct Tracker {
bool& destroyed;
@@ -168,3 +167,12 @@ constexpr T f12() {
}
static_assert(f12<int>() == 93);
static_assert(f12<unsigned>() == 93u);
+
+
+constexpr int labelNotFound() {
+ a: for (;;) {
+ break azzz; // expected-error {{'break' label does not name an enclosing loop or 'switch'}}
+ }
+ return 1;
+}
+static_assert(labelNotFound() == 1);
``````````
</details>
https://github.com/llvm/llvm-project/pull/168332
More information about the cfe-commits
mailing list