1 // PERMUTE_ARGS: 2 3 module breaker; 4 5 import core.stdc.stdio, core.vararg; 6 7 /**********************************/ 8 9 U foo(T, U)(U i) 10 { 11 return i + 1; 12 } 13 14 int foo(T)(int i) 15 { 16 return i + 2; 17 } 18 19 void test1() 20 { 21 auto i = foo!(int)(2L); 22 // assert(i == 4); // now returns 3 23 } 24 25 /**********************************/ 26 27 U foo2(T, U)(U i) 28 { 29 return i + 1; 30 } 31 32 void test2() 33 { 34 auto i = foo2!(int)(2L); 35 assert(i == 3); 36 } 37 38 /**********************************/ 39 40 class Foo3 41 { 42 T bar(T,U)(U u) 43 { 44 return cast(T)u; 45 } 46 } 47 48 void test3() 49 { 50 Foo3 foo = new Foo3; 51 int i = foo.bar!(int)(1.0); 52 assert(i == 1); 53 } 54 55 56 /**********************************/ 57 58 T* begin4(T)(T[] a) { return a.ptr; } 59 60 void copy4(string pred = "", Ranges...)(Ranges rs) 61 { 62 alias rs[$ - 1] target; 63 pragma(msg, typeof(target).stringof); 64 auto tb = begin4(target);//, te = end(target); 65 } 66 67 void test4() 68 { 69 int[] a, b, c; 70 copy4(a, b, c); 71 // comment the following line to prevent compiler from crashing 72 copy4!("a > 1")(a, b, c); 73 } 74 75 /**********************************/ 76 77 import std.stdio:writefln; 78 79 template foo5(T,S) 80 { 81 void foo5(T t, S s) { 82 writefln("typeof(T)=",typeid(T)," typeof(S)=",typeid(S)); 83 } 84 } 85 86 template bar5(T,S) 87 { 88 void bar5(S s) { 89 writefln("typeof(T)=",typeid(T),"typeof(S)=",typeid(S)); 90 } 91 } 92 93 94 void test5() 95 { 96 foo5(1.0,33); 97 bar5!(double,int)(33); 98 bar5!(float)(33); 99 } 100 101 /**********************************/ 102 103 int foo6(T...)(auto ref T x) 104 { int result; 105 106 foreach (i, v; x) 107 { 108 if (v == 10) 109 assert(__traits(isRef, x[i])); 110 else 111 assert(!__traits(isRef, x[i])); 112 result += v; 113 } 114 return result; 115 } 116 117 void test6() 118 { int y = 10; 119 int r; 120 r = foo6(8); 121 assert(r == 8); 122 r = foo6(y); 123 assert(r == 10); 124 r = foo6(3, 4, y); 125 assert(r == 17); 126 r = foo6(4, 5, y); 127 assert(r == 19); 128 r = foo6(y, 6, y); 129 assert(r == 26); 130 } 131 132 /**********************************/ 133 134 auto ref min(T, U)(auto ref T lhs, auto ref U rhs) 135 { 136 return lhs > rhs ? rhs : lhs; 137 } 138 139 void test7() 140 { int x = 7, y = 8; 141 int i; 142 143 i = min(4, 3); 144 assert(i == 3); 145 i = min(x, y); 146 assert(i == 7); 147 min(x, y) = 10; 148 assert(x == 10); 149 static assert(!__traits(compiles, min(3, y) = 10)); 150 static assert(!__traits(compiles, min(y, 3) = 10)); 151 } 152 153 /**********************************/ 154 // 5946 155 156 template TTest8() 157 { 158 int call(){ return this.g(); } 159 } 160 class CTest8 161 { 162 int f() { mixin TTest8!(); return call(); } 163 int g() { return 10; } 164 } 165 void test8() 166 { 167 assert((new CTest8()).f() == 10); 168 } 169 170 /**********************************/ 171 // 693 172 173 template TTest9(alias sym) 174 { 175 int call(){ return sym.g(); } 176 } 177 class CTest9 178 { 179 int f1() { mixin TTest9!(this); return call(); } 180 int f2() { mixin TTest9!this; return call(); } 181 int g() { return 10; } 182 } 183 void test9() 184 { 185 assert((new CTest9()).f1() == 10); 186 assert((new CTest9()).f2() == 10); 187 } 188 189 /**********************************/ 190 // 1780 191 192 template Tuple1780(Ts ...) { alias Ts Tuple1780; } 193 194 template Decode1780( T ) { alias Tuple1780!() Types; } 195 template Decode1780( T : TT!(Us), alias TT, Us... ) { alias Us Types; } 196 197 void test1780() 198 { 199 struct S1780(T1, T2) {} 200 201 // should extract tuple (bool,short) but matches the first specialisation 202 alias Decode1780!( S1780!(bool,short) ).Types SQ1780; // --> SQ2 is empty tuple! 203 static assert(is(SQ1780 == Tuple1780!(bool, short))); 204 } 205 206 /**********************************/ 207 // 1659 208 209 class Foo1659 { } 210 class Bar1659 : Foo1659 { } 211 212 void f1659(T : Foo1659)() { } 213 void f1659(alias T)() { static assert(false); } 214 215 void test1659() 216 { 217 f1659!Bar1659(); 218 } 219 220 /**********************************/ 221 // 2025 222 223 struct S2025 {} 224 void f2025() {} 225 226 template Foo2025(int i) { enum Foo2025 = 1; } 227 template Foo2025(TL...) { enum Foo2025 = 2; } 228 static assert(Foo2025!1 == 1); 229 static assert(Foo2025!int == 2); 230 static assert(Foo2025!S2025 == 2); 231 static assert(Foo2025!f2025 == 2); 232 233 template Bar2025(T) { enum Bar2025 = 1; } 234 template Bar2025(A...) { enum Bar2025 = 2; } 235 static assert(Bar2025!1 == 2); 236 static assert(Bar2025!int == 1); // 2 -> 1 237 static assert(Bar2025!S2025 == 1); // 2 -> 1 238 static assert(Bar2025!f2025 == 2); 239 240 template Baz2025(T) { enum Baz2025 = 1; } 241 template Baz2025(alias A) { enum Baz2025 = 2; } 242 static assert(Baz2025!1 == 2); 243 static assert(Baz2025!int == 1); 244 static assert(Baz2025!S2025 == 1); // 2 -> 1 245 static assert(Baz2025!f2025 == 2); 246 247 /**********************************/ 248 // 3608 249 250 template foo3608(T, U){} 251 252 template BaseTemplate3608(alias TTT : U!V, alias U, V...) 253 { 254 alias U BaseTemplate3608; 255 } 256 template TemplateParams3608(alias T : U!V, alias U, V...) 257 { 258 alias V TemplateParams3608; 259 } 260 261 template TyueTuple3608(T...) { alias T TyueTuple3608; } 262 263 void test3608() 264 { 265 alias foo3608!(int, long) Foo3608; 266 267 static assert(__traits(isSame, BaseTemplate3608!Foo3608, foo3608)); 268 static assert(is(TemplateParams3608!Foo3608 == TyueTuple3608!(int, long))); 269 } 270 271 /**********************************/ 272 // 5015 273 274 import breaker; 275 276 static if (is(ElemType!(int))){} 277 278 template ElemType(T) { 279 alias _ElemType!(T).type ElemType; 280 } 281 282 template _ElemType(T) { 283 alias r type; 284 } 285 286 /**********************************/ 287 // 5185 288 289 class C5185(V) 290 { 291 void f() 292 { 293 C5185!(C5185!(int)) c; 294 } 295 } 296 297 void test5185() 298 { 299 C5185!(C5185!(int)) c; 300 } 301 302 /**********************************/ 303 // 5893 304 305 class C5893 306 { 307 int concatAssign(C5893 other) { return 1; } 308 int concatAssign(int other) { return 2; } // to demonstrate overloading 309 310 template opOpAssign(string op) if (op == "~") 311 { alias concatAssign opOpAssign; } 312 313 int opOpAssign(string op)(int other) if (op == "+") { return 3; } 314 } 315 316 void test5893() 317 { 318 auto c = new C5893; 319 assert(c.opOpAssign!"~"(c) == 1); // works 320 assert(c.opOpAssign!"~"(1) == 2); // works 321 assert((c ~= 1) == 2); 322 assert((c += 1) == 3); // overload 323 } 324 325 /**********************************/ 326 // 5988 327 328 template Templ5988(alias T) 329 { 330 alias T!int Templ5988; 331 } 332 333 class C5988a(T) { Templ5988!C5988a foo; } 334 //Templ5988!C5988a foo5988a; // Commented version 335 void test5988a() { C5988a!int a; } // Was error, now works 336 337 class C5988b(T) { Templ5988!C5988b foo; } 338 Templ5988!C5988b foo5988b; // Uncomment version 339 void test5988b() { C5988b!int a; } // Works 340 341 /**********************************/ 342 // 6404 343 344 // receive only rvalue 345 void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {} 346 void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {} 347 348 // receive only lvalue 349 void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {} 350 void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {} 351 352 void test6404() 353 { 354 int n; 355 356 static assert(!__traits(compiles, rvalue(n))); 357 static assert( __traits(compiles, rvalue(0))); 358 359 static assert( __traits(compiles, lvalue(n))); 360 static assert(!__traits(compiles, lvalue(0))); 361 362 static assert(!__traits(compiles, rvalueVargs(n))); 363 static assert( __traits(compiles, rvalueVargs(0))); 364 365 static assert( __traits(compiles, lvalueVargs(n))); 366 static assert(!__traits(compiles, lvalueVargs(0))); 367 } 368 369 /**********************************/ 370 // 2246 371 372 class A2246(T,d){ 373 T p; 374 } 375 376 class B2246(int rk){ 377 int[rk] p; 378 } 379 380 class C2246(T,int rk){ 381 T[rk] p; 382 } 383 384 template f2246(T:A2246!(U,d),U,d){ 385 void f2246(){ } 386 } 387 388 template f2246(T:B2246!(rank),int rank){ 389 void f2246(){ } 390 } 391 392 template f2246(T:C2246!(U,rank),U,int rank){ 393 void f2246(){ } 394 } 395 396 void test2246(){ 397 A2246!(int,long) a; 398 B2246!(2) b; 399 C2246!(int,2) c; 400 f2246!(A2246!(int,long))(); 401 f2246!(B2246!(2))(); 402 f2246!(C2246!(int,2))(); 403 } 404 405 /**********************************/ 406 // 2296 407 408 void foo2296(size_t D)(int[D] i...){} 409 void test2296() 410 { 411 foo2296(1, 2, 3); 412 } 413 414 /**********************************/ 415 // 1684 416 417 template Test1684( uint memberOffset ){} 418 419 class MyClass1684 { 420 int flags2; 421 mixin Test1684!(cast(uint)flags2.offsetof) t1; // compiles ok 422 mixin Test1684!(cast(int)flags2.offsetof) t2; // compiles ok 423 mixin Test1684!(flags2.offsetof) t3; // Error: no property 'offsetof' for type 'int' 424 } 425 426 /**********************************/ 427 428 void bug4984a(int n)() if (n > 0 && is(typeof(bug4984a!(n-1) ()))) { 429 } 430 431 void bug4984a(int n : 0)() { 432 } 433 434 void bug4984b(U...)(U args) if ( is(typeof( bug4984b(args[1..$]) )) ) { 435 } 436 437 void bug4984b(U)(U u) { 438 } 439 440 void bug4984() { 441 // Note: compiling this overflows the stack if dmd is build with DEBUG 442 //bug4984a!400(); 443 bug4984a!200(); 444 bug4984b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19); 445 } 446 447 /***************************************/ 448 // 2579 449 450 void foo2579(T)(T delegate(in Object) dlg) 451 { 452 } 453 454 void test2579() 455 { 456 foo2579( (in Object o) { return 15; } ); 457 } 458 459 /**********************************/ 460 // 2803 461 462 auto foo2803(T)(T t = 0) { return t; } 463 464 struct S2803 {} 465 S2803 s2803; 466 ref S2803 getS2803() { return s2803; } 467 auto fun2803(T, U)(T t, ref U u = getS2803) 468 { 469 static assert(is(U == S2803)); 470 return &u; 471 } 472 473 // from the past version of std.conv 474 template to2803(T) { T to2803(S)(S src) { return T.init; } } 475 auto toImpl2803a(T, S)(S s, in T left, in T sep = ", ", in T right = "]") {} 476 auto toImpl2803b(T, S)(S s, in T left = to2803!T(S.stringof~"("), in T right = ")") {} 477 auto toImpl2803c(T, S)(S s, in T left = S.stringof~"(" , in T right = ")") {} // combination with enh 13944 478 479 // from std.range.package in 2.067a. 480 auto enumerate2803(En = size_t, R)(R r, En start = 0) 481 { 482 // The type of 'start' should be size_t, it's the defaultArg of En, 483 // rather than the deduced type from its defualtArg '0'. 484 static assert(is(typeof(start) == size_t)); 485 return start; 486 } 487 488 // from std.numeric. 489 alias ElementType2803(R) = typeof(R.init[0].init); 490 void normalize2803(R)(R range, ElementType2803!R sum = 1) 491 { 492 // The type of 'sum' should be determined to ElementType!(double[]) == double 493 // before the type deduction from its defaultArg '1'. 494 static assert(is(typeof(sum) == double)); 495 } 496 497 auto foo14468(T)(T[]...) { return 1; } 498 auto foo14468(bool flag, T)(T[]...) { return 2; } 499 500 void test2803() 501 { 502 assert(foo2803() == 0); 503 assert(foo2803(1) == 1); 504 505 S2803 s; 506 assert(fun2803(1) is &s2803); 507 assert(fun2803(1, s) is &s); 508 509 // regression cases 510 511 toImpl2803a!string(1, "["); 512 513 toImpl2803b! string(1); 514 toImpl2803b!wstring(1); 515 toImpl2803b!dstring(1); 516 517 toImpl2803c! string(1); 518 toImpl2803c!wstring(1); // requires enhancement 13944 519 toImpl2803c!dstring(1); // requires enhancement 13944 520 521 enumerate2803([1]); 522 523 double[] a = []; 524 normalize2803(a); 525 526 assert(foo14468!int() == 1); 527 } 528 529 /**********************************/ 530 // 6613 531 532 alias Tuple6613(T...) = T; 533 534 void f6613(T...)(int x = 0, T xs = Tuple6613!()) 535 { 536 assert(x == 0); 537 static assert(T.length == 0); 538 } 539 540 void test6613() 541 { 542 f6613(); 543 } 544 545 /**********************************/ 546 // 4953 547 548 void bug4953(T = void)(short x) {} 549 static assert(is(typeof(bug4953(3)))); 550 551 /**********************************/ 552 // 5886 & 5393 553 554 mixin template Foo5886(T) 555 { 556 void foo(U : T, this X)() const { static assert(is(X == const K5886)); } 557 } 558 559 struct K5886 560 { 561 void get1(this T)() const 562 { 563 pragma(msg, T); 564 } 565 void get2(int N=4, this T)() const 566 { 567 pragma(msg, N, " ; ", T); 568 } 569 570 mixin Foo5886!double; 571 mixin Foo5886!string; 572 573 void test() const 574 { 575 get1; // OK 576 get2; // OK 577 get2!8; // NG 578 579 foo!(int); 580 foo!(typeof(null)); 581 } 582 } 583 584 void test5886() 585 { 586 K5886 km; 587 const(K5886) kc; 588 immutable(K5886) ki; 589 590 km.get1; // OK 591 kc.get1; // OK 592 ki.get1; // OK 593 km.get2; // OK 594 kc.get2; // OK 595 ki.get2; // OK 596 km.get2!(1, K5886); // Ugly 597 kc.get2!(2, const(K5886)); // Ugly 598 ki.get2!(3, immutable(K5886)); // Ugly 599 km.get2!8; // Error 600 kc.get2!9; // Error 601 ki.get2!10; // Error 602 } 603 604 // -------- 605 606 void test5393() 607 { 608 class A 609 { 610 void opDispatch (string name, this T) () { } 611 } 612 613 class B : A {} 614 615 auto b = new B; 616 b.foobar(); 617 } 618 619 /**********************************/ 620 // 5896 621 622 struct X5896 623 { 624 T opCast(T)(){ return 1; } 625 const T opCast(T)(){ return 2; } 626 immutable T opCast(T)(){ return 3; } 627 shared T opCast(T)(){ return 4; } 628 const shared T opCast(T)(){ return 5; } 629 } 630 void test5896() 631 { 632 auto xm = X5896 (); 633 auto xc = const(X5896) (); 634 auto xi = immutable(X5896) (); 635 auto xs = shared(X5896) (); 636 auto xcs= const(shared(X5896))(); 637 assert(cast(int)xm == 1); 638 assert(cast(int)xc == 2); 639 assert(cast(int)xi == 3); 640 assert(cast(int)xs == 4); 641 assert(cast(int)xcs== 5); 642 } 643 644 /**********************************/ 645 // 6312 646 647 void h6312() {} 648 649 class Bla6312 650 { 651 mixin wrap6312!h6312; 652 } 653 654 mixin template wrap6312(alias f) 655 { 656 void blub(alias g = f)() 657 { 658 g(); 659 } 660 } 661 662 void test6312() 663 { 664 Bla6312 b = new Bla6312(); 665 b.blub(); 666 } 667 668 /**********************************/ 669 // 6825 670 671 void test6825() 672 { 673 struct File 674 { 675 void write(S...)(S args) {} 676 } 677 678 void dump(void delegate(string) d) {} 679 680 auto o = File(); 681 dump(&o.write!string); 682 } 683 684 /**********************************/ 685 // 6789 686 687 template isStaticArray6789(T) 688 { 689 static if (is(T U : U[N], size_t N)) // doesn't match 690 { 691 pragma(msg, "> U = ", U, ", N:", typeof(N), " = ", N); 692 enum isStaticArray6789 = true; 693 } 694 else 695 enum isStaticArray6789 = false; 696 } 697 698 void test6789() 699 { 700 alias int[3] T; 701 static assert(isStaticArray6789!T); 702 } 703 704 /**********************************/ 705 // 2778 706 707 struct ArrayWrapper2778(T) 708 { 709 T[] data; 710 alias data this; 711 } 712 713 void doStuffFunc2778(int[] data) {} 714 715 void doStuffTempl2778(T)(T[] data) {} 716 717 int doStuffTemplOver2778(T)(void* data) { return 1; } 718 int doStuffTemplOver2778(T)(ArrayWrapper2778!T w) { return 2; } 719 720 void test2778() 721 { 722 ArrayWrapper2778!(int) foo; 723 724 doStuffFunc2778(foo); // Works. 725 726 doStuffTempl2778!(int)(foo); // Works. 727 728 doStuffTempl2778(foo); // Error 729 730 assert(doStuffTemplOver2778(foo) == 2); 731 } 732 733 // ---- 734 735 void test2778aa() 736 { 737 void foo(K, V)(V[K] aa){ pragma(msg, "K=", K, ", V=", V); } 738 739 int[string] aa1; 740 foo(aa1); // OK 741 742 struct SubTypeOf(T) 743 { 744 T val; 745 alias val this; 746 } 747 SubTypeOf!(string[char]) aa2; 748 foo(aa2); // NG 749 } 750 751 // ---- 752 753 void test2778get() 754 { 755 void foo(ubyte[]){} 756 757 static struct S 758 { 759 ubyte[] val = [1,2,3]; 760 @property ref ubyte[] get(){ return val; } 761 alias get this; 762 } 763 S s; 764 foo(s); 765 } 766 767 /**********************************/ 768 // 6208 769 770 int getRefNonref(T)(ref T s){ return 1; } 771 int getRefNonref(T)( T s){ return 2; } 772 773 int getAutoRef(T)(auto ref T s){ return __traits(isRef, s) ? 1 : 2; } 774 775 void getOut(T)(out T s){ ; } 776 777 void getLazy1(T=int)(lazy void s){ s(), s(); } 778 void getLazy2(T)(lazy T s){ s(), s(); } 779 780 void test6208a() 781 { 782 int lvalue; 783 int rvalue(){ int t; return t; } 784 785 assert(getRefNonref(lvalue ) == 1); 786 assert(getRefNonref(rvalue()) == 2); 787 788 assert(getAutoRef(lvalue ) == 1); 789 assert(getAutoRef(rvalue()) == 2); 790 791 static assert( __traits(compiles, getOut(lvalue ))); 792 static assert(!__traits(compiles, getOut(rvalue()))); 793 794 int n1; getLazy1(++n1); assert(n1 == 2); 795 int n2; getLazy2(++n2); assert(n2 == 2); 796 797 struct X 798 { 799 int f(T)(auto ref T t){ return 1; } 800 int f(T)(auto ref T t, ...){ return -1; } 801 } 802 auto xm = X (); 803 auto xc = const(X)(); 804 int n; 805 assert(xm.f!int(n) == 1); // resolved 'auto ref' 806 assert(xm.f!int(0) == 1); // ditto 807 } 808 809 void test6208b() 810 { 811 void foo(T)(const T value) if (!is(T == int)) {} 812 813 int mn; 814 const int cn; 815 static assert(!__traits(compiles, foo(mn))); // OK -> OK 816 static assert(!__traits(compiles, foo(cn))); // NG -> OK 817 } 818 819 void test6208c() 820 { 821 struct S 822 { 823 // Original test case. 824 int foo(V)(in V v) { return 1; } 825 int foo(Args...)(auto ref const Args args) { return 2; } 826 827 // Reduced test cases 828 829 int hoo(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst 830 int hoo(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst 831 // If deduction matching level is same, tuple parameter is less specialized than others. 832 833 int bar(V)(V v) { return 1; } // typeof(10) : V -> MATCHexact 834 int bar(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst 835 836 int baz(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst 837 int baz(Args...)(Args args) { return 2; } // typeof(10) : Args[0] -> MATCHexact 838 839 inout(int) war(V)(inout V v) { return 1; } 840 inout(int) war(Args...)(inout Args args){ return 2; } 841 842 inout(int) waz(Args...)(inout Args args){ return 0; } // wild deduction test 843 } 844 845 S s; 846 847 int nm = 10; 848 assert(s.foo(nm) == 1); 849 assert(s.hoo(nm) == 1); 850 assert(s.bar(nm) == 1); 851 assert(s.baz(nm) == 2); 852 assert(s.war(nm) == 1); 853 static assert(is(typeof(s.waz(nm)) == int)); 854 855 const int nc = 10; 856 assert(s.foo(nc) == 1); 857 assert(s.hoo(nc) == 1); 858 assert(s.bar(nc) == 1); 859 assert(s.baz(nc) == 1); 860 assert(s.war(nc) == 1); 861 static assert(is(typeof(s.waz(nc)) == const(int))); 862 863 immutable int ni = 10; 864 assert(s.foo(ni) == 1); 865 assert(s.hoo(ni) == 1); 866 assert(s.bar(ni) == 1); 867 assert(s.baz(ni) == 2); 868 assert(s.war(ni) == 1); 869 static assert(is(typeof(s.waz(ni)) == immutable(int))); 870 871 static assert(is(typeof(s.waz(nm, nm)) == int)); 872 static assert(is(typeof(s.waz(nm, nc)) == const(int))); 873 static assert(is(typeof(s.waz(nm, ni)) == const(int))); 874 static assert(is(typeof(s.waz(nc, nm)) == const(int))); 875 static assert(is(typeof(s.waz(nc, nc)) == const(int))); 876 static assert(is(typeof(s.waz(nc, ni)) == const(int))); 877 static assert(is(typeof(s.waz(ni, nm)) == const(int))); 878 static assert(is(typeof(s.waz(ni, nc)) == const(int))); 879 static assert(is(typeof(s.waz(ni, ni)) == immutable(int))); 880 } 881 882 /**********************************/ 883 // 6805 884 885 struct T6805 886 { 887 template opDispatch(string name) 888 { 889 alias int Type; 890 } 891 } 892 static assert(is(T6805.xxx.Type == int)); 893 894 /**********************************/ 895 // 6738 896 897 struct Foo6738 898 { 899 int _val = 10; 900 901 @property int val()() { return _val; } 902 int get() { return val; } // fail 903 } 904 905 void test6738() 906 { 907 Foo6738 foo; 908 auto x = foo.val; // ok 909 assert(x == 10); 910 assert(foo.get() == 10); 911 } 912 913 /**********************************/ 914 // 7498 915 916 template IndexMixin(){ 917 void insert(T)(T value){ } 918 } 919 920 class MultiIndexContainer{ 921 mixin IndexMixin!() index0; 922 class Index0{ 923 void baburk(){ 924 this.outer.index0.insert(1); 925 } 926 } 927 } 928 929 /**********************************/ 930 // 6780 931 932 @property int foo6780()(){ return 10; } 933 934 int g6780; 935 @property void bar6780()(int n){ g6780 = n; } 936 937 void test6780() 938 { 939 auto n = foo6780; 940 assert(n == 10); 941 942 bar6780 = 10; 943 assert(g6780 == 10); 944 } 945 946 /**********************************/ 947 // 6810 948 949 int f6810(int n)(int) { return 1;} 950 int f6810(U...)(U) { assert(0); } 951 int f6810(U...)(U a) { assert(0); } 952 int f6810(U...)(U) if (true) { assert(0); } 953 int f6810(U...)(U a) if (true) { assert(0); } 954 955 void test6810() 956 { 957 assert(f6810!0(0) == 1); 958 } 959 960 /**********************************/ 961 // 6891 962 963 struct S6891(int N, T) 964 { 965 void f(U)(S6891!(N, U) u) { } 966 } 967 968 void test6891() 969 { 970 alias S6891!(1, void) A; 971 A().f(A()); 972 } 973 974 /**********************************/ 975 // 6994 976 977 struct Foo6994 978 { 979 T get(T)(){ return T.init; } 980 981 T func1(T)() 982 if (__traits(compiles, get!T())) 983 { return get!T; } 984 985 T func2(T)() 986 if (__traits(compiles, this.get!T())) // add explicit 'this' 987 { return get!T; } 988 } 989 void test6994() 990 { 991 Foo6994 foo; 992 foo.get!int(); // OK 993 foo.func1!int(); // OK 994 foo.func2!int(); // NG 995 } 996 997 /**********************************/ 998 // 6764 999 1000 enum N6764 = 1; //use const for D1 1001 1002 alias size_t[N6764] T6764; //workaround 1003 void f6764()(T6764 arr...) { } 1004 1005 void g6764()(size_t[1] arr...) { } 1006 1007 void h6764()(size_t[N6764] arr...) { } 1008 1009 void test6764() 1010 { 1011 f6764(0); //good 1012 g6764(0); //good 1013 h6764!()(0); //good 1014 h6764(0); //Error: template main.f() does not match any function template declaration 1015 } 1016 1017 /**********************************/ 1018 // 3467 & 6806 1019 1020 struct Foo3467( uint n ) 1021 { 1022 Foo3467!( n ) bar( ) { 1023 typeof( return ) result; 1024 return result; 1025 } 1026 } 1027 struct Vec3467(size_t N) 1028 { 1029 void opBinary(string op:"~", size_t M)(Vec3467!M) {} 1030 } 1031 void test3467() 1032 { 1033 Foo3467!( 4 ) baz; 1034 baz = baz.bar;// FAIL 1035 1036 Vec3467!2 a1; 1037 Vec3467!3 a2; 1038 a1 ~ a2; // line 7, Error 1039 } 1040 1041 struct TS6806(size_t n) { pragma(msg, typeof(n)); } 1042 static assert(is(TS6806!(1u) == TS6806!(1))); 1043 1044 /**********************************/ 1045 // 4413 1046 1047 struct Foo4413 1048 { 1049 alias typeof(this) typeof_this; 1050 void bar1(typeof_this other) {} 1051 void bar2()(typeof_this other) {} 1052 void bar3(typeof(this) other) {} 1053 void bar4()(typeof(this) other) {} 1054 } 1055 1056 void test4413() 1057 { 1058 Foo4413 f; 1059 f.bar1(f); // OK 1060 f.bar2(f); // OK 1061 f.bar3(f); // OK 1062 f.bar4(f); // ERR 1063 } 1064 1065 /**********************************/ 1066 // 4675 1067 1068 template isNumeric(T) 1069 { 1070 enum bool test1 = is(T : long); // should be hidden 1071 enum bool test2 = is(T : real); // should be hidden 1072 enum bool isNumeric = test1 || test2; 1073 } 1074 void test4675() 1075 { 1076 static assert( isNumeric!int); 1077 static assert(!isNumeric!string); 1078 static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error 1079 static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error 1080 static assert(!__traits(compiles, isNumeric!int.isNumeric)); 1081 } 1082 1083 /**********************************/ 1084 // 5525 1085 1086 template foo5525(T) 1087 { 1088 T foo5525(T t) { return t; } 1089 T foo5525(T t, T u) { return t + u; } 1090 } 1091 1092 void test5525() 1093 { 1094 alias foo5525!int f; 1095 assert(f(1) == 1); 1096 assert(f(1, 2) == 3); 1097 } 1098 1099 /**********************************/ 1100 // 5801 1101 1102 int a5801; 1103 void bar5801(T = double)(typeof(a5801) i) {} 1104 void baz5801(T)(typeof(a5801) i, T t) {} 1105 void test5801() 1106 { 1107 bar5801(2); // Does not compile. 1108 baz5801(3, "baz"); // Does not compile. 1109 } 1110 1111 /**********************************/ 1112 // 5832 1113 1114 struct Bar5832(alias v) {} 1115 1116 template isBar5832a(T) 1117 { 1118 static if (is(T _ : Bar5832!(v), alias v)) 1119 enum isBar5832a = true; 1120 else 1121 enum isBar5832a = false; 1122 } 1123 template isBar5832b(T) 1124 { 1125 static if (is(T _ : Bar5832!(v), alias int v)) 1126 enum isBar5832b = true; 1127 else 1128 enum isBar5832b = false; 1129 } 1130 template isBar5832c(T) 1131 { 1132 static if (is(T _ : Bar5832!(v), alias string v)) 1133 enum isBar5832c = true; 1134 else 1135 enum isBar5832c = false; 1136 } 1137 static assert( isBar5832a!(Bar5832!1234)); 1138 static assert( isBar5832b!(Bar5832!1234)); 1139 static assert(!isBar5832c!(Bar5832!1234)); 1140 1141 /**********************************/ 1142 // 2550 1143 1144 template pow10_2550(long n) 1145 { 1146 const long pow10_2550 = 0; 1147 static if (n < 0) 1148 const long pow10_2550 = 0; 1149 else 1150 const long pow10_2550 = 10 * pow10_2550!(n - 1); 1151 } 1152 template pow10_2550(long n:0) 1153 { 1154 const long pow10_2550 = 1; 1155 } 1156 static assert(pow10_2550!(0) == 1); 1157 1158 /**********************************/ 1159 // [2.057] Remove top const in IFTI, 9198 1160 1161 void foo10a(T )(T) { static assert(is(T == const(int)[])); } 1162 void foo10b(T...)(T) { static assert(is(T[0] == const(int)[])); } 1163 1164 // ref paramter doesn't remove top const 1165 void boo10a(T )(ref T) { static assert(is(T == const(int[]))); } 1166 void boo10b(T...)(ref T) { static assert(is(T[0] == const(int[]))); } 1167 1168 // auto ref with lvalue doesn't 1169 void goo10a(T )(auto ref T) { static assert(is(T == const(int[]))); } 1170 void goo10b(T...)(auto ref T) { static assert(is(T[0] == const(int[]))); } 1171 1172 // auto ref with rvalue does 1173 void hoo10a(T )(auto ref T) { static assert(is(T == const(int)[])); } 1174 void hoo10b(T...)(auto ref T) { static assert(is(T[0] == const(int)[])); } 1175 1176 void bar10a(T )(T) { static assert(is(T == const(int)*)); } 1177 void bar10b(T...)(T) { static assert(is(T[0] == const(int)*)); } 1178 1179 void test10() 1180 { 1181 const a = [1,2,3]; 1182 static assert(is(typeof(a) == const(int[]))); 1183 foo10a(a); 1184 foo10b(a); 1185 boo10a(a); 1186 boo10b(a); 1187 goo10a(a); 1188 goo10b(a); 1189 hoo10a(cast(const)[1,2,3]); 1190 hoo10b(cast(const)[1,2,3]); 1191 1192 int n; 1193 const p = &n; 1194 static assert(is(typeof(p) == const(int*))); 1195 bar10a(p); 1196 bar10b(p); 1197 } 1198 1199 /**********************************/ 1200 // 3092 1201 1202 template Foo3092(A...) 1203 { 1204 alias A[0] Foo3092; 1205 } 1206 static assert(is(Foo3092!(int, "foo") == int)); 1207 1208 /**********************************/ 1209 // 7037 1210 1211 struct Foo7037 {} 1212 struct Bar7037 { Foo7037 f; alias f this; } 1213 void works7037( T )( T value ) if ( is( T : Foo7037 ) ) {} 1214 void doesnotwork7037( T : Foo7037 )( T value ) {} 1215 1216 void test7037() 1217 { 1218 Bar7037 b; 1219 works7037( b ); 1220 doesnotwork7037( b ); 1221 } 1222 1223 /**********************************/ 1224 // 7110 1225 1226 struct S7110 1227 { 1228 int opSlice(int, int) const { return 0; } 1229 int opSlice() const { return 0; } 1230 int opIndex(int, int) const { return 0; } 1231 int opIndex(int) const { return 0; } 1232 } 1233 1234 enum e7110 = S7110(); 1235 1236 template T7110(alias a) { } // or T7110(a...) 1237 1238 alias T7110!( S7110 ) T71100; // passes 1239 alias T7110!((S7110)) T71101; // passes 1240 1241 alias T7110!( S7110()[0..0] ) A0; // passes 1242 alias T7110!( (e7110[0..0]) ) A1; // passes 1243 alias T7110!( e7110[0..0] ) A2; // passes 1244 1245 alias T7110!( S7110()[0, 0] ) B0; // passes 1246 alias T7110!( (e7110[0, 0]) ) B1; // passes 1247 alias T7110!( e7110[0, 0] ) B2; // passes 1248 1249 alias T7110!( S7110()[] ) C0; // passes 1250 alias T7110!( (e7110[]) ) C1; // passes 1251 alias T7110!( e7110[] ) C2; // fails: e7110 is used as a type 1252 1253 alias T7110!( S7110()[0] ) D0; // passes 1254 alias T7110!( (e7110[0]) ) D1; // passes 1255 alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110 1256 1257 /**********************************/ 1258 // 7124 1259 1260 template StaticArrayOf(T : E[dim], E, size_t dim) 1261 { 1262 pragma(msg, "T = ", T, ", E = ", E, ", dim = ", dim); 1263 alias E[dim] StaticArrayOf; 1264 } 1265 1266 template DynamicArrayOf(T : E[], E) 1267 { 1268 pragma(msg, "T = ", T, ", E = ", E); 1269 alias E[] DynamicArrayOf; 1270 } 1271 1272 template AssocArrayOf(T : V[K], K, V) 1273 { 1274 pragma(msg, "T = ", T, ", K = ", K, ", V = ", V); 1275 alias V[K] AssocArrayOf; 1276 } 1277 void test7124() 1278 { 1279 struct SA { int[5] sa; alias sa this; } 1280 static assert(is(StaticArrayOf!SA == int[5])); 1281 1282 struct DA { int[] da; alias da this; } 1283 static assert(is(DynamicArrayOf!DA == int[])); 1284 1285 struct AA { int[string] aa; alias aa this; } 1286 static assert(is(AssocArrayOf!AA == int[string])); 1287 } 1288 1289 /**********************************/ 1290 // 7359 1291 1292 bool foo7359(T)(T[] a ...) 1293 { 1294 return true; 1295 } 1296 1297 void test7359() 1298 { 1299 assert(foo7359(1,1,1,1,1,1)); // OK 1300 assert(foo7359("abc","abc","abc","abc")); // NG 1301 } 1302 1303 /**********************************/ 1304 // 7363 1305 1306 template t7363() 1307 { 1308 enum e = 0; 1309 static if (true) 1310 enum t7363 = 0; 1311 } 1312 static assert(!__traits(compiles, t7363!().t7363 == 0)); // Assertion fails 1313 static assert(t7363!() == 0); // Error: void has no value 1314 1315 template u7363() 1316 { 1317 static if (true) 1318 { 1319 enum e = 0; 1320 enum u73631 = 0; 1321 } 1322 alias u73631 u7363; 1323 } 1324 static assert(!__traits(compiles, u7363!().u7363 == 0)); // Assertion fails 1325 static assert(u7363!() == 0); // Error: void has no value 1326 1327 /**********************************/ 1328 1329 struct S4371(T ...) { } 1330 1331 alias S4371!("hi!") t; 1332 1333 static if (is(t U == S4371!(U))) { } 1334 1335 /**********************************/ 1336 // 7416 1337 1338 void t7416(alias a)() if(is(typeof(a()))) 1339 {} 1340 1341 void test7416() { 1342 void f() {} 1343 alias t7416!f x; 1344 } 1345 1346 /**********************************/ 1347 // 7563 1348 1349 class Test7563 1350 { 1351 void test(T, bool a = true)(T t) 1352 { 1353 1354 } 1355 } 1356 1357 void test7563() 1358 { 1359 auto test = new Test7563; 1360 pragma(msg, typeof(test.test!(int, true)).stringof); 1361 pragma(msg, typeof(test.test!(int)).stringof); // Error: expression (test.test!(int)) has no type 1362 } 1363 1364 /**********************************/ 1365 // 7572 1366 1367 class F7572 1368 { 1369 Tr fn7572(Tr, T...)(T t) { return 1; } 1370 } 1371 Tr Fn7572(Tr, T...)(T t) { return 2; } 1372 1373 void test7572() 1374 { 1375 F7572 f = new F7572(); 1376 int delegate() dg = &f.fn7572!int; 1377 assert(dg() == 1); 1378 1379 int function() fn = &Fn7572!int; 1380 assert(fn() == 2); 1381 } 1382 1383 /**********************************/ 1384 // 7580 1385 1386 struct S7580(T) 1387 { 1388 void opAssign()(T value) {} 1389 } 1390 struct X7580(T) 1391 { 1392 private T val; 1393 @property ref inout(T) get()() inout { return val; } // template 1394 alias get this; 1395 } 1396 struct Y7580(T) 1397 { 1398 private T val; 1399 @property ref auto get()() inout { return val; } // template + auto return 1400 alias get this; 1401 } 1402 1403 void test7580() 1404 { 1405 S7580!(int) s; 1406 X7580!int x; 1407 Y7580!int y; 1408 s = x; 1409 s = y; 1410 1411 shared(X7580!int) sx; 1412 static assert(!__traits(compiles, s = sx)); 1413 } 1414 1415 /**********************************/ 1416 // 7585 1417 1418 extern(C) alias void function() Callback; 1419 1420 template W7585a(alias dg) 1421 { 1422 //pragma(msg, typeof(dg)); 1423 extern(C) void W7585a() { dg(); } 1424 } 1425 1426 void test7585() 1427 { 1428 static void f7585a(){} 1429 Callback cb1 = &W7585a!(f7585a); // OK 1430 static assert(!__traits(compiles, 1431 { 1432 void f7585b(){} 1433 Callback cb2 = &W7585a!(f7585b); // NG 1434 })); 1435 1436 Callback cb3 = &W7585a!((){}); // NG -> OK 1437 Callback cb4 = &W7585a!(function(){}); // OK 1438 static assert(!__traits(compiles, 1439 { 1440 Callback cb5 = &W7585a!(delegate(){}); // NG 1441 })); 1442 1443 static int global; // global data 1444 Callback cb6 = &W7585a!((){return global;}); // NG -> OK 1445 static assert(!__traits(compiles, 1446 { 1447 int n; 1448 Callback cb7 = &W7585a!((){return n;}); // NG 1449 })); 1450 } 1451 1452 /**********************************/ 1453 // 7643 1454 1455 template T7643(A...){ alias A T7643; } 1456 1457 alias T7643!(long, "x", string, "y") Specs7643; 1458 1459 alias T7643!( Specs7643[] ) U7643; // Error: tuple A is used as a type 1460 1461 /**********************************/ 1462 // 7671 1463 1464 inout(int)[3] id7671n1 ( inout(int)[3] ); 1465 inout( U )[n] id7671x1(U, size_t n)( inout( U )[n] ); 1466 1467 shared(inout int)[3] id7671n2 ( shared(inout int)[3] ); 1468 shared(inout U )[n] id7671x2(U, size_t n)( shared(inout U )[n] ); 1469 1470 void test7671() 1471 { 1472 static assert(is( typeof( id7671n1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); 1473 static assert(is( typeof( id7671x1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); 1474 1475 static assert(is( typeof( id7671n2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); 1476 static assert(is( typeof( id7671x2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); 1477 } 1478 1479 /************************************/ 1480 // 7672 1481 1482 T foo7672(T)(T a){ return a; } 1483 1484 void test7672(inout(int[]) a = null, inout(int*) p = null) 1485 { 1486 static assert(is( typeof( a ) == inout(int[]) )); 1487 static assert(is( typeof(foo7672(a)) == inout(int)[] )); 1488 1489 static assert(is( typeof( p ) == inout(int*) )); 1490 static assert(is( typeof(foo7672(p)) == inout(int)* )); 1491 } 1492 1493 /**********************************/ 1494 // 7684 1495 1496 U[] id7684(U)( U[] ); 1497 shared(U[]) id7684(U)( shared(U[]) ); 1498 1499 void test7684() 1500 { 1501 shared(int)[] x; 1502 static assert(is( typeof(id7684(x)) == shared(int)[] )); 1503 } 1504 1505 /**********************************/ 1506 // 7694 1507 1508 void match7694(alias m)() 1509 { 1510 m.foo(); //removing this line supresses ice in both cases 1511 } 1512 1513 struct T7694 1514 { 1515 void foo(){} 1516 void bootstrap() 1517 { 1518 //next line causes ice 1519 match7694!(this)(); 1520 //while this works: 1521 alias this p; 1522 match7694!(p)(); 1523 } 1524 } 1525 1526 /**********************************/ 1527 // 7755 1528 1529 template to7755(T) 1530 { 1531 T to7755(A...)(A args) 1532 { 1533 return toImpl7755!T(args); 1534 } 1535 } 1536 1537 T toImpl7755(T, S)(S value) 1538 { 1539 return T.init; 1540 } 1541 1542 template Foo7755(T){} 1543 1544 struct Bar7755 1545 { 1546 void qux() 1547 { 1548 if (is(typeof(to7755!string(Foo7755!int)))){}; 1549 } 1550 } 1551 1552 /**********************************/ 1553 1554 U[] id11a(U)( U[] ); 1555 inout(U)[] id11a(U)( inout(U)[] ); 1556 inout(U[]) id11a(U)( inout(U[]) ); 1557 inout(shared(U[])) id11a(U)( inout(shared(U[])) ); 1558 1559 void test11a(inout int _ = 0) 1560 { 1561 shared(const(int))[] x; 1562 static assert(is( typeof(id11a(x)) == shared(const(int))[] )); 1563 1564 shared(int)[] y; 1565 static assert(is( typeof(id11a(y)) == shared(int)[] )); 1566 1567 inout(U)[n] idz(U, size_t n)( inout(U)[n] ); 1568 1569 inout(shared(bool[1])) z; 1570 static assert(is( typeof(idz(z)) == inout(shared(bool[1])) )); 1571 } 1572 1573 inout(U[]) id11b(U)( inout(U[]) ); 1574 1575 void test11b() 1576 { 1577 alias const(shared(int)[]) T; 1578 static assert(is(typeof(id11b(T.init)) == const(shared(int)[]))); 1579 } 1580 1581 /**********************************/ 1582 // 7769 1583 1584 void f7769(K)(inout(K) value){} 1585 void test7769() 1586 { 1587 f7769("abc"); 1588 } 1589 1590 /**********************************/ 1591 // 7812 1592 1593 template A7812(T...) {} 1594 1595 template B7812(alias C) if (C) {} 1596 1597 template D7812() 1598 { 1599 alias B7812!(A7812!(NonExistent!())) D7812; 1600 } 1601 1602 static assert(!__traits(compiles, D7812!())); 1603 1604 /**********************************/ 1605 // 7873 1606 1607 inout(T)* foo(T)(inout(T)* t) 1608 { 1609 static assert(is(T == int*)); 1610 return t; 1611 } 1612 1613 inout(T)* bar(T)(inout(T)* t) 1614 { 1615 return foo(t); 1616 } 1617 1618 void test7873() 1619 { 1620 int *i; 1621 bar(&i); 1622 } 1623 1624 /**********************************/ 1625 // 7933 1626 1627 struct Boo7933(size_t dim){int a;} 1628 struct Baa7933(size_t dim) 1629 { 1630 Boo7933!dim a; 1631 //Boo7933!1 a; //(1) This version causes no errors 1632 } 1633 1634 auto foo7933()(Boo7933!1 b){return b;} 1635 //auto fuu7933(Boo7933!1 b){return b;} //(2) This line neutralizes the error 1636 1637 void test7933() 1638 { 1639 Baa7933!1 a; //(3) This line causes the error message 1640 auto b = foo7933(Boo7933!1(1)); 1641 } 1642 1643 /**********************************/ 1644 // 8094 1645 1646 struct Tuple8094(T...) {} 1647 1648 template getParameters8094(T, alias P) 1649 { 1650 static if (is(T t == P!U, U...)) 1651 alias U getParameters8094; 1652 else 1653 static assert(false); 1654 } 1655 1656 void test8094() 1657 { 1658 alias getParameters8094!(Tuple8094!(int, string), Tuple8094) args; 1659 } 1660 1661 /**********************************/ 1662 1663 struct Tuple12(T...) 1664 { 1665 void foo(alias P)() 1666 { 1667 alias Tuple12 X; 1668 static if (is(typeof(this) t == X!U, U...)) 1669 alias U getParameters; 1670 else 1671 static assert(false); 1672 } 1673 } 1674 1675 void test12() 1676 { 1677 Tuple12!(int, string) t; 1678 t.foo!Tuple12(); 1679 } 1680 1681 /**********************************/ 1682 // 14290 1683 1684 struct Foo14290(int i) {} 1685 alias Foo14290a = Foo14290!1; 1686 static assert(!is(Foo14290!2 == Foo14290a!T, T...)); 1687 1688 /**********************************/ 1689 // 8125 1690 1691 void foo8125(){} 1692 1693 struct X8125(alias a) {} 1694 1695 template Y8125a(T : A!f, alias A, alias f) {} //OK 1696 template Y8125b(T : A!foo8125, alias A) {} //NG 1697 1698 void test8125() 1699 { 1700 alias Y8125a!(X8125!foo8125) y1; 1701 alias Y8125b!(X8125!foo8125) y2; 1702 } 1703 1704 /**********************************/ 1705 1706 struct A13() {} 1707 struct B13(TT...) {} 1708 struct C13(T1) {} 1709 struct D13(T1, TT...) {} 1710 struct E13(T1, T2) {} 1711 struct F13(T1, T2, TT...) {} 1712 1713 template Test13(alias X) 1714 { 1715 static if (is(X x : P!U, alias P, U...)) 1716 enum Test13 = true; 1717 else 1718 enum Test13 = false; 1719 } 1720 1721 void test13() 1722 { 1723 static assert(Test13!( A13!() )); 1724 static assert(Test13!( B13!(int) )); 1725 static assert(Test13!( B13!(int, double) )); 1726 static assert(Test13!( B13!(int, double, string) )); 1727 static assert(Test13!( C13!(int) )); 1728 static assert(Test13!( D13!(int) )); 1729 static assert(Test13!( D13!(int, double) )); 1730 static assert(Test13!( D13!(int, double, string) )); 1731 static assert(Test13!( E13!(int, double) )); 1732 static assert(Test13!( F13!(int, double) )); 1733 static assert(Test13!( F13!(int, double, string) )); 1734 static assert(Test13!( F13!(int, double, string, bool) )); 1735 } 1736 1737 /**********************************/ 1738 1739 struct A14(T, U, int n = 1) 1740 { 1741 } 1742 1743 template Test14(alias X) 1744 { 1745 static if (is(X x : P!U, alias P, U...)) 1746 alias U Test14; 1747 else 1748 static assert(0); 1749 } 1750 1751 void test14() 1752 { 1753 alias A14!(int, double) Type; 1754 alias Test14!Type Params; 1755 static assert(Params.length == 3); 1756 static assert(is(Params[0] == int)); 1757 static assert(is(Params[1] == double)); 1758 static assert( Params[2] == 1); 1759 } 1760 1761 /**********************************/ 1762 // test for evaluateConstraint assertion 1763 1764 bool canSearchInCodeUnits15(C)(dchar c) 1765 if (is(C == char)) 1766 { 1767 return true; 1768 } 1769 1770 void test15() 1771 { 1772 int needle = 0; 1773 auto b = canSearchInCodeUnits15!char(needle); 1774 } 1775 1776 /**********************************/ 1777 // 8129 1778 1779 class X8129 {} 1780 class A8129 {} 1781 class B8129 : A8129 {} 1782 1783 int foo8129(T : A8129)(X8129 x) { return 1; } 1784 int foo8129(T : A8129)(X8129 x, void function (T) block) { return 2; } 1785 1786 int bar8129(T, R)(R range, T value) { return 1; } 1787 1788 int baz8129(T, R)(R range, T value) { return 1; } 1789 int baz8129(T, R)(R range, Undefined value) { return 2; } 1790 1791 void test8129() 1792 { 1793 auto x = new X8129; 1794 assert(x.foo8129!B8129() == 1); 1795 assert(x.foo8129!B8129((a){}) == 2); 1796 assert(foo8129!B8129(x) == 1); 1797 assert(foo8129!B8129(x, (a){}) == 2); 1798 assert(foo8129!B8129(x) == 1); 1799 assert(foo8129!B8129(x, (B8129 b){}) == 2); 1800 1801 ubyte[] buffer = [0, 1, 2]; 1802 assert(bar8129!ushort(buffer, 915) == 1); 1803 1804 // While deduction, parameter type 'Undefined' shows semantic error. 1805 static assert(!__traits(compiles, { 1806 baz8129!ushort(buffer, 915); 1807 })); 1808 } 1809 1810 /**********************************/ 1811 // 8238 1812 1813 void test8238() 1814 { 1815 static struct S { template t(){ int t; } } 1816 1817 S s1, s2; 1818 assert(cast(void*)&s1 != cast(void*)&s2 ); 1819 assert(cast(void*)&s1 != cast(void*)&s1.t!()); 1820 assert(cast(void*)&s2 != cast(void*)&s2.t!()); 1821 assert(cast(void*)&s1.t!() == cast(void*)&s2.t!()); 1822 s1.t!() = 256; 1823 assert(s2.t!() == 256); 1824 } 1825 1826 /**********************************/ 1827 // 8669 1828 1829 struct X8669 1830 { 1831 void mfoo(this T)() 1832 { 1833 static assert(is(typeof(this) == T)); 1834 } 1835 void cfoo(this T)() const 1836 { 1837 static assert(is(typeof(this) == const(T))); 1838 } 1839 void sfoo(this T)() shared 1840 { 1841 static assert(is(typeof(this) == shared(T))); 1842 } 1843 void scfoo(this T)() shared const 1844 { 1845 static assert(is(typeof(this) == shared(const(T)))); 1846 } 1847 void ifoo(this T)() immutable 1848 { 1849 static assert(is(typeof(this) == immutable(T))); 1850 } 1851 } 1852 1853 void test8669() 1854 { 1855 X8669 mx; 1856 const X8669 cx; 1857 immutable X8669 ix; 1858 shared X8669 sx; 1859 shared const X8669 scx; 1860 1861 mx.mfoo(); 1862 cx.mfoo(); 1863 ix.mfoo(); 1864 sx.mfoo(); 1865 scx.mfoo(); 1866 1867 mx.cfoo(); 1868 cx.cfoo(); 1869 ix.cfoo(); 1870 sx.cfoo(); 1871 scx.cfoo(); 1872 1873 static assert(!is(typeof( mx.sfoo() ))); 1874 static assert(!is(typeof( cx.sfoo() ))); 1875 ix.sfoo(); 1876 sx.sfoo(); 1877 scx.sfoo(); 1878 1879 static assert(!is(typeof( mx.scfoo() ))); 1880 static assert(!is(typeof( cx.scfoo() ))); 1881 ix.scfoo(); 1882 sx.scfoo(); 1883 scx.scfoo(); 1884 1885 static assert(!is(typeof( mx.ifoo() ))); 1886 static assert(!is(typeof( cx.ifoo() ))); 1887 ix.ifoo(); 1888 static assert(!is(typeof( sx.ifoo() ))); 1889 static assert(!is(typeof( scx.ifoo() ))); 1890 } 1891 1892 /**********************************/ 1893 // 8833 1894 1895 template TypeTuple8833(T...) { alias TypeTuple = T; } 1896 1897 void func8833(alias arg)() { } 1898 1899 void test8833() 1900 { 1901 int x, y; 1902 1903 alias TypeTuple8833!( 1904 func8833!(x), 1905 func8833!(y), 1906 ) Map; 1907 } 1908 1909 /**********************************/ 1910 // 8976 1911 1912 void f8976(ref int) { } 1913 1914 void g8976()() 1915 { 1916 f8976(0); // line 5 1917 } 1918 1919 1920 void h8976()() 1921 { 1922 g8976!()(); 1923 } 1924 1925 static assert(! __traits(compiles, h8976!()() ) ); // causes error 1926 static assert(!is(typeof( h8976!()() ))); 1927 1928 void test8976() 1929 { 1930 static assert(! __traits(compiles, h8976!()() ) ); 1931 static assert(!is(typeof( h8976!()() ))); 1932 } 1933 1934 /****************************************/ 1935 // 8940 1936 1937 const int n8940; // or `immutable` 1938 static this() { n8940 = 3; } 1939 1940 void f8940(T)(ref int val) 1941 { 1942 assert(val == 3); 1943 ++val; 1944 } 1945 1946 static assert(!__traits(compiles, f8940!void(n8940))); // fails 1947 void test8940() 1948 { 1949 assert(n8940 == 3); 1950 static assert(!__traits(compiles, f8940!void(n8940))); 1951 //assert(n8940 == 3); // may pass as compiler caches comparison result 1952 //assert(n8940 != 4); // may pass but likely will fail 1953 } 1954 1955 /**********************************/ 1956 // 6969 + 8990 1957 1958 class A6969() { alias C6969!() C1; } 1959 class B6969 { alias A6969!() A1; } 1960 class C6969() : B6969 {} 1961 1962 struct A8990(T) { T t; } 1963 struct B8990(T) { A8990!T* a; } 1964 struct C8990 { B8990!C8990* b; } 1965 1966 /**********************************/ 1967 // 9018 1968 1969 template Inst9018(alias Template, T) 1970 { 1971 alias Template!T Inst; 1972 } 1973 1974 template Template9018(T) 1975 { 1976 enum Template9018 = T; 1977 } 1978 1979 static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert passes 1980 static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert fails 1981 1982 /**********************************/ 1983 // 9022 1984 1985 class C9022 1986 { 1987 struct X {} 1988 1989 alias B = X; 1990 } 1991 class D9022 1992 { 1993 struct X {} 1994 } 1995 1996 void test9022() 1997 { 1998 auto c = new C9022(); 1999 auto d = new D9022(); 2000 auto cx = C9022.X(); 2001 auto dx = D9022.X(); 2002 2003 void foo1(T)(T, T.X) { static assert(is(T == C9022)); } 2004 void foo2(T)(T.X, T) { static assert(is(T == C9022)); } 2005 foo1(c, cx); 2006 foo2(cx, c); 2007 2008 void hoo1(T)(T, T.B) { static assert(is(T == C9022)); } 2009 void hoo2(T)(T.B, T) { static assert(is(T == C9022)); } 2010 hoo1(c, cx); 2011 hoo1(c, cx); 2012 2013 void bar1(alias A)(A.C9022, A.D9022) { static assert(A.stringof == "module breaker"); } 2014 void bar2(alias A)(A.D9022, A.C9022) { static assert(A.stringof == "module breaker"); } 2015 bar1(c, d); 2016 bar2(d, c); 2017 2018 void var1(alias A)(A.C9022, A.D9022.X) { static assert(A.stringof == "module breaker"); } 2019 void var2(alias A)(A.D9022.X, A.C9022) { static assert(A.stringof == "module breaker"); } 2020 var1(c, dx); 2021 var2(dx, c); 2022 2023 void baz(T)(T.X t, T.X u) { } 2024 static assert(!__traits(compiles, baz(cx, dx))); 2025 } 2026 2027 /**********************************/ 2028 // 9026 2029 2030 mixin template node9026() 2031 { 2032 static if (is(this == struct)) 2033 alias typeof(this)* E; 2034 else 2035 alias typeof(this) E; 2036 E prev, next; 2037 } 2038 2039 struct list9026(alias N) 2040 { 2041 N.E head; 2042 N.E tail; 2043 } 2044 2045 class A9026 2046 { 2047 mixin node9026 L1; 2048 mixin node9026 L2; 2049 } 2050 2051 list9026!(A9026.L1) g9026_l1; 2052 list9026!(A9026.L2) g9026_l2; 2053 2054 void test9026() 2055 { 2056 list9026!(A9026.L1) l9026_l1; 2057 list9026!(A9026.L2) l9026_l2; 2058 } 2059 2060 /**********************************/ 2061 // 9038 2062 2063 mixin template Foo9038() 2064 { 2065 string data = "default"; 2066 } 2067 2068 class Bar9038 2069 { 2070 string data; 2071 mixin Foo9038 f; 2072 } 2073 2074 void check_data9038(alias M, T)(T obj) 2075 { 2076 //writeln(M.stringof); 2077 assert(obj.data == "Bar"); 2078 assert(obj.f.data == "F"); 2079 } 2080 2081 void test9038() 2082 { 2083 auto bar = new Bar9038; 2084 bar.data = "Bar"; 2085 bar.f.data = "F"; 2086 2087 assert(bar.data == "Bar"); 2088 assert(bar.f.data == "F"); 2089 2090 check_data9038!(Bar9038)(bar); 2091 check_data9038!(Bar9038.f)(bar); 2092 check_data9038!(bar.f)(bar); 2093 } 2094 2095 /**********************************/ 2096 // 9050 2097 2098 struct A9050(T) {} 2099 2100 struct B9050(T) 2101 { 2102 void f() { foo9050(A9050!int()); } 2103 } 2104 2105 auto foo9050()(A9050!int base) pure 2106 { 2107 return B9050!int(); 2108 } 2109 2110 auto s9050 = foo9050(A9050!int()); 2111 2112 /**********************************/ 2113 // 10936 (dup of 9050) 2114 2115 struct Vec10936(string s) 2116 { 2117 auto foo(string v)() 2118 { 2119 return Vec10936!(v)(); 2120 } 2121 2122 static void bar() 2123 { 2124 Vec10936!"" v; 2125 auto p = v.foo!"sup"; 2126 } 2127 } 2128 2129 Vec10936!"" v; 2130 2131 /**********************************/ 2132 // 9076 2133 2134 template forward9076(args...) 2135 { 2136 @property forward9076()(){ return args[0]; } 2137 } 2138 2139 void test9076() 2140 { 2141 int a = 1; 2142 int b = 1; 2143 assert(a == forward9076!b); 2144 } 2145 2146 /**********************************/ 2147 // 9083 2148 2149 template isFunction9083(X...) if (X.length == 1) 2150 { 2151 enum isFunction9083 = true; 2152 } 2153 2154 struct S9083 2155 { 2156 static string func(alias Class)() 2157 { 2158 foreach (m; __traits(allMembers, Class)) 2159 { 2160 pragma(msg, m); // prints "func" 2161 enum x1 = isFunction9083!(mixin(m)); //NG 2162 enum x2 = isFunction9083!(func); //OK 2163 } 2164 return ""; 2165 } 2166 } 2167 enum nothing9083 = S9083.func!S9083(); 2168 2169 class C9083 2170 { 2171 int x; // some class members 2172 2173 void func() 2174 { 2175 void templateFunc(T)(const T obj) 2176 { 2177 enum x1 = isFunction9083!(mixin("x")); // NG 2178 enum x2 = isFunction9083!(x); // NG 2179 } 2180 templateFunc(this); 2181 } 2182 } 2183 2184 /**********************************/ 2185 // 9100 2186 2187 template Id(alias A) { alias Id = A; } 2188 template ErrId(alias A) { static assert(0); } 2189 template TypeTuple9100(TL...) { alias TypeTuple9100 = TL; } 2190 2191 class C9100 2192 { 2193 int value; 2194 2195 int fun() { return value; } 2196 int tfun(T)() { return value; } 2197 TypeTuple9100!(int, long) field; 2198 2199 void test() 2200 { 2201 this.value = 1; 2202 auto c = new C9100(); 2203 c.value = 2; 2204 2205 alias t1a = Id!(c.fun); // OK 2206 alias t1b = Id!(this.fun); // Prints weird error, bad 2207 // -> internally given TOKdotvar 2208 assert(t1a() == this.value); 2209 assert(t1b() == this.value); 2210 2211 alias t2a = Id!(c.tfun); // OK 2212 static assert(!__traits(compiles, ErrId!(this.tfun))); 2213 alias t2b = Id!(this.tfun); // No error occurs, why? 2214 // -> internally given TOKdottd 2215 assert(t2a!int() == this.value); 2216 assert(t2b!int() == this.value); 2217 2218 alias t3a = Id!(foo9100); // OK 2219 alias t3b = Id!(mixin("foo9100")); // Prints weird error, bad 2220 // -> internally given TOKtemplate 2221 assert(t3a() == 10); 2222 assert(t3b() == 10); 2223 2224 assert(field[0] == 0); 2225 alias t4a = TypeTuple9100!(field); // NG 2226 alias t4b = TypeTuple9100!(GetField9100!()); // NG 2227 t4a[0] = 1; assert(field[0] == 1); 2228 t4b[0] = 2; assert(field[0] == 2); 2229 } 2230 } 2231 2232 int foo9100()() { return 10; } 2233 template GetField9100() { alias GetField9100 = C9100.field[0]; } 2234 2235 void test9100() 2236 { 2237 (new C9100()).test(); 2238 } 2239 2240 /**********************************/ 2241 // 9101 2242 2243 class Node9101 2244 { 2245 template ForwardCtorNoId() 2246 { 2247 this() {} // default constructor 2248 void foo() { 0 = 1; } // wrong code 2249 } 2250 } 2251 enum x9101 = __traits(compiles, Node9101.ForwardCtorNoId!()); 2252 2253 /**********************************/ 2254 // 9124 2255 2256 struct Foo9124a(N...) 2257 { 2258 enum SIZE = N[0]; 2259 private int _val; 2260 2261 public void opAssign (T) (T other) 2262 if (is(T unused == Foo9124a!(_N), _N...)) 2263 { 2264 _val = other._val; // compile error 2265 this._val = other._val; // explicit this make it work 2266 } 2267 2268 public auto opUnary (string op) () if (op == "~") { 2269 Foo9124a!(SIZE) result = this; 2270 return result; 2271 } 2272 } 2273 void test9124a() 2274 { 2275 Foo9124a!(28) a; 2276 Foo9124a!(28) b = ~a; 2277 } 2278 2279 // -------- 2280 2281 template Foo9124b(T, U, string OP) 2282 { 2283 enum N = T.SIZE; 2284 alias Foo9124b = Foo9124b!(false, true, N); 2285 } 2286 struct Foo9124b(bool S, bool L, N...) 2287 { 2288 enum SIZE = 5; 2289 long[1] _a = 0; 2290 void someFunction() const { 2291 auto data1 = _a; // Does not compile 2292 auto data2 = this._a; // <--- Compiles 2293 } 2294 auto opBinary(string op, T)(T) { 2295 Foo9124b!(typeof(this), T, op) test; 2296 } 2297 } 2298 void test9124b() 2299 { 2300 auto p = Foo9124b!(false, false, 5)(); 2301 auto q = Foo9124b!(false, false, 5)(); 2302 p|q; 2303 p&q; 2304 } 2305 2306 /**********************************/ 2307 // 9143 2308 2309 struct Foo9143a(bool S, bool L) 2310 { 2311 auto noCall() { 2312 Foo9143a!(S, false) x1; // compiles if this line commented 2313 static if(S) Foo9143a!(true, false) x2; 2314 else Foo9143a!(false, false) x2; 2315 } 2316 this(T)(T other) // constructor 2317 if (is(T unused == Foo9143a!(P, Q), bool P, bool Q)) { } 2318 } 2319 2320 struct Foo9143b(bool L, size_t N) 2321 { 2322 void baaz0() { 2323 bar!(Foo9143b!(false, N))(); // line 7 2324 // -> move to before the baaz semantic 2325 } 2326 void baaz() { 2327 bar!(Foo9143b!(false, 2LU))(); // line 3 2328 bar!(Foo9143b!(true, 2LU))(); // line 4 2329 bar!(Foo9143b!(L, N))(); // line 5 2330 bar!(Foo9143b!(true, N))(); // line 6 2331 bar!(Foo9143b!(false, N))(); // line 7 2332 } 2333 void bar(T)() 2334 if (is(T unused == Foo9143b!(_L, _N), bool _L, size_t _N)) 2335 {} 2336 } 2337 2338 void test9143() 2339 { 2340 Foo9143a!(false, true) k = Foo9143a!(false, false)(); 2341 2342 auto p = Foo9143b!(true, 2LU)(); 2343 } 2344 2345 /**********************************/ 2346 // 9266 2347 2348 template Foo9266(T...) 2349 { 2350 T Foo9266; 2351 } 2352 struct Bar9266() 2353 { 2354 alias Foo9266!int f; 2355 } 2356 void test9266() 2357 { 2358 Bar9266!() a, b; 2359 } 2360 2361 /**********************************/ 2362 // 9361 2363 2364 struct Unit9361(A) 2365 { 2366 void butPleaseDontUseMe()() 2367 if (is(unitType9361!((this)))) // ! 2368 {} 2369 2370 } 2371 template isUnit9361(alias T) if ( is(T)) {} 2372 template isUnit9361(alias T) if (!is(T)) {} 2373 2374 template unitType9361(alias T) if (isUnit9361!T) {} 2375 2376 void test9361() 2377 { 2378 Unit9361!int u; 2379 static assert(!__traits(compiles, u.butPleaseDontUseMe())); // crashes 2380 } 2381 2382 /**********************************/ 2383 // 9536 2384 2385 struct S9536 2386 { 2387 static A foo(A)(A a) 2388 { 2389 return a * 2; 2390 } 2391 int bar() const 2392 { 2393 return foo(42); 2394 } 2395 } 2396 2397 void test9536() 2398 { 2399 S9536 s; 2400 assert(s.bar() == 84); 2401 } 2402 2403 /**********************************/ 2404 // 9578 2405 2406 template t9578(alias f) { void tf()() { f(); } } 2407 2408 void g9578a(alias f)() { f(); } // Error -> OK 2409 void g9578b(alias ti)() { ti.tf(); } // Error -> OK 2410 2411 void test9578() 2412 { 2413 int i = 0; 2414 int m() { return i; } 2415 2416 g9578a!(t9578!m.tf)(); 2417 g9578b!(t9578!m)(); 2418 } 2419 2420 /**********************************/ 2421 // 9596 2422 2423 int foo9596a(K, V)(inout( V [K])) { return 1; } 2424 int foo9596a(K, V)(inout(shared(V) [K])) { return 2; } 2425 2426 int foo9596b(K, V)(inout( V [K])) { return 1; } 2427 int foo9596b(K, V)(inout( const(V) [K])) { return 3; } 2428 2429 int foo9596c(K, V)(inout(shared(V) [K])) { return 2; } 2430 int foo9596c(K, V)(inout( const(V) [K])) { return 3; } 2431 2432 int foo9596d(K, V)(inout( V [K])) { return 1; } 2433 int foo9596d(K, V)(inout(shared(V) [K])) { return 2; } 2434 int foo9596d(K, V)(inout( const(V) [K])) { return 3; } 2435 2436 int foo9596e(K, V)(inout(shared(V) [K])) { return 2; } 2437 int foo9596e(K, V)(inout( V [K])) { return 1; } 2438 int foo9596e(K, V)(inout( const(V) [K])) { return 3; } 2439 2440 void test9596() 2441 { 2442 shared(int)[int] aa; 2443 static assert(!__traits(compiles, foo9596a(aa))); 2444 2445 assert(foo9596b(aa) == 1); 2446 assert(foo9596c(aa) == 2); 2447 2448 static assert(!__traits(compiles, foo9596d(aa))); 2449 static assert(!__traits(compiles, foo9596e(aa))); 2450 } 2451 2452 /******************************************/ 2453 // 9806 2454 2455 struct S9806a(alias x) 2456 { 2457 alias S9806a!0 N; 2458 } 2459 enum expr9806a = 0 * 0; 2460 alias S9806a!expr9806a T9806a; 2461 2462 // -------- 2463 2464 struct S9806b(alias x) 2465 { 2466 template Next() 2467 { 2468 enum expr = x + 1; 2469 alias S9806b!expr Next; 2470 } 2471 } 2472 alias S9806b!1 One9806b; 2473 alias S9806b!0.Next!() OneAgain9806b; 2474 2475 // -------- 2476 2477 struct S9806c(x...) 2478 { 2479 template Next() 2480 { 2481 enum expr = x[0] + 1; 2482 alias S9806c!expr Next; 2483 } 2484 } 2485 alias S9806c!1 One9806c; 2486 alias S9806c!0.Next!() OneAgain9806c; 2487 2488 /******************************************/ 2489 // 9837 2490 2491 void test9837() 2492 { 2493 enum DA : int[] { a = [1,2,3] } 2494 DA da; 2495 int[] bda = da; 2496 static assert(is(DA : int[])); 2497 void fda1(int[] a) {} 2498 void fda2(T)(T[] a) {} 2499 fda1(da); 2500 fda2(da); 2501 2502 enum SA : int[3] { a = [1,2,3] } 2503 SA sa; 2504 int[3] bsa = sa; 2505 static assert(is(SA : int[3])); 2506 void fsa1(int[3] a) {} 2507 void fsa2(T)(T[3] a) {} 2508 void fsa3(size_t d)(int[d] a) {} 2509 void fsa4(T, size_t d)(T[d] a) {} 2510 fsa1(sa); 2511 fsa2(sa); 2512 fsa3(sa); 2513 fsa4(sa); 2514 2515 enum AA : int[int] { a = null } 2516 AA aa; 2517 int[int] baa = aa; 2518 static assert(is(AA : int[int])); 2519 void faa1(int[int] a) {} 2520 void faa2(V)(V[int] a) {} 2521 void faa3(K)(int[K] a) {} 2522 void faa4(K, V)(V[K] a) {} 2523 faa1(aa); 2524 faa2(aa); 2525 faa3(aa); 2526 faa4(aa); 2527 } 2528 2529 /******************************************/ 2530 // 9874 2531 2532 bool foo9874() { return true; } 2533 void bar9874(T)(T) if (foo9874()) {} // OK 2534 void baz9874(T)(T) if (foo9874) {} // error 2535 2536 void test9874() 2537 { 2538 foo9874; // OK 2539 bar9874(0); 2540 baz9874(0); 2541 } 2542 2543 /******************************************/ 2544 2545 void test9885() 2546 { 2547 void foo(int[1][]) {} 2548 void boo()(int[1][]){} 2549 struct X(T...) { static void xoo(T){} } 2550 struct Y(T...) { static void yoo()(T){} } 2551 struct Z(T...) { static void zoo(U...)(T, U){} } 2552 2553 struct V(T...) { static void voo()(T, ...){} } 2554 struct W(T...) { static void woo()(T...){} } 2555 2556 struct R(T...) { static void roo(U...)(int, U, T){} } 2557 2558 // OK 2559 foo([[10]]); 2560 boo([[10]]); 2561 2562 // OK 2563 X!(int[1][]).xoo([[10]]); 2564 2565 // NG! 2566 Y!().yoo(); 2567 Y!(int).yoo(1); 2568 Y!(int, int[]).yoo(1, [10]); 2569 static assert(!__traits(compiles, Y!().yoo(1))); 2570 static assert(!__traits(compiles, Y!(int).yoo("a"))); 2571 static assert(!__traits(compiles, Y!().yoo!(int)())); 2572 2573 // NG! 2574 Z!().zoo(); 2575 Z!().zoo([1], [1:1]); 2576 Z!(int, string).zoo(1, "a"); 2577 Z!(int, string).zoo(1, "a", [1], [1:1]); 2578 Z!().zoo!()(); 2579 static assert(!__traits(compiles, Z!().zoo!()(1))); // (none) <- 1 2580 static assert(!__traits(compiles, Z!(int).zoo!()())); // int <- (none) 2581 static assert(!__traits(compiles, Z!(int).zoo!()(""))); // int <- "" 2582 static assert(!__traits(compiles, Z!().zoo!(int)())); // int <- (none) 2583 static assert(!__traits(compiles, Z!().zoo!(int)(""))); // int <- "" 2584 2585 V!().voo(1,2,3); 2586 V!(int).voo(1,2,3); 2587 V!(int, long).voo(1,2,3); 2588 static assert(!__traits(compiles, V!(int).voo())); // int <- (none) 2589 static assert(!__traits(compiles, V!(int, long).voo(1))); // long <- (none) 2590 static assert(!__traits(compiles, V!(int, string).voo(1,2,3))); // string <- 2 2591 2592 W!().woo(); 2593 //W!().woo(1, 2, 3); // Access Violation 2594 { // this behavior is consistent with: 2595 //alias TL = TypeTuple!(); 2596 //void foo(TL...) {} 2597 //foo(1, 2, 3); // Access Violation 2598 //pragma(msg, typeof(foo)); // void(...) -> D-style variadic function? 2599 } 2600 W!(int,int[]).woo(1,2,3); 2601 W!(int,int[2]).woo(1,2,3); 2602 static assert(!__traits(compiles, W!(int,int,int).woo(1,2,3))); // int... <- 2 2603 static assert(!__traits(compiles, W!(int,int).woo(1,2))); // int... <- 2 2604 static assert(!__traits(compiles, W!(int,int[2]).woo(1,2))); // int[2]... <- 2 2605 2606 R!().roo(1, "", []); 2607 R!(int).roo(1, "", [], 1); 2608 R!(int, string).roo(1, "", [], 1, ""); 2609 R!(int, string).roo(1, 2, ""); 2610 static assert(!__traits(compiles, R!(int).roo(1, "", []))); // int <- [] 2611 static assert(!__traits(compiles, R!(int, int).roo(1, "", []))); // int <- [] 2612 static assert(!__traits(compiles, R!(int, string).roo(1, 2, 3))); // string <- 3 2613 2614 // test case 2615 struct Tuple(T...) { this()(T values) {} } 2616 alias T = Tuple!(int[1][]); 2617 auto t = T([[10]]); 2618 } 2619 2620 /******************************************/ 2621 // 9971 2622 2623 void goo9971()() 2624 { 2625 auto g = &goo9971; 2626 } 2627 2628 struct S9971 2629 { 2630 void goo()() 2631 { 2632 auto g = &goo; 2633 static assert(is(typeof(g) == delegate)); 2634 } 2635 } 2636 2637 void test9971() 2638 { 2639 goo9971!()(); 2640 2641 S9971.init.goo!()(); 2642 } 2643 2644 /******************************************/ 2645 // 9977 2646 2647 void test9977() 2648 { 2649 struct S1(T) { T value; } 2650 auto func1(T)(T value) { return value; } 2651 static assert(is(S1!int == struct)); 2652 assert(func1(10) == 10); 2653 2654 template S2(T) { struct S2 { T value; } } 2655 template func2(T) { auto func2(T value) { return value; } } 2656 static assert(is(S2!int == struct)); 2657 assert(func2(10) == 10); 2658 2659 template X(T) { alias X = T[3]; } 2660 static assert(is(X!int == int[3])); 2661 2662 int a; 2663 template Y(T) { alias Y = T[typeof(a)]; } 2664 static assert(is(Y!double == double[int])); 2665 2666 int v = 10; 2667 template Z() { alias Z = v; } 2668 assert(v == 10); 2669 Z!() = 20; 2670 assert(v == 20); 2671 } 2672 2673 /******************************************/ 2674 2675 enum T8848a(int[] a) = a; 2676 enum T8848b(int[int] b) = b; 2677 enum T8848c(void* c) = c; 2678 2679 static assert(T8848a!([1,2,3]) == [1,2,3]); 2680 static assert(T8848b!([1:2,3:4]) == [1:2,3:4]); 2681 static assert(T8848c!(null) == null); 2682 2683 /******************************************/ 2684 // 9990 2685 2686 auto initS9990() { return "hi"; } 2687 2688 class C9990(alias init) {} 2689 2690 alias SC9990 = C9990!(initS9990); 2691 2692 /******************************************/ 2693 // 10067 2694 2695 struct assumeSize10067(alias F) {} 2696 2697 template useItemAt10067(size_t idx, T) 2698 { 2699 void impl(){ } 2700 2701 alias useItemAt10067 = assumeSize10067!(impl); 2702 } 2703 2704 useItemAt10067!(0, char) mapS10067; 2705 2706 /******************************************/ 2707 // 4072 2708 2709 void bug4072(T)(T x) 2710 if (is(typeof(bug4072(x)))) 2711 {} 2712 2713 static assert(!is(typeof(bug4072(7)))); 2714 2715 /******************************************/ 2716 // 10074 2717 2718 template foo10074(F) 2719 { 2720 enum foo10074 = false; 2721 } 2722 bool foo10074(F)(F f) 2723 if (foo10074!F) 2724 { 2725 return false; 2726 } 2727 2728 static assert(!is(typeof(foo10074(1)))); 2729 2730 /******************************************/ 2731 // 10083 2732 2733 // [a-c] IFTI can find syntactic eponymous member 2734 template foo10083a(T) 2735 { 2736 int foo10083a(double) { return 1; } 2737 int foo10083a(T) { return 2; } 2738 } 2739 template foo10083b(T) 2740 { 2741 int foo10083b(T) { return 1; } 2742 int foo10083b(T, T) { return 2; } 2743 } 2744 template foo10083c1(T) 2745 { 2746 int foo10083c1(T) { return 1; } 2747 static if (true) { int x; } 2748 } 2749 template foo10083c2(T) 2750 { 2751 int foo10083c2(T) { return 1; } 2752 static if (true) { int x; } else { int y; } 2753 } 2754 2755 // [d-f] IFTI cannot find syntactic eponymous member 2756 template foo10083d1(T) 2757 { 2758 static if (true) 2759 { 2760 int foo10083d1(T) { return 1; } 2761 } 2762 else 2763 { 2764 } 2765 } 2766 template foo10083d2(T) 2767 { 2768 static if (true) 2769 { 2770 } 2771 else 2772 { 2773 int foo10083d2(T) { return 1; } 2774 } 2775 } 2776 template foo10083e(T) 2777 { 2778 static if (true) 2779 { 2780 int foo10083e(double arg) { return 1; } 2781 } 2782 int foo10083e(T arg) { return 2; } 2783 } 2784 template foo10083f(T) 2785 { 2786 static if (true) 2787 { 2788 int foo10083f(T) { return 1; } 2789 } 2790 else 2791 { 2792 int foo10083f(T) { return 2; } 2793 } 2794 } 2795 2796 void test10083() 2797 { 2798 assert(foo10083a(1) == 2); 2799 assert(foo10083a!int(1) == 2); 2800 assert(foo10083a!int(1.0) == 1); 2801 static assert(!__traits(compiles, foo10083a!double(1))); 2802 static assert(!__traits(compiles, foo10083a!double(1.0))); 2803 static assert(!__traits(compiles, foo10083a!real(1))); 2804 assert(foo10083a!real(1.0) == 1); 2805 assert(foo10083a!real(1.0L) == 2); 2806 2807 assert(foo10083b(2) == 1); 2808 assert(foo10083b(3, 4) == 2); 2809 static assert(!__traits(compiles, foo10083b(2, ""))); 2810 2811 assert(foo10083c1(1) == 1); 2812 assert(foo10083c2(1) == 1); 2813 2814 static assert(!__traits(compiles, foo10083d1(2))); 2815 static assert(!__traits(compiles, foo10083d2(2))); 2816 static assert(!__traits(compiles, foo10083e(3))); 2817 static assert(!__traits(compiles, foo10083f(3))); 2818 } 2819 2820 /******************************************/ 2821 // 10134 2822 2823 template ReturnType10134(alias func) 2824 { 2825 static if (is(typeof(func) R == return)) 2826 alias R ReturnType10134; 2827 else 2828 static assert(0); 2829 } 2830 2831 struct Result10134(T) {} 2832 2833 template getResultType10134(alias func) 2834 { 2835 static if(is(ReturnType10134!(func.exec) _ == Result10134!(T), T)) 2836 { 2837 alias getResultType10134 = T; 2838 } 2839 } 2840 2841 template f10134(alias func) 2842 { 2843 Result10134!(getResultType10134!(func)) exec(int i) 2844 { 2845 return typeof(return)(); 2846 } 2847 } 2848 2849 template a10134() 2850 { 2851 Result10134!(double) exec(int i) 2852 { 2853 return b10134!().exec(i); 2854 } 2855 } 2856 2857 template b10134() 2858 { 2859 Result10134!(double) exec(int i) 2860 { 2861 return f10134!(a10134!()).exec(i); 2862 } 2863 } 2864 2865 pragma(msg, getResultType10134!(a10134!())); 2866 2867 /******************************************/ 2868 // 10313 2869 2870 void test10313() 2871 { 2872 struct Nullable(T) 2873 { 2874 this()(inout T value) inout {} 2875 } 2876 2877 struct S { S[] array; } 2878 S s; 2879 auto ns = Nullable!S(s); 2880 2881 class C { C[] array; } 2882 C c; 2883 auto nc = Nullable!C(c); 2884 } 2885 2886 /******************************************/ 2887 // 10498 2888 2889 template triggerIssue10498a() 2890 { 2891 enum triggerIssue10498a = __traits(compiles, { T10498a; }); 2892 } 2893 2894 template PackedGenericTuple10498a(Args...) 2895 { 2896 alias Args Tuple; 2897 enum e = triggerIssue10498a!(); 2898 } 2899 2900 struct S10498a { } 2901 2902 template T10498a() 2903 { 2904 alias PackedGenericTuple10498a!S10498a T10498a; 2905 } 2906 2907 void test10498a() 2908 { 2909 alias T10498a!() t; 2910 static assert(is(t.Tuple[0])); // Fails -> OK 2911 } 2912 2913 // -------- 2914 2915 template triggerIssue10498b(A...) 2916 { 2917 enum triggerIssue10498b = __traits(compiles, { auto a = A[0]; }); 2918 } 2919 2920 template PackedGenericTuple10498b(Args...) 2921 { 2922 alias Args Tuple; 2923 enum e = triggerIssue10498b!Args; 2924 } 2925 2926 template T10498b() 2927 { 2928 struct S {} // The fact `S` is in `T` causes the problem 2929 alias PackedGenericTuple10498b!S T10498b; 2930 } 2931 2932 void test10498b() 2933 { 2934 alias T10498b!() t; 2935 static assert(is(t.Tuple[0])); 2936 } 2937 2938 /******************************************/ 2939 // 10537 2940 2941 struct Iota10537 2942 { 2943 int s,e,i; 2944 mixin Yield10537!q{ ; }; 2945 } 2946 2947 auto skipStrings10537(T)(T source) 2948 { 2949 return ""; 2950 } 2951 2952 mixin template Yield10537(dstring code) 2953 { 2954 alias X = typeof({ enum x = rewriteCode10537(code); }()); 2955 } 2956 2957 dstring rewriteCode10537(dstring code) 2958 { 2959 skipStrings10537(code); // IFTI causes forward reference 2960 return ""; 2961 } 2962 2963 /******************************************/ 2964 // 10558 2965 2966 template Template10558() {} 2967 2968 struct Struct10558(alias T){} 2969 2970 alias bar10558 = foo10558!(Template10558!()); 2971 2972 template foo10558(alias T) 2973 { 2974 alias foobar = Struct10558!T; 2975 2976 void fun() 2977 { 2978 alias a = foo10558!T; 2979 } 2980 } 2981 2982 /******************************************/ 2983 // 10592 2984 2985 void test10592() 2986 { 2987 struct A(E) 2988 { 2989 int put()(const(E)[] data) 2990 { 2991 return 1; 2992 } 2993 2994 int put()(const(dchar)[] data) if (!is(E == dchar)) 2995 { 2996 return 2; 2997 } 2998 2999 int put(C)(const(C)[] data) if (!is(C == dchar) && !is(E == C)) 3000 { 3001 return 3; 3002 } 3003 } 3004 3005 A!char x; 3006 assert(x.put("abcde"c) == 1); // OK: hit 1 3007 assert(x.put("abcde"w) == 3); // NG: this should hit 3 3008 assert(x.put("abcde"d) == 2); // OK: hit 2 3009 } 3010 3011 /******************************************/ 3012 // 11242 3013 3014 inout(T[]) fromString11242(T)(inout(char[]) s, T[] dst) 3015 { 3016 return s; 3017 } 3018 3019 void test11242() 3020 { 3021 char[] a; 3022 fromString11242(a, a); 3023 } 3024 3025 /******************************************/ 3026 // 10811 3027 3028 void foo10811a(R1, R2)(R1, R2) {} 3029 template foo10811a(alias pred) { void foo10811a(R1, R2)(R1, R2) {} } 3030 3031 template foo10811b(alias pred) { void foo10811b(R1, R2)(R1, R2) {} } 3032 void foo10811b(R1, R2)(R1, R2) {} 3033 3034 void test10811() 3035 { 3036 foo10811a(1, 2); 3037 foo10811a!(a => a)(1, 2); 3038 3039 foo10811b(1, 2); 3040 foo10811b!(a => a)(1, 2); 3041 } 3042 3043 /******************************************/ 3044 // 10969 3045 3046 template A10969(T, U...) { alias A10969 = T; } 3047 void foo10969(T, U...)(A10969!(T, U) a) {} 3048 3049 template B10969(T, U) { alias B10969 = T; } 3050 void bar10969(T, U...)(B10969!(T, U[0]) a) {} 3051 3052 void test10969() 3053 { 3054 foo10969!(int, float)(3); 3055 bar10969!(int, float)(3); 3056 } 3057 3058 /******************************************/ 3059 // 11271 3060 3061 struct SmartPtr11271(T) 3062 { 3063 ~this() {} 3064 void opAssign(U)(auto ref U rh) {} 3065 } 3066 3067 void test11271() 3068 { 3069 SmartPtr11271!Object a; 3070 a = SmartPtr11271!Object(); 3071 } 3072 3073 /******************************************/ 3074 // 11533 3075 3076 version (none) 3077 { 3078 struct S11533 3079 { 3080 void put(alias fun)() { fun!int(); } 3081 } 3082 void test11533a() 3083 { 3084 static void foo(T)() {} 3085 S11533 s; 3086 s.put!foo(); 3087 } 3088 3089 void test11533b() 3090 { 3091 static void bar(alias fun)() { fun(); } 3092 void nested() {} 3093 bar!nested(); 3094 } 3095 3096 void test11533c() 3097 { 3098 static struct Foo(alias fun) 3099 { 3100 auto call() { return fun(); } 3101 } 3102 int var = 1; 3103 auto getVar() { return var; } 3104 Foo!getVar foo; 3105 assert(foo.call() == var); 3106 var += 1; 3107 assert(foo.call() == var); 3108 } 3109 3110 void test11533() 3111 { 3112 test11533a(); 3113 test11533b(); 3114 test11533c(); 3115 } 3116 } 3117 else 3118 { 3119 void test11533() 3120 { 3121 } 3122 } 3123 3124 /******************************************/ 3125 // 11553 3126 3127 struct Pack11553(T ...) 3128 { 3129 alias Unpack = T; 3130 enum length = T.length; 3131 } 3132 3133 template isPack11553(TList ...) 3134 { 3135 static if (TList.length == 1 && is(Pack11553!(TList[0].Unpack) == TList[0])) 3136 { 3137 enum isPack11553 = true; 3138 } 3139 else 3140 { 3141 enum isPack11553 = false; 3142 } 3143 } 3144 3145 template PartialApply11553(alias T, uint argLoc, Arg ...) 3146 if (Arg.length == 1) 3147 { 3148 template PartialApply11553(L ...) 3149 { 3150 alias PartialApply11553 = T!(L[0 .. argLoc], Arg, L[argLoc .. $]); 3151 } 3152 } 3153 3154 template _hasLength11553(size_t len, T) 3155 { 3156 static if (T.length == len) 3157 { 3158 enum _hasLength11553 = true; 3159 } 3160 else 3161 { 3162 enum _hasLength11553 = false; 3163 } 3164 } 3165 3166 alias _hasLength11553(size_t len) = PartialApply11553!(._hasLength11553, 0, len); 3167 3168 3169 alias hl11553 = _hasLength11553!1; 3170 3171 // this segfaults 3172 static if (!isPack11553!hl11553) { pragma(msg, "All good 1"); } 3173 3174 // these are fine 3175 static if ( hl11553!(Pack11553!(5))) { pragma(msg, "All good 2"); } 3176 3177 static if (!hl11553!(Pack11553!( ))) { pragma(msg, "All good 3"); } 3178 3179 /******************************************/ 3180 // 11818 3181 3182 enum E11818 { e0, e1 } 3183 3184 struct SortedRange11818 3185 { 3186 void fun(E11818 e = true ? E11818.e0 : E11818.e1)() 3187 { 3188 } 3189 } 3190 3191 void test11818() 3192 { 3193 SortedRange11818 s; 3194 s.fun(); 3195 } 3196 3197 /******************************************/ 3198 // 11843 3199 3200 void test11843() 3201 { 3202 struct Foo 3203 { 3204 int x[string]; 3205 } 3206 3207 struct Bar(alias foo) {} 3208 3209 enum bar1 = Bar!(Foo(["a": 1]))(); 3210 enum bar2 = Bar!(Foo(["a": 1]))(); 3211 static assert(is(typeof(bar1) == typeof(bar2))); 3212 3213 enum foo1 = Foo(["a": 1]); 3214 enum foo2 = Foo(["b": -1]); 3215 static assert(!__traits(isSame, foo1, foo2)); 3216 enum bar3 = Bar!foo1(); 3217 enum bar4 = Bar!foo2(); 3218 static assert(!is(typeof(bar3) == typeof(bar4))); 3219 } 3220 3221 /******************************************/ 3222 // 11872 3223 3224 class Foo11872 3225 { 3226 auto test(int v)() {} 3227 auto test(int v)(string) {} 3228 3229 template Bar(T) 3230 { 3231 void test(T) {} 3232 } 3233 } 3234 3235 void test11872() 3236 { 3237 auto foo = new Foo11872(); 3238 3239 with (foo) 3240 { 3241 // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) 3242 foo.test!2(); // works 3243 test!2(); // works <- fails 3244 test!2; // works <- fails 3245 3246 // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) -> DotExp(wthis, ScopeExp) 3247 foo.Bar!int.test(1); // works 3248 Bar!int.test(1); // works <- fails 3249 } 3250 } 3251 3252 /******************************************/ 3253 // 12042 3254 3255 struct S12042 3256 { 3257 int[] t; 3258 3259 void m()() 3260 { 3261 t = null; // CTFE error -> OK 3262 } 3263 } 3264 3265 int test12042() 3266 { 3267 S12042 s; 3268 3269 with (s) 3270 m!()(); 3271 3272 return 1; 3273 } 3274 3275 static assert(test12042()); 3276 3277 /******************************************/ 3278 // 12077 3279 3280 struct S12077(A) {} 3281 3282 alias T12077(alias T : Base!Args, alias Base, Args...) = Base; 3283 static assert(__traits(isSame, T12077!(S12077!int), S12077)); 3284 3285 alias U12077(alias T : Base!Args, alias Base, Args...) = Base; 3286 alias U12077( T : Base!Args, alias Base, Args...) = Base; 3287 static assert(__traits(isSame, U12077!(S12077!int), S12077)); 3288 3289 /******************************************/ 3290 // 12262 3291 3292 template Inst12262(T) { int x; } 3293 3294 enum fqnSym12262(alias a) = 1; 3295 enum fqnSym12262(alias a : B!A, alias B, A...) = 2; 3296 3297 static assert(fqnSym12262!(Inst12262!(Object)) == 2); 3298 static assert(fqnSym12262!(Inst12262!(Object).x) == 1); 3299 3300 /******************************************/ 3301 // 12264 3302 3303 struct S12264(A) {} 3304 3305 template AX12264(alias A1) { enum AX12264 = 1; } 3306 template AX12264(alias A2 : B!A, alias B, A...) { enum AX12264 = 2; } 3307 template AY12264(alias A1) { enum AY12264 = 1; } 3308 template AY12264(alias A2 : B!int, alias B) { enum AY12264 = 2; } 3309 template AZ12264(alias A1) { enum AZ12264 = 1; } 3310 template AZ12264(alias A2 : S12264!T, T) { enum AZ12264 = 2; } 3311 static assert(AX12264!(S12264!int) == 2); 3312 static assert(AY12264!(S12264!int) == 2); 3313 static assert(AZ12264!(S12264!int) == 2); 3314 3315 template TX12264(T1) { enum TX12264 = 1; } 3316 template TX12264(T2 : B!A, alias B, A...) { enum TX12264 = 2; } 3317 template TY12264(T1) { enum TY12264 = 1; } 3318 template TY12264(T2 : B!int, alias B) { enum TY12264 = 2; } 3319 template TZ12264(T1) { enum TZ12264 = 1; } 3320 template TZ12264(T2 : S12264!T, T) { enum TZ12264 = 2; } 3321 static assert(TX12264!(S12264!int) == 2); 3322 static assert(TY12264!(S12264!int) == 2); 3323 static assert(TZ12264!(S12264!int) == 2); 3324 3325 /******************************************/ 3326 // 12122 3327 3328 enum N12122 = 1; 3329 3330 void foo12122(T)(T[N12122]) if(is(T == int)) {} 3331 3332 void test12122() 3333 { 3334 int[N12122] data; 3335 foo12122(data); 3336 } 3337 3338 /******************************************/ 3339 // 12186 3340 3341 template map_front12186(fun...) 3342 { 3343 auto map_front12186(Range)(Range r) 3344 { 3345 return fun[0](r[0]); 3346 } 3347 } 3348 3349 void test12186() 3350 { 3351 immutable int[][] mat; 3352 3353 mat.map_front12186!((in r) => 0); // OK 3354 mat.map_front12186!((const r) => 0); // OK 3355 mat.map_front12186!((immutable int[] r) => 0); // OK 3356 mat.map_front12186!((immutable r) => 0); // OK <- Error 3357 } 3358 3359 /******************************************/ 3360 // 12207 3361 3362 void test12207() 3363 { 3364 static struct S 3365 { 3366 static void f(T)(T) {} 3367 } 3368 3369 immutable S s; 3370 3371 s.f(1); 3372 } 3373 3374 /******************************************/ 3375 // 12263 3376 3377 template A12263(alias a) { int x; } 3378 template B12263(alias a) { int x; } 3379 3380 template fqnSym12263(alias T : B12263!A, alias B12263, A...) 3381 { 3382 enum fqnSym12263 = true; 3383 } 3384 3385 static assert(fqnSym12263!(A12263!(Object))); 3386 static assert(fqnSym12263!(B12263!(Object))); 3387 3388 /******************************************/ 3389 // 12290 3390 3391 void test12290() 3392 { 3393 short[] arrS; 3394 float[] arrF; 3395 double[] arrD; 3396 real[] arrR; 3397 string cstr; 3398 wstring wstr; 3399 dstring dstr; 3400 short[short] aa; 3401 3402 auto func1a(E)(E[], E) { return E.init; } 3403 auto func1b(E)(E, E[]) { return E.init; } 3404 3405 static assert(is(typeof(func1a(arrS, 1)) == short)); 3406 static assert(is(typeof(func1b(1, arrS)) == short)); 3407 static assert(is(typeof(func1a(arrF, 1.0)) == float)); 3408 static assert(is(typeof(func1b(1.0, arrF)) == float)); 3409 static assert(is(typeof(func1a(arrD, 1.0L)) == double)); 3410 static assert(is(typeof(func1b(1.0L, arrD)) == double)); 3411 static assert(is(typeof(func1a(arrR, 1)) == real)); 3412 static assert(is(typeof(func1b(1, arrR)) == real)); 3413 static assert(is(typeof(func1a("str" , 'a')) == immutable char)); 3414 static assert(is(typeof(func1b('a', "str" )) == immutable char)); 3415 static assert(is(typeof(func1a("str"c, 'a')) == immutable char)); 3416 static assert(is(typeof(func1b('a', "str"c)) == immutable char)); 3417 static assert(is(typeof(func1a("str"w, 'a')) == immutable wchar)); 3418 static assert(is(typeof(func1b('a', "str"w)) == immutable wchar)); 3419 static assert(is(typeof(func1a("str"d, 'a')) == immutable dchar)); 3420 static assert(is(typeof(func1b('a', "str"d)) == immutable dchar)); 3421 static assert(is(typeof(func1a([1,2,3], 1L)) == long)); 3422 static assert(is(typeof(func1b(1L, [1,2,3])) == long)); 3423 static assert(is(typeof(func1a([1,2,3], 1.5)) == double)); 3424 static assert(is(typeof(func1b(1.5, [1,2,3])) == double)); 3425 static assert(is(typeof(func1a(["a","b"], "s"c)) == string)); 3426 static assert(is(typeof(func1b("s"c, ["a","b"])) == string)); 3427 static assert(is(typeof(func1a(["a","b"], "s"w)) == wstring)); 3428 static assert(is(typeof(func1b("s"w, ["a","b"])) == wstring)); 3429 static assert(is(typeof(func1a(["a","b"], "s"d)) == dstring)); 3430 static assert(is(typeof(func1b("s"d, ["a","b"])) == dstring)); 3431 3432 auto func2a(K, V)(V[K], K, V) { return V[K].init; } 3433 auto func2b(K, V)(V, K, V[K]) { return V[K].init; } 3434 3435 static assert(is(typeof(func2a(aa, 1, 1)) == short[short])); 3436 static assert(is(typeof(func2b(1, 1, aa)) == short[short])); 3437 static assert(is(typeof(func2a([1:10,2:20,3:30], 1L, 10L)) == long[long])); 3438 static assert(is(typeof(func2b(1L, 10L, [1:20,2:20,3:30])) == long[long])); 3439 3440 auto func3a(T)(T, T) { return T.init; } 3441 auto func3b(T)(T, T) { return T.init; } 3442 3443 static assert(is(typeof(func3a(arrS, null)) == short[])); 3444 static assert(is(typeof(func3b(null, arrS)) == short[])); 3445 static assert(is(typeof(func3a(arrR, null)) == real[])); 3446 static assert(is(typeof(func3b(null, arrR)) == real[])); 3447 static assert(is(typeof(func3a(cstr, "str")) == string)); 3448 static assert(is(typeof(func3b("str", cstr)) == string)); 3449 static assert(is(typeof(func3a(wstr, "str")) == wstring)); 3450 static assert(is(typeof(func3b("str", wstr)) == wstring)); 3451 static assert(is(typeof(func3a(dstr, "str")) == dstring)); 3452 static assert(is(typeof(func3b("str", dstr)) == dstring)); 3453 static assert(is(typeof(func3a("str1" , "str2"c)) == string)); 3454 static assert(is(typeof(func3b("str1"c, "str2" )) == string)); 3455 static assert(is(typeof(func3a("str1" , "str2"w)) == wstring)); 3456 static assert(is(typeof(func3b("str1"w, "str2" )) == wstring)); 3457 static assert(is(typeof(func3a("str1" , "str2"d)) == dstring)); 3458 static assert(is(typeof(func3b("str1"d, "str2" )) == dstring)); 3459 3460 inout(V) get(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; } 3461 3462 short[short] hash12220; 3463 short res12220 = get(hash12220, 1, 1); 3464 3465 short[short] hash12221; 3466 enum Key12221 : short { a } 3467 get(hash12221, Key12221.a, Key12221.a); 3468 3469 int[][string] mapping13026; 3470 int[] v = get(mapping13026, "test", []); 3471 } 3472 3473 /******************************************/ 3474 // 12292 3475 3476 void test12292() 3477 { 3478 void fun(T : string)(T data) {} 3479 3480 ubyte[3] sa; 3481 static assert(!__traits(compiles, fun(sa))); 3482 static assert(!__traits(compiles, { alias f = fun!(ubyte[3]); })); 3483 } 3484 3485 /******************************************/ 3486 // 12376 3487 3488 static auto encode12376(size_t sz)(dchar ch) if (sz > 1) 3489 { 3490 undefined; 3491 } 3492 3493 void test12376() 3494 { 3495 enum x = __traits(compiles, encode12376!2(x)); 3496 } 3497 3498 /******************************************/ 3499 // 12447 3500 3501 enum test12447(string str) = str; // [1] 3502 string test12447(T...)(T args) if (T.length) { return args[0]; } // [2] 3503 3504 // With [1]: The template parameter str cannot be be deduced -> no match 3505 // With [2]: T is deduced to a type tuple (string), then match to the function call. 3506 static assert(test12447("foo") == "foo"); 3507 3508 // With [1]: template parameter str is deduced to "bar", then match. 3509 // With [2]: T is deduced to an expression tuple ("bar"), but it will make invalid the function signature (T args). 3510 // The failure should be masked silently and prefer the 1st version. 3511 static assert(test12447!("bar") == "bar"); 3512 3513 /******************************************/ 3514 // 12651 3515 3516 alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args; 3517 3518 struct S12651(T) { } 3519 3520 static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float))); 3521 3522 /******************************************/ 3523 // 12719 3524 3525 struct A12719 3526 { 3527 B12719!int b(); 3528 } 3529 3530 struct B12719(T) 3531 { 3532 A12719 a; 3533 void m() 3534 { 3535 auto v = B12719!T.init; 3536 } 3537 } 3538 3539 // -------- 3540 3541 enum canDoIt12719(R) = is(typeof(W12719!R)); 3542 3543 struct W12719(R) 3544 { 3545 R r; 3546 static if (canDoIt12719!R) {} 3547 } 3548 3549 W12719!int a12719; 3550 3551 /******************************************/ 3552 // 12746 3553 3554 template foo12746() 3555 { 3556 void bar() 3557 { 3558 static assert(!__traits(compiles, bar(1))); 3559 } 3560 alias foo12746 = bar; 3561 } 3562 3563 void foo12746(int) 3564 { 3565 assert(0); 3566 } 3567 3568 void test12746() 3569 { 3570 foo12746(); // instantiate 3571 } 3572 3573 /******************************************/ 3574 // 12748 3575 3576 void foo12748(S, C : typeof(S.init[0]))(S s, C c) 3577 { 3578 } 3579 3580 void test12748() 3581 { 3582 foo12748("abc", 'd'); 3583 } 3584 3585 /******************************************/ 3586 // 9708 3587 3588 struct S9708 3589 { 3590 void f()(inout(Object)) inout {} 3591 } 3592 3593 void test9708() 3594 { 3595 S9708 s; 3596 s.f(new Object); 3597 } 3598 3599 /******************************************/ 3600 // 12880 3601 3602 void f12880(T)(in T value) { static assert(is(T == string)); } 3603 void test12880() { f12880(string.init); } 3604 3605 /******************************************/ 3606 // 13087 3607 3608 struct Vec13087 3609 { 3610 int x; 3611 void m() { auto n = component13087!(this, 'x'); } 3612 void c() const { auto n = component13087!(this, 'x'); } 3613 void w() inout { auto n = component13087!(this, 'x'); } 3614 void wc() inout const { auto n = component13087!(this, 'x'); } 3615 void s() shared { auto n = component13087!(this, 'x'); } 3616 void sc() shared const { auto n = component13087!(this, 'x'); } 3617 void sw() shared inout { auto n = component13087!(this, 'x'); } 3618 void swc() shared inout const { auto n = component13087!(this, 'x'); } 3619 void i() immutable { auto n = component13087!(this, 'x'); } 3620 } 3621 3622 template component13087(alias vec, char c) 3623 { 3624 alias component13087 = vec.x; 3625 } 3626 3627 /******************************************/ 3628 // 13127 3629 3630 /+void test13127(inout int = 0) 3631 { 3632 int [] ma1; 3633 const(int)[] ca1; 3634 const(int[]) ca2; 3635 inout( int)[] wma1; 3636 inout( int[]) wma2; 3637 inout(const int)[] wca1; 3638 inout(const int[]) wca2; 3639 immutable(int)[] ia1; 3640 immutable(int[]) ia2; 3641 shared( int)[] sma1; 3642 shared( int[]) sma2; 3643 shared( const int)[] sca1; 3644 shared( const int[]) sca2; 3645 shared(inout int)[] swma1; 3646 shared(inout int[]) swma2; 3647 shared(inout const int)[] swca1; 3648 shared(inout const int[]) swca2; 3649 3650 /* In all cases, U should be deduced to top-unqualified type. 3651 */ 3652 3653 /* Parameter is (shared) mutable 3654 */ 3655 U f_m(U)( U) { return null; } 3656 U fsm(U)(shared U) { return null; } 3657 // 9 * 2 - 1 3658 static assert(is(typeof(f_m( ma1)) == int [])); 3659 static assert(is(typeof(f_m( ca1)) == const(int)[])); 3660 static assert(is(typeof(f_m( ca2)) == const(int)[])); 3661 static assert(is(typeof(f_m( wma1)) == inout( int)[])); 3662 static assert(is(typeof(f_m( wma2)) == inout( int)[])); 3663 static assert(is(typeof(f_m( wca1)) == inout(const int)[])); 3664 static assert(is(typeof(f_m( wca2)) == inout(const int)[])); 3665 static assert(is(typeof(f_m( ia1)) == immutable(int)[])); 3666 static assert(is(typeof(f_m( ia2)) == immutable(int)[])); 3667 static assert(is(typeof(f_m( sma1)) == shared( int)[])); 3668 static assert(is(typeof(f_m( sma2)) == shared( int)[])); // <- shared(int[]) 3669 static assert(is(typeof(f_m( sca1)) == shared( const int)[])); 3670 static assert(is(typeof(f_m( sca2)) == shared( const int)[])); // <- shared(const(int)[]) 3671 static assert(is(typeof(f_m(swma1)) == shared(inout int)[])); 3672 static assert(is(typeof(f_m(swma2)) == shared(inout int)[])); // <- shared(inout(int[])) 3673 static assert(is(typeof(f_m(swca1)) == shared(inout const int)[])); 3674 static assert(is(typeof(f_m(swca2)) == shared(inout const int)[])); // <- shared(inout(const(int))[]) 3675 // 9 * 2 - 1 3676 static assert(is(typeof(fsm( ma1))) == false); 3677 static assert(is(typeof(fsm( ca1))) == false); 3678 static assert(is(typeof(fsm( ca2))) == false); 3679 static assert(is(typeof(fsm( wma1))) == false); 3680 static assert(is(typeof(fsm( wma2))) == false); 3681 static assert(is(typeof(fsm( wca1))) == false); 3682 static assert(is(typeof(fsm( wca2))) == false); 3683 static assert(is(typeof(fsm( ia1))) == false); 3684 static assert(is(typeof(fsm( ia2))) == false); 3685 static assert(is(typeof(fsm( sma1)) == shared( int)[])); // <- NG 3686 static assert(is(typeof(fsm( sma2)) == shared( int)[])); 3687 static assert(is(typeof(fsm( sca1)) == shared( const int)[])); // <- NG 3688 static assert(is(typeof(fsm( sca2)) == shared( const int)[])); 3689 static assert(is(typeof(fsm(swma1)) == shared(inout int)[])); // <- NG 3690 static assert(is(typeof(fsm(swma2)) == shared(inout int)[])); 3691 static assert(is(typeof(fsm(swca1)) == shared(inout const int)[])); // <- NG 3692 static assert(is(typeof(fsm(swca2)) == shared(inout const int)[])); 3693 3694 /* Parameter is (shared) const 3695 */ 3696 U f_c(U)( const U) { return null; } 3697 U fsc(U)(shared const U) { return null; } 3698 // 9 * 2 - 1 3699 static assert(is(typeof(f_c( ma1)) == int [])); 3700 static assert(is(typeof(f_c( ca1)) == const(int)[])); 3701 static assert(is(typeof(f_c( ca2)) == const(int)[])); 3702 static assert(is(typeof(f_c( wma1)) == inout( int)[])); 3703 static assert(is(typeof(f_c( wma2)) == inout( int)[])); 3704 static assert(is(typeof(f_c( wca1)) == inout(const int)[])); 3705 static assert(is(typeof(f_c( wca2)) == inout(const int)[])); 3706 static assert(is(typeof(f_c( ia1)) == immutable(int)[])); 3707 static assert(is(typeof(f_c( ia2)) == immutable(int)[])); 3708 static assert(is(typeof(f_c( sma1)) == shared( int)[])); 3709 static assert(is(typeof(f_c( sma2)) == shared( int)[])); // <- shared(int[]) 3710 static assert(is(typeof(f_c( sca1)) == shared( const int)[])); 3711 static assert(is(typeof(f_c( sca2)) == shared( const int)[])); // <- shared(const(int)[]) 3712 static assert(is(typeof(f_c(swma1)) == shared(inout int)[])); 3713 static assert(is(typeof(f_c(swma2)) == shared(inout int)[])); // shared(inout(int)[]) 3714 static assert(is(typeof(f_c(swca1)) == shared(inout const int)[])); 3715 static assert(is(typeof(f_c(swca2)) == shared(inout const int)[])); // shared(inout(const(int))[]) 3716 // 9 * 2 - 1 3717 static assert(is(typeof(fsc( ma1))) == false); 3718 static assert(is(typeof(fsc( ca1))) == false); 3719 static assert(is(typeof(fsc( ca2))) == false); 3720 static assert(is(typeof(fsc( wma1))) == false); 3721 static assert(is(typeof(fsc( wma2))) == false); 3722 static assert(is(typeof(fsc( wca1))) == false); 3723 static assert(is(typeof(fsc( wca2))) == false); 3724 static assert(is(typeof(fsc( ia1)) == immutable(int)[])); // <- NG 3725 static assert(is(typeof(fsc( ia2)) == immutable(int)[])); // <- NG 3726 static assert(is(typeof(fsc( sma1)) == shared( int)[])); // <- NG 3727 static assert(is(typeof(fsc( sma2)) == shared( int)[])); 3728 static assert(is(typeof(fsc( sca1)) == shared( const int)[])); // <- NG 3729 static assert(is(typeof(fsc( sca2)) == shared( const int)[])); 3730 static assert(is(typeof(fsc(swma1)) == shared(inout int)[])); // <- NG 3731 static assert(is(typeof(fsc(swma2)) == shared(inout int)[])); 3732 static assert(is(typeof(fsc(swca1)) == shared(inout const int)[])); // <- NG 3733 static assert(is(typeof(fsc(swca2)) == shared(inout const int)[])); 3734 3735 /* Parameter is immutable 3736 */ 3737 U fi(U)(immutable U) { return null; } 3738 // 9 * 2 - 1 3739 static assert(is(typeof(fi( ma1))) == false); 3740 static assert(is(typeof(fi( ca1))) == false); 3741 static assert(is(typeof(fi( ca2))) == false); 3742 static assert(is(typeof(fi( wma1))) == false); 3743 static assert(is(typeof(fi( wma2))) == false); 3744 static assert(is(typeof(fi( wca1))) == false); 3745 static assert(is(typeof(fi( wca2))) == false); 3746 static assert(is(typeof(fi( ia1)) == immutable(int)[])); // <- NG 3747 static assert(is(typeof(fi( ia2)) == immutable(int)[])); // <- NG 3748 static assert(is(typeof(fi( sma1))) == false); 3749 static assert(is(typeof(fi( sma2))) == false); 3750 static assert(is(typeof(fi( sca1))) == false); 3751 static assert(is(typeof(fi( sca2))) == false); 3752 static assert(is(typeof(fi(swma1))) == false); 3753 static assert(is(typeof(fi(swma2))) == false); 3754 static assert(is(typeof(fi(swca1))) == false); 3755 static assert(is(typeof(fi(swca2))) == false); 3756 3757 /* Parameter is (shared) inout 3758 */ 3759 U f_w(U)( inout U) { return null; } 3760 U fsw(U)(shared inout U) { return null; } 3761 // 9 * 2 - 1 3762 static assert(is(typeof(f_w( ma1)) == int [])); 3763 static assert(is(typeof(f_w( ca1)) == int [])); // <- const(int)[] 3764 static assert(is(typeof(f_w( ca2)) == int [])); // <- const(int)[] 3765 static assert(is(typeof(f_w( wma1)) == int [])); // <- inout(int)[] 3766 static assert(is(typeof(f_w( wma2)) == int [])); // <- inout(int)[] 3767 static assert(is(typeof(f_w( wca1)) == const(int)[])); // <- inout(const(int))[] 3768 static assert(is(typeof(f_w( wca2)) == const(int)[])); // <- inout(const(int))[] 3769 static assert(is(typeof(f_w( ia1)) == int [])); // <- immutable(int)[] 3770 static assert(is(typeof(f_w( ia2)) == int [])); // <- immutable(int)[] 3771 static assert(is(typeof(f_w( sma1)) == shared( int)[])); 3772 static assert(is(typeof(f_w( sma2)) == shared( int)[])); // <- shared(int[]) 3773 static assert(is(typeof(f_w( sca1)) == shared( int)[])); // <- shared(const(int))[] 3774 static assert(is(typeof(f_w( sca2)) == shared( int)[])); // <- shared(const(int)[]) 3775 static assert(is(typeof(f_w(swma1)) == shared( int)[])); // <- shared(inout(int))[] 3776 static assert(is(typeof(f_w(swma2)) == shared( int)[])); // <- shared(inout(int)[]) 3777 static assert(is(typeof(f_w(swca1)) == shared(const int)[])); // <- shared(inout(const(int)))[] 3778 static assert(is(typeof(f_w(swca2)) == shared(const int)[])); // <- shared(inout(const(int))[]) 3779 // 9 * 2 - 1 3780 static assert(is(typeof(fsw( ma1))) == false); 3781 static assert(is(typeof(fsw( ca1))) == false); 3782 static assert(is(typeof(fsw( ca2))) == false); 3783 static assert(is(typeof(fsw( wma1))) == false); 3784 static assert(is(typeof(fsw( wma2))) == false); 3785 static assert(is(typeof(fsw( wca1))) == false); 3786 static assert(is(typeof(fsw( wca2))) == false); 3787 static assert(is(typeof(fsw( ia1)) == int [])); // <- NG 3788 static assert(is(typeof(fsw( ia2)) == int [])); // <- NG 3789 static assert(is(typeof(fsw( sma1)) == int [])); // <- NG 3790 static assert(is(typeof(fsw( sma2)) == int [])); 3791 static assert(is(typeof(fsw( sca1)) == int [])); // <- NG 3792 static assert(is(typeof(fsw( sca2)) == int [])); // const(int)[] 3793 static assert(is(typeof(fsw(swma1)) == int [])); // <- NG 3794 static assert(is(typeof(fsw(swma2)) == int [])); // inout(int)[] 3795 static assert(is(typeof(fsw(swca1)) == const(int)[])); // <- NG 3796 static assert(is(typeof(fsw(swca2)) == const(int)[])); // <- inout(const(int))[] 3797 3798 /* Parameter is (shared) inout const 3799 */ 3800 U f_wc(U)( inout const U) { return null; } 3801 U fswc(U)(shared inout const U) { return null; } 3802 // 9 * 2 - 1 3803 static assert(is(typeof(f_wc( ma1)) == int [])); 3804 static assert(is(typeof(f_wc( ca1)) == int [])); // <- const(int)[] 3805 static assert(is(typeof(f_wc( ca2)) == int [])); // <- const(int)[] 3806 static assert(is(typeof(f_wc( wma1)) == int [])); // <- inout(int)[] 3807 static assert(is(typeof(f_wc( wma2)) == int [])); // <- inout(int)[] 3808 static assert(is(typeof(f_wc( wca1)) == int [])); // <- inout(const(int))[] 3809 static assert(is(typeof(f_wc( wca2)) == int [])); // <- inout(const(int))[] 3810 static assert(is(typeof(f_wc( ia1)) == int [])); // <- immutable(int)[] 3811 static assert(is(typeof(f_wc( ia2)) == int [])); // <- immutable(int)[] 3812 static assert(is(typeof(f_wc( sma1)) == shared(int)[])); 3813 static assert(is(typeof(f_wc( sma2)) == shared(int)[])); // <- shared(int[]) 3814 static assert(is(typeof(f_wc( sca1)) == shared(int)[])); // <- shared(const(int))[] 3815 static assert(is(typeof(f_wc( sca2)) == shared(int)[])); // <- shared(const(int)[]) 3816 static assert(is(typeof(f_wc(swma1)) == shared(int)[])); // <- shared(inout(int))[] 3817 static assert(is(typeof(f_wc(swma2)) == shared(int)[])); // <- shared(inout(int)[]) 3818 static assert(is(typeof(f_wc(swca1)) == shared(int)[])); // <- shared(inout(const(int)))[] 3819 static assert(is(typeof(f_wc(swca2)) == shared(int)[])); // <- shared(inout(const(int))[]) 3820 // 9 * 2 - 1 3821 static assert(is(typeof(fswc( ma1))) == false); 3822 static assert(is(typeof(fswc( ca1))) == false); 3823 static assert(is(typeof(fswc( ca2))) == false); 3824 static assert(is(typeof(fswc( wma1))) == false); 3825 static assert(is(typeof(fswc( wma2))) == false); 3826 static assert(is(typeof(fswc( wca1))) == false); 3827 static assert(is(typeof(fswc( wca2))) == false); 3828 static assert(is(typeof(fswc( ia1)) == int [])); // <- NG 3829 static assert(is(typeof(fswc( ia2)) == int [])); // <- NG 3830 static assert(is(typeof(fswc( sma1)) == int [])); // <- NG 3831 static assert(is(typeof(fswc( sma2)) == int [])); 3832 static assert(is(typeof(fswc( sca1)) == int [])); // <- NG 3833 static assert(is(typeof(fswc( sca2)) == int [])); // <- const(int)[] 3834 static assert(is(typeof(fswc(swma1)) == int [])); // <- NG 3835 static assert(is(typeof(fswc(swma2)) == int [])); // <- inout(int)[] 3836 static assert(is(typeof(fswc(swca1)) == int [])); // <- NG 3837 static assert(is(typeof(fswc(swca2)) == int [])); // <- inout(const(int))[] 3838 }+/ 3839 3840 void test13127a() 3841 { 3842 void foo(T)(in T[] src, T[] dst) { static assert(is(T == int[])); } 3843 3844 int[][] a; 3845 foo(a, a); 3846 } 3847 3848 /******************************************/ 3849 // 13159 3850 3851 template maxSize13159(T...) 3852 { 3853 static if (T.length == 1) 3854 { 3855 enum size_t maxSize13159 = T[0].sizeof; 3856 } 3857 else 3858 { 3859 enum size_t maxSize13159 = 3860 T[0].sizeof >= maxSize13159!(T[1 .. $]) 3861 ? T[0].sizeof 3862 : maxSize13159!(T[1 .. $]); 3863 } 3864 } 3865 3866 struct Node13159 3867 { 3868 struct Pair 3869 { 3870 Node13159 value; 3871 } 3872 3873 //alias Algebraic!(Node[], int) Value; 3874 enum n = maxSize13159!(Node13159[], int); 3875 } 3876 3877 /******************************************/ 3878 // 13180 3879 3880 void test13180() 3881 { 3882 inout(V) get1a(K, V)(inout(V[K]) aa, lazy inout(V) defaultValue) 3883 { 3884 static assert(is(V == string)); 3885 static assert(is(K == string)); 3886 return defaultValue; 3887 } 3888 inout(V) get1b(K, V)(lazy inout(V) defaultValue, inout(V[K]) aa) 3889 { 3890 static assert(is(V == string)); 3891 static assert(is(K == string)); 3892 return defaultValue; 3893 } 3894 3895 inout(V) get2a(K, V)(inout(V)[K] aa, lazy inout(V) defaultValue) 3896 { 3897 static assert(is(V == string)); 3898 static assert(is(K == string)); 3899 return defaultValue; 3900 } 3901 inout(V) get2b(K, V)(lazy inout(V) defaultValue, inout(V)[K] aa) 3902 { 3903 static assert(is(V == string)); 3904 static assert(is(K == string)); 3905 return defaultValue; 3906 } 3907 string def; 3908 string[string] aa; 3909 string s1a = get1a(aa, def); 3910 string s1b = get1b(def, aa); 3911 string s2a = get2a(aa, def); 3912 string s2b = get2b(def, aa); 3913 } 3914 3915 /******************************************/ 3916 // 13204 3917 3918 struct A13204(uint v) 3919 { 3920 alias whatever = A13204y; 3921 static assert(is(whatever == A13204)); 3922 } 3923 alias A13204x = A13204!1; 3924 alias A13204y = A13204x; 3925 3926 struct B13204(uint v) 3927 { 3928 alias whatever = B13204z; 3929 static assert(is(whatever == B13204)); 3930 } 3931 alias B13204x = B13204!1; 3932 alias B13204y = B13204x; 3933 alias B13204z = B13204y; 3934 3935 void test13204() 3936 { 3937 static assert(is(A13204x == A13204!1)); 3938 static assert(is(A13204x == A13204!1.whatever)); 3939 static assert(is(A13204x == A13204y)); 3940 3941 static assert(is(B13204x == B13204!1)); 3942 static assert(is(B13204x == B13204!1.whatever)); 3943 static assert(is(B13204x == B13204y)); 3944 static assert(is(B13204x == B13204z)); 3945 } 3946 3947 /******************************************/ 3948 // 8462 (dup of 13204) 3949 3950 alias FP8462 = void function(C8462.Type arg); 3951 3952 class C8462 3953 { 3954 enum Type { Foo } 3955 alias funcPtrPtr = FP8462*; 3956 } 3957 3958 /******************************************/ 3959 // 13218 3960 3961 template isCallable13218(T...) 3962 if (T.length == 1) 3963 { 3964 static assert(0); 3965 } 3966 3967 template ParameterTypeTuple13218(func...) 3968 if (func.length == 1 && isCallable13218!func) 3969 { 3970 static assert(0); 3971 } 3972 3973 struct R13218 3974 { 3975 private static string mangleFuncPtr(ArgTypes...)() 3976 { 3977 string result = "fnp_"; 3978 foreach (T; ArgTypes) 3979 result ~= T.mangleof; 3980 return result; 3981 } 3982 void function(int) fnp_i; 3983 double delegate(double) fnp_d; 3984 3985 void opAssign(FnT)(FnT func) 3986 { 3987 mixin(mangleFuncPtr!( ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as TypeInstance 3988 //mixin(mangleFuncPtr!(.ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as DotTemplateInstanceExp -> works 3989 } 3990 } 3991 3992 /******************************************/ 3993 // 13219 3994 3995 struct Map13219(V) {} 3996 3997 void test13219a(alias F, VA, VB)(Map13219!VA a, Map13219!VB b) 3998 if (is(VA : typeof(F(VA.init, VB.init)))) 3999 {} 4000 4001 void test13219b(alias F)() 4002 { 4003 test13219a!((a, b) => b)(Map13219!int.init, Map13219!int.init); 4004 } 4005 4006 void test13219() 4007 { 4008 int x; 4009 test13219b!x(); 4010 } 4011 4012 /******************************************/ 4013 // 13223 4014 4015 void test13223() 4016 { 4017 T[] f1(T)(T[] a1, T[] a2) 4018 { 4019 static assert(is(T == int)); 4020 return a1 ~ a2; 4021 } 4022 T[] f2(T)(T[] a1, T[] a2) 4023 { 4024 static assert(is(T == int)); 4025 return a1 ~ a2; 4026 } 4027 int[] a = [1, 2]; 4028 static assert(is(typeof(f1(a, [])) == int[])); 4029 static assert(is(typeof(f2([], a)) == int[])); 4030 static assert(is(typeof(f1(a, null)) == int[])); 4031 static assert(is(typeof(f2(null, a)) == int[])); 4032 4033 T[] f3(T)(T[] a) { return a; } 4034 static assert(is(typeof(f3([])) == void[])); 4035 static assert(is(typeof(f3(null)) == void[])); 4036 4037 T f4(T)(T a) { return a; } 4038 static assert(is(typeof(f4([])) == void[])); 4039 static assert(is(typeof(f4(null)) == typeof(null))); 4040 4041 T[][] f5(T)(T[][] a) { return a; } 4042 static assert(is(typeof(f5([])) == void[][])); 4043 static assert(is(typeof(f5(null)) == void[][])); 4044 4045 void translate(C = immutable char)(const(C)[] toRemove) 4046 { 4047 static assert(is(C == char)); 4048 } 4049 translate(null); 4050 } 4051 4052 void test13223a() 4053 { 4054 T f(T)(T, T) { return T.init; } 4055 4056 immutable i = 0; 4057 const c = 0; 4058 auto m = 0; 4059 shared s = 0; 4060 4061 static assert(is(typeof(f(i, i)) == immutable int)); 4062 static assert(is(typeof(f(i, c)) == const int)); 4063 static assert(is(typeof(f(c, i)) == const int)); 4064 static assert(is(typeof(f(i, m)) == int)); 4065 static assert(is(typeof(f(m, i)) == int)); 4066 static assert(is(typeof(f(c, m)) == int)); 4067 static assert(is(typeof(f(m, c)) == int)); 4068 static assert(is(typeof(f(m, m)) == int)); 4069 static assert(is(typeof(f(i, s)) == shared int)); 4070 static assert(is(typeof(f(s, i)) == shared int)); 4071 static assert(is(typeof(f(c, s)) == shared int)); 4072 static assert(is(typeof(f(s, c)) == shared int)); 4073 static assert(is(typeof(f(s, s)) == shared int)); 4074 static assert(is(typeof(f(s, m)) == int)); 4075 static assert(is(typeof(f(m, s)) == int)); 4076 } 4077 4078 /******************************************/ 4079 // 13235 4080 4081 struct Tuple13235(T...) 4082 { 4083 T expand; 4084 alias expand field; 4085 4086 this(T values) 4087 { 4088 field = values; 4089 } 4090 } 4091 struct Foo13235 4092 { 4093 Tuple13235!(int, Foo13235)* foo; 4094 } 4095 4096 template Inst13235(T...) 4097 { 4098 struct Tuple 4099 { 4100 T expand; 4101 alias expand field; 4102 4103 this(T values) 4104 { 4105 field = values; 4106 } 4107 } 4108 alias Inst13235 = Tuple*; 4109 } 4110 struct Bar13235 4111 { 4112 Inst13235!(int, Bar13235) bar; 4113 } 4114 4115 void test13235() 4116 { 4117 alias Tup1 = Tuple13235!(int, Foo13235); 4118 assert(Tup1(1, Foo13235()).expand[0] == 1); 4119 4120 alias Tup2 = typeof(*Inst13235!(int, Bar13235).init); 4121 assert(Tup2(1, Bar13235()).expand[0] == 1); 4122 } 4123 4124 /******************************************/ 4125 // 13252 4126 4127 alias TypeTuple13252(T...) = T; 4128 4129 static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int )); 4130 static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long)); 4131 4132 static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float )); 4133 static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double)); 4134 4135 static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat )); 4136 static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble)); 4137 4138 static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string )); 4139 static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG 4140 4141 static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring)); 4142 static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring)); 4143 4144 static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] )); 4145 static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG 4146 4147 struct S13252 { } 4148 static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252))); 4149 static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG 4150 4151 /******************************************/ 4152 // 13294 4153 4154 void test13294() 4155 { 4156 void f(T)(const ref T src, ref T dst) 4157 { 4158 pragma(msg, "T = ", T); 4159 static assert(!is(T == const)); 4160 } 4161 { 4162 const byte src; 4163 byte dst; 4164 f(src, dst); 4165 } 4166 { 4167 const char src; 4168 char dst; 4169 f(src, dst); 4170 } 4171 4172 // 13351 4173 T add(T)(in T x, in T y) 4174 { 4175 T z; 4176 z = x + y; 4177 return z; 4178 } 4179 const double a = 1.0; 4180 const double b = 2.0; 4181 double c; 4182 c = add(a,b); 4183 } 4184 4185 /******************************************/ 4186 // 13299 4187 4188 struct Foo13299 4189 { 4190 Foo13299 opDispatch(string name)(int a, int[] b...) 4191 if (name == "bar") 4192 { 4193 return Foo13299(); 4194 } 4195 4196 Foo13299 opDispatch(string name)() 4197 if (name != "bar") 4198 { 4199 return Foo13299(); 4200 } 4201 } 4202 4203 void test13299() 4204 { 4205 Foo13299() 4206 .bar(0) 4207 .bar(1) 4208 .bar(2); 4209 4210 Foo13299() 4211 .opDispatch!"bar"(0) 4212 .opDispatch!"bar"(1) 4213 .opDispatch!"bar"(2); 4214 } 4215 4216 /******************************************/ 4217 // 13333 4218 4219 template AliasThisTypeOf13333(T) 4220 { 4221 static assert(0, T.stringof); // T.stringof is important 4222 } 4223 4224 template StaticArrayTypeOf13333(T) 4225 { 4226 static if (is(AliasThisTypeOf13333!T AT)) 4227 alias X = StaticArrayTypeOf13333!AT; 4228 else 4229 alias X = T; 4230 4231 static if (is(X : E[n], E, size_t n)) 4232 alias StaticArrayTypeOf13333 = X; 4233 else 4234 static assert(0, T.stringof~" is not a static array type"); 4235 } 4236 4237 enum bool isStaticArray13333(T) = is(StaticArrayTypeOf13333!T); 4238 4239 struct VaraiantN13333(T) 4240 { 4241 static if (isStaticArray13333!T) 4242 ~this() { static assert(0); } 4243 } 4244 4245 struct DummyScope13333 4246 { 4247 alias A = VaraiantN13333!C; 4248 4249 static class C 4250 { 4251 A entity; 4252 } 4253 } 4254 4255 void test13333() 4256 { 4257 struct DummyScope 4258 { 4259 alias A = VaraiantN13333!C; 4260 4261 static class C 4262 { 4263 A entity; 4264 } 4265 } 4266 } 4267 4268 /******************************************/ 4269 // 13374 4270 4271 int f13374(alias a)() { return 1; } 4272 int f13374(string s)() { return 2; } 4273 4274 void x13374(int i) {} 4275 4276 void test13374() 4277 { 4278 assert(f13374!x13374() == 1); 4279 } 4280 4281 /******************************************/ 4282 // 14109 4283 4284 string f14109() { return "a"; } 4285 string g14109()() { return "a"; } 4286 4287 struct S14109(string s) { static assert(s == "a"); } 4288 4289 alias X14109 = S14109!(f14109); 4290 alias Y14109 = S14109!(g14109!()); 4291 static assert(is(X14109 == Y14109)); 4292 4293 /******************************************/ 4294 // 13378 4295 4296 struct Vec13378(size_t n, T, string as) 4297 { 4298 T[n] data; 4299 } 4300 4301 void doSome13378(size_t n, T, string as)(Vec13378!(n,T,as) v) {} 4302 4303 void test13378() 4304 { 4305 auto v = Vec13378!(3, float, "xyz")([1,2,3]); 4306 doSome13378(v); 4307 } 4308 4309 /******************************************/ 4310 // 13379 4311 4312 void test13379() 4313 { 4314 match13379(""); 4315 } 4316 4317 auto match13379(RegEx )(RegEx re) 4318 if (is(RegEx == Regex13379!char)) // #1 Regex!char (speculative && tinst == NULL) 4319 {} 4320 auto match13379(String)(String re) 4321 {} 4322 4323 struct Regex13379(Char) 4324 { 4325 ShiftOr13379!Char kickstart; // #2 ShiftOr!char (speculative && tinst == Regex!char) 4326 } 4327 struct ShiftOr13379(Char) 4328 { 4329 this(ref Regex13379!Char re) // #3 Regex!Char (speculative && tinst == ShiftOr!char) 4330 { 4331 uint n_length; 4332 uint idx; 4333 n_length = min13379(idx, n_length); 4334 } 4335 } 4336 4337 template MinType13379(T...) 4338 { 4339 alias MinType13379 = T[0]; 4340 } 4341 MinType13379!T min13379(T...)(T args) // #4 MinType!uint (speculative && thist == ShiftOr!char) 4342 { 4343 alias a = args[0]; 4344 alias b = args[$-1]; 4345 return cast(typeof(return)) (a < b ? a : b); 4346 } 4347 4348 /******************************************/ 4349 // 13417 4350 4351 struct V13417(size_t N, E, alias string AS) 4352 { 4353 } 4354 4355 auto f13417(E)(in V13417!(4, E, "ijka")) 4356 { 4357 return V13417!(3, E, "xyz")(); 4358 } 4359 4360 void test13417() 4361 { 4362 f13417(V13417!(4, float, "ijka")()); 4363 } 4364 4365 /******************************************/ 4366 // 13484 4367 4368 int foo13484()(void delegate() hi) { return 1; } 4369 int foo13484(T)(void delegate(T) hi) { return 2; } 4370 4371 void test13484() 4372 { 4373 assert(foo13484({}) == 1); // works 4374 assert(foo13484((float v){}) == 2); // works <- throws error 4375 } 4376 4377 /******************************************/ 4378 // 13675 4379 4380 enum E13675; 4381 4382 bool foo13675(T : E13675)() 4383 { 4384 return false; 4385 } 4386 4387 void test13675() 4388 { 4389 if (foo13675!E13675) 4390 {} 4391 } 4392 4393 /******************************************/ 4394 // 13694 4395 4396 auto foo13694(T)(string A, T[] G ...) { return 1; } 4397 auto foo13694(T)(string A, long E, T[] G ...) { return 2; } 4398 4399 void test13694() 4400 { 4401 struct S {} 4402 4403 S v; 4404 assert(foo13694("A", v) == 1); // <- OK 4405 assert(foo13694("A", 0, v) == 2); // <- used to be OK but now fails 4406 assert(foo13694!S("A", 0, v) == 2); // <- workaround solution 4407 } 4408 4409 /******************************************/ 4410 // 13760 4411 4412 void test13760() 4413 { 4414 void func(K, V)(inout(V[K]) aa, inout(V) val) {} 4415 4416 class C {} 4417 C[int] aa; 4418 func(aa, new C); 4419 } 4420 4421 /******************************************/ 4422 // 13714 4423 4424 struct JSONValue13714 4425 { 4426 this(T)(T arg) 4427 { 4428 } 4429 this(T : JSONValue13714)(inout T arg) inout 4430 { 4431 //store = arg.store; 4432 } 4433 4434 void opAssign(T)(T arg) 4435 { 4436 } 4437 } 4438 4439 void test13714() 4440 { 4441 enum DummyStringEnum 4442 { 4443 foo = "bar" 4444 } 4445 4446 JSONValue13714[string] aa; 4447 aa["A"] = DummyStringEnum.foo; 4448 } 4449 4450 /******************************************/ 4451 // 13807 4452 4453 T f13807(T)(inout(T)[] arr) 4454 { 4455 return T.init; 4456 } 4457 4458 void test13807() 4459 { 4460 static assert(is(typeof(f13807([1, 2, 3])) == int)); // OK 4461 static assert(is(typeof(f13807(["a", "b"])) == string)); // OK <- Error 4462 static assert(is(typeof(f13807!string(["a", "b"])) == string)); // OK 4463 } 4464 4465 /******************************************/ 4466 // 14174 4467 4468 struct Config14174(a, b) {} 4469 4470 struct N14174 {} 4471 4472 alias defConfig14174 = Config14174!(N14174, N14174); 4473 4474 void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)() 4475 { 4476 static assert(accepter14174a.mangleof 4477 == "_D7breaker131__T14"~ 4478 "accepter14174a"~ 4479 "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ 4480 "accepter14174a"~ 4481 "FZv"); 4482 } 4483 4484 void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)() 4485 { 4486 static assert(accepter14174b.mangleof 4487 == "_D7breaker131__T14"~ 4488 "accepter14174b"~ 4489 "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ 4490 "accepter14174b"~ 4491 "FZv"); 4492 } 4493 4494 void test14174() 4495 { 4496 accepter14174a!()(); // ok 4497 accepter14174b(); // error 4498 } 4499 4500 /******************************************/ 4501 // 14836 4502 4503 template a14836x(alias B, C...) 4504 { 4505 int a14836x(D...)() if (D.length == 0) { return 1; } 4506 int a14836x(D...)(D d) if (D.length > 0) { return 2; } 4507 } 4508 template a14836y(alias B, C...) 4509 { 4510 int a14836y(T, D...)(T t) if (D.length == 0) { return 1; } 4511 int a14836y(T, D...)(T t, D d) if (D.length > 0) { return 2; } 4512 } 4513 4514 void test14836() 4515 { 4516 int v; 4517 assert(a14836x!(v)() == 1); 4518 assert(a14836x!(v)(1) == 2); 4519 assert(a14836y!(v)(1) == 1); 4520 assert(a14836y!(v)(1, 2) == 2); 4521 } 4522 4523 /******************************************/ 4524 // 14357 4525 4526 template Qux14357(T : U*, U : V*, V) 4527 { 4528 pragma(msg, T); // no match <- float** 4529 pragma(msg, U); // no match <- float* 4530 pragma(msg, V); // no match <- int 4531 enum Qux14357 = T.sizeof + V.sizeof; 4532 } 4533 static assert(!__traits(compiles, Qux14357!(float**, int*))); 4534 4535 /******************************************/ 4536 // 14481 4537 4538 template someT14481(alias e) 4539 { 4540 alias someT14481 = e; 4541 } 4542 4543 mixin template Mix14481(alias e) 4544 { 4545 alias SomeAlias = someT14481!e; 4546 } 4547 4548 struct Hoge14481 4549 { 4550 mixin Mix14481!e; 4551 enum e = 10; 4552 } 4553 4554 /******************************************/ 4555 // 14520 4556 4557 template M14520(alias a) { enum M14520 = 1; } 4558 template M14520(string s) { enum M14520 = 2; } 4559 4560 int f14520a(); 4561 string f14520b() { assert(0); } 4562 string f14520c() { return "a"; } 4563 4564 static assert(M14520!f14520a == 1); 4565 static assert(M14520!f14520b == 1); 4566 static assert(M14520!f14520c == 1); 4567 4568 /******************************************/ 4569 // 14568 4570 4571 struct Interval14568() 4572 { 4573 auto left = INVALID; 4574 4575 auto opAssign()(Interval14568) { left; } 4576 } 4577 4578 auto interval14568(T)(T point) 4579 { 4580 Interval14568!(); 4581 } 4582 4583 alias Instantiate14568(alias symbol, Args...) = symbol!Args; 4584 4585 template Match14568(patterns...) 4586 { 4587 static if (__traits(compiles, Instantiate14568!(patterns[0]))) 4588 { 4589 alias Match14568 = patterns[0]; 4590 } 4591 else static if (patterns.length == 1) 4592 {} 4593 } 4594 4595 template SubOps14568(Args...) 4596 { 4597 auto opIndex() 4598 { 4599 template IntervalType(T...) 4600 { 4601 alias Point() = typeof(T.interval14568); 4602 4603 alias IntervalType = Match14568!(Point); 4604 } 4605 alias Subspace = IntervalType!(Args); 4606 } 4607 } 4608 4609 struct Nat14568 { mixin SubOps14568!(null); } 4610 4611 /******************************************/ 4612 // 14603, 14604 4613 4614 struct S14603 4615 { 4616 template opDispatch(string name) 4617 { 4618 void opDispatch()() {} 4619 } 4620 } 4621 alias a14603 = S14603.opDispatch!"go"; // OK 4622 alias b14603 = S14603.go; // OK <- NG 4623 4624 struct S14604 4625 { 4626 template opDispatch(string name) 4627 { 4628 void opDispatch()() {} 4629 } 4630 } 4631 alias Id14604(alias thing) = thing; 4632 alias c14604 = Id14604!(S14604.opDispatch!"go"); // ok 4633 alias d14604 = Id14604!(S14604.go); // issue 14604, 'Error: template instance opDispatch!"go" cannot resolve forward reference' 4634 4635 /******************************************/ 4636 // 14735 4637 4638 enum CS14735 { yes, no } 4639 4640 int indexOf14735a(Range )(Range s, in dchar c) { return 1; } 4641 int indexOf14735a(T, size_t n)(ref T[n] s, in dchar c) { return 2; } 4642 4643 int indexOf14735b(Range )(Range s, in dchar c, in CS14735 cs = CS14735.yes) { return 1; } 4644 int indexOf14735b(T, size_t n)(ref T[n] s, in dchar c, in CS14735 cs = CS14735.yes) { return 2; } 4645 4646 void test14735() 4647 { 4648 char[64] buf; 4649 4650 // Supported from 2.063: (http://dlang.org/changelog#implicitarraycast) 4651 assert(indexOf14735a(buf[0..32], '\0') == 2); 4652 assert(indexOf14735b(buf[0..32], '\0') == 2); 4653 4654 // Have to work as same as above. 4655 assert(indexOf14735a(buf[], '\0') == 2); 4656 assert(indexOf14735b(buf[], '\0') == 2); 4657 } 4658 4659 /******************************************/ 4660 // 14743 4661 4662 class A14743 4663 { 4664 auto func1 = (A14743 a) { a.func2!int(); }; 4665 auto func2(T)() {} 4666 } 4667 4668 /******************************************/ 4669 // 14802 4670 4671 void test14802() 4672 { 4673 auto func(T)(T x, T y) { return x; } 4674 4675 struct S1 { double x; alias x this; } 4676 struct S2 { double x; alias x this; } 4677 S1 s1; 4678 S2 s2; 4679 4680 enum E1 : double { a = 1.0 } 4681 enum E2 : double { a = 1.0 } 4682 4683 static assert(is(typeof( func(1 , 1 ) ) == int)); 4684 static assert(is(typeof( func(1u, 1u) ) == uint)); 4685 static assert(is(typeof( func(1u, 1 ) ) == uint)); 4686 static assert(is(typeof( func(1 , 1u) ) == uint)); 4687 4688 static assert(is(typeof( func(1.0f, 1.0f) ) == float)); 4689 static assert(is(typeof( func(1.0 , 1.0 ) ) == double)); 4690 static assert(is(typeof( func(1.0 , 1.0f) ) == double)); 4691 static assert(is(typeof( func(1.0f, 1.0 ) ) == double)); 4692 4693 static assert(is(typeof( func(s1, s1) ) == S1)); 4694 static assert(is(typeof( func(s2, s2) ) == S2)); 4695 static assert(is(typeof( func(s1, s2) ) == double)); 4696 static assert(is(typeof( func(s2, s1) ) == double)); 4697 4698 static assert(is(typeof( func(E1.a, E1.a) ) == E1)); 4699 static assert(is(typeof( func(E2.a, E2.a) ) == E2)); 4700 static assert(is(typeof( func(E1.a, 1.0) ) == double)); 4701 static assert(is(typeof( func(E2.a, 1.0) ) == double)); 4702 static assert(is(typeof( func(1.0, E1.a) ) == double)); 4703 static assert(is(typeof( func(1.0, E2.a) ) == double)); 4704 static assert(is(typeof( func(E1.a, E2.a) ) == double)); 4705 static assert(is(typeof( func(E2.a, E1.a) ) == double)); 4706 } 4707 4708 /******************************************/ 4709 // 14886 4710 4711 void test14886() 4712 { 4713 alias R = int[100_000]; 4714 4715 auto front(T)(T[] a) {} 4716 front(R.init); 4717 4718 auto bar1(T)(T, T[] a) { return T.init; } 4719 auto bar2(T)(T[] a, T) { return T.init; } 4720 4721 static assert(is(typeof(bar1(1L, R.init)) == long)); 4722 static assert(is(typeof(bar2(R.init, 1L)) == long)); 4723 // <-- T should be deduced to int because R.init is rvalue...? 4724 4725 ubyte x; 4726 static assert(is(typeof(bar1(x, R.init)) == int)); 4727 static assert(is(typeof(bar2(R.init, x)) == int)); 4728 } 4729 4730 /******************************************/ 4731 // 15156 4732 4733 // 15156 4734 auto f15116a(T)(string s, string arg2) { return 1; } 4735 auto f15116b(T)(int i, string arg2) { return 2; } 4736 4737 template bish15116(T) 4738 { 4739 alias bish15116 = f15116a!T; 4740 alias bish15116 = f15116b!T; 4741 } 4742 4743 void test15116() 4744 { 4745 alias func = bish15116!string; 4746 assert(func("", "") == 1); 4747 assert(func(12, "") == 2); 4748 } 4749 4750 /******************************************/ 4751 // 15152 4752 4753 void test15152() 4754 { 4755 void func(string M)() { } 4756 4757 struct S 4758 { 4759 enum name = "a"; 4760 } 4761 4762 enum s = S.init; 4763 func!(s.name); 4764 } 4765 4766 /******************************************/ 4767 // 15352 4768 4769 struct S15352(T, T delegate(uint idx) supplier) 4770 { 4771 } 4772 4773 auto make15352a(T, T delegate(uint idx) supplier)() 4774 { 4775 enum local = supplier; // OK 4776 S15352!(T, local) ret; 4777 return ret; 4778 } 4779 4780 auto make15352b(T, T delegate(uint idx) supplier)() 4781 { 4782 S15352!(T, supplier) ret; // OK <- Error 4783 return ret; 4784 } 4785 4786 void test15352() 4787 { 4788 enum dg = delegate(uint idx) => idx; 4789 auto s1 = S15352!(uint, dg)(); 4790 auto s2 = make15352a!(uint, dg)(); 4791 auto s3 = make15352b!(uint, dg)(); 4792 assert(is(typeof(s1) == typeof(s2))); 4793 assert(is(typeof(s1) == typeof(s3))); 4794 } 4795 4796 /******************************************/ 4797 // 15623 4798 4799 struct WithFoo15623a { void foo() {} } 4800 struct WithFoo15623b { void foo() {} } 4801 struct WithFoo15623c { void foo() {} } 4802 struct WithFoo15623d { void foo() {} } 4803 4804 struct WithoutFoo15623a {} 4805 struct WithoutFoo15623b {} 4806 struct WithoutFoo15623c {} 4807 struct WithoutFoo15623d {} 4808 4809 struct CallsFoo15623(T) 4810 { 4811 T t; 4812 void bar() { t.foo(); } // error occurs during TemplateInstance.semantic3 4813 } 4814 4815 // Instantiations outside of function bodies 4816 static assert( is(CallsFoo15623!WithFoo15623a)); 4817 static assert(!is(CallsFoo15623!WithoutFoo15623a)); // OK <- NG 4818 static assert( __traits(compiles, CallsFoo15623!WithFoo15623b)); 4819 static assert(!__traits(compiles, CallsFoo15623!WithoutFoo15623b)); // OK <- NG 4820 4821 // Instantiations inside function bodies (OK) 4822 static assert( is(typeof({ alias Baz = CallsFoo15623!WithFoo15623c; return Baz.init; }()))); 4823 static assert(!is(typeof({ alias Baz = CallsFoo15623!WithoutFoo15623c; return Baz.init; }()))); 4824 static assert( __traits(compiles, { alias Baz = CallsFoo15623!WithFoo15623d; return Baz.init; }())); 4825 static assert(!__traits(compiles, { alias Baz = CallsFoo15623!WithoutFoo15623d; return Baz.init; }())); 4826 4827 /******************************************/ 4828 // 15781 4829 4830 void test15781() 4831 { 4832 static struct S 4833 { 4834 int value; 4835 } 4836 4837 T foo(T)(T a, T b) 4838 { 4839 return T(); 4840 } 4841 4842 const S cs; 4843 S ms; 4844 static assert(is(typeof(foo(ms, ms)) == S)); 4845 static assert(is(typeof(foo(ms, cs)) == const S)); 4846 static assert(is(typeof(foo(cs, ms)) == const S)); 4847 static assert(is(typeof(foo(cs, cs)) == const S)); 4848 } 4849 4850 /******************************************/ 4851 4852 int main() 4853 { 4854 test1(); 4855 test2(); 4856 test3(); 4857 test4(); 4858 test5(); 4859 test6(); 4860 test7(); 4861 test8(); 4862 test9(); 4863 test1780(); 4864 test3608(); 4865 test5893(); 4866 test6404(); 4867 test2246(); 4868 test2296(); 4869 bug4984(); 4870 test2579(); 4871 test2803(); 4872 test6613(); 4873 test5886(); 4874 test5393(); 4875 test5896(); 4876 test6825(); 4877 test6789(); 4878 test2778(); 4879 test2778aa(); 4880 test2778get(); 4881 test6208a(); 4882 test6208b(); 4883 test6208c(); 4884 test6738(); 4885 test6780(); 4886 test6810(); 4887 test6891(); 4888 test6994(); 4889 test6764(); 4890 test3467(); 4891 test4413(); 4892 test5525(); 4893 test5801(); 4894 test10(); 4895 test7037(); 4896 test7124(); 4897 test7359(); 4898 test7416(); 4899 test7563(); 4900 test7572(); 4901 test7580(); 4902 test7585(); 4903 test7671(); 4904 test7672(); 4905 test7684(); 4906 test11a(); 4907 test11b(); 4908 test7769(); 4909 test7873(); 4910 test7933(); 4911 test8094(); 4912 test12(); 4913 test8125(); 4914 test13(); 4915 test14(); 4916 test8129(); 4917 test8238(); 4918 test8669(); 4919 test8833(); 4920 test8976(); 4921 test8940(); 4922 test9022(); 4923 test9026(); 4924 test9038(); 4925 test9076(); 4926 test9100(); 4927 test9124a(); 4928 test9124b(); 4929 test9143(); 4930 test9266(); 4931 test9536(); 4932 test9578(); 4933 test9596(); 4934 test9837(); 4935 test9874(); 4936 test9885(); 4937 test9971(); 4938 test9977(); 4939 test10083(); 4940 test10592(); 4941 test11242(); 4942 test10811(); 4943 test10969(); 4944 test11271(); 4945 test11533(); 4946 test11818(); 4947 test11843(); 4948 test11872(); 4949 test12122(); 4950 test12207(); 4951 test12376(); 4952 test13235(); 4953 test13294(); 4954 test13299(); 4955 test13374(); 4956 test13378(); 4957 test13379(); 4958 test13484(); 4959 test13694(); 4960 test14836(); 4961 test14735(); 4962 test14802(); 4963 test15116(); 4964 4965 printf("Success\n"); 4966 return 0; 4967 }