brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 8b24c4a Raw
123 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s2// XFAIL: *3 4// NOTE: This test is marked XFAIL until we come up with a good language design5// for a worfklow to use this warning outside of C++11.6 7int fallthrough(int n) {8  switch (n / 10) {9      if (n - 1) {10        n = 100;11      } else if (n - 2) {12        n = 101;13      } else if (n - 3) {14        n = 102;15      }16    case -1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}17      ;18    case 0: {// expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}19    }20    case 1:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}21      n += 100         ;22    case 3:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}23      if (n > 0)24        n += 200;25    case 4:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}26      if (n < 0)27        ;28    case 5:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}29      switch (n) {30      case 111:31        break;32      case 112:33        break;34      case 113:35        break    ;36      }37    case 6:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}38      n += 300;39  }40  switch (n / 30) {41    case 11:42    case 12:  // no warning here, intended fall-through, no statement between labels43      n += 1600;44  }45  switch (n / 40) {46    case 13:47      if (n % 2 == 0) {48        return 1;49      } else {50        return 2;51      }52    case 15:  // no warning here, there's no fall-through53      n += 3200;54  }55  switch (n / 50) {56    case 17: {57      if (n % 2 == 0) {58        return 1;59      } else {60        return 2;61      }62    }63    case 19: { // no warning here, there's no fall-through64      n += 6400;65      return 3;66    }67    case 21: { // no warning here, there's no fall-through68      break;69    }70    case 23: // no warning here, there's no fall-through71      n += 128000;72      break;73    case 25: // no warning here, there's no fall-through74      break;75  }76 77  return n;78}79 80class ClassWithDtor {81public:82  ~ClassWithDtor() {}83};84 85void fallthrough2(int n) {86  switch (n) {87    case 0:88    {89      ClassWithDtor temp;90      break;91    }92    default: // no warning here, there's no fall-through93      break;94  }95}96 97#define MY_SWITCH(X, Y, Z, U, V) switch (X) { case Y: Z; case U: V; }98#define MY_SWITCH2(X, Y, Z) switch (X) { Y; Z; }99#define MY_CASE(X, Y) case X: Y100#define MY_CASE2(X, Y, U, V) case X: Y; case U: V101 102int fallthrough_macro1(int n) {103  MY_SWITCH(n, 13, n *= 2, 14, break)  // expected-warning{{unannotated fall-through between switch labels}}104 105  switch (n + 1) {106    MY_CASE(33, n += 2);107    MY_CASE(44, break);  // expected-warning{{unannotated fall-through between switch labels}}108    MY_CASE(55, n += 3);109  }110 111  switch (n + 3) {112    MY_CASE(333, return 333);113    MY_CASE2(444, n += 44, 4444, break);  // expected-warning{{unannotated fall-through between switch labels}}114    MY_CASE(555, n += 33);115  }116 117  MY_SWITCH2(n + 4, MY_CASE(17, n *= 3), MY_CASE(19, break))  // expected-warning{{unannotated fall-through between switch labels}}118 119  MY_SWITCH2(n + 5, MY_CASE(21, break), MY_CASE2(23, n *= 7, 25, break))  // expected-warning{{unannotated fall-through between switch labels}}120 121  return n;122}123