154 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] -DUNCHOSEN=[[fallthrough]] %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s4// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s5// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] -DUNCHOSEN=[[clang::fallthrough]] %s6 7int fallthrough_compatibility_macro_from_command_line(int n) {8 switch (n) {9 case 0:10 n = n * 10;11 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'COMMAND_LINE_FALLTHROUGH;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}12 ;13 }14 return n;15}16 17#ifdef CLANG_PREFIX18#define COMPATIBILITY_FALLTHROUGH [ [ /* test */ clang /* test */ \19 :: fallthrough ] ] // testing whitespace and comments in macro definition20#else21#define COMPATIBILITY_FALLTHROUGH [ [ /* test */ /* test */ \22 fallthrough ] ] // testing whitespace and comments in macro definition23#endif24 25int fallthrough_compatibility_macro_from_source(int n) {26 switch (n) {27 case 0:28 n = n * 20;29 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'COMPATIBILITY_FALLTHROUGH;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}30 ;31 }32 return n;33}34 35// Deeper macro substitution36#ifdef CLANG_PREFIX37#define M1 [[clang::fallthrough]]38#else39#define M1 [[fallthrough]]40#endif41#ifdef __clang__42#define M2 M143#else44#define M245#endif46 47#define WRONG_MACRO1 clang::fallthrough48#define WRONG_MACRO2 [[clang::fallthrough]49#define WRONG_MACRO3 [[clang::fall through]]50#define WRONG_MACRO4 [[clang::fallthrough]]]51 52int fallthrough_compatibility_macro_in_macro(int n) {53 switch (n) {54 case 0:55 n = n * 20;56 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'M1;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}57 // there was an idea that this ^ should be M258 ;59 }60 return n;61}62 63#undef M164#undef M265#undef COMPATIBILITY_FALLTHROUGH66#undef COMMAND_LINE_FALLTHROUGH67#undef UNCHOSEN68 69int fallthrough_compatibility_macro_undefined(int n) {70 switch (n) {71 case 0:72 n = n * 20;73#if __cplusplus <= 201402L74 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}75#else76 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}77#endif78 ;79 }80#define TOO_LATE [[clang::fallthrough]]81 return n;82}83#undef TOO_LATE84 85#define MACRO_WITH_HISTORY 1111111186#undef MACRO_WITH_HISTORY87#define MACRO_WITH_HISTORY [[clang::fallthrough]]88#undef MACRO_WITH_HISTORY89#define MACRO_WITH_HISTORY 222222290 91int fallthrough_compatibility_macro_history(int n) {92 switch (n) {93 case 0:94 n = n * 20;95#undef MACRO_WITH_HISTORY96#if __cplusplus <= 201402L97 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}98#else99 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}100#endif101 ;102#define MACRO_WITH_HISTORY [[clang::fallthrough]]103 }104 return n;105}106 107#undef MACRO_WITH_HISTORY108#define MACRO_WITH_HISTORY 11111111109#undef MACRO_WITH_HISTORY110#define MACRO_WITH_HISTORY [[clang::fallthrough]]111#undef MACRO_WITH_HISTORY112#define MACRO_WITH_HISTORY 2222222113#undef MACRO_WITH_HISTORY114 115int fallthrough_compatibility_macro_history2(int n) {116 switch (n) {117 case 0:118 n = n * 20;119#define MACRO_WITH_HISTORY [[clang::fallthrough]]120 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'MACRO_WITH_HISTORY;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}121 ;122#undef MACRO_WITH_HISTORY123#define MACRO_WITH_HISTORY 3333333124#undef MACRO_WITH_HISTORY125#define MACRO_WITH_HISTORY 4444444126#undef MACRO_WITH_HISTORY127#define MACRO_WITH_HISTORY 5555555128 }129 return n;130}131 132template<const int N>133int fallthrough_compatibility_macro_history_template(int n) {134 switch (N * n) {135 case 0:136 n = n * 20;137#define MACRO_WITH_HISTORY2 [[clang::fallthrough]]138 case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'MACRO_WITH_HISTORY2;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}139 ;140#undef MACRO_WITH_HISTORY2141#define MACRO_WITH_HISTORY2 3333333142 }143 return n;144}145 146#undef MACRO_WITH_HISTORY2147#define MACRO_WITH_HISTORY2 4444444148#undef MACRO_WITH_HISTORY2149#define MACRO_WITH_HISTORY2 5555555150 151void f() {152 fallthrough_compatibility_macro_history_template<1>(0); // expected-note{{in instantiation of function template specialization 'fallthrough_compatibility_macro_history_template<1>' requested here}}153}154