xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/switch-implicit-fallthrough-per-method.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough-per-function %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc 
fallthrough(int n)4*f4a2713aSLionel Sambuc int fallthrough(int n) {
5*f4a2713aSLionel Sambuc   switch (n / 10) {
6*f4a2713aSLionel Sambuc     case 0:
7*f4a2713aSLionel Sambuc       n += 100;
8*f4a2713aSLionel Sambuc     case 1:  // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
9*f4a2713aSLionel Sambuc       switch (n) {
10*f4a2713aSLionel Sambuc       case 111:
11*f4a2713aSLionel Sambuc         n += 111;
12*f4a2713aSLionel Sambuc         [[clang::fallthrough]];
13*f4a2713aSLionel Sambuc       case 112:
14*f4a2713aSLionel Sambuc         n += 112;
15*f4a2713aSLionel Sambuc       case 113:  // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
16*f4a2713aSLionel Sambuc         n += 113;
17*f4a2713aSLionel Sambuc         break    ;
18*f4a2713aSLionel Sambuc       }
19*f4a2713aSLionel Sambuc   }
20*f4a2713aSLionel Sambuc   return n;
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
fallthrough2(int n)23*f4a2713aSLionel Sambuc int fallthrough2(int n) {
24*f4a2713aSLionel Sambuc   switch (n / 10) {
25*f4a2713aSLionel Sambuc     case 0:
26*f4a2713aSLionel Sambuc       n += 100;
27*f4a2713aSLionel Sambuc     case 1:  // no warning, as we didn't "opt-in" for it in this method
28*f4a2713aSLionel Sambuc       switch (n) {
29*f4a2713aSLionel Sambuc       case 111:
30*f4a2713aSLionel Sambuc         n += 111;
31*f4a2713aSLionel Sambuc       case 112:  // no warning, as we didn't "opt-in" for it in this method
32*f4a2713aSLionel Sambuc         n += 112;
33*f4a2713aSLionel Sambuc       case 113:  // no warning, as we didn't "opt-in" for it in this method
34*f4a2713aSLionel Sambuc         n += 113;
35*f4a2713aSLionel Sambuc         break    ;
36*f4a2713aSLionel Sambuc       }
37*f4a2713aSLionel Sambuc   }
38*f4a2713aSLionel Sambuc   return n;
39*f4a2713aSLionel Sambuc }
40*f4a2713aSLionel Sambuc 
unscoped(int n)41*f4a2713aSLionel Sambuc void unscoped(int n) {
42*f4a2713aSLionel Sambuc   switch (n % 2) {
43*f4a2713aSLionel Sambuc     case 0:
44*f4a2713aSLionel Sambuc       // FIXME: This should be typo-corrected, probably.
45*f4a2713aSLionel Sambuc       [[fallthrough]]; // expected-warning{{unknown attribute 'fallthrough' ignored}}
46*f4a2713aSLionel Sambuc     case 2: // expected-warning{{unannotated fall-through}} expected-note{{clang::fallthrough}} expected-note{{break;}}
47*f4a2713aSLionel Sambuc       [[clang::fallthrough]];
48*f4a2713aSLionel Sambuc     case 1:
49*f4a2713aSLionel Sambuc       break;
50*f4a2713aSLionel Sambuc   }
51*f4a2713aSLionel Sambuc }
52