1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s
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
) {
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}}
22 case 3: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
25 case 4: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
28 case 5: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
37 case 6: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}}
42 case 12: // no warning here, intended fall-through, no statement between labels
52 case 15: // no warning here, there's no fall-through
63 case 19: { // no warning here, there's no fall-through
67 case 21: { // no warning here, there's no fall-through
70 case 23: // no warning here, there's no fall-through
73 case 25: // no warning here, there's no fall-through
85 void fallthrough2(int n
) {
92 default: // no warning here, there's no fall-through
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}}
107 MY_CASE(44, break); // expected-warning{{unannotated fall-through between switch labels}}
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}}