brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 14e83c8 Raw
81 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case %t -- -- -fno-delayed-template-parsing2 3typedef int MyInt;4enum EnumType { eE2 };5typedef EnumType MyEnum;6 7void positive() {8  int I1 = 0;9  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]10  switch (I1) {11  case 0:12    break;13  }14 15  MyInt I2 = 0;16  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]17  switch (I2) {18  case 0:19    break;20  }21 22  int getValue(void);23  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]24  switch (getValue()) {25  case 0:26    break;27  }28}29 30void negative() {31  enum E { eE1 };32  E E1 = eE1;33  switch (E1) { // no-warning34  case eE1:35    break;36  }37 38  MyEnum E2 = eE2;39  switch (E2) { // no-warning40  case eE2:41    break;42  }43 44  int I1 = 0;45  switch (I1) { // no-warning46  case 0:47    break;48  default:49    break;50  }51 52  MyInt I2 = 0;53  switch (I2) { // no-warning54  case 0:55    break;56  default:57    break;58  }59 60  int getValue(void);61  switch (getValue()) { // no-warning62  case 0:63    break;64    default:65    break;66  }67}68 69template<typename T>70void testTemplate(T Value) {71  switch (Value) {72    case 0:73      break;74  }75}76 77void exampleUsage() {78  testTemplate(5);79  testTemplate(EnumType::eE2);80}81