]>
Commit | Line | Data |
---|---|---|
5fee5ec3 IB |
1 | /* |
2 | REQUIRED_ARGS: -preview=rvaluerefparam | |
3 | EXTRA_SOURCES: imports/ovs1528a.d imports/ovs1528b.d | |
4 | EXTRA_SOURCES: imports/template_ovs1.d imports/template_ovs2.d imports/template_ovs3.d | |
5 | EXTRA_FILES: imports/m8668a.d imports/m8668b.d imports/m8668c.d | |
6 | RUN_OUTPUT: | |
7 | --- | |
8 | Success | |
9 | --- | |
10 | */ | |
b4c522fa IB |
11 | |
12 | import imports.template_ovs1; | |
13 | import imports.template_ovs2; | |
14 | import imports.template_ovs3; | |
15 | ||
16 | extern(C) int printf(const char* fmt, ...); | |
17 | ||
18 | template TypeTuple(T...){ alias T TypeTuple; } | |
19 | template Id( T){ alias T Id; } | |
20 | template Id(alias A){ alias A Id; } | |
21 | ||
22 | /***************************************************/ | |
5fee5ec3 | 23 | // https://issues.dlang.org/show_bug.cgi?id=1528 |
b4c522fa IB |
24 | |
25 | int foo1528(long){ return 1; } | |
26 | int foo1528(int[]){ return 2; } | |
27 | int foo1528(T)(T) if ( is(T:real)) { return 3; } | |
28 | int foo1528(T)(T) if (!is(T:real)) { return 4; } | |
29 | int bar1528(T)(T) if (!is(T:real)) { return 4; } | |
30 | int bar1528(T)(T) if ( is(T:real)) { return 3; } | |
31 | int bar1528(int[]){ return 2; } | |
32 | int bar1528(long){ return 1; } | |
33 | ||
34 | @property auto getfoo1528 () { return 1; } | |
35 | @property auto getfoo1528(T)() { return 2; } | |
36 | @property auto getbar1528(T)() { return 2; } | |
37 | @property auto getbar1528 () { return 1; } | |
38 | ||
39 | @property auto setfoo1528 (int) { return 1; } | |
40 | @property auto setfoo1528(T)(int) { return 2; } | |
41 | @property auto setbar1528(T)(int) { return 2; } | |
42 | @property auto setbar1528 (int) { return 1; } | |
43 | ||
44 | struct S1528 | |
45 | { | |
46 | int foo(long){ return 1; } | |
47 | int foo(int[]){ return 2; } | |
48 | int foo(T)(T) if ( is(T:real)) { return 3; } | |
49 | int foo(T)(T) if (!is(T:real)) { return 4; } | |
50 | int bar(T)(T) if (!is(T:real)) { return 4; } | |
51 | int bar(T)(T) if ( is(T:real)) { return 3; } | |
52 | int bar(int[]){ return 2; } | |
53 | int bar(long){ return 1; } | |
54 | ||
55 | @property auto getfoo () { return 1; } | |
56 | @property auto getfoo(T)() { return 2; } | |
57 | @property auto getbar(T)() { return 2; } | |
58 | @property auto getbar () { return 1; } | |
59 | ||
60 | @property auto setfoo (int) { return 1; } | |
61 | @property auto setfoo(T)(int) { return 2; } | |
62 | @property auto setbar(T)(int) { return 2; } | |
63 | @property auto setbar (int) { return 1; } | |
64 | ||
65 | @property auto propboo () { return 1; } | |
66 | @property auto propboo(T)(T) { return 2; } | |
67 | @property auto propbaz(T)(T) { return 2; } | |
68 | @property auto propbaz () { return 1; } | |
69 | } | |
70 | ||
71 | auto ufoo1528 (S1528) { return 1; } | |
72 | auto ufoo1528(T)(S1528) { return 2; } | |
73 | auto ubar1528(T)(S1528) { return 2; } | |
74 | auto ubar1528 (S1528) { return 1; } | |
75 | ||
76 | @property auto ugetfoo1528 (S1528) { return 1; } | |
77 | @property auto ugetfoo1528(T)(S1528) { return 2; } | |
78 | @property auto ugetbar1528(T)(S1528) { return 2; } | |
79 | @property auto ugetbar1528 (S1528) { return 1; } | |
80 | ||
81 | @property auto usetfoo1528 (S1528, int) { return 1; } | |
82 | @property auto usetfoo1528(T)(S1528, int) { return 2; } | |
83 | @property auto usetbar1528(T)(S1528, int) { return 2; } | |
84 | @property auto usetbar1528 (S1528, int) { return 1; } | |
85 | ||
86 | @property auto upropboo1528 (S1528) { return 1; } | |
87 | @property auto upropboo1528(T)(S1528, T) { return 2; } | |
88 | @property auto upropbaz1528(T)(S1528, T) { return 2; } | |
89 | @property auto upropbaz1528 (S1528) { return 1; } | |
90 | ||
91 | void test1528a() | |
92 | { | |
93 | // global | |
94 | assert(foo1528(100) == 1); | |
95 | assert(foo1528(10L) == 1); | |
96 | assert(foo1528([1]) == 2); | |
97 | assert(foo1528(1.0) == 3); | |
98 | assert(foo1528("a") == 4); | |
99 | assert(bar1528(100) == 1); | |
100 | assert(bar1528(10L) == 1); | |
101 | assert(bar1528([1]) == 2); | |
102 | assert(bar1528(1.0) == 3); | |
103 | assert(bar1528("a") == 4); | |
104 | ||
105 | assert(getfoo1528 == 1); | |
106 | assert(getfoo1528!string == 2); | |
107 | assert(getbar1528 == 1); | |
108 | assert(getbar1528!string == 2); | |
109 | ||
110 | assert((setfoo1528 = 1) == 1); | |
111 | assert((setfoo1528!string = 1) == 2); | |
112 | assert((setbar1528 = 1) == 1); | |
113 | assert((setbar1528!string = 1) == 2); | |
114 | ||
115 | S1528 s; | |
116 | ||
117 | // member | |
118 | assert(s.foo(100) == 1); | |
119 | assert(s.foo(10L) == 1); | |
120 | assert(s.foo([1]) == 2); | |
121 | assert(s.foo(1.0) == 3); | |
122 | assert(s.foo("a") == 4); | |
123 | assert(s.bar(100) == 1); | |
124 | assert(s.bar(10L) == 1); | |
125 | assert(s.bar([1]) == 2); | |
126 | assert(s.bar(1.0) == 3); | |
127 | assert(s.bar("a") == 4); | |
128 | ||
129 | assert(s.getfoo == 1); | |
130 | assert(s.getfoo!string == 2); | |
131 | assert(s.getbar == 1); | |
132 | assert(s.getbar!string == 2); | |
133 | ||
134 | assert((s.setfoo = 1) == 1); | |
135 | assert((s.setfoo!string = 1) == 2); | |
136 | assert((s.setbar = 1) == 1); | |
137 | assert((s.setbar!string = 1) == 2); | |
138 | ||
139 | assert((s.propboo = 1) == 2); | |
140 | assert( s.propboo == 1); | |
141 | assert((s.propbaz = 1) == 2); | |
142 | assert( s.propbaz == 1); | |
143 | ||
144 | // UFCS | |
145 | assert(s.ufoo1528 () == 1); | |
146 | assert(s.ufoo1528!string() == 2); | |
147 | assert(s.ubar1528 () == 1); | |
148 | assert(s.ubar1528!string() == 2); | |
149 | ||
150 | assert(s.ugetfoo1528 == 1); | |
151 | assert(s.ugetfoo1528!string == 2); | |
152 | assert(s.ugetbar1528 == 1); | |
153 | assert(s.ugetbar1528!string == 2); | |
154 | ||
155 | assert((s.usetfoo1528 = 1) == 1); | |
156 | assert((s.usetfoo1528!string = 1) == 2); | |
157 | assert((s.usetbar1528 = 1) == 1); | |
158 | assert((s.usetbar1528!string = 1) == 2); | |
159 | ||
160 | assert((s.upropboo1528 = 1) == 2); | |
161 | assert( s.upropboo1528 == 1); | |
162 | assert((s.upropbaz1528 = 1) == 2); | |
163 | assert( s.upropbaz1528 == 1); | |
164 | ||
165 | // overload set | |
166 | import imports.ovs1528a, imports.ovs1528b; | |
167 | assert(func1528() == 1); | |
168 | assert(func1528(1.0) == 2); | |
169 | assert(func1528("a") == 3); | |
170 | assert(func1528([1.0]) == 4); | |
171 | assert(bunc1528() == 1); | |
172 | assert(bunc1528(1.0) == 2); | |
173 | assert(bunc1528("a") == 3); | |
174 | assert(bunc1528([1.0]) == 4); | |
175 | ||
176 | assert(vunc1528(100) == 1); | |
177 | assert(vunc1528("a") == 2); | |
178 | assert(wunc1528(100) == 1); | |
179 | assert(wunc1528("a") == 2); | |
180 | ||
181 | //assert(opUnary1528!"+"(10) == 1); | |
182 | //assert(opUnary1528!"-"(10) == 2); | |
183 | } | |
184 | ||
185 | // ---- | |
186 | ||
187 | int doo1528a(int a, double=10) { return 1; } | |
188 | int doo1528a(int a, string="") { return 2; } | |
189 | ||
190 | int doo1528b(int a) { return 1; } | |
191 | int doo1528b(T:int)(T b) { return 2; } | |
192 | ||
193 | int doo1528c(T:int)(T b, double=10) { return 2; } | |
194 | int doo1528c(T:int)(T b, string="") { return 2; } | |
195 | ||
196 | int doo1528d(int a) { return 1; } | |
197 | int doo1528d(T)(T b) { return 2; } | |
198 | ||
199 | void test1528b() | |
200 | { | |
201 | // MatchLevel by tiargs / by fargs | |
202 | static assert(!__traits(compiles, doo1528a(1))); | |
203 | // 1: MATCHexact / MATCHexact | |
204 | // 2: MATCHexact / MATCHexact | |
205 | static assert(!__traits(compiles, doo1528a(1L))); | |
206 | // 1: MATCHexact / MATCHconvert | |
207 | // 2: MATCHexact / MATCHconvert | |
208 | ||
209 | static assert(!__traits(compiles, doo1528b(1))); | |
210 | // 1: MATCHexact / MATCHexact | |
211 | // 2: MATCHexact / MATCHexact | |
212 | assert(doo1528b(1L) == 1); | |
213 | // 1: MATCHexact / MATCHconvert | |
214 | // 2: MATCHnomatch / - | |
215 | ||
216 | static assert(!__traits(compiles, doo1528c(1))); | |
217 | // 1: MATCHexact / MATCHexact | |
218 | // 2: MATCHexact / MATCHexact | |
219 | static assert(!__traits(compiles, doo1528c(1L))); | |
220 | // 1: MATCHnomatch / - | |
221 | // 2: MATCHnomatch / - | |
222 | ||
223 | assert(doo1528d(1) == 1); | |
224 | // 1: MATCHexact / MATCHexact | |
225 | // 2: MATCHconvert / MATCHexact | |
226 | assert(doo1528d(1L) == 1); | |
227 | // 1: MATCHexact / MATCHconvert | |
228 | // 2: MATCHconvert / MATCHexact | |
229 | // -> not sure, may be ambiguous...? | |
230 | } | |
231 | ||
232 | // ---- | |
233 | ||
234 | char[num*2] toHexString1528(int order, size_t num)(in ubyte[num] digest) { return typeof(return).init; } | |
235 | string toHexString1528(int order)(in ubyte[] digest) { assert(0); } | |
236 | ||
237 | char[8] test1528c() | |
238 | { | |
239 | ubyte[4] foo() { return typeof(return).init; } | |
240 | return toHexString1528!10(foo); | |
241 | } | |
242 | ||
243 | // ---- | |
244 | ||
245 | int f1528d1(int a, double=10) { return 1; } | |
246 | int f1528d1(int a, string="") { return 2; } | |
247 | ||
248 | int f1528d2(T:int)(T b, double=10) { return 1; } | |
249 | int f1528d2(T:int)(T b, string="") { return 2; } | |
250 | ||
251 | // vs deduced parameter | |
252 | int f1528d3(int a) { return 1; } | |
253 | int f1528d3(T)(T b) { return 2; } | |
254 | ||
255 | // vs specialized parameter | |
256 | int f1528d4(int a) { return 1; } | |
257 | int f1528d4(T:int)(T b) { return 2; } | |
258 | ||
259 | // vs deduced parameter + template constraint (1) | |
260 | int f1528d5(int a) { return 1; } | |
261 | int f1528d5(T)(T b) if (is(T == int)) { return 2; } | |
262 | ||
263 | // vs deduced parameter + template constraint (2) | |
264 | int f1528d6(int a) { return 1; } | |
265 | int f1528d6(T)(T b) if (is(T : int)) { return 2; } | |
266 | ||
267 | // vs nallowing conversion | |
268 | int f1528d7(ubyte a) { return 1; } | |
269 | int f1528d7(T)(T b) if (is(T : int)) { return 2; } | |
270 | ||
271 | int f1528d10(int, int) { return 1; } | |
272 | int f1528d10(T)(T, int) { return 2; } | |
273 | ||
274 | void test1528d() | |
275 | { | |
276 | static assert(!__traits(compiles, f1528d1(1))); // ambiguous | |
277 | static assert(!__traits(compiles, f1528d1(1L))); // ambiguous | |
278 | ||
279 | static assert(!__traits(compiles, f1528d2(1))); // ambiguous | |
280 | static assert(!__traits(compiles, f1528d2(1L))); // no match | |
281 | ||
282 | assert(f1528d3(1) == 1); | |
283 | assert(f1528d3(1L) == 1); // '1L' matches int | |
284 | short short_val = 42; | |
285 | assert(f1528d3(cast(short) 42) == 1); | |
286 | assert(f1528d3(short_val) == 1); | |
287 | ||
288 | static assert(!__traits(compiles, f1528d4(1))); | |
289 | assert(f1528d4(1L) == 1); | |
290 | ||
291 | assert(f1528d5(1) == 1); | |
292 | assert(f1528d5(1L) == 1); | |
293 | ||
294 | assert(f1528d6(1) == 1); | |
295 | assert(f1528d6(1L) == 1); | |
296 | static assert(!__traits(compiles, f1528d6(ulong.max))); // no match | |
297 | // needs to fix bug 9617 | |
298 | ulong ulval = 1; | |
299 | static assert(!__traits(compiles, f1528d6(ulval))); // no match | |
300 | ||
301 | assert(f1528d7(200u) == 1); // '200u' matches ubyte | |
302 | assert(f1528d7(400u) == 2); | |
303 | uint uival = 400; // TDPL-like range knowledge lost here. | |
304 | assert(f1528d7(uival) == 2); | |
305 | uival = 200; // Ditto. | |
306 | assert(f1528d7(uival) == 2); | |
307 | ||
308 | ||
309 | assert(f1528d10( 1, 9) == 1); | |
310 | assert(f1528d10( 1U, 9) == 1); | |
311 | assert(f1528d10( 1L, 9) == 1); | |
312 | assert(f1528d10( 1LU, 9) == 1); | |
313 | assert(f1528d10( long.max, 9) == 2); | |
314 | assert(f1528d10(ulong.max, 9) == 2); | |
315 | assert(f1528d10( 1, 9L) == 1); | |
316 | assert(f1528d10( 1U, 9L) == 1); | |
317 | assert(f1528d10( 1L, 9L) == 1); | |
318 | assert(f1528d10( 1LU, 9L) == 1); | |
319 | assert(f1528d10( long.max, 9L) == 2); | |
320 | assert(f1528d10(ulong.max, 9L) == 2); | |
321 | } | |
322 | ||
323 | /***************************************************/ | |
5fee5ec3 | 324 | // https://issues.dlang.org/show_bug.cgi?id=1680 |
b4c522fa IB |
325 | |
326 | struct S1680 | |
327 | { | |
328 | ulong _y; | |
329 | ||
330 | ulong blah1() { return _y; } | |
331 | static S1680 blah1(ulong n) { return S1680(n); } | |
332 | ||
333 | static S1680 blah2(ulong n) { return S1680(n); } | |
334 | static S1680 blah2(char[] n) { return S1680(n.length); } | |
335 | } | |
336 | ||
337 | class C1680 | |
338 | { | |
339 | ulong _y; | |
340 | this(ulong n){} | |
341 | ||
342 | ulong blah1() { return _y; } | |
343 | static C1680 blah1(ulong n) { return new C1680(n); } | |
344 | ||
345 | static C1680 blah2(ulong n) { return new C1680(n); } | |
346 | static C1680 blah2(char[] n) { return new C1680(n.length); } | |
347 | } | |
348 | ||
349 | void test1680() | |
350 | { | |
351 | // OK | |
352 | S1680 s = S1680.blah1(5); | |
353 | void fs() | |
354 | { | |
355 | S1680 s1 = S1680.blah2(5); // OK | |
356 | S1680 s2 = S1680.blah2("hello".dup); // OK | |
357 | S1680 s3 = S1680.blah1(5); | |
358 | // Error: 'this' is only allowed in non-static member functions, not f | |
359 | } | |
360 | ||
361 | C1680 c = C1680.blah1(5); | |
362 | void fc() | |
363 | { | |
364 | C1680 c1 = C1680.blah2(5); | |
365 | C1680 c2 = C1680.blah2("hello".dup); | |
366 | C1680 c3 = C1680.blah1(5); | |
367 | } | |
368 | } | |
369 | ||
370 | /***************************************************/ | |
5fee5ec3 | 371 | // https://issues.dlang.org/show_bug.cgi?id=7418 |
b4c522fa IB |
372 | |
373 | int foo7418(uint a) { return 1; } | |
374 | int foo7418(char[] a) { return 2; } | |
375 | ||
376 | alias foo7418 foo7418a; | |
377 | template foo7418b(T = void) { alias foo7418 foo7418b; } | |
378 | ||
379 | void test7418() | |
380 | { | |
381 | assert(foo7418a(1U) == 1); | |
382 | assert(foo7418a("a".dup) == 2); | |
383 | ||
384 | assert(foo7418b!()(1U) == 1); | |
385 | assert(foo7418b!()("a".dup) == 2); | |
386 | } | |
387 | ||
388 | /***************************************************/ | |
5fee5ec3 | 389 | // https://issues.dlang.org/show_bug.cgi?id=7552 |
b4c522fa IB |
390 | |
391 | struct S7552 | |
392 | { | |
393 | static void foo(){} | |
394 | static void foo(int){} | |
395 | } | |
396 | ||
397 | struct T7552 | |
398 | { | |
399 | alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; | |
400 | alias FooInS[0] foo; // should be S7552.foo() | |
401 | static void foo(string){} | |
402 | } | |
403 | ||
404 | struct U7552 | |
405 | { | |
406 | alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; | |
407 | alias FooInS[1] foo; // should be S7552.foo(int) | |
408 | static void foo(string){} | |
409 | } | |
410 | ||
411 | void test7552() | |
412 | { | |
413 | alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; | |
414 | static assert(FooInS.length == 2); | |
415 | FooInS[0](); | |
416 | static assert(!__traits(compiles, FooInS[0](0))); | |
417 | static assert(!__traits(compiles, FooInS[1]())); | |
418 | FooInS[1](0); | |
419 | ||
420 | Id!(FooInS[0])(); | |
421 | static assert(!__traits(compiles, Id!(FooInS[0])(0))); | |
422 | static assert(!__traits(compiles, Id!(FooInS[1])())); | |
423 | Id!(FooInS[1])(0); | |
424 | ||
425 | alias TypeTuple!(__traits(getOverloads, T7552, "foo")) FooInT; | |
426 | static assert(FooInT.length == 2); // fail | |
427 | FooInT[0](); | |
428 | static assert(!__traits(compiles, FooInT[0](0))); | |
429 | static assert(!__traits(compiles, FooInT[0](""))); | |
430 | static assert(!__traits(compiles, FooInT[1]())); | |
431 | static assert(!__traits(compiles, FooInT[1](0))); // fail | |
432 | FooInT[1](""); // fail | |
433 | ||
434 | alias TypeTuple!(__traits(getOverloads, U7552, "foo")) FooInU; | |
435 | static assert(FooInU.length == 2); | |
436 | static assert(!__traits(compiles, FooInU[0]())); | |
437 | FooInU[0](0); | |
438 | static assert(!__traits(compiles, FooInU[0](""))); | |
439 | static assert(!__traits(compiles, FooInU[1]())); | |
440 | static assert(!__traits(compiles, FooInU[1](0))); | |
441 | FooInU[1](""); | |
442 | } | |
443 | ||
444 | /***************************************************/ | |
5fee5ec3 | 445 | // https://issues.dlang.org/show_bug.cgi?id=8668 |
b4c522fa IB |
446 | |
447 | import imports.m8668a; | |
448 | import imports.m8668c; //replace with m8668b to make it work | |
449 | ||
450 | void test8668() | |
451 | { | |
452 | split8668("abc"); | |
453 | split8668(123); | |
454 | } | |
455 | ||
456 | /***************************************************/ | |
5fee5ec3 | 457 | // https://issues.dlang.org/show_bug.cgi?id=8943 |
b4c522fa IB |
458 | |
459 | void test8943() | |
460 | { | |
461 | struct S | |
462 | { | |
463 | void foo(); | |
464 | } | |
465 | ||
466 | alias TypeTuple!(__traits(getOverloads, S, "foo")) Overloads; | |
467 | alias TypeTuple!(__traits(parent, Overloads[0])) P; // fail | |
468 | static assert(is(P[0] == S)); | |
469 | } | |
470 | ||
471 | /***************************************************/ | |
5fee5ec3 | 472 | // https://issues.dlang.org/show_bug.cgi?id=9410 |
b4c522fa IB |
473 | |
474 | struct S {} | |
475 | int foo(float f, ref S s) { return 1; } | |
476 | int foo(float f, S s) { return 2; } | |
477 | void test9410() | |
478 | { | |
479 | S s; | |
480 | assert(foo(1, s ) == 1); // works fine. Print: ref | |
5fee5ec3 IB |
481 | |
482 | /* With the rvalue to ref param change, this calls the 'ref' version | |
483 | * because both are the same match level, but the 'ref' version is | |
484 | * considered "more specialized", as the non-ref version undergoes | |
485 | * a "conversion" to call the ref version. | |
486 | */ | |
487 | assert(foo(1, S()) == 1); | |
b4c522fa IB |
488 | } |
489 | ||
490 | /***************************************************/ | |
5fee5ec3 | 491 | // https://issues.dlang.org/show_bug.cgi?id=10171 |
b4c522fa IB |
492 | |
493 | struct B10171(T) { static int x; } | |
494 | ||
495 | void test10171() | |
496 | { | |
497 | auto mp = &B10171!(B10171!int).x; | |
498 | } | |
499 | ||
500 | /***************************************************/ | |
5fee5ec3 IB |
501 | // https://issues.dlang.org/show_bug.cgi?id=1900 |
502 | // template overload set | |
b4c522fa IB |
503 | |
504 | void test1900a() | |
505 | { | |
506 | // function vs function template with IFTI call | |
507 | assert(foo1900a(100) == 1); | |
508 | assert(foo1900a("s") == 2); | |
509 | assert(foo1900b(100) == 1); | |
510 | assert(foo1900b("s") == 2); | |
511 | // function template call with explicit template arguments | |
512 | assert(foo1900a!string("s") == 2); | |
513 | assert(foo1900b!string("s") == 2); | |
514 | ||
515 | // function template overloaded set call with IFTI | |
516 | assert(bar1900a(100) == 1); | |
517 | assert(bar1900a("s") == 2); | |
518 | assert(bar1900b(100) == 1); | |
519 | assert(bar1900b("s") == 2); | |
520 | // function template overloaded set call with explicit template arguments | |
521 | assert(bar1900a!double(100) == 1); | |
522 | assert(bar1900a!string("s") == 2); | |
523 | assert(bar1900b!double(100) == 1); | |
524 | assert(bar1900b!string("s") == 2); | |
525 | ||
526 | // function template overloaded set call with IFTI | |
527 | assert(baz1900(1234567890) == 1); | |
528 | assert(baz1900([1:1, 2:2]) == 2); | |
529 | assert(baz1900(new Object) == 3); | |
530 | assert(baz1900("deadbeaf") == 4); | |
531 | // function template overloaded set call with explicit template arguments | |
532 | assert(baz1900!(double)(14142135) == 1); | |
533 | assert(baz1900!(int[int])([12:34]) == 2); | |
534 | assert(baz1900!(Object)(new Object) == 3); | |
535 | assert(baz1900!(string)("cafe babe") == 4); | |
536 | ||
537 | static assert(!__traits(compiles, bad1900!"++"())); | |
538 | } | |
539 | ||
540 | void test1900b() | |
541 | { | |
542 | S1900 s; | |
543 | ||
544 | // function vs function template with IFTI call | |
545 | assert(s.foo1900a(100) == 1); | |
546 | assert(s.foo1900a("s") == 2); | |
547 | assert(s.foo1900b(100) == 1); | |
548 | assert(s.foo1900b("s") == 2); | |
549 | // function template call with explicit template arguments | |
550 | assert(s.foo1900a!string("s") == 2); | |
551 | assert(s.foo1900b!string("s") == 2); | |
552 | ||
553 | // function template overloaded set call with IFTI | |
554 | assert(s.bar1900a(100) == 1); | |
555 | assert(s.bar1900a("s") == 2); | |
556 | assert(s.bar1900b(100) == 1); | |
557 | assert(s.bar1900b("s") == 2); | |
558 | // function template overloaded set call with explicit template arguments | |
559 | assert(s.bar1900a!double(100) == 1); | |
560 | assert(s.bar1900a!string("s") == 2); | |
561 | assert(s.bar1900b!double(100) == 1); | |
562 | assert(s.bar1900b!string("s") == 2); | |
563 | ||
564 | // function template overloaded set call with IFTI | |
565 | assert(s.baz1900(1234567890) == 1); | |
566 | assert(s.baz1900([1:1, 2:2]) == 2); | |
567 | assert(s.baz1900(new Object) == 3); | |
568 | assert(s.baz1900("deadbeaf") == 4); | |
569 | // function template overloaded set call with explicit template arguments | |
570 | assert(s.baz1900!(double)(14142135) == 1); | |
571 | assert(s.baz1900!(int[int])([12:34]) == 2); | |
572 | assert(s.baz1900!(Object)(new Object) == 3); | |
573 | assert(s.baz1900!(string)("cafe babe") == 4); | |
574 | ||
575 | static assert(!__traits(compiles, s.bad1900!"++"())); | |
576 | } | |
577 | ||
578 | void test1900c() | |
579 | { | |
580 | S1900 s; | |
581 | ||
582 | // This is a kind of Issue 1528 - [tdpl] overloading template and non-template functions | |
583 | //s.funca(); | |
584 | //s.funca(10); | |
585 | //s.funcb(); | |
586 | //s.funcb(10); | |
587 | ||
588 | // Call function template overload set through mixin member lookup | |
589 | assert(s.mixfooa() == 1); | |
590 | assert(s.mixfooa(10) == 2); | |
591 | assert(s.mixfoob() == 1); | |
592 | assert(s.mixfoob(10) == 2); | |
593 | ||
594 | // Call function template overload set through mixin^2 member lookup | |
595 | assert(s.mixsubfooa() == 1); | |
596 | assert(s.mixsubfooa(10) == 2); | |
597 | assert(s.mixsubfoob() == 1); | |
598 | assert(s.mixsubfoob(10) == 2); | |
599 | ||
600 | // Using mixin identifier can limit overload set | |
601 | assert(s.a.mixfooa() == 1); static assert(!__traits(compiles, s.a.mixfooa(10))); | |
602 | assert(s.b.mixfooa(10) == 2); static assert(!__traits(compiles, s.b.mixfooa())); | |
603 | assert(s.b.mixfoob() == 1); static assert(!__traits(compiles, s.b.mixfoob(10))); | |
604 | assert(s.a.mixfoob(10) == 2); static assert(!__traits(compiles, s.a.mixfoob())); | |
605 | } | |
606 | ||
607 | alias merge1900 = imports.template_ovs1.merge1900; | |
608 | alias merge1900 = imports.template_ovs2.merge1900; | |
609 | ||
610 | void test1900d() | |
611 | { | |
612 | assert( merge1900!double(100) == 1); | |
613 | assert(.merge1900!double(100) == 1); | |
614 | } | |
615 | ||
616 | mixin template Foo1900e(T) | |
617 | { | |
618 | void foo(U : T)() { v++;} | |
619 | } | |
620 | void test1900e() | |
621 | { | |
622 | struct S | |
623 | { | |
624 | int v; | |
625 | mixin Foo1900e!double; | |
626 | mixin Foo1900e!string; | |
627 | void test() | |
628 | { | |
629 | foo!(int); // ScopeExp(ti->tempovers != NULL) | |
630 | foo!(typeof(null)); // ScopeExp(ti->tempovers != NULL) | |
631 | } | |
632 | } | |
633 | ||
634 | S s; | |
635 | assert(s.v == 0); | |
636 | s.test(); | |
637 | assert(s.v == 2); | |
638 | } | |
639 | ||
640 | /***************************************************/ | |
5fee5ec3 | 641 | // https://issues.dlang.org/show_bug.cgi?id=1900 |
b4c522fa IB |
642 | |
643 | void test1900() | |
644 | { | |
645 | AClass1900 a; | |
646 | BClass1900 b; | |
647 | ||
648 | static assert(Traits1900!(AClass1900).name == "AClass"); | |
649 | static assert(Traits1900!(BClass1900).name == "BClass"); | |
650 | static assert(Traits1900!(int).name == "any"); | |
651 | ||
652 | Traits1900!(long) obj; | |
653 | ||
654 | static assert(Value1900a!double == 1); | |
655 | static assert(Value1900b!double == 1); | |
656 | static assert(Value1900a!string == 2); | |
657 | static assert(Value1900b!string == 2); | |
658 | } | |
659 | ||
660 | alias imports.template_ovs1.Traits1900 Traits1900X; | |
661 | alias imports.template_ovs2.Traits1900 Traits1900X; | |
662 | alias imports.template_ovs3.Traits1900 Traits1900X; | |
663 | static assert(Traits1900X!(AClass1900).name == "AClass"); | |
664 | static assert(Traits1900X!(BClass1900).name == "BClass"); | |
665 | static assert(Traits1900X!(int).name == "any"); | |
666 | ||
667 | // Traits1900Y is exact same as imports.template_ovs1.Traits1900. | |
668 | alias imports.template_ovs1.Traits1900 Traits1900Y1; | |
669 | alias imports.template_ovs1.Traits1900 Traits1900Y2; | |
670 | alias Traits1900Y1 Traits1900Y; | |
671 | alias Traits1900Y2 Traits1900Y; | |
672 | static assert(Traits1900Y!(AClass1900).name == "AClass"); | |
673 | static assert(!__traits(compiles, Traits1900Y!(BClass1900))); | |
674 | static assert(!__traits(compiles, Traits1900Y!(int))); | |
675 | ||
676 | template Foo1900(T) | |
677 | { | |
678 | template Bar1900(U : T) | |
679 | { | |
680 | } | |
681 | } | |
682 | mixin Foo1900!(int) A1900; | |
683 | mixin Foo1900!(char) B1900; | |
684 | alias Bar1900!(int) bar1900; // error | |
685 | ||
686 | /***************************************************/ | |
5fee5ec3 | 687 | // https://issues.dlang.org/show_bug.cgi?id=7780 |
b4c522fa IB |
688 | |
689 | mixin template A7780() | |
690 | { | |
691 | template C(int n : 0) { int C = 0; } | |
692 | } | |
693 | mixin template B7780() | |
694 | { | |
695 | template C(int n : 1) { int C = 1; } | |
696 | } | |
697 | ||
698 | class Foo7780 | |
699 | { | |
700 | mixin A7780!(); | |
701 | mixin B7780!(); | |
702 | } | |
703 | ||
704 | void test7780() | |
705 | { | |
706 | assert(Foo7780.C!0 == 0); | |
707 | } | |
708 | ||
709 | /***************************************************/ | |
710 | ||
711 | auto foo7849(string) { return 1; } | |
712 | auto foo7849(dstring) { return 2; } | |
713 | ||
714 | enum str7849a = "string"; | |
715 | immutable str7849ai = "string"; | |
716 | immutable str7849bi = str7849ai; | |
717 | enum str7849b = str7849ai; | |
718 | enum str7849c = str7849bi; | |
719 | ||
720 | void test7849() | |
721 | { | |
722 | assert(foo7849(str7849a) == 1); | |
723 | assert(foo7849(str7849b) == 1); | |
724 | assert(foo7849(str7849c) == 1); | |
725 | } | |
726 | ||
727 | /***************************************************/ | |
5fee5ec3 | 728 | // https://issues.dlang.org/show_bug.cgi?id=8352 |
b4c522fa IB |
729 | |
730 | void test8352() | |
731 | { | |
732 | [1, 2].remove8352a!(x => x == 2)(); | |
733 | [1, 2].remove8352b!(x => x == 2)(); | |
734 | remove8352a("deleteme"); | |
735 | remove8352b("deleteme"); | |
736 | } | |
737 | ||
738 | /***************************************************/ | |
5fee5ec3 | 739 | // https://issues.dlang.org/show_bug.cgi?id=8441 |
b4c522fa IB |
740 | |
741 | mixin template T8441a(string i) | |
742 | { | |
743 | auto j(string s = "a", U)(U u1, U u2) | |
744 | { | |
745 | return 0; | |
746 | } | |
747 | auto j(int i,string s = "a", W)(W u1, W u2) | |
748 | { | |
749 | return i; | |
750 | } | |
751 | ||
752 | mixin(" | |
753 | class F" ~ i ~ " | |
754 | { | |
755 | auto j(string s = \"a\", U)(U u1, U u2) | |
756 | { | |
757 | return this.outer.t" ~ i ~ ".j!(s, U)(u1, u2); | |
758 | } | |
759 | auto j(int i, string s = \"a\", W)(W u1, W u2) | |
760 | { | |
761 | return this.outer.t" ~ i ~ ".j!(i, s, W)(u1, u2); // <- dmd is giving error for j!(...).j's type | |
762 | } | |
763 | } | |
764 | auto f" ~ i ~ "() | |
765 | { | |
766 | return new F" ~ i ~ "(); | |
767 | } | |
768 | "); | |
769 | } | |
770 | class X8441a | |
771 | { | |
772 | mixin T8441a!("1") t0; | |
773 | alias t0 t1; | |
774 | } | |
775 | void test8441a() | |
776 | { | |
777 | auto x = new X8441a(); | |
778 | x.f1().j!(3,"a")(2.2, 3.3); | |
779 | } | |
780 | ||
781 | // ---- | |
782 | ||
783 | mixin template T8441b() | |
784 | { | |
785 | void k()() {} | |
786 | ||
787 | void j()() {} | |
788 | void j(int i)() {} | |
789 | } | |
790 | class X8441b | |
791 | { | |
792 | mixin T8441b t0; | |
793 | } | |
794 | void test8441b() | |
795 | { | |
796 | auto x = new X8441b(); | |
797 | x.k!()(); // Fine | |
798 | x.j!()(); // Fine | |
799 | x.t0.k!()(); // Fine | |
800 | x.t0.j!()(); // Derp | |
801 | } | |
802 | ||
803 | // ---- | |
804 | ||
805 | mixin template Signal8441c(Args...) | |
806 | { | |
807 | bool call = false; | |
808 | final void connect(string method, ClassType)(ClassType obj) | |
809 | if (is(ClassType == class) && __traits(compiles, { void delegate(Args) dg = mixin("&obj."~method); })) | |
810 | { | |
811 | call = true; | |
812 | } | |
813 | } | |
814 | void test8441c() | |
815 | { | |
816 | class Observer | |
817 | { | |
818 | void watchInt(string str, int i) {} | |
819 | } | |
820 | class Bar | |
821 | { | |
822 | mixin Signal8441c!(string, int) s1; | |
823 | mixin Signal8441c!(string, int) s2; | |
824 | mixin Signal8441c!(string, long) s3; | |
825 | } | |
826 | auto a = new Bar; | |
827 | auto o1 = new Observer; | |
828 | ||
829 | a.s1.connect!"watchInt"(o1); | |
830 | ||
831 | assert( a.s1.call); | |
832 | assert(!a.s2.call); | |
833 | assert(!a.s3.call); | |
834 | } | |
835 | ||
836 | /***************************************************/ | |
5fee5ec3 | 837 | // https://issues.dlang.org/show_bug.cgi?id=9235 |
b4c522fa IB |
838 | |
839 | template FlowEvaluator9235() | |
840 | { | |
841 | // if control flow | |
842 | bool execute(Command cmd)() | |
843 | if (cmd == Command.Jump || | |
844 | cmd == Command.Fork) | |
845 | { | |
846 | return false; | |
847 | } | |
848 | } | |
849 | template MatchEvaluator9235() | |
850 | { | |
851 | // if operation | |
852 | bool execute(Command cmd)() | |
853 | if (cmd == Command.Char || | |
854 | cmd == Command.Any || | |
855 | cmd == Command.End) | |
856 | { | |
857 | return true; | |
858 | } | |
859 | } | |
860 | void test9235a() | |
861 | { | |
862 | enum Command | |
863 | { | |
864 | Char, Any, Fork, Jump, End | |
865 | } | |
866 | struct Machine | |
867 | { | |
868 | mixin FlowEvaluator9235; | |
869 | mixin MatchEvaluator9235; | |
870 | ||
871 | bool exec_flow() | |
872 | { | |
873 | return execute!(Command.Jump)(); | |
874 | } | |
875 | bool exec_match() | |
876 | { | |
877 | return execute!(Command.Any)(); | |
878 | } | |
879 | } | |
880 | ||
881 | Machine m; | |
882 | assert(!m.exec_flow()); | |
883 | assert( m.exec_match()); | |
884 | } | |
885 | ||
886 | // ---- | |
887 | ||
888 | mixin template mixA9235() | |
889 | { | |
890 | int foo(string s)() if (s == "a") { return 1; } | |
891 | } | |
892 | mixin template mixB9235() | |
893 | { | |
894 | int foo(string s)() if (s == "b") { return 2; } | |
895 | } | |
896 | struct Foo9235 | |
897 | { | |
898 | mixin mixA9235 A; | |
899 | mixin mixB9235 B; | |
900 | alias A.foo foo; | |
901 | alias B.foo foo; | |
902 | } | |
903 | void test9235b() | |
904 | { | |
905 | Foo9235 f; | |
906 | assert(f.foo!"a"() == 1); | |
907 | assert(f.foo!"b"() == 2); | |
908 | } | |
909 | ||
910 | /***************************************************/ | |
5fee5ec3 | 911 | // https://issues.dlang.org/show_bug.cgi?id=10658 |
b4c522fa IB |
912 | |
913 | alias Val10658 = imports.template_ovs1.Val10658; | |
914 | alias Val10658 = imports.template_ovs2.Val10658; | |
915 | static assert(Val10658!1 == 1); | |
916 | static assert(Val10658!1L == 2); | |
917 | ||
918 | // ---- | |
919 | ||
920 | template Foo10658(T) if (is(T == double)) { enum Foo10658 = 1; } | |
921 | template Bar10658(T) if (is(T == string)) { enum Bar10658 = 2; } | |
922 | alias Baz10658 = Foo10658; | |
923 | alias Baz10658 = Bar10658; | |
924 | ||
925 | template Voo10658(T) if (is(T == cfloat)) { enum Voo10658 = 5; } | |
926 | template Voo10658(T) if (is(T == Object)) { enum Voo10658 = 6; } | |
927 | ||
928 | alias Vaz10658 = Baz10658; // OvarDeclaration | |
929 | alias Vaz10658 = Voo10658; // TemplateDeclaration (overnext != NULL) | |
930 | ||
931 | template Merge10658a(alias A) | |
932 | { | |
933 | enum Merge10658a = A!double + A!string; | |
934 | } | |
935 | template Merge10658b(alias A) | |
936 | { | |
937 | enum Merge10658b = A!double + A!string + A!cfloat + A!Object; | |
938 | } | |
939 | ||
940 | void test10658a() | |
941 | { | |
942 | static assert(Baz10658!double == 1); | |
943 | static assert(Baz10658!string == 2); | |
944 | static assert(Voo10658!cfloat == 5); | |
945 | static assert(Voo10658!Object == 6); | |
946 | ||
947 | // pass OverDeclaration through TemplateAliasParameter | |
948 | static assert(Merge10658a!Baz10658 == 1 + 2); | |
949 | static assert(Merge10658b!Vaz10658 == 1 + 2 + 5 + 6); | |
950 | } | |
951 | ||
952 | // ---- | |
953 | ||
954 | mixin template mix10658A() | |
955 | { | |
956 | int f10658(string s)() if (s == "a") { return 1; } | |
957 | } | |
958 | mixin template mix10658B() | |
959 | { | |
960 | int f10658(string s)() if (s == "b") { return 2; } | |
961 | } | |
962 | mixin mix10658A A10658; | |
963 | mixin mix10658B B10658; | |
964 | alias A10658.f10658 foo10658; | |
965 | alias B10658.f10658 foo10658; | |
966 | ||
967 | mixin template mix10658C() | |
968 | { | |
969 | int f10658(string s, T)(T arg) if (s == "c") { return 3; } | |
970 | } | |
971 | mixin template mix10658D() | |
972 | { | |
973 | int f10658(string s, T)(T arg) if (s == "d") { return 4; } | |
974 | } | |
975 | struct S10658 | |
976 | { | |
977 | mixin mix10658C C10658; | |
978 | mixin mix10658D D10658; | |
979 | alias C10658.f10658 foo10658; | |
980 | alias D10658.f10658 foo10658; | |
981 | } | |
982 | ||
983 | void test10658b() | |
984 | { | |
985 | assert( foo10658!"a"() == 1); | |
986 | assert(.foo10658!"b"() == 2); | |
987 | ||
988 | S10658 s; | |
989 | assert(s.foo10658!"c"(0) == 3); | |
990 | assert(s.foo10658!"d"(0) == 4); | |
991 | } | |
992 | ||
993 | /***************************************************/ | |
994 | ||
995 | class InputStream11785 | |
996 | { | |
997 | long read(ubyte* bytes, long len) | |
998 | { | |
999 | return 0; | |
1000 | } | |
1001 | void read(T)(ref T val) | |
1002 | { | |
1003 | read(cast(ubyte*)&val, cast(long)val.sizeof); | |
1004 | } | |
1005 | } | |
1006 | ||
1007 | long read11785(ubyte* bytes, long len) | |
1008 | { | |
1009 | return 0; | |
1010 | } | |
1011 | void read11785(T)(ref T val) | |
1012 | { | |
1013 | read11785(cast(ubyte*)&val, cast(long)val.sizeof); | |
1014 | } | |
1015 | ||
1016 | void test11785() | |
1017 | { | |
1018 | int v; | |
1019 | ||
1020 | read11785(v); | |
1021 | ||
1022 | auto input = new InputStream11785(); | |
1023 | input.read(v); | |
1024 | } | |
1025 | ||
1026 | /***************************************************/ | |
5fee5ec3 | 1027 | // https://issues.dlang.org/show_bug.cgi?id=11915 |
b4c522fa IB |
1028 | |
1029 | int f11915( int) { return 1; } | |
1030 | int f11915(ref int) { return 2; } | |
1031 | ||
1032 | int g11915( int) { return 1; } | |
1033 | int g11915(out int) { return 2; } | |
1034 | ||
1035 | void test11915() | |
1036 | { | |
1037 | const int n = 1; | |
1038 | assert(f11915(n) == 1); | |
1039 | assert(g11915(n) == 1); | |
1040 | } | |
1041 | ||
1042 | /***************************************************/ | |
5fee5ec3 | 1043 | // https://issues.dlang.org/show_bug.cgi?id=11916 |
b4c522fa IB |
1044 | |
1045 | auto f11916(T)( T) { return 1; } | |
1046 | auto f11916(T)(out T) if (false) { return 2; } | |
1047 | ||
1048 | auto g11916(T)( T) { return 1; } | |
1049 | auto g11916(T)(out T) { return 2; } | |
1050 | ||
1051 | void test11916() | |
1052 | { | |
1053 | const int c = 1; | |
1054 | int m = 2; | |
1055 | ||
1056 | // 'out const int' is invalid function parameter, so (out T) version will be dropped | |
1057 | // from overload candidates before template constraint evaluated. | |
1058 | assert(f11916(c) == 1); | |
1059 | ||
1060 | // Both (T) and (out T) have valid signatures with T == int, but the 2nd overload will be | |
1061 | // dropped from overload candidates because of the template constraint. | |
1062 | assert(f11916(m) == 1); | |
1063 | ||
1064 | // 'out const int' parameter is invalid, so non-out version is selected. | |
1065 | assert(g11916(c) == 1); | |
1066 | ||
1067 | // MATCHconst for (T) version, and MATCHexact for (out T) version. | |
1068 | assert(g11916(m) == 2); | |
1069 | } | |
1070 | ||
1071 | /***************************************************/ | |
5fee5ec3 | 1072 | // https://issues.dlang.org/show_bug.cgi?id=13783 |
b4c522fa IB |
1073 | |
1074 | enum E13783 { a = 5 } | |
1075 | ||
1076 | inout(int) f( inout(int) t) { return t * 2; } | |
5fee5ec3 | 1077 | ref inout(int) f(return ref inout(int) t) { return t; } |
b4c522fa IB |
1078 | |
1079 | void test13783() | |
1080 | { | |
1081 | const E13783 e = E13783.a; | |
1082 | assert(f(e) == 10); | |
1083 | } | |
1084 | ||
1085 | /***************************************************/ | |
5fee5ec3 | 1086 | // https://issues.dlang.org/show_bug.cgi?id=14858 |
b4c522fa IB |
1087 | |
1088 | int foo14858()() { return 1; } | |
1089 | int bar14858(int) { return 2; } | |
1090 | ||
1091 | alias foobar14858 = foo14858; | |
1092 | alias foobar14858 = bar14858; | |
1093 | ||
1094 | void test14858() | |
1095 | { | |
1096 | assert(foobar14858() == 1); | |
1097 | assert(foobar14858(1) == 2); // OK <- NG | |
1098 | } | |
1099 | ||
1100 | /***************************************************/ | |
5fee5ec3 | 1101 | // https://issues.dlang.org/show_bug.cgi?id=14989 |
b4c522fa IB |
1102 | |
1103 | template Foo14989(T) if (is(T == int)) { enum Foo14989 = 1; } | |
1104 | template Bar14989(T) if (is(T == double)) { enum Bar14989 = 2; } | |
1105 | template Baz14989(T) if (is(T == string)) { enum Baz14989 = 3; } | |
1106 | ||
1107 | alias X14989 = Foo14989; | |
1108 | alias X14989 = Bar14989; | |
1109 | // X is an alias to is OverDeclaration | |
1110 | alias A14989 = X14989; | |
1111 | // first, A->aliassym == X | |
1112 | static if (true) | |
1113 | { | |
1114 | alias A14989 = Baz14989; | |
1115 | // A->aliassym = new OverDeclaration('A') | |
1116 | // then, A->aliassym->overloadInsert(Baz) | |
1117 | } | |
1118 | ||
1119 | template Mix14989a() { alias M14989 = Foo14989; } | |
1120 | template Mix14989b() { alias M14989 = Bar14989; } | |
1121 | mixin Mix14989a; | |
1122 | mixin Mix14989b; | |
1123 | alias Y14989 = M14989; | |
1124 | // Y is an alias to OverloadSet | |
1125 | alias B14989 = Y14989; | |
1126 | // first, B->aliassym == Y | |
1127 | static if (true) | |
1128 | { | |
1129 | alias B14989 = Baz14989; | |
1130 | // (B->aliassym = new OverloadSet('B') | |
1131 | // then, B->aliassym->overloadInsert(Baz) | |
1132 | } | |
1133 | ||
1134 | void test14989() | |
1135 | { | |
1136 | static assert(X14989!int == 1); | |
1137 | static assert(X14989!double == 2); | |
1138 | static assert(!__traits(compiles, X14989!string)); // Baz is not in X | |
1139 | ||
1140 | static assert(A14989!int == 1); | |
1141 | static assert(A14989!double == 2); | |
1142 | static assert(A14989!string == 3); // OK <- error | |
1143 | ||
1144 | static assert(Y14989!int == 1); | |
1145 | static assert(Y14989!double == 2); | |
1146 | static assert(!__traits(compiles, Y14989!string)); // Baz is not in Y | |
1147 | ||
1148 | static assert(B14989!int == 1); | |
1149 | static assert(B14989!double == 2); | |
1150 | static assert(B14989!string == 3); // OK <- error | |
1151 | } | |
1152 | ||
1153 | /***************************************************/ | |
5fee5ec3 | 1154 | // https://issues.dlang.org/show_bug.cgi?id=14965 |
b4c522fa IB |
1155 | |
1156 | auto f14965a1() { return f14965a1(123); } | |
1157 | int f14965a1(int x) { return x; } | |
1158 | ||
1159 | int f14965a2(int x) { return x; } | |
1160 | auto f14965a2() { return f14965a2(123); } | |
1161 | ||
1162 | auto f14965b1() { int function(int) fp = &f14965b1; return fp(123); } | |
1163 | int f14965b1(int x) { return x; } | |
1164 | ||
1165 | int f14965b2(int x) { return x; } | |
1166 | auto f14965b2() { int function(int) fp = &f14965b2; return fp(123); } | |
1167 | ||
1168 | auto f14965c1() { auto fp = cast(int function(int))&f14965c1; return fp(123); } | |
1169 | int f14965c1(int x) { return x; } | |
1170 | ||
1171 | int f14965c2(int x) { return x; } | |
1172 | auto f14965c2() { auto fp = cast(int function(int))&f14965c2; return fp(123); } | |
1173 | ||
1174 | int function(int) f14965d1() { return &f14965d1; } | |
1175 | int f14965d1(int n) { return 10 + n; } | |
1176 | ||
1177 | int f14965d2(int n) { return 10 + n; } | |
1178 | int function(int) f14965d2() { return &f14965d2; } | |
1179 | ||
1180 | class C | |
1181 | { | |
1182 | auto fa1() { return this.fa1(123); } | |
1183 | int fa1(int x) { return x; } | |
1184 | ||
1185 | int fa2(int x) { return x; } | |
1186 | auto fa2() { return this.fa2(123); } | |
1187 | ||
1188 | auto fb1() { int delegate(int) dg = &this.fb1; return dg(123); } | |
1189 | int fb1(int x) { return x; } | |
1190 | ||
1191 | int fb2(int x) { return x; } | |
1192 | auto fb2() { int delegate(int) dg = &this.fb2; return dg(123); } | |
1193 | ||
1194 | auto fc1() { auto dg = cast(int delegate(int))&this.fc1; return dg(123); } | |
1195 | int fc1(int x) { return x; } | |
1196 | ||
1197 | int fc2(int x) { return x; } | |
1198 | auto fc2() { auto dg = cast(int delegate(int))&this.fc2; return dg(123); } | |
1199 | ||
1200 | int delegate(int) fd1() { return &fd1; } | |
1201 | int fd1(int n) { return 10 + n; } | |
1202 | ||
1203 | int fd2(int n) { return 10 + n; } | |
1204 | int delegate(int) fd2() { return &fd2; } | |
1205 | } | |
1206 | ||
1207 | void test14965() | |
1208 | { | |
1209 | assert(f14965a1() == 123); | |
1210 | assert(f14965b1() == 123); | |
1211 | assert(f14965c1() == 123); | |
1212 | assert(f14965d1()(113) == 123); | |
1213 | assert(f14965a2() == 123); | |
1214 | assert(f14965b2() == 123); | |
1215 | assert(f14965c2() == 123); | |
1216 | assert(f14965d2()(113) == 123); | |
1217 | ||
1218 | auto c = new C(); | |
1219 | assert(c.fa1() == 123); | |
1220 | assert(c.fb1() == 123); | |
1221 | assert(c.fc1() == 123); | |
1222 | assert(c.fd1()(113) == 123); | |
1223 | assert(c.fa2() == 123); | |
1224 | assert(c.fb2() == 123); | |
1225 | assert(c.fc2() == 123); | |
1226 | assert(c.fd2()(113) == 123); | |
1227 | } | |
1228 | ||
5fee5ec3 IB |
1229 | /***************************************************/ |
1230 | // https://issues.dlang.org/show_bug.cgi?id=21481 | |
1231 | ||
1232 | struct S21481 | |
1233 | { | |
1234 | void funB2(char a) {} | |
1235 | alias funB = funB2; | |
1236 | // template as first symbol in overload set and overloading an alias | |
1237 | void funB()(float t) {} | |
1238 | void funB(int b) {} // function was lost -> OK now | |
1239 | } | |
1240 | ||
1241 | void test21481() | |
1242 | { | |
1243 | static assert(__traits(getOverloads, S21481, "funB", true).length == 3); | |
1244 | } | |
1245 | ||
1246 | /***************************************************/ | |
1247 | // https://issues.dlang.org/show_bug.cgi?id=21522 | |
1248 | ||
1249 | struct S21522 | |
1250 | { | |
1251 | // alias to template as first symbol in overload set | |
1252 | void funA2()(int a) {} | |
1253 | void funA2(char a) {} // function was lost -> OK now | |
1254 | alias funA = funA2; | |
1255 | void funA(float b) {} | |
1256 | } | |
1257 | ||
1258 | void test21522() | |
1259 | { | |
1260 | static assert(__traits(getOverloads, S21522, "funA", true).length == 3); | |
1261 | } | |
1262 | ||
b4c522fa IB |
1263 | /***************************************************/ |
1264 | ||
1265 | int main() | |
1266 | { | |
1267 | test1528a(); | |
1268 | test1528b(); | |
1269 | test1528c(); | |
1270 | test1528d(); | |
1271 | test1680(); | |
1272 | test7418(); | |
1273 | test7552(); | |
1274 | test8668(); | |
1275 | test8943(); | |
1276 | test9410(); | |
1277 | test10171(); | |
1278 | test1900a(); | |
1279 | test1900b(); | |
1280 | test1900c(); | |
1281 | test1900d(); | |
1282 | test1900e(); | |
1283 | test7780(); | |
1284 | test7849(); | |
1285 | test8352(); | |
1286 | test8441a(); | |
1287 | test8441b(); | |
1288 | test8441c(); | |
1289 | test9235a(); | |
1290 | test9235b(); | |
1291 | test10658a(); | |
1292 | test10658b(); | |
1293 | test11785(); | |
1294 | test11915(); | |
1295 | test11916(); | |
1296 | test13783(); | |
1297 | test14858(); | |
1298 | test14965(); | |
5fee5ec3 IB |
1299 | test21481(); |
1300 | test21522(); | |
b4c522fa IB |
1301 | |
1302 | printf("Success\n"); | |
1303 | return 0; | |
1304 | } |