switch.c revision 6dde0d5dc09f45f4d9508c964703e36fef1a0198
1// RUN: clang -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-error {{previous case value}}
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-error {{previous case value}}
19  case 43 ... 45:  ;         // expected-error {{duplicate case value}}
20
21  case 100 ... 20000:;       // expected-error {{previous case value}}
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 {{case label does not reduce to an integer constant}}
43  case 0 ... g(): // expected-error {{case label does not reduce to an integer constant}}
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 {{case label does not reduce to an integer constant}}
54    break;
55  }
56
57  switch (1) {
58  case 0 ... g() || 1: // expected-error {{case label does not reduce to an integer constant}}
59    break;
60  }
61}
62
63