d: Merge upstream dmd 47871363d, druntime, c52e28b7, phobos 99e9c1b77.
[official-gcc.git] / gcc / testsuite / gdc.test / compilable / test602.d
blobc87f88308c66d4d9eefbdfff610d021cbaea4bd6
1 // REQUIRED_ARGS: -o-
2 // PERMUTE_ARGS:
4 // Disallow skipping variable decl
5 static assert(!__traits(compiles, (bool b)
7 if (b) goto label;
8 int x;
9 label: {}
10 assert(!x);
11 }));
13 // Disallow skipping variable in block backwards
14 static assert(!__traits(compiles, (bool b)
17 int x;
18 label: {}
19 assert(!x);
21 if (b) goto label;
22 }));
24 // Disallow skipping backwards int block
25 static assert(!__traits(compiles, (bool b)
28 int x;
29 label: {}
30 assert(!x);
32 if (b) goto label;
33 }));
35 // Variable inside try block
36 static assert(!__traits(compiles, (bool b)
38 if (b) goto label;
39 try
41 int x;
42 label: {}
43 assert(!x);
45 catch(Throwable)
48 }));
50 // Variable inside catch block
51 static assert(!__traits(compiles, (bool b)
53 if (b) goto label;
54 try
57 catch(Throwable)
59 int x;
60 label: {}
61 assert(!x);
63 }));
65 // Goto into catch block with unnamed exception
66 static assert(__traits(compiles, (bool b)
68 if (b) goto label;
69 try
72 catch(Exception)
74 label: {}
76 }));
78 // Goto into catch block with named exception
79 static assert(!__traits(compiles, (bool b)
81 if (b) goto label;
82 try
85 catch(Exception e)
87 label: {}
88 assert(e);
90 }));
92 // Goto into finally block
93 static assert(!__traits(compiles, (bool b)
95 if (b) goto label;
96 try
99 finally
101 label: {}
103 }));
105 // Goto into variable with block
106 static assert(!__traits(compiles, (bool b)
108 if (b) goto label;
109 struct S
111 int x;
113 with (S())
115 label: {}
116 assert(!x);
118 }));
120 // Goto backwards into variable with block
121 static assert(!__traits(compiles, (bool b)
123 struct S
125 int x;
127 with (S())
129 label: {}
130 assert(!x);
132 if (b) goto label;
133 }));
135 // Goto into symbolic with block
136 static assert(__traits(compiles, (bool b)
138 if (b) goto label;
139 struct S
141 int x;
143 with (S)
145 label: {}
147 }));
149 // Goto backwards into symbolic with block
150 static assert(__traits(compiles, (bool b)
152 struct S
154 int x;
156 with (S)
158 label: {}
160 if (b) goto label;
161 }));
163 // Goto into for loop
164 static assert(!__traits(compiles, (bool b)
166 if (b) goto label;
167 for (int i = 0; i < 8; ++i)
169 label: {}
170 assert(i);
172 }));
174 // Goto into for loop backwards
175 static assert(!__traits(compiles, (bool b)
177 for (int i = 0; i < 8; ++i)
179 label: {}
180 assert(i);
182 if (b) goto label;
183 }));
185 // Goto into foreach loop
186 static assert(!__traits(compiles, (bool b)
188 if (b) goto label;
189 foreach(i; 0..8)
191 label: {}
192 assert(i);
194 }));
196 // Goto into foreach loop backwards
197 static assert(!__traits(compiles, (bool b)
199 foreach(i; 0..8)
201 label: {}
202 assert(i);
204 if (b) goto label;
205 }));
207 // Goto into if block with variable
208 static assert(!__traits(compiles, (bool b)
210 if (b) goto label;
211 if (auto x = b)
213 label: {}
214 assert(x);
216 }));
218 // Goto backwards into if block with variable
219 static assert(!__traits(compiles, (bool b)
221 if (auto x = b)
223 label: {}
224 assert(x);
226 if (b) goto label;
227 }));
229 // Goto into if block without variable
230 static assert(__traits(compiles, (bool b)
232 if (b) goto label;
233 if (b)
235 label: {}
237 }));
239 // Goto into else block
240 static assert(__traits(compiles, (bool b)
242 if (b) goto label;
243 if (auto x = b)
246 else
248 label: {}
250 }));
252 // Goto backwards into else with variable
253 static assert(!__traits(compiles, (bool b)
255 if (auto x = b)
258 else
260 int y;
261 label: {}
263 if (b) goto label;
264 }));
266 // Goto into while block
267 static assert(__traits(compiles, (bool b)
269 if (b) goto label;
270 while (b)
272 label: {}
274 }));
276 // Goto into while block with internal variable
277 static assert(!__traits(compiles, (bool b)
279 if (b) goto label;
280 while (b)
282 int x;
283 label: {}
284 assert(!x);
286 }));
288 // Goto into do block
289 static assert(__traits(compiles, (bool b)
291 if (b) goto label;
294 label: {}
296 while (b);
297 }));
299 // Goto over switch variable
300 static assert(!__traits(compiles, (bool b)
302 if (b) goto label;
303 switch(0)
305 default:
306 break;
307 int x;
308 label: {}
310 }));
312 // Goto over switch variable
313 static assert(!__traits(compiles, (bool b)
315 if (b) goto label;
316 switch(0)
318 default:
319 break;
320 case 0:
321 int x;
322 label: {}
324 }));
326 // Goto into synchronized statement
327 static assert(!__traits(compiles, (bool b)
329 if (b)
330 goto label;
331 synchronized
333 label: {}
335 }));
337 // Goto into scope(success) with variable
338 static assert(!__traits(compiles, (bool b)
340 scope(success) { int x; label: {} assert(!x); }
341 if (b)
342 goto label;
343 }));
345 // Goto into scope(failure)
346 static assert(!__traits(compiles, (bool b)
348 if (b)
349 goto label;
350 scope(failure) { label: {} }
351 }));
353 // Goto into scope(failure) with variable
354 static assert(!__traits(compiles, (bool b)
356 scope(failure) { int x; label: {} assert(!x); }
357 if (b)
358 goto label;
359 }));
361 // Goto into scope(exit)
362 static assert(!__traits(compiles, (bool b)
364 if (b)
365 goto label;
366 scope(exit) { label: {} }
367 }));
369 // Goto into scope(exit)
370 static assert(!__traits(compiles, (bool b)
372 scope(exit) { label: {} }
373 if (b)
374 goto label;
375 }));
377 // Goto into scope(exit) with variable
378 static assert(!__traits(compiles, (bool b)
380 scope(exit) { int x; label: {} assert(!x); }
381 if (b)
382 goto label;
383 }));
385 /***************************************************/
386 // https://issues.dlang.org/show_bug.cgi?id=11659
388 int test11659()
390 goto LABEL;
391 enum expr = "0";
392 LABEL:
393 return mixin(expr);
396 /***************************************************/
397 // https://issues.dlang.org/show_bug.cgi?id=13321
399 void test13321(bool b)
401 static struct Foo
403 this(int) {}
406 Foo x;
407 if (b)
408 goto EXIT;
409 x = Foo(1);
410 EXIT: