Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail_scope.d(43): Error: returning `cast(char[])string` escapes a reference to local variable `string`
5 fail_compilation/fail_scope.d(61): Error: returning `s.bar()` escapes a reference to local variable `s`
6 fail_compilation/fail_scope.d(72): Error: `fail_scope.foo8` called with argument types `(int)` matches multiple overloads exactly:
7 fail_compilation/fail_scope.d(66): `fail_scope.foo8(ref int x)`
8 and:
9 fail_compilation/fail_scope.d(67): `fail_scope.foo8(return ref int x)`
10 fail_compilation/fail_scope.d(80): Error: returning `& string` escapes a reference to local variable `string`
11 fail_compilation/fail_scope.d(90): Error: returning `cast(int[])a` escapes a reference to local variable `a`
12 fail_compilation/fail_scope.d(98): Error: returning `cast(int[])a` escapes a reference to local variable `a`
13 fail_compilation/fail_scope.d(106): Error: escaping reference to outer local variable `x`
14 fail_compilation/fail_scope.d(135): Error: returning `foo16226(i)` escapes a reference to local variable `i`
15 ---
16 //fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
17 //fail_compilation/fail_scope.d(37): Error: scope variable `o` may not be returned
18 //fail_compilation/fail_scope.d(38): Error: scope variable `dg` may not be returned
19 //fail_compilation/fail_scope.d(40): Error: scope variable `p` may not be returned
20 */
21
22
23
24
25
26 alias int delegate() dg_t;
27
28 int[] checkEscapeScope1(scope int[] da) { return da; }
29 int[3] checkEscapeScope2(scope int[3] sa) { return sa; }
30 Object checkEscapeScope3(scope Object o) { return o; }
31 dg_t checkEscapeScope4(scope dg_t dg) { return dg; }
32
33 int[] checkEscapeScope1() { scope int[] da = []; return da; }
34 int[3] checkEscapeScope2() { scope int[3] sa = [1,2,3]; return sa; }
35 Object checkEscapeScope3() { scope Object o = new Object; return o; } // same with fail7294.d
36 dg_t checkEscapeScope4() { scope dg_t dg = () => 1; return dg; }
37
38 int* test(scope int* p) @safe { return p; }
39
40 char[] foo140()
41 {
42 char[4] string = "abcd";
43 return string;
44 }
45
46 /************/
47
48 struct S
49 {
50 int x;
51
52 ref int bar() return
53 {
54 return x;
55 }
56 }
57
58 ref int test()
59 {
60 S s;
61 return s.bar();
62 }
63
64 /************/
65
66 ref int foo8(ref int x);
67 ref int foo8(return ref int x);
68
69 void testover()
70 {
71 int x;
72 foo8(x);
73 }
74
75 /************/
76
77 char* fail141()
78 {
79 char[4] string = "abcd";
80 return string.ptr;
81 }
82
83 /************/
84
85 int[] test1313b()
86 out{}
87 do
88 {
89 int[2] a;
90 return a;
91 }
92
93 int[] test1313a()
94 //out{}
95 do
96 {
97 int[2] a;
98 return a;
99 }
100
101 /******************/
102 // https://issues.dlang.org/show_bug.cgi?id=15192
103
104 ref int fun15192(ref int x) @safe
105 {
106 ref int bar(){ return x; }
107 return bar();
108 }
109
110 ref int fun15192_2(return ref int x) @safe
111 {
112 ref int bar(){ return x; }
113 return bar();
114 }
115
116 /**************************/
117 // https://issues.dlang.org/show_bug.cgi?id=15193
118
119 ref int foo15193()@safe{
120 struct S{
121 int x;
122 ref int bar() { return x; }
123 }
124 S s;
125 return s.bar();
126 }
127
128
129 /*****************************/
130 // https://issues.dlang.org/show_bug.cgi?id=16226
131
132 ref int test16226() @safe
133 {
134 int i;
135 return foo16226(i);
136 }
137
138
139 ref foo16226(ref int bar) @safe
140 {
141 return bar;
142 }