Debian Codegraph @

gcc/testsuite/gdc.test/compilable/test602.d

raw
1 // REQUIRED_ARGS: -o-
2 // PERMUTE_ARGS:
3
4 // Disallow skipping variable decl
5 static assert(!__traits(compiles, (bool b)
6 {
7 if (b) goto label;
8 int x;
9 label: {}
10 assert(!x);
11 }));
12
13 // Disallow skipping variable in block backwards
14 static assert(!__traits(compiles, (bool b)
15 {
16 {
17 int x;
18 label: {}
19 assert(!x);
20 }
21 if (b) goto label;
22 }));
23
24 // Disallow skipping backwards int block
25 static assert(!__traits(compiles, (bool b)
26 {
27 {
28 int x;
29 label: {}
30 assert(!x);
31 }
32 if (b) goto label;
33 }));
34
35 // Variable inside try block
36 static assert(!__traits(compiles, (bool b)
37 {
38 if (b) goto label;
39 try
40 {
41 int x;
42 label: {}
43 assert(!x);
44 }
45 catch(Throwable)
46 {
47 }
48 }));
49
50 // Variable inside catch block
51 static assert(!__traits(compiles, (bool b)
52 {
53 if (b) goto label;
54 try
55 {
56 }
57 catch(Throwable)
58 {
59 int x;
60 label: {}
61 assert(!x);
62 }
63 }));
64
65 // Goto into catch block with unnamed exception
66 static assert(__traits(compiles, (bool b)
67 {
68 if (b) goto label;
69 try
70 {
71 }
72 catch(Exception)
73 {
74 label: {}
75 }
76 }));
77
78 // Goto into catch block with named exception
79 static assert(!__traits(compiles, (bool b)
80 {
81 if (b) goto label;
82 try
83 {
84 }
85 catch(Exception e)
86 {
87 label: {}
88 assert(e);
89 }
90 }));
91
92 // Goto into finally block
93 static assert(!__traits(compiles, (bool b)
94 {
95 if (b) goto label;
96 try
97 {
98 }
99 finally
100 {
101 label: {}
102 }
103 }));
104
105 // Goto into variable with block
106 static assert(!__traits(compiles, (bool b)
107 {
108 if (b) goto label;
109 struct S
110 {
111 int x;
112 }
113 with (S())
114 {
115 label: {}
116 assert(!x);
117 }
118 }));
119
120 // Goto backwards into variable with block
121 static assert(!__traits(compiles, (bool b)
122 {
123 struct S
124 {
125 int x;
126 }
127 with (S())
128 {
129 label: {}
130 assert(!x);
131 }
132 if (b) goto label;
133 }));
134
135 // Goto into symbolic with block
136 static assert(__traits(compiles, (bool b)
137 {
138 if (b) goto label;
139 struct S
140 {
141 int x;
142 }
143 with (S)
144 {
145 label: {}
146 }
147 }));
148
149 // Goto backwards into symbolic with block
150 static assert(__traits(compiles, (bool b)
151 {
152 struct S
153 {
154 int x;
155 }
156 with (S)
157 {
158 label: {}
159 }
160 if (b) goto label;
161 }));
162
163 // Goto into for loop
164 static assert(!__traits(compiles, (bool b)
165 {
166 if (b) goto label;
167 for (int i = 0; i < 8; ++i)
168 {
169 label: {}
170 assert(i);
171 }
172 }));
173
174 // Goto into for loop backwards
175 static assert(!__traits(compiles, (bool b)
176 {
177 for (int i = 0; i < 8; ++i)
178 {
179 label: {}
180 assert(i);
181 }
182 if (b) goto label;
183 }));
184
185 // Goto into foreach loop
186 static assert(!__traits(compiles, (bool b)
187 {
188 if (b) goto label;
189 foreach(i; 0..8)
190 {
191 label: {}
192 assert(i);
193 }
194 }));
195
196 // Goto into foreach loop backwards
197 static assert(!__traits(compiles, (bool b)
198 {
199 foreach(i; 0..8)
200 {
201 label: {}
202 assert(i);
203 }
204 if (b) goto label;
205 }));
206
207 // Goto into if block with variable
208 static assert(!__traits(compiles, (bool b)
209 {
210 if (b) goto label;
211 if (auto x = b)
212 {
213 label: {}
214 assert(x);
215 }
216 }));
217
218 // Goto backwards into if block with variable
219 static assert(!__traits(compiles, (bool b)
220 {
221 if (auto x = b)
222 {
223 label: {}
224 assert(x);
225 }
226 if (b) goto label;
227 }));
228
229 // Goto into if block without variable
230 static assert(__traits(compiles, (bool b)
231 {
232 if (b) goto label;
233 if (b)
234 {
235 label: {}
236 }
237 }));
238
239 // Goto into else block
240 static assert(__traits(compiles, (bool b)
241 {
242 if (b) goto label;
243 if (auto x = b)
244 {
245 }
246 else
247 {
248 label: {}
249 }
250 }));
251
252 // Goto backwards into else with variable
253 static assert(!__traits(compiles, (bool b)
254 {
255 if (auto x = b)
256 {
257 }
258 else
259 {
260 int y;
261 label: {}
262 }
263 if (b) goto label;
264 }));
265
266 // Goto into while block
267 static assert(__traits(compiles, (bool b)
268 {
269 if (b) goto label;
270 while (b)
271 {
272 label: {}
273 }
274 }));
275
276 // Goto into while block with internal variable
277 static assert(!__traits(compiles, (bool b)
278 {
279 if (b) goto label;
280 while (b)
281 {
282 int x;
283 label: {}
284 assert(!x);
285 }
286 }));
287
288 // Goto into do block
289 static assert(__traits(compiles, (bool b)
290 {
291 if (b) goto label;
292 do
293 {
294 label: {}
295 }
296 while (b);
297 }));
298
299 // Goto over switch variable
300 static assert(!__traits(compiles, (bool b)
301 {
302 if (b) goto label;
303 switch(0)
304 {
305 default:
306 break;
307 int x;
308 label: {}
309 }
310 }));
311
312 // Goto over switch variable
313 static assert(!__traits(compiles, (bool b)
314 {
315 if (b) goto label;
316 switch(0)
317 {
318 default:
319 break;
320 case 0:
321 int x;
322 label: {}
323 }
324 }));
325
326 // Goto into synchronized statement
327 static assert(!__traits(compiles, (bool b)
328 {
329 if (b)
330 goto label;
331 synchronized
332 {
333 label: {}
334 }
335 }));
336
337 // Goto into scope(success) with variable
338 static assert(!__traits(compiles, (bool b)
339 {
340 scope(success) { int x; label: {} assert(!x); }
341 if (b)
342 goto label;
343 }));
344
345 // Goto into scope(failure)
346 static assert(!__traits(compiles, (bool b)
347 {
348 if (b)
349 goto label;
350 scope(failure) { label: {} }
351 }));
352
353 // Goto into scope(failure) with variable
354 static assert(!__traits(compiles, (bool b)
355 {
356 scope(failure) { int x; label: {} assert(!x); }
357 if (b)
358 goto label;
359 }));
360
361 // Goto into scope(exit)
362 static assert(!__traits(compiles, (bool b)
363 {
364 if (b)
365 goto label;
366 scope(exit) { label: {} }
367 }));
368
369 // Goto into scope(exit)
370 static assert(!__traits(compiles, (bool b)
371 {
372 scope(exit) { label: {} }
373 if (b)
374 goto label;
375 }));
376
377 // Goto into scope(exit) with variable
378 static assert(!__traits(compiles, (bool b)
379 {
380 scope(exit) { int x; label: {} assert(!x); }
381 if (b)
382 goto label;
383 }));
384
385 /***************************************************/
386 // https://issues.dlang.org/show_bug.cgi?id=11659
387
388 int test11659()
389 {
390 goto LABEL;
391 enum expr = "0";
392 LABEL:
393 return mixin(expr);
394 }
395
396 /***************************************************/
397 // https://issues.dlang.org/show_bug.cgi?id=13321
398
399 void test13321(bool b)
400 {
401 static struct Foo
402 {
403 this(int) {}
404 }
405
406 Foo x;
407 if (b)
408 goto EXIT;
409 x = Foo(1);
410 EXIT:
411 }