| 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: inital values in enum 'EError' are not consistent |
| 10 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital 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: inital values in enum 'EMacro1' are not consistent |
| 38 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital 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: inital values in enum 'EMacro2' are not consistent |
| 49 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital 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 |
enum EnumZeroFirstInitialValue { |
| 57 |
EnumZeroFirstInitialValue_0 = 0, |
| 58 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:3: warning: zero initial value for the first enumerator in 'EnumZeroFirstInitialValue' can be disregarded |
| 59 |
// CHECK-FIXES-ENABLE: EnumZeroFirstInitialValue_0 , |
| 60 |
EnumZeroFirstInitialValue_1, |
| 61 |
EnumZeroFirstInitialValue_2, |
| 62 |
}; |
| 63 |
|
| 64 |
enum EnumZeroFirstInitialValueWithComment { |
| 65 |
EnumZeroFirstInitialValueWithComment_0 = /* == */ 0, |
| 66 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:3: warning: zero initial value for the first enumerator in 'EnumZeroFirstInitialValueWithComment' can be disregarded |
| 67 |
// CHECK-FIXES-ENABLE: EnumZeroFirstInitialValueWithComment_0 /* == */ , |
| 68 |
EnumZeroFirstInitialValueWithComment_1, |
| 69 |
EnumZeroFirstInitialValueWithComment_2, |
| 70 |
}; |
| 71 |
|
| 72 |
enum EnumSequentialInitialValue { |
| 73 |
// CHECK-MESSAGES-ENABLE: :[[@LINE-1]]:1: warning: sequential initial value in 'EnumSequentialInitialValue' can be ignored |
| 74 |
EnumSequentialInitialValue_0 = 2, |
| 75 |
// CHECK-FIXES-ENABLE: EnumSequentialInitialValue_0 = 2, |
| 76 |
EnumSequentialInitialValue_1 = 3, |
| 77 |
// CHECK-FIXES-ENABLE: EnumSequentialInitialValue_1 , |
| 78 |
EnumSequentialInitialValue_2 = 4, |
| 79 |
// CHECK-FIXES-ENABLE: EnumSequentialInitialValue_2 , |
| 80 |
}; |