MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test_switch_error.d
blob41b6e52545e09aa552b140d4fede23ce21bc0fb8
1 /++
2 https://issues.dlang.org/show_bug.cgi?id=22514
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test_switch_error.d(13): Error: undefined identifier `doesNotExist`
6 fail_compilation/test_switch_error.d(16): Error: undefined identifier `alsoDoesNotExits`
7 fail_compilation/test_switch_error.d(19): Error: duplicate `case 2` in `switch` statement
8 ---
9 ++/
11 void test1()
13 switch (doesNotExist)
15 case 1:
16 alsoDoesNotExits();
17 break;
18 case 2: break;
19 case 2: break;
23 /++
24 TEST_OUTPUT:
25 ---
26 fail_compilation/test_switch_error.d(105): Error: undefined identifier `doesNotExist`
27 ---
28 ++/
29 #line 100
31 enum foo = 1;
33 void test2()
35 switch (doesNotExist)
37 case foo: break;
41 /++
42 TEST_OUTPUT:
43 ---
44 fail_compilation/test_switch_error.d(206): Error: undefined identifier `a`
45 fail_compilation/test_switch_error.d(207): Error: undefined identifier `b`
46 ---
47 ++/
48 #line 200
50 void test3()
53 switch (1)
55 case a: break;
56 case b: break;
60 /++
61 TEST_OUTPUT:
62 ---
63 fail_compilation/test_switch_error.d(303): Error: undefined identifier `doesNotExits`
64 ---
65 ++/
66 #line 300
68 void test4()
70 auto foo = doesNotExits();
71 switch (1)
73 case foo: break;
74 case foo: break;
78 /++
79 TEST_OUTPUT:
80 ---
81 fail_compilation/test_switch_error.d(405): Error: `case` variables have to be `const` or `immutable`
82 fail_compilation/test_switch_error.d(412): Error: `case` variables not allowed in `final switch` statements
83 ---
84 ++/
85 #line 400
87 void test5(int i)
89 switch (i)
91 case i: break;
92 default: break;
95 const int j = i;
96 final switch (i)
98 case j: break;
104 TEST_OUTPUT:
106 fail_compilation/test_switch_error.d(513): Error: undefined identifier `undefinedFunc`
107 fail_compilation/test_switch_error.d(517): Error: `case` expression must be a compile-time `string` or an integral constant, not `Strukt(1)`
108 fail_compilation/test_switch_error.d(518): Error: `case` variables have to be `const` or `immutable`
109 fail_compilation/test_switch_error.d(518): Error: `case` variables not allowed in `final switch` statements
110 fail_compilation/test_switch_error.d(519): Error: `case` variables not allowed in `final switch` statements
111 fail_compilation/test_switch_error.d(522): Error: undefined identifier `undefinedFunc2`
114 #line 500
116 enum Foo
118 one, two
121 struct Strukt
123 int i;
126 void errorsWithErrors(int param, immutable int constant)
128 final switch(undefinedFunc())
130 case Foo.one: break;
131 case Foo.two: break;
132 case Strukt(1): break;
133 case param: break;
134 case constant: break;
137 switch (undefinedFunc2())
139 case constant: break;
144 TEST_OUTPUT:
146 fail_compilation/test_switch_error.d(622): Error: undefined identifier `undefinedFunc`
147 fail_compilation/test_switch_error.d(624): Error: `case` expression must be a compile-time `string` or an integral constant, not `SubtypeOfInt(2)`
148 fail_compilation/test_switch_error.d(625): Error: `case` expression must be a compile-time `string` or an integral constant, not `SubtypeOfIntMethod()`
151 #line 600
153 struct SubtypeOfInt
155 int i;
156 alias i this;
159 struct SubtypeOfIntMethod
161 int getI() { return 0; }
162 alias getI this;
165 void errorsWithErrors2(int param)
167 final switch(param)
169 case SubtypeOfInt(1): break;
170 case SubtypeOfIntMethod(): break;
173 // This snippet causes somewhat misleading error messages
174 final switch(undefinedFunc())
176 case SubtypeOfInt(2): break;
177 case SubtypeOfIntMethod(): break;