Skip to content

Commit 48d3d21

Browse files
committed
add fwd decl test for the other cases + fix diagnostic typo
1 parent 991b6a7 commit 48d3d21

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
161161
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("inconsistent")) {
162162
DiagnosticBuilder Diag =
163163
diag(Enum->getBeginLoc(),
164-
"inital values in enum %0 are not consistent, consider explicit "
164+
"initial values in enum %0 are not consistent, consider explicit "
165165
"initialization of all, none or only the first enumerator")
166166
<< Enum;
167167
for (const EnumConstantDecl *ECD : Enum->enumerators())

clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// RUN: }}'
77

88
enum EError {
9-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EError' are not consistent
10-
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 'EError' are not consistent
9+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EError' are not consistent
10+
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 'EError' are not consistent
1111
EError_a = 1,
1212
EError_b,
1313
// CHECK-FIXES: EError_b = 2,
@@ -34,8 +34,8 @@ enum EAll {
3434

3535
#define ENUMERATOR_1 EMacro1_b
3636
enum EMacro1 {
37-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EMacro1' are not consistent
38-
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 'EMacro1' are not consistent
37+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EMacro1' are not consistent
38+
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 'EMacro1' are not consistent
3939
EMacro1_a = 1,
4040
ENUMERATOR_1,
4141
// CHECK-FIXES: ENUMERATOR_1 = 2,
@@ -45,8 +45,8 @@ enum EMacro1 {
4545

4646
#define ENUMERATOR_2 EMacro2_b = 2
4747
enum EMacro2 {
48-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EMacro2' are not consistent
49-
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 'EMacro2' are not consistent
48+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EMacro2' are not consistent
49+
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 'EMacro2' are not consistent
5050
EMacro2_a = 1,
5151
ENUMERATOR_2,
5252
EMacro2_c,
@@ -80,15 +80,38 @@ enum EnumSequentialInitialValue {
8080
};
8181

8282
// 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,
83+
enum WithFwdDeclInconsistent : int;
84+
85+
enum WithFwdDeclInconsistent : int {
86+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'WithFwdDeclInconsistent' are not consistent
87+
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 'WithFwdDeclInconsistent' are not consistent
88+
EFI0,
89+
// CHECK-FIXES: EFI0 = 0,
90+
EFI1 = 1,
91+
EFI2,
92+
// CHECK-FIXES: EFI2 = 2,
93+
};
94+
95+
enum WithFwdDeclZeroFirst : int;
96+
97+
enum WithFwdDeclZeroFirst : int {
98+
// CHECK-MESSAGES-ENABLE: :[[@LINE+1]]:3: warning: zero initial value for the first enumerator in 'WithFwdDeclZeroFirst' can be disregarded
99+
EFZ0 = 0,
100+
// CHECK-FIXES-ENABLE: EFZ0 ,
101+
EFZ1,
102+
EFZ2,
103+
};
104+
105+
106+
enum WithFwdDeclSequential : int;
107+
108+
enum WithFwdDeclSequential : int {
109+
// CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:1: warning: sequential initial value in 'WithFwdDeclSequential' can be ignored
110+
EFS0 = 2,
111+
// CHECK-FIXES-ENABLE: EFS0 = 2,
112+
EFS1 = 3,
113+
// CHECK-FIXES-ENABLE: EFS1 ,
114+
EFS2 = 4,
115+
// CHECK-FIXES-ENABLE: EFS2 ,
93116
};
94117

clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %check_clang_tidy %s readability-enum-initial-value %t
22

33
enum class EError {
4-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EError' are not consistent
4+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EError' are not consistent
55
EError_a = 1,
66
EError_b,
77
// CHECK-FIXES: EError_b = 2,

0 commit comments

Comments
 (0)