-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy] only diagnose definitions in readability-enum-initial-value #107652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
5chmidti
merged 3 commits into
llvm:main
from
5chmidti:clang_tidy_enum_initial_only_def
Sep 17, 2024
Merged
[clang-tidy] only diagnose definitions in readability-enum-initial-value #107652
5chmidti
merged 3 commits into
llvm:main
from
5chmidti:clang_tidy_enum_initial_only_def
Sep 17, 2024
Conversation
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
@llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Julian Schmidt (5chmidti) ChangesWith the Fixes #107590 Full diff: https://github.com/llvm/llvm-project/pull/107652.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 8f2841c32259a2..60b129196ba955 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -141,16 +141,18 @@ void EnumInitialValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- enumDecl(unless(isMacro()), unless(hasConsistentInitialValues()))
- .bind("inconsistent"),
- this);
+ Finder->addMatcher(enumDecl(isDefinition(), unless(isMacro()),
+ unless(hasConsistentInitialValues()))
+ .bind("inconsistent"),
+ this);
if (!AllowExplicitZeroFirstInitialValue)
Finder->addMatcher(
- enumDecl(hasZeroInitialValueForFirstEnumerator()).bind("zero_first"),
+ enumDecl(isDefinition(), hasZeroInitialValueForFirstEnumerator())
+ .bind("zero_first"),
this);
if (!AllowExplicitSequentialInitialValues)
- Finder->addMatcher(enumDecl(unless(isMacro()), hasSequentialInitialValues())
+ Finder->addMatcher(enumDecl(isDefinition(), unless(isMacro()),
+ hasSequentialInitialValues())
.bind("sequential"),
this);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 8d028f8863cb7a..469dd4e54b1181 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -120,6 +120,10 @@ Changes in existing checks
<clang-tidy/checks/modernize/use-std-print>` check to support replacing
member function calls too.
+- Improved :doc:`readability-enum-initial-value
+ <clang-tidy/checks/readability-enum-initial-value>` check to only issue
+ diagnostics for the definition of an ``enum``.
+
- Improved :doc:`readablility-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check
by adding the option `UseUpperCaseLiteralSuffix` to select the
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
index c66288cbe3e957..36727d00c10a48 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
@@ -78,3 +78,17 @@ enum EnumSequentialInitialValue {
EnumSequentialInitialValue_2 = 4,
// CHECK-FIXES-ENABLE: EnumSequentialInitialValue_2 ,
};
+
+// gh107590
+enum WithFwdDecl : int;
+
+enum WithFwdDecl : int {
+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'WithFwdDecl' are not consistent
+ // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 'WithFwdDecl' are not consistent
+ E0,
+ // CHECK-FIXES: E0 = 0,
+ E1 = 1,
+ E2,
+ // CHECK-FIXES: E2 = 2,
+};
+
|
SimplyDanny
approved these changes
Sep 7, 2024
HerrCai0907
approved these changes
Sep 13, 2024
With the `isDefinition` matcher, the analysis and diagnostics will be constrained to definitions only. Previously forward declarations were diagnosed as well. Fixes llvm#107590
c3329bc
to
e94f36b
Compare
tmsri
pushed a commit
to tmsri/llvm-project
that referenced
this pull request
Sep 19, 2024
…lue (llvm#107652) With the `isDefinition` matcher, the analysis and diagnostics will be constrained to definitions only. Previously forward declarations were diagnosed as well. Fixes llvm#107590
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.
With the
isDefinition
matcher, the analysis and diagnostics will beconstrained to definitions only. Previously forward declarations were
diagnosed as well.
Fixes #107590