1 // RUN: %clang_cc1 -fsyntax-only -verify %s
6 switch (a
) { // expected-error{{use of undeclared identifier 'a'}}
12 case 17 // expected-error{{expected ':' after 'case'}}
15 default // expected-error{{expected ':' after 'default'}}
23 switch (x
) { // expected-warning {{enumeration value 'Xb' not handled in switch}}
24 case Xa
; // expected-error {{expected ':' after 'case'}}
29 default; // expected-error {{expected ':' after 'default'}}
37 2: return 1; // expected-error {{expected 'case' keyword before expression}}
45 1: return -1; // expected-error {{expected 'case' keyword before expression}}
51 case 1: case 2: case 3: return 1;
53 4:5:6:7: return 2; // expected-error 4{{expected 'case' keyword before expression}}
63 // This class provides extra single colon tokens. Make sure no
64 // errors are seen here.
71 5: // expected-error {{expected 'case' keyword before expression}}
79 true ? 1 : 2: // expected-error {{expected 'case' keyword before expression}}
81 14 ? 3 : 4; // expected-warning {{expression result unused}}
90 A
: return 0; // FIXME: give a warning for unused labels that could also be
96 // Stress test to make sure Clang doesn't crash.
97 void test9(int x
) { // expected-note {{'x' declared here}}
100 2: case; // expected-error {{expected 'case' keyword before expression}} \
101 expected
-error
{{expected expression
}}
102 4:5:6: return; // expected-error 3{{expected 'case' keyword before expression}}
103 7: :x
; // expected-error {{expected 'case' keyword before expression}} \
104 expected
-error
{{expected expression
}}
105 8:: x
; // expected-error {{expected ';' after expression}} \
106 expected
-error
{{no member named
'x' in the global
namespace; did you mean simply
'x'?}} \
107 expected
-warning
{{expression result unused
}}
108 9:: :y
; // expected-error {{expected ';' after expression}} \
109 expected
-error
{{expected unqualified
-id
}} \
110 expected
-warning
{{expression result unused
}}
111 :; // expected-error {{expected expression}}
112 ::; // expected-error {{expected unqualified-id}}
121 2: y
++; // expected-error {{expected ';' after expression}} \
122 // expected-warning {{expression result unused}}
136 E
: break; // FIXME: give a 'case' fix-it for unused labels that
137 // could also be an expression an a case label.
138 E
+1: break; // expected-error {{expected 'case' keyword before expression}}
145 0: // expected-error {{expected 'case' keyword before expression}}
147 1: // expected-error {{expected 'case' keyword before expression}}
149 2: // expected-error {{expected 'case' keyword before expression}}
151 3: // expected-error {{expected 'case' keyword before expression}}
159 void missing_statement_case(int x
) {
163 } // expected-warning {{label at end of compound statement is a C++23 extension}}
166 void missing_statement_default(int x
) {
170 } // expected-warning {{label at end of compound statement is a C++23 extension}}
174 switch (int x
) // expected-error {{variable declaration in condition must have an initializer}}
175 case v
: ; // expected-error {{use of undeclared identifier 'v'}}
178 void pr19022_1a(int x
) {
180 case 1 // expected-error{{expected ':' after 'case'}}
181 } // expected-warning {{label at end of compound statement is a C++23 extension}}
184 void pr19022_1b(int x
) {
186 case v
// expected-error{{use of undeclared identifier 'v'}} \
187 // expected-error{{expected ':' after 'case'}}
188 } // expected-error{{expected statement}}
192 switch (int x
) // expected-error {{variable declaration in condition must have an initializer}}
193 case v1
: case v2
: ; // expected-error {{use of undeclared identifier 'v1'}} \
194 // expected-error {{use of undeclared identifier 'v2'}}
197 void pr19022_3(int x
) {
199 case 1: case v2
: ; // expected-error {{use of undeclared identifier 'v2'}}
202 int pr19022_4(int x
) {
204 case 1 // expected-error{{expected ':' after 'case'}} expected-note{{previous case defined here}}
205 case 1 : return x
; // expected-error{{duplicate case value '1'}}
209 void pr19022_5(int x
) {
211 case 1: case // expected-error{{expected ':' after 'case'}}
212 } // expected-error{{expected expression}} \
213 // expected-warning {{label at end of compound statement is a C++23 extension}}
219 switch (int foo0
) //expected-error{{variable declaration in condition must have an initializer}}
220 case bar5
: ; // expected-error{{use of undeclared identifier 'bar5'}}
227 switch (0 // expected-note{{to match this '('}}
228 { // expected-error{{expected ')'}}
230 } // expected-error{{expected statement}}