1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] -DUNCHOSEN=[[fallthrough]] %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
4 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
5 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] -DUNCHOSEN=[[clang::fallthrough]] %s
7 int fallthrough_compatibility_macro_from_command_line(int n
) {
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}}
18 #define COMPATIBILITY_FALLTHROUGH [ [ /* test */ clang /* test */ \
19 :: fallthrough ] ] // testing whitespace and comments in macro definition
21 #define COMPATIBILITY_FALLTHROUGH [ [ /* test */ /* test */ \
22 fallthrough ] ] // testing whitespace and comments in macro definition
25 int fallthrough_compatibility_macro_from_source(int n
) {
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}}
35 // Deeper macro substitution
37 #define M1 [[clang::fallthrough]]
39 #define M1 [[fallthrough]]
47 #define WRONG_MACRO1 clang::fallthrough
48 #define WRONG_MACRO2 [[clang::fallthrough]
49 #define WRONG_MACRO3 [[clang::fall through]]
50 #define WRONG_MACRO4 [[clang::fallthrough]]]
52 int fallthrough_compatibility_macro_in_macro(int n
) {
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 M2
65 #undef COMPATIBILITY_FALLTHROUGH
66 #undef COMMAND_LINE_FALLTHROUGH
69 int fallthrough_compatibility_macro_undefined(int n
) {
73 #if __cplusplus <= 201402L
74 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}}
76 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}}
80 #define TOO_LATE [[clang::fallthrough]]
85 #define MACRO_WITH_HISTORY 11111111
86 #undef MACRO_WITH_HISTORY
87 #define MACRO_WITH_HISTORY [[clang::fallthrough]]
88 #undef MACRO_WITH_HISTORY
89 #define MACRO_WITH_HISTORY 2222222
91 int fallthrough_compatibility_macro_history(int n
) {
95 #undef MACRO_WITH_HISTORY
96 #if __cplusplus <= 201402L
97 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}}
99 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}}
102 #define MACRO_WITH_HISTORY [[clang::fallthrough]]
107 #undef MACRO_WITH_HISTORY
108 #define MACRO_WITH_HISTORY 11111111
109 #undef MACRO_WITH_HISTORY
110 #define MACRO_WITH_HISTORY [[clang::fallthrough]]
111 #undef MACRO_WITH_HISTORY
112 #define MACRO_WITH_HISTORY 2222222
113 #undef MACRO_WITH_HISTORY
115 int fallthrough_compatibility_macro_history2(int n
) {
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}}
122 #undef MACRO_WITH_HISTORY
123 #define MACRO_WITH_HISTORY 3333333
124 #undef MACRO_WITH_HISTORY
125 #define MACRO_WITH_HISTORY 4444444
126 #undef MACRO_WITH_HISTORY
127 #define MACRO_WITH_HISTORY 5555555
132 template<const int N
>
133 int fallthrough_compatibility_macro_history_template(int n
) {
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}}
140 #undef MACRO_WITH_HISTORY2
141 #define MACRO_WITH_HISTORY2 3333333
146 #undef MACRO_WITH_HISTORY2
147 #define MACRO_WITH_HISTORY2 4444444
148 #undef MACRO_WITH_HISTORY2
149 #define MACRO_WITH_HISTORY2 5555555
152 fallthrough_compatibility_macro_history_template
<1>(0); // expected-note{{in instantiation of function template specialization 'fallthrough_compatibility_macro_history_template<1>' requested here}}