| 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough-per-function %s |
| 2 | |
| 3 | |
| 4 | int fallthrough(int n) { |
| 5 | switch (n / 10) { |
| 6 | case 0: |
| 7 | n += 100; |
| 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}} |
| 9 | switch (n) { |
| 10 | case 111: |
| 11 | n += 111; |
| 12 | [[clang::fallthrough]]; |
| 13 | case 112: |
| 14 | n += 112; |
| 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}} |
| 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 | } |
| 40 | |
| 41 | void unscoped(int n) { |
| 42 | switch (n % 2) { |
| 43 | case 0: |
| 44 | [[fallthrough]]; |
| 45 | case 2: |
| 46 | [[clang::fallthrough]]; |
| 47 | case 1: |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |