1 // RUNNABLE_PHOBOS_TEST
2 // REQUIRED_ARGS: -dip25
3
4 import core.stdc.stdio;
5
6 /********************************************/
7
8 struct SS
9 {
10 ref ulong foo1(return ref int* delegate() return p) return;
11 ref int foo2(return ref int delegate() p);
12 ref int foo3(inout ref int* p);
13 ref int foo4(return inout ref int* p);
14 }
15
16 pragma(msg, "foo1 ", typeof(&SS.foo1));
17 pragma(msg, "foo2 ", typeof(&SS.foo2));
18 pragma(msg, "foo3 ", typeof(&SS.foo3));
19 pragma(msg, "foo4 ", typeof(&SS.foo4));
20
21
test3()22 void test3()
23 {
24 version (all)
25 {
26 import std.stdio;
27 writeln(SS.foo1.mangleof);
28 writeln(SS.foo2.mangleof);
29 writeln(SS.foo3.mangleof);
30 writeln(SS.foo4.mangleof);
31 writeln(typeof(SS.foo1).stringof);
32 writeln(typeof(SS.foo2).stringof);
33 writeln(typeof(SS.foo3).stringof);
34 writeln(typeof(SS.foo4).stringof);
35 }
36
37 version (all)
38 {
39 // Test scope mangling
40 assert(SS.foo1.mangleof == "_D10testscope22SS4foo1MFNcNjNkKDFNjZPiZm");
41 assert(SS.foo2.mangleof == "_D10testscope22SS4foo2MFNcNkKDFZiZi");
42 assert(SS.foo3.mangleof == "_D10testscope22SS4foo3MFNcNkKNgPiZi");
43 assert(SS.foo4.mangleof == "_D10testscope22SS4foo4MFNcNkKNgPiZi");
44
45 // Test scope pretty-printing
46 assert(typeof(SS.foo1).stringof == "ref return ulong(return ref int* delegate() return p)");
47 assert(typeof(SS.foo2).stringof == "ref int(return ref int delegate() p)");
48 assert(typeof(SS.foo3).stringof == "ref int(return ref inout(int*) p)");
49 assert(typeof(SS.foo4).stringof == "ref int(return ref inout(int*) p)");
50 }
51 }
52
53 /********************************************/
54
foo(return ref int x)55 ref int foo(return ref int x)
56 {
57 return x;
58 }
59
60 struct S
61 {
62 int x;
63
64 ref S bar() return
65 {
66 return this;
67 }
68 }
69
70 ref T foo2(T)(ref T x)
71 {
72 return x;
73 }
74
75 void test4()
76 {
77 int x;
78 foo2(x);
79 }
80
81 /********************************************/
82
83 ref int foo(return ref int x, ref int y)
84 {
85 return x;
86 }
87
88 ref int bar()
89 {
90 int x;
91 static int y = 7;
92 return foo(y, x);
93 }
94
95 void test5()
96 {
97 int x = bar();
98 assert(x == 7);
99 }
100
101 /********************************************/
102
103 struct S6
104 {
105 int x = 8;
106
107 ref int bar() return
108 {
109 return x;
110 }
111 }
112
113 void test6()
114 {
115 S6 s;
116 int b = s.bar();
117 assert(b == 8);
118 }
119
120 /********************************************/
121
122 class C
123 {
124 int x;
125 ref int foo(return ref int x) { return x; }
126 ref int bar() return { return x; }
127 }
128
129 class D : C
130 {
131 override ref int foo(ref int x) { static int y; return y; }
132 override ref int bar() { static int y; return y; }
133 }
134
135 void test7()
136 {
137 }
138
139 /********************************************/
140
141 struct S8(T)
142 {
143 int x;
144
145 ref int bar() // infer 'return'
146 {
147 return x;
148 }
149 }
150
151 ref int test8a(return ref S8!int s)
152 {
153 return s.bar();
154 }
155
156 void test8()
157 {
158 }
159
160 /********************************************/
161
162 char[] foo9(return out char[4] buf)
163 {
164 return buf[0 .. 1];
165 }
166
167 /********************************************/
168
169 struct S10
170 {
171 int x;
172
173 ref inout(int) foo() inout
174 {
175 return x;
176 }
177 }
178
179 /********************************************/
180
181 struct RC
182 {
183 this(this) { }
184 }
185
186 struct S11
187 {
188 @disable this(this);
189
190 void remove()
191 {
192 _ptr[0] = _ptr[1];
193 }
194
195 RC* _ptr;
196 }
197
198
199 void test11()
200 {
201 S11 ary;
202 }
203
204 /********************************************/
205
206 int[10] a12;
207
208 int* foo12()
209 {
210 foreach (ref x; a12)
211 return &x;
212 return null;
213 }
214
215 /********************************************/
216
217 struct FullCaseEntry
218 {
219 dchar[3] seq;
220 ubyte n, size;// n number in batch, size - size of batch
221 ubyte entry_len;
222
223 @property auto value() const @trusted pure nothrow @nogc return
224 {
225 return seq[0..entry_len];
226 }
227 }
228
229 /********************************************/
230
231 class C12
232 {
233 void member() scope { }
234 }
235
236 /********************************************/
237
238 void main()
239 {
240 test3();
241 test4();
242 test5();
243 test6();
244 test7();
245 test8();
246 test11();
247 printf("Success\n");
248 }
249
250