Home | History | Annotate | Download | only in SemaCXX
      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       // FIXME: This should be typo-corrected, probably.
     45       [[fallthrough]]; // expected-warning{{unknown attribute 'fallthrough' ignored}}
     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 }
     52