[clang] [C][Parser] Diagnostic for attribute declaration where statement is required (PR #146224)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 28 09:04:19 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,c,cpp -- clang/test/Sema/c2x-fallthrough2.c clang/test/Sema/fallthrough.cpp clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseStmt.cpp clang/test/Parser/statements.c clang/test/Sema/c2x-fallthrough.c
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 7c85bbefe..cb42d6374 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -7160,93 +7160,94 @@ public:
private:
/// Flags describing a context in which we're parsing a statement.
- enum class ParsedStmtContext {
- /// This context permits declarations in language modes where declarations
- /// are not statements.
- AllowDeclarationsInC = 0x1,
- /// This context permits standalone OpenMP directives.
- AllowStandaloneOpenMPDirectives = 0x2,
- /// This context is at the top level of a GNU statement expression.
- InStmtExpr = 0x4,
- /// This context is the C99 secondary-block in selection-/iteration-statement.
- SecondaryBlock = 0x8,
-
- /// The context of a regular substatement.
- SubStmt = 0,
- /// The context of a compound-statement.
- Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
-
- LLVM_MARK_AS_BITMASK_ENUM(SecondaryBlock)
- };
+ enum class ParsedStmtContext {
+ /// This context permits declarations in language modes where declarations
+ /// are not statements.
+ AllowDeclarationsInC = 0x1,
+ /// This context permits standalone OpenMP directives.
+ AllowStandaloneOpenMPDirectives = 0x2,
+ /// This context is at the top level of a GNU statement expression.
+ InStmtExpr = 0x4,
+ /// This context is the C99 secondary-block in
+ /// selection-/iteration-statement.
+ SecondaryBlock = 0x8,
+
+ /// The context of a regular substatement.
+ SubStmt = 0,
+ /// The context of a compound-statement.
+ Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
+
+ LLVM_MARK_AS_BITMASK_ENUM(SecondaryBlock)
+ };
- /// Act on an expression statement that might be the last statement in a
- /// GNU statement expression. Checks whether we are actually at the end of
- /// a statement expression and builds a suitable expression statement.
- StmtResult handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx);
+ /// Act on an expression statement that might be the last statement in a
+ /// GNU statement expression. Checks whether we are actually at the end of
+ /// a statement expression and builds a suitable expression statement.
+ StmtResult handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx);
- //===--------------------------------------------------------------------===//
- // C99 6.8: Statements and Blocks.
+ //===--------------------------------------------------------------------===//
+ // C99 6.8: Statements and Blocks.
- /// Parse a standalone statement (for instance, as the body of an 'if',
- /// 'while', or 'for').
- StmtResult
- ParseStatement(SourceLocation *TrailingElseLoc = nullptr,
- ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt);
+ /// Parse a standalone statement (for instance, as the body of an 'if',
+ /// 'while', or 'for').
+ StmtResult
+ ParseStatement(SourceLocation *TrailingElseLoc = nullptr,
+ ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt);
- /// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
- /// \verbatim
- /// StatementOrDeclaration:
- /// statement
- /// declaration
- ///
- /// statement:
- /// labeled-statement
- /// compound-statement
- /// expression-statement
- /// selection-statement
- /// iteration-statement
- /// jump-statement
- /// [C++] declaration-statement
- /// [C++] try-block
- /// [MS] seh-try-block
- /// [OBC] objc-throw-statement
- /// [OBC] objc-try-catch-statement
- /// [OBC] objc-synchronized-statement
- /// [GNU] asm-statement
- /// [OMP] openmp-construct [TODO]
- ///
- /// labeled-statement:
- /// identifier ':' statement
- /// 'case' constant-expression ':' statement
- /// 'default' ':' statement
- ///
- /// selection-statement:
- /// if-statement
- /// switch-statement
- ///
- /// iteration-statement:
- /// while-statement
- /// do-statement
- /// for-statement
- ///
- /// expression-statement:
- /// expression[opt] ';'
- ///
- /// jump-statement:
- /// 'goto' identifier ';'
- /// 'continue' ';'
- /// 'break' ';'
- /// 'return' expression[opt] ';'
- /// [GNU] 'goto' '*' expression ';'
- ///
- /// [OBC] objc-throw-statement:
- /// [OBC] '@' 'throw' expression ';'
- /// [OBC] '@' 'throw' ';'
- /// \endverbatim
- ///
- StmtResult
- ParseStatementOrDeclaration(StmtVector &Stmts, ParsedStmtContext StmtCtx,
- SourceLocation *TrailingElseLoc = nullptr);
+ /// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
+ /// \verbatim
+ /// StatementOrDeclaration:
+ /// statement
+ /// declaration
+ ///
+ /// statement:
+ /// labeled-statement
+ /// compound-statement
+ /// expression-statement
+ /// selection-statement
+ /// iteration-statement
+ /// jump-statement
+ /// [C++] declaration-statement
+ /// [C++] try-block
+ /// [MS] seh-try-block
+ /// [OBC] objc-throw-statement
+ /// [OBC] objc-try-catch-statement
+ /// [OBC] objc-synchronized-statement
+ /// [GNU] asm-statement
+ /// [OMP] openmp-construct [TODO]
+ ///
+ /// labeled-statement:
+ /// identifier ':' statement
+ /// 'case' constant-expression ':' statement
+ /// 'default' ':' statement
+ ///
+ /// selection-statement:
+ /// if-statement
+ /// switch-statement
+ ///
+ /// iteration-statement:
+ /// while-statement
+ /// do-statement
+ /// for-statement
+ ///
+ /// expression-statement:
+ /// expression[opt] ';'
+ ///
+ /// jump-statement:
+ /// 'goto' identifier ';'
+ /// 'continue' ';'
+ /// 'break' ';'
+ /// 'return' expression[opt] ';'
+ /// [GNU] 'goto' '*' expression ';'
+ ///
+ /// [OBC] objc-throw-statement:
+ /// [OBC] '@' 'throw' expression ';'
+ /// [OBC] '@' 'throw' ';'
+ /// \endverbatim
+ ///
+ StmtResult
+ ParseStatementOrDeclaration(StmtVector &Stmts, ParsedStmtContext StmtCtx,
+ SourceLocation *TrailingElseLoc = nullptr);
StmtResult ParseStatementOrDeclarationAfterAttributes(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
``````````
</details>
https://github.com/llvm/llvm-project/pull/146224
More information about the cfe-commits
mailing list