1 // REQUIRED_ARGS: -o- -d -m64
11 fail_compilation/fail13902.d(45): Error: using the result of a comma expression is not allowed
12 fail_compilation/fail13902.d(32): Error: returning `& x` escapes a reference to local variable `x`
13 fail_compilation/fail13902.d(33): Error: returning `&s1.v` escapes a reference to local variable `s1`
14 fail_compilation/fail13902.d(38): Error: returning `& sa1` escapes a reference to local variable `sa1`
15 fail_compilation/fail13902.d(39): Error: returning `& sa2` escapes a reference to local variable `sa2`
16 fail_compilation/fail13902.d(40): Error: returning `& x` escapes a reference to local variable `x`
17 fail_compilation/fail13902.d(41): Error: returning `(& x+4)` escapes a reference to local variable `x`
18 fail_compilation/fail13902.d(42): Error: returning `& x + cast(long)x * 4L` escapes a reference to local variable `x`
19 fail_compilation/fail13902.d(45): Error: returning `& y` escapes a reference to local variable `y`
34 if (0) return &x
; // VarExp
35 if (0) return &s1
.v
; // DotVarExp
36 if (0) return s2
.p
; // no error
37 if (0) return &c
.v
; // no error
38 if (0) return &da1
[0]; // no error
39 if (0) return &da2
[0][0]; // no error
40 if (0) return &sa1
[0]; // IndexExp
41 if (0) return &sa2
[0][0]; // IndexExp
43 if (0) return &x
+ 1; // optimized to SymOffExp == (& x+4)
45 //if (0) return ptr += &x + 1; // semantic error
46 if (0) ptr
-= &x
- &y
; // no error
47 if (0) return (&x
, &y
); // CommaExp
56 fail_compilation/fail13902.d(88): Error: using the result of a comma expression is not allowed
57 fail_compilation/fail13902.d(75): Error: returning `& x` escapes a reference to parameter `x`
58 fail_compilation/fail13902.d(76): Error: returning `&s1.v` escapes a reference to parameter `s1`
59 fail_compilation/fail13902.d(81): Error: returning `& sa1` escapes a reference to parameter `sa1`
60 fail_compilation/fail13902.d(82): Error: returning `& sa2` escapes a reference to parameter `sa2`
61 fail_compilation/fail13902.d(83): Error: returning `& x` escapes a reference to parameter `x`
62 fail_compilation/fail13902.d(84): Error: returning `(& x+4)` escapes a reference to parameter `x`
63 fail_compilation/fail13902.d(85): Error: returning `& x + cast(long)x * 4L` escapes a reference to parameter `x`
64 fail_compilation/fail13902.d(88): Error: returning `& y` escapes a reference to parameter `y`
79 if (0) return &x
; // VarExp
80 if (0) return &s1
.v
; // DotVarExp
81 if (0) return s2
.p
; // no error
82 if (0) return &c
.v
; // no error
83 if (0) return &da1
[0]; // no error
84 if (0) return &da2
[0][0]; // no error
85 if (0) return &sa1
[0]; // IndexExp
86 if (0) return &sa2
[0][0]; // IndexExp
88 if (0) return &x
+ 1; // optimized to SymOffExp == (& x+4)
90 //if (0) return ptr += &x + 1; // semantic error
91 if (0) ptr
-= &x
- &y
; // no error
92 if (0) return (&x
, &y
); // CommaExp
101 fail_compilation/fail13902.d(123): Error: using the result of a comma expression is not allowed
105 return ref int x
, return ref int y
,
108 return ref int[1] sa1
,
109 return ref int[1][1] sa2
,
116 if (0) return &x
; // VarExp
117 if (0) return &s1
.v
; // DotVarExp
118 if (0) return s2
.p
; // no error
119 if (0) return &c
.v
; // no error
120 if (0) return &da1
[0]; // no error
121 if (0) return &da2
[0][0]; // no error
122 if (0) return &sa1
[0]; // IndexExp
123 if (0) return &sa2
[0][0]; // IndexExp
124 if (0) return ptr
= &x
;
125 if (0) return ptr
= &x
+ 1; // optimized to SymOffExp == (& x+4)
126 if (0) return ptr
= &x
+ x
;
127 //if (0) return ptr += &x + 1; // semantic error
128 if (0) return ptr
-= &x
- &y
; // no error
129 if (0) return (&x
, &y
); // CommaExp
137 fail_compilation/fail13902.d(150): Error: returning `cast(int[])sa1` escapes a reference to parameter `sa1`
138 fail_compilation/fail13902.d(151): Error: returning `cast(int[])sa1` escapes a reference to parameter `sa1`
139 fail_compilation/fail13902.d(152): Error: returning `sa1[]` escapes a reference to parameter `sa1`
140 fail_compilation/fail13902.d(155): Error: returning `cast(int[])sa2` escapes a reference to local variable `sa2`
141 fail_compilation/fail13902.d(156): Error: returning `cast(int[])sa2` escapes a reference to local variable `sa2`
142 fail_compilation/fail13902.d(157): Error: returning `sa2[]` escapes a reference to local variable `sa2`
143 fail_compilation/fail13902.d(161): Error: returning `cast(int[])s.sa` escapes a reference to local variable `s`
144 fail_compilation/fail13902.d(162): Error: returning `cast(int[])s.sa` escapes a reference to local variable `s`
145 fail_compilation/fail13902.d(163): Error: returning `s.sa[]` escapes a reference to local variable `s`
146 fail_compilation/fail13902.d(166): Error: escaping reference to stack allocated value returned by `makeSA()`
147 fail_compilation/fail13902.d(167): Error: escaping reference to stack allocated value returned by `makeSA()`
148 fail_compilation/fail13902.d(168): Error: escaping reference to stack allocated value returned by `makeSA()`
149 fail_compilation/fail13902.d(171): Error: escaping reference to stack allocated value returned by `makeS()`
150 fail_compilation/fail13902.d(172): Error: escaping reference to stack allocated value returned by `makeS()`
151 fail_compilation/fail13902.d(173): Error: escaping reference to stack allocated value returned by `makeS()`
154 int[] testEscape4(int[3] sa1
) // https://issues.dlang.org/show_bug.cgi?id=9279
156 if (0) return sa1
; // error <- no error
157 if (0) return cast(int[])sa1
; // error <- no error
158 if (0) return sa1
[]; // error
161 if (0) return sa2
; // error
162 if (0) return cast(int[])sa2
; // error
163 if (0) return sa2
[]; // error
165 struct S
{ int[3] sa
; }
167 if (0) return s
.sa
; // error <- no error
168 if (0) return cast(int[])s
.sa
; // error <- no error
169 if (0) return s
.sa
[]; // error
171 int[3] makeSA() { int[3] ret; return ret; }
172 if (0) return makeSA(); // error <- no error
173 if (0) return cast(int[])makeSA(); // error <- no error
174 if (0) return makeSA()[]; // error <- no error
176 S
makeS() { S s
; return s
; }
177 if (0) return makeS().sa
; // error <- no error
178 if (0) return cast(int[])makeS().sa
; // error <- no error
179 if (0) return makeS().sa
[]; // error <- no error
187 fail_compilation/fail13902.d(201): Error: returning `x` escapes a reference to local variable `x`
188 fail_compilation/fail13902.d(202): Error: returning `s1.v` escapes a reference to local variable `s1`
189 fail_compilation/fail13902.d(206): Error: returning `sa1[0]` escapes a reference to local variable `sa1`
190 fail_compilation/fail13902.d(207): Error: returning `sa2[0][0]` escapes a reference to local variable `sa2`
191 fail_compilation/fail13902.d(208): Error: returning `x = 1` escapes a reference to local variable `x`
192 fail_compilation/fail13902.d(209): Error: returning `x += 1` escapes a reference to local variable `x`
193 fail_compilation/fail13902.d(210): Error: returning `s1.v = 1` escapes a reference to local variable `s1`
194 fail_compilation/fail13902.d(211): Error: returning `s1.v += 1` escapes a reference to local variable `s1`
197 ref int testEscapeRef1()
207 if (0) return x
; // VarExp
208 if (0) return s1
.v
; // DotVarExp
209 if (0) return c
.v
; // no error
210 if (0) return da1
[0]; // no error
211 if (0) return da2
[0][0]; // no error
212 if (0) return sa1
[0]; // IndexExp
213 if (0) return sa2
[0][0]; // IndexExp
214 if (0) return x
= 1; // AssignExp
215 if (0) return x
+= 1; // BinAssignExp
216 if (0) return s1
.v
= 1; // AssignExp (e1 is DotVarExp)
217 if (0) return s1
.v
+= 1; // BinAssignExp (e1 is DotVarExp)
226 fail_compilation/fail13902.d(240): Error: returning `x` escapes a reference to parameter `x`
227 fail_compilation/fail13902.d(241): Error: returning `s1.v` escapes a reference to parameter `s1`
228 fail_compilation/fail13902.d(245): Error: returning `sa1[0]` escapes a reference to parameter `sa1`
229 fail_compilation/fail13902.d(246): Error: returning `sa2[0][0]` escapes a reference to parameter `sa2`
230 fail_compilation/fail13902.d(247): Error: returning `x = 1` escapes a reference to parameter `x`
231 fail_compilation/fail13902.d(248): Error: returning `x += 1` escapes a reference to parameter `x`
232 fail_compilation/fail13902.d(249): Error: returning `s1.v = 1` escapes a reference to parameter `s1`
233 fail_compilation/fail13902.d(250): Error: returning `s1.v += 1` escapes a reference to parameter `s1`
236 ref int testEscapeRef2(
246 if (0) return x
; // VarExp
247 if (0) return s1
.v
; // DotVarExp
248 if (0) return c
.v
; // no error
249 if (0) return da1
[0]; // no error
250 if (0) return da2
[0][0]; // no error
251 if (0) return sa1
[0]; // IndexExp
252 if (0) return sa2
[0][0]; // IndexExp
253 if (0) return x
= 1; // AssignExp
254 if (0) return x
+= 1; // BinAssignExp
255 if (0) return s1
.v
= 1; // AssignExp (e1 is DotVarExp)
256 if (0) return s1
.v
+= 1; // BinAssignExp (e1 is DotVarExp)
267 ref int testEscapeRef2(
271 return ref int[1] sa1
,
272 return ref int[1][1] sa2
,
277 if (0) return x
; // VarExp
278 if (0) return s1
.v
; // DotVarExp
279 if (0) return c
.v
; // no error
280 if (0) return da1
[0]; // no error
281 if (0) return da2
[0][0]; // no error
282 if (0) return sa1
[0]; // IndexExp
283 if (0) return sa2
[0][0]; // IndexExp
284 if (0) return x
= 1; // AssignExp
285 if (0) return x
+= 1; // BinAssignExp
286 if (0) return s1
.v
= 1; // AssignExp (e1 is DotVarExp)
287 if (0) return s1
.v
+= 1; // BinAssignExp (e1 is DotVarExp)
296 fail_compilation/fail13902.d(294): Error: returning `[& x]` escapes a reference to local variable `x`
297 fail_compilation/fail13902.d(295): Error: returning `[& x]` escapes a reference to local variable `x`
300 int*[] testArrayLiteral1() { int x
; return [&x
]; }
301 int*[1] testArrayLiteral2() { int x
; return [&x
]; }
306 fail_compilation/fail13902.d(304): Error: returning `S2(& x)` escapes a reference to local variable `x`
307 fail_compilation/fail13902.d(305): Error: returning `new S2(& x)` escapes a reference to local variable `x`
310 S2
testStructLiteral1() { int x
; return S2(&x
); }
311 S2
* testStructLiteral2() { int x
; return new S2(&x
); }
316 fail_compilation/fail13902.d(314): Error: returning `sa[]` escapes a reference to local variable `sa`
317 fail_compilation/fail13902.d(315): Error: returning `sa[cast(ulong)n..2][1..2]` escapes a reference to local variable `sa`
320 int[] testSlice1() { int[3] sa
; return sa
[]; }
321 int[] testSlice2() { int[3] sa
; int n
; return sa
[n
..2][1..2]; }
326 fail_compilation/fail13902.d(324): Error: returning `vda[0]` escapes a reference to parameter `vda`
330 ref int testDynamicArrayVariadic1(int[] vda
...) { return vda
[0]; }
331 @safe int[] testDynamicArrayVariadic2(int[] vda
...) { return vda
[]; }
332 int[3] testDynamicArrayVariadic3(int[] vda
...) { return vda
[0..3]; } // no error
337 fail_compilation/fail13902.d(335): Error: returning `vsa[0]` escapes a reference to parameter `vsa`
338 fail_compilation/fail13902.d(336): Error: returning `vsa[]` escapes a reference to variadic parameter `vsa`
341 ref int testStaticArrayVariadic1(int[3] vsa
...) { return vsa
[0]; }
342 int[] testStaticArrayVariadic2(int[3] vsa
...) { return vsa
[]; }
343 int[3] testStaticArrayVariadic3(int[3] vsa
...) { return vsa
[0..3]; } // no error