[clang] [clang] Reject a label with no statement as a substatement (PR #244133)

Mohit Mishra via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 21:25:13 PST 2026


================
@@ -7516,6 +7516,14 @@ class Parser : public CodeCompletionHandler {
 
   void DiagnoseLabelAtEndOfCompoundStatement();
 
+  /// Whether a label in this context may be followed directly by the closing
+  /// brace, i.e. the label appears in a compound statement rather than as a
+  /// substatement such as the body of an 'if' or 'switch' without braces.
+  static bool isCompoundStatementContext(ParsedStmtContext StmtCtx) {
+    return (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+           ParsedStmtContext();
+  }
+
----------------
mohitmishra786 wrote:

moved it out of the header. `ParsedStmtContext` is private to `Parser`, so it can't be a static function in ParseStmt.cpp either; the check is now written inline at the three places, the same way the existing `AllowDeclarationsInC` checks in that file are written. also rebased on main.

about side effects, the helper only tested a bit of `StmtCtx` and didn't change anything. could you say which part you meant?


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


More information about the cfe-commits mailing list