================
@@ -0,0 +1,73 @@
+// RUN: %check_clang_tidy %s readability-enum-initial-value %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN:
readability-enum-initial-value.AllowConsecutiveInitialValuesExceptLast: true, \
+// RUN: }}'
+
+// OK: consecutive except last, starting at zero.
+enum class EConsecutive {
+ EConsecutive_a = 0,
+ EConsecutive_b = 1,
+ EConsecutive_c = 2,
+ EConsecutive_size,
+};
+
+// OK: consecutive except last, with a non-zero starting offset.
+enum class EConsecutiveOffset {
+ EConsecutiveOffset_a = 10,
+ EConsecutiveOffset_b = 11,
+ EConsecutiveOffset_c = 12,
+ EConsecutiveOffset_size,
+};
+
+// OK: consecutive except last, with negative values.
+enum class EConsecutiveNegative {
+ EConsecutiveNegative_a = -2,
+ EConsecutiveNegative_b = -1,
+ EConsecutiveNegative_c = 0,
+ EConsecutiveNegative_size,
+};
+
+// OK: minimal case, only two enumerators.
+enum class EConsecutiveMinimal {
+ EConsecutiveMinimal_a = 5,
+ EConsecutiveMinimal_size,
+};
+
+// Error: not consecutive (gap between b and c).
+enum class EConsecutiveBreak {
+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum
'EConsecutiveBreak' are not consistent
+ EConsecutiveBreak_a = 0,
+ EConsecutiveBreak_b = 1,
+ EConsecutiveBreak_c = 3,
+ EConsecutiveBreak_size,
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: note: uninitialized enumerator
'EConsecutiveBreak_size' defined here
+ // CHECK-FIXES: EConsecutiveBreak_size = 4,
+};
+
+// Error: one of the "except last" enumerators is left uninitialized, so the
+// remaining explicit values are not consecutive with each other.
+enum class EConsecutiveGap {
+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum
'EConsecutiveGap' are not consistent
+ EConsecutiveGap_a = 0,
+ EConsecutiveGap_b,
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: note: uninitialized enumerator
'EConsecutiveGap_b' defined here
+ // CHECK-FIXES: EConsecutiveGap_b = 1,
+ EConsecutiveGap_c = 2,
+ EConsecutiveGap_size,
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: note: uninitialized enumerator
'EConsecutiveGap_size' defined here
+ // CHECK-FIXES: EConsecutiveGap_size = 3,
+};
+
+// Error: the last enumerator is also explicitly initialized (the
----------------
zeyi2 wrote:
Nit: Could we trim this comment down? In general, we keep comments minimal in
clang-tidy tests and rely on `// CHECK` directives to document the expected
behavior.
https://github.com/llvm/llvm-project/pull/228399
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits