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