Debian Codegraph @

gcc/testsuite/gdc.test/runnable/testscope2.d

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