[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / switch-implicit-fallthrough-cxx98.cpp
blob8b24c4a3b1304a2964c6fdb2004af705fee7dec7
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s
2 // XFAIL: *
4 // NOTE: This test is marked XFAIL until we come up with a good language design
5 // for a worfklow to use this warning outside of C++11.
7 int 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;
16 case -1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
18 case 0: {// expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
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)
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 ;
37 case 6: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
38 n += 300;
40 switch (n / 30) {
41 case 11:
42 case 12: // no warning here, intended fall-through, no statement between labels
43 n += 1600;
45 switch (n / 40) {
46 case 13:
47 if (n % 2 == 0) {
48 return 1;
49 } else {
50 return 2;
52 case 15: // no warning here, there's no fall-through
53 n += 3200;
55 switch (n / 50) {
56 case 17: {
57 if (n % 2 == 0) {
58 return 1;
59 } else {
60 return 2;
63 case 19: { // no warning here, there's no fall-through
64 n += 6400;
65 return 3;
67 case 21: { // no warning here, there's no fall-through
68 break;
70 case 23: // no warning here, there's no fall-through
71 n += 128000;
72 break;
73 case 25: // no warning here, there's no fall-through
74 break;
77 return n;
80 class ClassWithDtor {
81 public:
82 ~ClassWithDtor() {}
85 void fallthrough2(int n) {
86 switch (n) {
87 case 0:
89 ClassWithDtor temp;
90 break;
92 default: // no warning here, there's no fall-through
93 break;
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: Y
100 #define MY_CASE2(X, Y, U, V) case X: Y; case U: V
102 int fallthrough_macro1(int n) {
103 MY_SWITCH(n, 13, n *= 2, 14, break) // expected-warning{{unannotated fall-through between switch labels}}
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);
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);
117 MY_SWITCH2(n + 4, MY_CASE(17, n *= 3), MY_CASE(19, break)) // expected-warning{{unannotated fall-through between switch labels}}
119 MY_SWITCH2(n + 5, MY_CASE(21, break), MY_CASE2(23, n *= 7, 25, break)) // expected-warning{{unannotated fall-through between switch labels}}
121 return n;