1 // RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default -triple x86_64-linux-gnu %s
4 default: z
--; // expected-error {{statement not in switch}}
10 case 42: ; // expected-note {{previous case}}
11 case 5000000000LL: // expected-warning {{overflow}}
12 case 42: // expected-error {{duplicate case value '42'}}
15 case 100 ... 99: ; // expected-warning {{empty case range}}
17 case 43: ; // expected-note {{previous case}}
18 case 43 ... 45: ; // expected-error {{duplicate case value}}
20 case 100 ... 20000:; // expected-note {{previous case}}
21 case 15000 ... 40000000:; // expected-error {{duplicate case value}}
27 switch (0); // expected-warning {{no case matching constant switch condition '0'}} \
28 // expected-warning {{switch statement has empty body}} \
29 // expected-note{{put the semicolon on a separate line to silence this warning}}
44 case g(): // expected-error {{expression is not an integer constant expression}}
45 case 0 ... g(): // expected-error {{expression is not an integer constant expression}}
50 case 0 && g() ... 1 || g():
55 case g() // expected-error {{expression is not an integer constant expression}}
62 g() // expected-error {{expression is not an integer constant expression}}
70 default: // expected-note {{previous case defined here}}
71 default: // expected-error {{multiple default labels in one switch}}
79 case 1234: // expected-warning {{overflow converting case value}}
86 switch (va
) { // expected-error{{use of undeclared identifier 'va'}}
100 switch(a
) { //expected-warning{{enumeration value 'B' not handled in switch}}
112 case 3: // expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
118 case 3 ... //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
119 4: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
127 case 0 ... 2: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
131 case 1 ... 3: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
135 case 0 ... //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
136 3: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
158 switch(a
) { //expected-warning{{enumeration value 'B' not handled in switch}}
170 case 0: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
172 case 2: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
174 case 4: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
187 case 0 ... //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
188 1: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
190 case 5 ... //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
191 9: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
193 case 13 ... //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
194 16: //expected-warning{{case value not in enumerated type 'enum (unnamed enum}}
205 switch(a
) { //expected-warning{{enumeration value 'A' not handled in switch}}
211 switch(a
) { //expected-warning{{enumeration value 'A' not explicitly handled in switch}}
233 // <rdar://problem/7643909>
240 int test13(my_type_t t
) {
241 switch(t
) { // expected-warning{{enumeration value 'val3' not handled in switch}}
250 // <rdar://problem/7658121>
264 void f1(unsigned x
) {
273 switch (1) { // expected-warning {{no case matching constant switch condition '1'}}
274 case 0: i
= 0; break;
281 switch (c
) { // expected-warning {{no case matching constant switch condition '53'}}
286 struct bitfield_member
{
292 switch (x
>= 17) { // expected-warning {{switch condition has boolean value}}
296 switch ((int) (x
<= 17)) {
300 struct bitfield_member bm
;
301 switch (bm
.bf
) { // no warning
313 case 7: return 1; // expected-warning {{case value not in enumerated type}}
314 default: return 2; // expected-warning {{default label in switch which covers all enumeration values}}
323 void rdar110822110(Ints i
)
328 case 2: // expected-warning {{case value not in enumerated type 'Ints'}}
330 default: // expected-warning {{default label in switch which covers all enumeration values}}
336 #define TEST19MACRO 5
340 kTest19Enum2
= kTest19Enum1
344 case 5: // expected-note {{previous case}}
345 case TEST19MACRO
: // expected-error {{duplicate case value '5'}}
347 case 7: // expected-note {{previous case}}
348 case kTest19Enum1
: // expected-error {{duplicate case value: '7' and 'kTest19Enum1' both equal '7'}} \
349 // expected-note {{previous case}}
350 case kTest19Enum1
: // expected-error {{duplicate case value 'kTest19Enum1'}} \
351 // expected-note {{previous case}}
352 case kTest19Enum2
: // expected-error {{duplicate case value: 'kTest19Enum1' and 'kTest19Enum2' both equal '7'}} \
353 // expected-note {{previous case}}
354 case (int)kTest19Enum2
: //expected-error {{duplicate case value 'kTest19Enum2'}}
356 case 3: // expected-note {{previous case}}
357 case a
: // expected-error {{duplicate case value: '3' and 'a' both equal '3'}} \
358 // expected-note {{previous case}}
359 case a
: // expected-error {{duplicate case value 'a'}}
364 // Allow the warning 'case value not in enumerated type' to be silenced with
365 // the following pattern.
367 // If 'case' expression refers to a static const variable of the correct enum
368 // type, then we count this as a sufficient declaration of intent by the user,
369 // so we silence the warning.
375 enum ExtendedEnum1_unrelated
{ EE1_misc
};
377 static const enum ExtendedEnum1 EE1_c
= 100;
378 static const enum ExtendedEnum1_unrelated EE1_d
= 101;
380 void switch_on_ExtendedEnum1(enum ExtendedEnum1 e
) {
384 case EE1_c
: break; // no-warning
385 case EE1_d
: break; // expected-warning {{case value not in enumerated type 'enum ExtendedEnum1'}}
386 // expected-warning@-1 {{comparison of different enumeration types in switch statement ('enum ExtendedEnum1' and 'enum ExtendedEnum1_unrelated')}}
390 void PR11778(char c
, int n
, long long ll
) {
391 // Do not reject this; we don't have duplicate case values because we
392 // check for duplicates in the promoted type.
393 switch (c
) case 1: case 257: ; // expected-warning {{overflow}}
395 switch (n
) case 0x100000001LL
: case 1: ; // expected-warning {{overflow}} expected-error {{duplicate}} expected-note {{previous}}
396 switch ((int)ll
) case 0x100000001LL
: case 1: ; // expected-warning {{overflow}} expected-error {{duplicate}} expected-note {{previous}}
397 switch ((long long)n
) case 0x100000001LL
: case 1: ;
398 switch (ll
) case 0x100000001LL
: case 1: ;