Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/goto2.d

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/goto2.d(1024): Error: case cannot be in different `try` block level from `switch`
5 fail_compilation/goto2.d(1026): Error: default cannot be in different `try` block level from `switch`
6 fail_compilation/goto2.d(1003): Error: cannot `goto` into `try` block
7 ---
8 */
9
10
11 void foo();
12 void bar();
13
14 #line 1000
15
16 void test1()
17 {
18 goto L1;
19 try
20 {
21 foo();
22 L1:
23 { }
24 }
25 finally
26 {
27 bar();
28 }
29
30 /********************************/
31
32 int i;
33 switch (i)
34 {
35 case 1:
36 try
37 {
38 foo();
39 case 2:
40 { }
41 default:
42 { }
43 }
44 finally
45 {
46 bar();
47 }
48 break;
49 }
50 }
51
52 /**************************************************
53 https://issues.dlang.org/show_bug.cgi?id=11540
54 goto label + try-catch-finally / with statement
55
56 TEST_OUTPUT:
57 ---
58 fail_compilation/goto2.d(1121): Error: cannot `goto` into `try` block
59 ---
60 */
61 #line 1100
62
63 int interpret3a()
64 {
65 // enter to TryCatchStatement.body
66 {
67 bool c = false;
68 try
69 {
70 if (c) // need to bypass front-end optimization
71 throw new Exception("");
72 else
73 {
74 goto Lx;
75 L1:
76 c = true;
77 }
78 }
79 catch (Exception e) {}
80
81 Lx:
82 if (!c)
83 goto L1;
84 }
85 return 1;
86 }
87
88 /**************************************************
89 https://issues.dlang.org/show_bug.cgi?id=11540
90 goto label + try-catch-finally / with statement
91
92 TEST_OUTPUT:
93 ---
94 fail_compilation/goto2.d(1217): Error: cannot `goto` into `try` block
95 ---
96 */
97 #line 1200
98
99 int interpret3b()
100 {
101 // enter back to TryFinallyStatement.body
102 {
103 bool c = false;
104 try
105 {
106 goto Lx;
107 L1:
108 c = true;
109 }
110 finally {
111 }
112
113 Lx:
114 if (!c)
115 goto L1;
116 }
117
118 return 1;
119 }
120
121 /**************************************************
122 https://issues.dlang.org/show_bug.cgi?id=13815
123
124 TEST_OUTPUT:
125 ---
126 fail_compilation/goto2.d(1234): Error: cannot `goto` into `try` block
127 ---
128 */
129
130 bool f()
131 {
132 goto L;
133 try
134 {
135 L: // line 7
136 throw new Exception(""); // line 8
137 }
138 catch (Exception e)
139 {
140 return true;
141 }
142 return false;
143 }