Debian Codegraph @

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

raw
1 /* REQUIRED_ARGS: -preview=dip1000
2 TEST_OUTPUT:
3 ---
4 fail_compilation/test18282.d(25): Error: returning scope variable `aa` is not allowed in a `@safe` function
5 fail_compilation/test18282.d(34): Error: escaping a reference to local variable `i` by copying `& i` into allocated memory is not allowed in a `@safe` function
6 fail_compilation/test18282.d(35): Error: escaping a reference to local variable `i` by copying `& i` into allocated memory is not allowed in a `@safe` function
7 fail_compilation/test18282.d(36): Error: returning scope variable `staa` is not allowed in a `@safe` function
8 fail_compilation/test18282.d(44): Error: escaping a reference to local variable `i` by copying `S2000(& i)` into allocated memory is not allowed in a `@safe` function
9 fail_compilation/test18282.d(53): Error: escaping a reference to local variable `i` by copying `& i` into allocated memory is not allowed in a `@safe` function
10 fail_compilation/test18282.d(53): Error: escaping a reference to local variable `c` by copying `& c` into allocated memory is not allowed in a `@safe` function
11 ---
12 */
13
14 // https://issues.dlang.org/show_bug.cgi?id=18282
15
16 string* f() @safe
17 {
18 scope string*[] ls;
19 return ls[0];
20 }
21
22 int* g() @safe
23 {
24 scope int*[3] aa;
25 return aa[0];
26 }
27
28 @safe:
29
30 auto bar1()
31 {
32 int i = void;
33 int*[1] staa = [ &i ];
34 auto dyna = [ &i ];
35 int*[ ] dynb = [ &i ];
36 return staa[0];
37 }
38
39 struct S2000 { int* p; }
40
41 S2000 bar2()
42 {
43 int i;
44 S2000[] arr = [ S2000(&i) ];
45 return arr[0];
46 }
47
48
49 void bar3()
50 {
51 int i;
52 char c;
53 char*[int*] aa = [ &i : &c ];
54 }
55
56
57 /******************************
58 TEST_OUTPUT:
59 ---
60 fail_compilation/test18282.d(1007): Error: escaping a reference to local variable `foo` by copying `& foo` into allocated memory is not allowed in a `@safe` function
61 fail_compilation/test18282.d(1008): Error: escaping a reference to local variable `foo` by copying `& foo` into allocated memory is not allowed in a `@safe` function
62 fail_compilation/test18282.d(1009): Error: escaping a reference to local variable `foo` by copying `& foo` into allocated memory is not allowed in a `@safe` function
63 fail_compilation/test18282.d(1016): Error: escaping a reference to parameter `this` by copying `&this` into allocated memory is not allowed in a `@safe` function
64 ---
65 */
66
67 #line 1000
68
69 // https://issues.dlang.org/show_bug.cgi?id=18282
70
71 void test18282() @safe
72 {
73 string foo = "foo";
74 scope string*[] ls;
75 ls = ls ~ &foo;
76 ls = &foo ~ ls;
77 ls ~= &foo;
78 }
79
80 struct S
81 {
82 auto fun()
83 {
84 arr ~= &this;
85 }
86
87 S*[] arr;
88 }