switch.c revision d7d5f0223bd30dfd618762349c6209dd1d5ea3e6
1// RUN: clang-cc -fsyntax-only -verify %s 2 3void f (int z) { 4 while (z) { 5 default: z--; // expected-error {{statement not in switch}} 6 } 7} 8 9void foo(int X) { 10 switch (X) { 11 case 42: ; // expected-note {{previous case}} 12 case 5000000000LL: // expected-warning {{overflow}} 13 case 42: // expected-error {{duplicate case value}} 14 ; 15 16 case 100 ... 99: ; // expected-warning {{empty case range}} 17 18 case 43: ; // expected-note {{previous case}} 19 case 43 ... 45: ; // expected-error {{duplicate case value}} 20 21 case 100 ... 20000:; // expected-note {{previous case}} 22 case 15000 ... 40000000:; // expected-error {{duplicate case value}} 23 } 24} 25 26void test3(void) { 27 // empty switch; 28 switch (0); 29} 30 31extern int g(); 32 33void test4() 34{ 35 switch (1) { 36 case 0 && g(): 37 case 1 || g(): 38 break; 39 } 40 41 switch(1) { 42 case g(): // expected-error {{expression is not an integer constant expression}} 43 case 0 ... g(): // expected-error {{expression is not an integer constant expression}} 44 break; 45 } 46 47 switch (1) { 48 case 0 && g() ... 1 || g(): 49 break; 50 } 51 52 switch (1) { 53 case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} 54 break; 55 } 56 57 switch (1) { 58 case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} 59 break; 60 } 61} 62 63void test5(int z) { 64 switch(z) { 65 default: // expected-note {{previous case defined here}} 66 default: // expected-error {{multiple default labels in one switch}} 67 break; 68 } 69} 70 71