blob: 009c8180b1bb877e8b9a77946516001daaf92357 [file] [log] [blame]
Sean Huntc2f51cf2012-06-15 21:22:05 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough-per-function %s
Alexander Kornienko19736342012-06-02 01:01:07 +00002
3
4int fallthrough(int n) {
5 switch (n / 10) {
6 case 0:
7 n += 100;
Sean Huntc2f51cf2012-06-15 21:22:05 +00008 case 1: // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
Alexander Kornienko19736342012-06-02 01:01:07 +00009 switch (n) {
10 case 111:
11 n += 111;
12 [[clang::fallthrough]];
13 case 112:
14 n += 112;
Sean Huntc2f51cf2012-06-15 21:22:05 +000015 case 113: // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
Alexander Kornienko19736342012-06-02 01:01:07 +000016 n += 113;
17 break ;
18 }
19 }
20 return n;
21}
22
23int fallthrough2(int n) {
24 switch (n / 10) {
25 case 0:
26 n += 100;
27 case 1: // no warning, as we didn't "opt-in" for it in this method
28 switch (n) {
29 case 111:
30 n += 111;
31 case 112: // no warning, as we didn't "opt-in" for it in this method
32 n += 112;
33 case 113: // no warning, as we didn't "opt-in" for it in this method
34 n += 113;
35 break ;
36 }
37 }
38 return n;
39}
Sean Hunt93f95f22012-06-18 16:13:52 +000040
41void unscoped(int n) {
42 switch (n % 2) {
43 case 0:
44 // FIXME: This should be typo-corrected, probably.
Michael Han6880f492012-10-03 01:56:22 +000045 [[fallthrough]]; // expected-warning{{unknown attribute 'fallthrough' ignored}}
Sean Hunt93f95f22012-06-18 16:13:52 +000046 case 2: // expected-warning{{unannotated fall-through}} expected-note{{clang::fallthrough}} expected-note{{break;}}
47 [[clang::fallthrough]];
48 case 1:
49 break;
50 }
51}