Author: Muhammad Bassiouni
Date: 2026-07-16T22:47:50+03:00
New Revision: 1387002dc6bee9b9f4b430afebc4141a0f603bb1

URL: 
https://github.com/llvm/llvm-project/commit/1387002dc6bee9b9f4b430afebc4141a0f603bb1
DIFF: 
https://github.com/llvm/llvm-project/commit/1387002dc6bee9b9f4b430afebc4141a0f603bb1.diff

LOG: [Clang][NFC] Update diagnostic handling for C2y compatibility in parser 
(#209920)

Follow-up on #198244 after #209241

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticParseKinds.td
    clang/lib/Parse/ParseExprCXX.cpp
    clang/lib/Parse/ParseStmt.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index cfd35fba7ea07..c411d89ef2fea 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -12,6 +12,9 @@
 
 let Component = "Parse" in {
 let CategoryName = "Parse Issue" in {
+// C2y compatibility with C89.
+defm decl_statement : C2yCompat<"'%select{if|switch}0' declaration statements 
are">;
+
 // C++11 compatibility with C++98.
 defm enum_fixed_underlying_type : CXX11Compat<
   "enumeration types with a fixed underlying type are",
@@ -169,12 +172,6 @@ def ext_c2y_generic_with_type_arg : Extension<
 def warn_c2y_compat_generic_with_type_arg : Warning<
   "passing a type argument as the first operand to '_Generic' is incompatible "
   "with C standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
-def warn_c2y_compat_decl_statement : Warning<
-  "'%select{if|switch}0' declaration statements are incompatible with "
-  "C standards before C2y">, DefaultIgnore, InGroup<CPre2yCompat>;
-def ext_c2y_decl_statement : Extension<
-  "'%select{if|switch}0' declaration statements are a C2y extension">,
-  InGroup<C2y>;
 
 def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup<C99>;

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index bb0cfaad4bc36..b2b1e74b07133 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1908,9 +1908,7 @@ Sema::ConditionResult Parser::ParseCondition(StmtResult 
*InitStmt,
                                   : diag::ext_init_statement)
           << (CK == Sema::ConditionKind::Switch);
     else
-      Diag(Tok.getLocation(), getLangOpts().C2y
-                                  ? diag::warn_c2y_compat_decl_statement
-                                  : diag::ext_c2y_decl_statement)
+      DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
           << (CK == Sema::ConditionKind::Switch);
   };
 

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 75374f608c5ea..65f63bb5756e1 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1340,9 +1340,7 @@ bool Parser::ParseParenExprOrCondition(StmtResult 
*InitStmt,
             << Cond.get().first->getSourceRange();
     } else if (Cond.get().first != nullptr)
       // Handle: if (int decl = 0) {}.
-      Diag(Cond.get().first->getBeginLoc(),
-           getLangOpts().C2y ? diag::warn_c2y_compat_decl_statement
-                             : diag::ext_c2y_decl_statement)
+      DiagCompat(Cond.get().first->getBeginLoc(), diag_compat::decl_statement)
           << (CK == Sema::ConditionKind::Switch);
   }
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to