MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail_scope.d
bloba9e5429366af2dc30d9d70d2e6018506c0b94f66
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail_scope.d(28): Deprecation: scope parameter `da` may not be returned
5 fail_compilation/fail_scope.d(30): Deprecation: scope parameter `o` may not be returned
6 fail_compilation/fail_scope.d(31): Deprecation: scope parameter `dg` may not be returned
7 fail_compilation/fail_scope.d(38): Deprecation: scope parameter `p` may not be returned
8 fail_compilation/fail_scope.d(43): Error: returning `cast(char[])string` escapes a reference to local variable `string`
9 fail_compilation/fail_scope.d(61): Error: returning `s.bar()` escapes a reference to local variable `s`
10 fail_compilation/fail_scope.d(72): Error: `fail_scope.foo8` called with argument types `(int)` matches both:
11 fail_compilation/fail_scope.d(66): `fail_scope.foo8(ref int x)`
12 and:
13 fail_compilation/fail_scope.d(67): `fail_scope.foo8(return ref int x)`
14 fail_compilation/fail_scope.d(80): Error: returning `& string` escapes a reference to local variable `string`
15 fail_compilation/fail_scope.d(90): Error: returning `cast(int[])a` escapes a reference to local variable `a`
16 fail_compilation/fail_scope.d(98): Error: returning `cast(int[])a` escapes a reference to local variable `a`
17 fail_compilation/fail_scope.d(106): Error: escaping reference to outer local variable `x`
18 fail_compilation/fail_scope.d(135): Error: returning `foo16226(i)` escapes a reference to local variable `i`
19 ---
20 //fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
21 //fail_compilation/fail_scope.d(37): Error: scope variable `o` may not be returned
22 //fail_compilation/fail_scope.d(38): Error: scope variable `dg` may not be returned
23 //fail_compilation/fail_scope.d(40): Error: scope variable `p` may not be returned
26 alias int delegate() dg_t;
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; }
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; }
38 int* test(scope int* p) @safe { return p; }
40 char[] foo140()
42 char[4] string = "abcd";
43 return string;
46 /************/
48 struct S
50 int x;
52 ref int bar() return
54 return x;
58 ref int test()
60 S s;
61 return s.bar();
64 /************/
66 ref int foo8(ref int x);
67 ref int foo8(return ref int x);
69 void testover()
71 int x;
72 foo8(x);
75 /************/
77 char* fail141()
79 char[4] string = "abcd";
80 return string.ptr;
83 /************/
85 int[] test1313b()
86 out{}
89 int[2] a;
90 return a;
93 int[] test1313a()
94 //out{}
97 int[2] a;
98 return a;
101 /******************/
102 // https://issues.dlang.org/show_bug.cgi?id=15192
104 ref int fun15192(ref int x) @safe
106 ref int bar(){ return x; }
107 return bar();
110 ref int fun15192_2(return ref int x) @safe
112 ref int bar(){ return x; }
113 return bar();
116 /**************************/
117 // https://issues.dlang.org/show_bug.cgi?id=15193
119 ref int foo15193()@safe{
120 struct S{
121 int x;
122 ref int bar() { return x; }
124 S s;
125 return s.bar();
129 /*****************************/
130 // https://issues.dlang.org/show_bug.cgi?id=16226
132 ref int test16226() @safe
134 int i;
135 return foo16226(i);
139 ref foo16226(ref int bar) @safe
141 return bar;