1 | // RUN: %check_clang_tidy %s readability-enum-initial-value %t |
2 | // RUN: %check_clang_tidy -check-suffix=ENABLE %s readability-enum-initial-value %t -- \ |
3 | // RUN: -config='{CheckOptions: { \ |
4 | // RUN: readability-enum-initial-value.AllowExplicitZeroFirstInitialValue: false, \ |
5 | // RUN: readability-enum-initial-value.AllowExplicitSequentialInitialValues: false, \ |
6 | // RUN: }}' |
7 | |
8 | enum EError { |
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 |
11 | EError_a = 1, |
12 | EError_b, |
13 | // CHECK-FIXES: EError_b = 2, |
14 | EError_c = 3, |
15 | }; |
16 | |
17 | enum ENone { |
18 | ENone_a, |
19 | ENone_b, |
20 | EENone_c, |
21 | }; |
22 | |
23 | enum EFirst { |
24 | EFirst_a = 1, |
25 | EFirst_b, |
26 | EFirst_c, |
27 | }; |
28 | |
29 | enum EAll { |
30 | EAll_a = 1, |
31 | EAll_b = 2, |
32 | EAll_c = 4, |
33 | }; |
34 | |
35 | #define ENUMERATOR_1 EMacro1_b |
36 | enum EMacro1 { |
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 |
39 | EMacro1_a = 1, |
40 | ENUMERATOR_1, |
41 | // CHECK-FIXES: ENUMERATOR_1 = 2, |
42 | EMacro1_c = 3, |
43 | }; |
44 | |
45 | |
46 | #define ENUMERATOR_2 EMacro2_b = 2 |
47 | enum EMacro2 { |
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 |
50 | EMacro2_a = 1, |
51 | ENUMERATOR_2, |
52 | EMacro2_c, |
53 | // CHECK-FIXES: EMacro2_c = 3, |
54 | }; |
55 | |
56 | |
57 | enum { |
58 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum '<unnamed>' are not consistent |
59 | // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum '<unnamed>' are not consistent |
60 | EAnonymous_a = 1, |
61 | EAnonymous_b, |
62 | // CHECK-FIXES: EAnonymous_b = 2, |
63 | EAnonymous_c = 3, |
64 | }; |
65 | |
66 | |
67 | enum EnumZeroFirstInitialValue { |
68 | EnumZeroFirstInitialValue_0 = 0, |
69 | // CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:3: warning: zero initial value for the first enumerator in 'EnumZeroFirstInitialValue' can be disregarded |
70 | // CHECK-FIXES-ENABLE: EnumZeroFirstInitialValue_0 , |
71 | EnumZeroFirstInitialValue_1, |
72 | EnumZeroFirstInitialValue_2, |
73 | }; |
74 | |
75 | enum { |
76 | = /* == */ 0, |
77 | // CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:3: warning: zero initial value for the first enumerator in 'EnumZeroFirstInitialValueWithComment' can be disregarded |
78 | // CHECK-FIXES-ENABLE: EnumZeroFirstInitialValueWithComment_0 /* == */ , |
79 | , |
80 | , |
81 | }; |
82 | |
83 | enum EnumSequentialInitialValue { |
84 | // CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:1: warning: sequential initial value in 'EnumSequentialInitialValue' can be ignored |
85 | EnumSequentialInitialValue_0 = 2, |
86 | // CHECK-FIXES-ENABLE: EnumSequentialInitialValue_0 = 2, |
87 | EnumSequentialInitialValue_1 = 3, |
88 | // CHECK-FIXES-ENABLE: EnumSequentialInitialValue_1 , |
89 | EnumSequentialInitialValue_2 = 4, |
90 | // CHECK-FIXES-ENABLE: EnumSequentialInitialValue_2 , |
91 | }; |
92 | |
93 | // gh107590 |
94 | enum WithFwdDeclInconsistent : int; |
95 | |
96 | enum WithFwdDeclInconsistent : int { |
97 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'WithFwdDeclInconsistent' are not consistent |
98 | // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 'WithFwdDeclInconsistent' are not consistent |
99 | EFI0, |
100 | // CHECK-FIXES: EFI0 = 0, |
101 | EFI1 = 1, |
102 | EFI2, |
103 | // CHECK-FIXES: EFI2 = 2, |
104 | }; |
105 | |
106 | enum WithFwdDeclZeroFirst : int; |
107 | |
108 | enum WithFwdDeclZeroFirst : int { |
109 | // CHECK-MESSAGES-ENABLE: :[[@LINE+1]]:3: warning: zero initial value for the first enumerator in 'WithFwdDeclZeroFirst' can be disregarded |
110 | EFZ0 = 0, |
111 | // CHECK-FIXES-ENABLE: EFZ0 , |
112 | EFZ1, |
113 | EFZ2, |
114 | }; |
115 | |
116 | |
117 | enum WithFwdDeclSequential : int; |
118 | |
119 | enum WithFwdDeclSequential : int { |
120 | // CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:1: warning: sequential initial value in 'WithFwdDeclSequential' can be ignored |
121 | EFS0 = 2, |
122 | // CHECK-FIXES-ENABLE: EFS0 = 2, |
123 | EFS1 = 3, |
124 | // CHECK-FIXES-ENABLE: EFS1 , |
125 | EFS2 = 4, |
126 | // CHECK-FIXES-ENABLE: EFS2 , |
127 | }; |
128 | |