File tree Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -141,16 +141,18 @@ void EnumInitialValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
141
141
}
142
142
143
143
void EnumInitialValueCheck::registerMatchers (MatchFinder *Finder) {
144
- Finder->addMatcher (
145
- enumDecl ( unless ( isMacro ()), unless (hasConsistentInitialValues ()))
146
- .bind (" inconsistent" ),
147
- this );
144
+ Finder->addMatcher (enumDecl ( isDefinition (), unless ( isMacro ()),
145
+ unless (hasConsistentInitialValues ()))
146
+ .bind (" inconsistent" ),
147
+ this );
148
148
if (!AllowExplicitZeroFirstInitialValue)
149
149
Finder->addMatcher (
150
- enumDecl (hasZeroInitialValueForFirstEnumerator ()).bind (" zero_first" ),
150
+ enumDecl (isDefinition (), hasZeroInitialValueForFirstEnumerator ())
151
+ .bind (" zero_first" ),
151
152
this );
152
153
if (!AllowExplicitSequentialInitialValues)
153
- Finder->addMatcher (enumDecl (unless (isMacro ()), hasSequentialInitialValues ())
154
+ Finder->addMatcher (enumDecl (isDefinition (), unless (isMacro ()),
155
+ hasSequentialInitialValues ())
154
156
.bind (" sequential" ),
155
157
this );
156
158
}
Original file line number Diff line number Diff line change @@ -132,6 +132,10 @@ Changes in existing checks
132
132
<clang-tidy/checks/modernize/use-std-print>` check to support replacing
133
133
member function calls too.
134
134
135
+ - Improved :doc: `readability-enum-initial-value
136
+ <clang-tidy/checks/readability-enum-initial-value>` check to only issue
137
+ diagnostics for the definition of an ``enum ``.
138
+
135
139
- Improved :doc: `performance-avoid-endl
136
140
<clang-tidy/checks/performance/avoid-endl>` check to use ``std::endl `` as
137
141
placeholder when lexer cannot get source text.
Original file line number Diff line number Diff line change @@ -78,3 +78,17 @@ enum EnumSequentialInitialValue {
78
78
EnumSequentialInitialValue_2 = 4 ,
79
79
// CHECK-FIXES-ENABLE: EnumSequentialInitialValue_2 ,
80
80
};
81
+
82
+ // gh107590
83
+ enum WithFwdDecl : int ;
84
+
85
+ enum WithFwdDecl : int {
86
+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'WithFwdDecl' are not consistent
87
+ // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 'WithFwdDecl' are not consistent
88
+ E0 ,
89
+ // CHECK-FIXES: E0 = 0,
90
+ E1 = 1 ,
91
+ E2 ,
92
+ // CHECK-FIXES: E2 = 2,
93
+ };
94
+
You can’t perform that action at this time.
0 commit comments