[Clang][NFC] Update diagnostic handling for C2y compatibility in parser#209920
Open
bassiounix wants to merge 2 commits into
Open
[Clang][NFC] Update diagnostic handling for C2y compatibility in parser#209920bassiounix wants to merge 2 commits into
bassiounix wants to merge 2 commits into
Conversation
|
@llvm/pr-subscribers-clang Author: Muhammad Bassiouni (bassiounix) ChangesFollow-up on #198244 after #209241 Full diff: https://github.com/llvm/llvm-project/pull/209920.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index cfd35fba7ea07..e083a87cc62fb 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -169,12 +169,7 @@ 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>;
+defm decl_statement : C2yCompat<"'%select{if|switch}0' declaration statements are">;
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);
}
|
Fznamznon
approved these changes
Jul 16, 2026
| @@ -169,12 +169,7 @@ def ext_c2y_generic_with_type_arg : Extension< | |||
| def warn_c2y_compat_generic_with_type_arg : Warning< | |||
Contributor
There was a problem hiding this comment.
Not related to this patch but we probably need to switch this one too.
Member
There was a problem hiding this comment.
Yes, I only updated the ones in DiagnosticSemaKinds.td in my patch; we should do this file as well
Sirraide
reviewed
Jul 16, 2026
| @@ -169,12 +169,7 @@ def ext_c2y_generic_with_type_arg : Extension< | |||
| def warn_c2y_compat_generic_with_type_arg : Warning< | |||
Member
There was a problem hiding this comment.
Yes, I only updated the ones in DiagnosticSemaKinds.td in my patch; we should do this file as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up on #198244 after #209241