[clang] [clang] Add break/continue stmts with missing lable to the AST (PR #168332)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 17 06:13:44 PST 2025


================
@@ -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();
----------------
tbaederr wrote:

> > Yes, so how do we communicate that there was an error at all?
> 
> In the static analyser, we just check if there was an error anywhere in the TU (iirc it calls `Sema::hasUnrecoverableErrorOccurred()` or whatever it it’s called); I’m not sure we have a way of tracking this on a per-function basis at the moment but I feel like it should be possible.

Well what we have is `RecoveryExpr` and `Expr::containsErrors`, but none of those are used for broken break statements (one of the reasons being that they aren't expressions). 
We can also mark declarations as invalid but that has other side-effects like not taking part in later name lookup, which causes weird diagnostics.

https://github.com/llvm/llvm-project/pull/168332


More information about the cfe-commits mailing list