Sean Hunt | c2f51cf | 2012-06-15 21:22:05 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough-per-function %s |
Alexander Kornienko | 1973634 | 2012-06-02 01:01:07 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | int fallthrough(int n) { |
| 5 | switch (n / 10) { |
| 6 | case 0: |
| 7 | n += 100; |
Sean Hunt | c2f51cf | 2012-06-15 21:22:05 +0000 | [diff] [blame] | 8 | 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 Kornienko | 1973634 | 2012-06-02 01:01:07 +0000 | [diff] [blame] | 9 | switch (n) { |
| 10 | case 111: |
| 11 | n += 111; |
| 12 | [[clang::fallthrough]]; |
| 13 | case 112: |
| 14 | n += 112; |
Sean Hunt | c2f51cf | 2012-06-15 21:22:05 +0000 | [diff] [blame] | 15 | 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 Kornienko | 1973634 | 2012-06-02 01:01:07 +0000 | [diff] [blame] | 16 | n += 113; |
| 17 | break ; |
| 18 | } |
| 19 | } |
| 20 | return n; |
| 21 | } |
| 22 | |
| 23 | int 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 Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame] | 40 | |
| 41 | void unscoped(int n) { |
| 42 | switch (n % 2) { |
| 43 | case 0: |
| 44 | // FIXME: This should be typo-corrected, probably. |
Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 45 | [[fallthrough]]; // expected-warning{{unknown attribute 'fallthrough' ignored}} |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame] | 46 | case 2: // expected-warning{{unannotated fall-through}} expected-note{{clang::fallthrough}} expected-note{{break;}} |
| 47 | [[clang::fallthrough]]; |
| 48 | case 1: |
| 49 | break; |
| 50 | } |
| 51 | } |