1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s
2 
3 
4 int fallthrough(int n) {
5   switch (n / 10) {
6       if (n - 1) {
7         n = 100;
8       } else if (n - 2) {
9         n = 101;
10       } else if (n - 3) {
11         n = 102;
12       }
13     case -1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
14       ;
15     case 0: {// expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
16     }
17     case 1:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
18       n += 100         ;
19     case 3:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
20       if (n > 0)
21         n += 200;
22     case 4:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
23       if (n < 0)
24         ;
25     case 5:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
26       switch (n) {
27       case 111:
28         break;
29       case 112:
30         break;
31       case 113:
32         break    ;
33       }
34     case 6:  // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
35       n += 300;
36   }
37   switch (n / 30) {
38     case 11:
39     case 12:  // no warning here, intended fall-through, no statement between labels
40       n += 1600;
41   }
42   switch (n / 40) {
43     case 13:
44       if (n % 2 == 0) {
45         return 1;
46       } else {
47         return 2;
48       }
49     case 15:  // no warning here, there's no fall-through
50       n += 3200;
51   }
52   switch (n / 50) {
53     case 17: {
54       if (n % 2 == 0) {
55         return 1;
56       } else {
57         return 2;
58       }
59     }
60     case 19: { // no warning here, there's no fall-through
61       n += 6400;
62       return 3;
63     }
64     case 21: { // no warning here, there's no fall-through
65       break;
66     }
67     case 23: // no warning here, there's no fall-through
68       n += 128000;
69       break;
70     case 25: // no warning here, there's no fall-through
71       break;
72   }
73 
74   return n;
75 }
76 
77 class ClassWithDtor {
78 public:
79   ~ClassWithDtor() {}
80 };
81 
82 void fallthrough2(int n) {
83   switch (n) {
84     case 0:
85     {
86       ClassWithDtor temp;
87       break;
88     }
89     default: // no warning here, there's no fall-through
90       break;
91   }
92 }
93 
94 #define MY_SWITCH(X, Y, Z, U, V) switch (X) { case Y: Z; case U: V; }
95 #define MY_SWITCH2(X, Y, Z) switch (X) { Y; Z; }
96 #define MY_CASE(X, Y) case X: Y
97 #define MY_CASE2(X, Y, U, V) case X: Y; case U: V
98 
99 int fallthrough_macro1(int n) {
100   MY_SWITCH(n, 13, n *= 2, 14, break)  // expected-warning{{unannotated fall-through between switch labels}}
101 
102   switch (n + 1) {
103     MY_CASE(33, n += 2);
104     MY_CASE(44, break);  // expected-warning{{unannotated fall-through between switch labels}}
105     MY_CASE(55, n += 3);
106   }
107 
108   switch (n + 3) {
109     MY_CASE(333, return 333);
110     MY_CASE2(444, n += 44, 4444, break);  // expected-warning{{unannotated fall-through between switch labels}}
111     MY_CASE(555, n += 33);
112   }
113 
114   MY_SWITCH2(n + 4, MY_CASE(17, n *= 3), MY_CASE(19, break))  // expected-warning{{unannotated fall-through between switch labels}}
115 
116   MY_SWITCH2(n + 5, MY_CASE(21, break), MY_CASE2(23, n *= 7, 25, break))  // expected-warning{{unannotated fall-through between switch labels}}
117 
118   return n;
119 }
120