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