d: Merge upstream dmd 47871363d, druntime, c52e28b7, phobos 99e9c1b77.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test18282.d
blobcf26878c39a2938f67f6c944b9bc14c4bbc439f2
1 /* REQUIRED_ARGS: -preview=dip1000
2 TEST_OUTPUT:
3 ---
4 fail_compilation/test18282.d(25): Error: scope variable `aa` may not be returned
5 fail_compilation/test18282.d(34): Error: copying `& i` into allocated memory escapes a reference to local variable `i`
6 fail_compilation/test18282.d(35): Error: copying `& i` into allocated memory escapes a reference to local variable `i`
7 fail_compilation/test18282.d(36): Error: scope variable `staa` may not be returned
8 fail_compilation/test18282.d(44): Error: copying `S2000(& i)` into allocated memory escapes a reference to local variable `i`
9 fail_compilation/test18282.d(53): Error: copying `& i` into allocated memory escapes a reference to local variable `i`
10 fail_compilation/test18282.d(53): Error: copying `& c` into allocated memory escapes a reference to local variable `c`
11 ---
14 // https://issues.dlang.org/show_bug.cgi?id=18282
16 string* f() @safe
18 scope string*[] ls;
19 return ls[0];
22 int* g() @safe
24 scope int*[3] aa;
25 return aa[0];
28 @safe:
30 auto bar1()
32 int i = void;
33 int*[1] staa = [ &i ];
34 auto dyna = [ &i ];
35 int*[ ] dynb = [ &i ];
36 return staa[0];
39 struct S2000 { int* p; }
41 S2000 bar2()
43 int i;
44 S2000[] arr = [ S2000(&i) ];
45 return arr[0];
49 void bar3()
51 int i;
52 char c;
53 char*[int*] aa = [ &i : &c ];
57 /******************************
58 TEST_OUTPUT:
59 ---
60 fail_compilation/test18282.d(1007): Error: copying `& foo` into allocated memory escapes a reference to local variable `foo`
61 fail_compilation/test18282.d(1008): Error: copying `& foo` into allocated memory escapes a reference to local variable `foo`
62 fail_compilation/test18282.d(1009): Error: copying `& foo` into allocated memory escapes a reference to local variable `foo`
63 fail_compilation/test18282.d(1016): Error: copying `&this` into allocated memory escapes a reference to parameter variable `this`
64 ---
67 #line 1000
69 // https://issues.dlang.org/show_bug.cgi?id=18282
71 void test18282() @safe
73 string foo = "foo";
74 scope string*[] ls;
75 ls = ls ~ &foo;
76 ls = &foo ~ ls;
77 ls ~= &foo;
80 struct S
82 auto fun()
84 arr ~= &this;
87 S*[] arr;