1 // RUNNABLE_PHOBOS_TEST
2 // PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g
3 /* TEST_OUTPUT:
4 ---
5 Boo!double
6 Boo!int
7 true
8 int
9 !! immutable(int)[]
10 int(int i, long j = 7L)
11 long
12 C10390(C10390(C10390(<recursion>)))
13 tuple(height)
14 tuple(get, get)
15 tuple(clear)
16 tuple(draw, draw)
17 runnable/xtest46.d(149): Deprecation: `opDot` is deprecated. Use `alias this`
18 runnable/xtest46.d(151): Deprecation: `opDot` is deprecated. Use `alias this`
19 runnable/xtest46.d(152): Deprecation: `opDot` is deprecated. Use `alias this`
20 runnable/xtest46.d(154): Deprecation: `opDot` is deprecated. Use `alias this`
21 runnable/xtest46.d(181): Deprecation: `opDot` is deprecated. Use `alias this`
22 runnable/xtest46.d(183): Deprecation: `opDot` is deprecated. Use `alias this`
23 runnable/xtest46.d(184): Deprecation: `opDot` is deprecated. Use `alias this`
24 runnable/xtest46.d(186): Deprecation: `opDot` is deprecated. Use `alias this`
25 const(int)
26 string[]
27 double[]
28 double[]
29 {}
30 tuple("m")
31 true
32 TFunction1: extern (C) void function()
33 ---
34 */
35 
36 import std.stdio;
37 import core.stdc.stdio;
38 
39 /******************************************/
40 
41 struct S
42 {
opStarS43     int opStar() { return 7; }
44 }
45 
test1()46 void test1()
47 {
48     S s;
49 
50     printf("%d\n", *s);
51     assert(*s == 7);
52 }
53 
54 /******************************************/
55 
test2()56 void test2()
57 {
58   double[1][2] bar;
59   bar[0][0] = 1.0;
60   bar[1][0] = 2.0;
61   foo2(bar);
62 }
63 
foo2(T...)64 void foo2(T...)(T args)
65 {
66     foreach (arg; args[0 .. $])
67     {
68         //writeln(arg);
69         bar2!(typeof(arg))(&arg);
70     }
71 }
72 
73 
bar2(D)74 void bar2(D)(const(void)* arg)
75 {
76     D obj = *cast(D*) arg;
77 }
78 
79 /***************************************************/
80 
test3()81 void test3()
82 {
83     version (unittest)
84     {
85         printf("unittest!\n");
86     }
87     else
88     {
89         printf("no unittest!\n");
90     }
91 
92     version (assert)
93     {
94         printf("assert!\n");
95     }
96     else
97     {
98         printf("no assert!\n");
99     }
100 }
101 
102 
103 /***************************************************/
104 
test4()105 void test4()
106 {
107   immutable int maxi = 8;
108   int[][maxi] neighbors = [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4],
109 [ 2, 3, 5], [ 4, 5, 6 ] ];
110   int[maxi] grid;
111 
112   // neighbors[0].length = 0;
113 
114   void place(int k, uint mask)
115   { if(k<maxi) {
116       for(uint m = 1, d = 1; d <= maxi; d++, m<<=1)
117         if(!(mask & m)) {
118           bool ok = true;
119           int dif;
120           foreach(nb; neighbors[k])
121             if((dif=grid[nb]-d)==1 || dif==-1) {
122               ok = false; break;
123             }
124           if(ok) {
125             grid[k] = d;
126             place(k+1, mask | m);
127           }
128         }
129     } else {
130       printf("  %d\n%d %d %d\n%d %d %d\n  %d\n\n",
131              grid[0], grid[1], grid[2], grid[3], grid[4], grid[5], grid[6], grid[7]);
132     }
133   }
134   place(0, 0);
135 }
136 
137 
138 /***************************************************/
139 
140 struct S5
141 {
142   enum S5 some_constant = {2};
143 
144   int member;
145 }
146 
test5()147 void test5()
148 {
149 }
150 
151 /***************************************************/
152 
153 struct S6
154 {
155     int a, b, c;
156 }
157 
158 struct T6
159 {
160     S6 s;
161     int b = 7;
162 
opDot()163     S6* opDot()
164     {
165         return &s;
166     }
167 }
168 
test6()169 void test6()
170 {
171     T6 t;
172     t.a = 4;
173     t.b = 5;
174     t.c = 6;
175     assert(t.a == 4);
176     assert(t.b == 5);
177     assert(t.c == 6);
178     assert(t.s.b == 0);
179     assert(t.sizeof == 4*4);
180     assert(t.init.sizeof == 4*4);
181 }
182 
183 /***************************************************/
184 
185 struct S7
186 {
187     int a, b, c;
188 }
189 
190 class C7
191 {
192     S7 s;
193     int b = 7;
194 
opDot()195     S7* opDot()
196     {
197         return &s;
198     }
199 }
200 
test7()201 void test7()
202 {
203     C7 t = new C7();
204     t.a = 4;
205     t.b = 5;
206     t.c = 6;
207     assert(t.a == 4);
208     assert(t.b == 5);
209     assert(t.c == 6);
210     assert(t.s.b == 0);
211     assert(t.sizeof == (void*).sizeof);
212     assert(t.init is null);
213 }
214 
215 /***************************************************/
216 
217 void foo8(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)
218 {
219     assert(n1 < n2);
220     printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr);
221 }
222 
test8()223 void test8()
224 {
225     foo8();
226 }
227 
228 /***************************************************/
229 
230 void foo9(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)()
231 {
232     assert(n1 < n2);
233     printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr);
234 }
235 
test9()236 void test9()
237 {
238     foo9();
239 }
240 
241 /***************************************************/
242 
foo10(char c)243 int foo10(char c) pure nothrow
244 {
245     return 1;
246 }
247 
test10()248 void test10()
249 {
250     int function(char c) fp;
251     int function(char c) pure nothrow fq;
252 
253     fp = &foo10;
254     fq = &foo10;
255 }
256 
257 /***************************************************/
258 
259 class Base11 {}
260 class Derived11 : Base11 {}
261 class MoreDerived11 : Derived11 {}
262 
fun11(Base11)263 int fun11(Base11) { return 1; }
fun11(Derived11)264 int fun11(Derived11) { return 2; }
265 
test11()266 void test11()
267 {
268     MoreDerived11 m;
269 
270     auto i = fun11(m);
271     assert(i == 2);
272 }
273 
274 /***************************************************/
275 
276 interface ABC {};
277 interface AB: ABC {};
278 interface BC: ABC {};
279 interface AC: ABC {};
280 interface A: AB, AC {};
281 interface B: AB, BC {};
282 interface C: AC, BC {};
283 
f12(AB ab)284 int f12(AB ab) { return 1; }
f12(ABC abc)285 int f12(ABC abc) { return 2; }
286 
test12()287 void test12()
288 {
289     A a;
290     auto i = f12(a);
291     assert(i == 1);
292 }
293 
294 /***************************************************/
295 
Foo13(alias x)296 template Foo13(alias x)
297 {
298     enum bar = x + 1;
299 }
300 
301 static assert(Foo13!(2+1).bar == 4);
302 
Bar13(alias x)303 template Bar13(alias x)
304 {
305     enum bar = x;
306 }
307 
308 static assert(Bar13!("abc").bar == "abc");
309 
test13()310 void test13()
311 {
312 }
313 
314 /***************************************************/
315 
Foo14(alias a)316 template Foo14(alias a)
317 {
318     alias Bar14!(a) Foo14;
319 }
320 
Bar14(alias a)321 int Bar14(alias a)()
322 {
323     return a.sizeof;
324 }
325 
test14()326 void test14()
327 {
328     auto i = Foo14!("hello")();
329     printf("i = %d\n", i);
330     assert(i == "hello".sizeof);
331     i = Foo14!(1)();
332     printf("i = %d\n", i);
333     assert(i == 4);
334 }
335 
336 /***************************************************/
337 
foo15()338 auto foo15()(int x)
339 {
340     return 3 + x;
341 }
342 
test15()343 void test15()
344 {
345 
346     auto bar()(int x)
347     {
348         return 5 + x;
349     }
350 
351     printf("%d\n", foo15(4));
352     printf("%d\n", bar(4));
353 }
354 
355 /***************************************************/
356 
foo16(int x)357 int foo16(int x) { return 1; }
foo16(ref int x)358 int foo16(ref int x) { return 2; }
359 
test16()360 void test16()
361 {
362     int y;
363     auto i = foo16(y);
364     printf("i == %d\n", i);
365     assert(i == 2);
366     i = foo16(3);
367     assert(i == 1);
368 }
369 
370 /***************************************************/
371 
372 class A17 { }
373 class B17 : A17 { }
374 class C17 : B17 { }
375 
foo17(A17,ref int x)376 int foo17(A17, ref int x) { return 1; }
foo17(B17,ref int x)377 int foo17(B17, ref int x) { return 2; }
378 
test17()379 void test17()
380 {
381     C17 c;
382     int y;
383     auto i = foo17(c, y);
384     printf("i == %d\n", i);
385     assert(i == 2);
386 }
387 
388 /***************************************************/
389 
390 class C18
391 {
foo(int x)392     void foo(int x) { foo("abc"); }
foo(string s)393     void foo(string s) { }  // this is hidden, but that's ok 'cuz no overlap
bar()394     void bar()
395     {
396         foo("abc");
397     }
398 }
399 
400 class D18 : C18
401 {
foo(int x)402     override void foo(int x) { }
403 }
404 
test18()405 void test18()
406 {
407     D18 d = new D18();
408     d.bar();
409 }
410 
411 /***************************************************/
412 
foo19(alias int a)413 int foo19(alias int a)() { return a; }
414 
test19()415 void test19()
416 {
417     int y = 7;
418     auto i = foo19!(y)();
419     printf("i == %d\n", i);
420     assert(i == 7);
421 
422     i = foo19!(4)();
423     printf("i == %d\n", i);
424     assert(i == 4);
425 }
426 
427 /***************************************************/
428 
429 template Foo20(int x) if (x & 1)
430 {
431     const int Foo20 = 6;
432 }
433 
434 template Foo20(int x) if ((x & 1) == 0)
435 {
436     const int Foo20 = 7;
437 }
438 
test20()439 void test20()
440 {
441     int i = Foo20!(3);
442     printf("%d\n", i);
443     assert(i == 6);
444     i = Foo20!(4);
445     printf("%d\n", i);
446     assert(i == 7);
447 }
448 
449 /***************************************************/
450 
451 template isArray21(T : U[], U)
452 {
453   static const isArray21 = 1;
454 }
455 
isArray21(T)456 template isArray21(T)
457 {
458   static const isArray21 = 0;
459 }
460 
461 int foo21(T)(T x) if (isArray21!(T))
462 {
463     return 1;
464 }
465 
466 int foo21(T)(T x) if (!isArray21!(T))
467 {
468     return 2;
469 }
470 
test21()471 void test21()
472 {
473     auto i = foo21(5);
474     assert(i == 2);
475     int[] a;
476     i = foo21(a);
477     assert(i == 1);
478 }
479 
480 /***************************************************/
481 
test22()482 void test22()
483 {
484     immutable uint x, y;
485     foreach (i; x .. y) {}
486 }
487 
488 /***************************************************/
489 
490 const bool foo23 = is(typeof(function void() { }));
491 const bar23      = is(typeof(function void() { }));
492 
test23()493 void test23()
494 {
495     assert(foo23 == true);
496     assert(bar23 == true);
497 }
498 
499 /***************************************************/
500 
foo24(int i)501 ref int foo24(int i)
502 {
503     static int x;
504     x = i;
505     return x;
506 }
507 
test24()508 void test24()
509 {
510     int x = foo24(3);
511     assert(x == 3);
512 }
513 
514 /***************************************************/
515 
foo25(int i)516 ref int foo25(int i)
517 {
518     static int x;
519     x = i;
520     return x;
521 }
522 
bar25(ref int x)523 int bar25(ref int x)
524 {
525     return x + 1;
526 }
527 
test25()528 void test25()
529 {
530     int x = bar25(foo25(3));
531     assert(x == 4);
532 }
533 
534 /***************************************************/
535 
536 static int x26;
537 
foo26(int i)538 ref int foo26(int i)
539 {
540     x26 = i;
541     return x26;
542 }
543 
test26()544 void test26()
545 {
546     int* p = &foo26(3);
547     assert(*p == 3);
548 }
549 
550 /***************************************************/
551 
552 static int x27 = 3;
553 
foo27(int i)554 ref int foo27(int i)
555 {
556     return x27;
557 }
558 
test27()559 void test27()
560 {
561     foo27(3) = 4;
562     assert(x27 == 4);
563 }
564 
565 /***************************************************/
566 
foo28(ref int x)567 ref int foo28(ref int x) { return x; }
568 
test28()569 void test28()
570 {
571     int a;
572     foo28(a);
573 }
574 
575 /***************************************************/
576 
wyda(int[]a)577 void wyda(int[] a) { printf("aaa\n"); }
wyda(int[int]a)578 void wyda(int[int] a) { printf("bbb\n"); }
579 
580 struct S29
581 {
582     int[] a;
583 
wydaS29584     void wyda()
585     {
586         a.wyda;
587         a.wyda();
588     }
589 }
590 
test29()591 void test29()
592 {
593     int[] a;
594     a.wyda;
595     int[5] b;
596     b.wyda;
597     int[int] c;
598     c.wyda;
599 
600     S29 s;
601     s.wyda();
602 }
603 
604 /***************************************************/
605 
606 void foo30(D)(D arg) if (isIntegral!D)
607 {
608 }
609 
S30(T)610 struct S30(T) { }
U30(int T)611 struct U30(int T) { }
612 
613 alias int myint30;
614 
test30()615 void test30()
616 {
617 
618     S30!myint30 u;
619     S30!int s;
620     S30!(int) t = s;
621 
622 //    U30!3 v = s;
623 }
624 
625 /***************************************************/
626 
627 class A31
628 {
foo(int * p)629     void foo(int* p) { }
630 }
631 
632 class B31 : A31
633 {
foo(scope int * p)634     override void foo(scope int* p) { }
635 }
636 
test31()637 void test31()
638 {
639 }
640 
641 /***************************************************/
642 
bar32()643 void bar32() { }
644 
foo32(int * p)645 nothrow void foo32(int* p)
646 {
647     //try { bar32(); } catch (Object o) { }
648     try { bar32(); } catch (Throwable o) { }
649     try { bar32(); } catch (Exception o) { }
650 }
651 
test32()652 void test32()
653 {   int i;
654 
655     foo32(&i);
656 }
657 
658 /***************************************************/
659 
660 struct Integer
661 {
thisInteger662     this(int i)
663     {
664         this.i = i;
665     }
666 
thisInteger667     this(long ii)
668     {
669       i = 3;
670     }
671 
672     const int i;
673 }
674 
test33()675 void test33()
676 {
677 }
678 
679 /***************************************************/
680 
test34()681 void test34()
682 {
683   alias uint Uint;
684   foreach(Uint u;1..10) {}
685   for(Uint u=1;u<10;u++) {}
686 }
687 
688 /***************************************************/
689 
foo35(bool condition,ref int lhs,ref int rhs)690 ref int foo35(bool condition, ref int lhs, ref int rhs)
691 {
692         if ( condition ) return lhs;
693         return rhs;
694 }
695 
bar35()696 ref int bar35()(bool condition, ref int lhs, ref int rhs)
697 {
698         if ( condition ) return lhs;
699         return rhs;
700 }
701 
test35()702 void test35()
703 {
704         int a = 10, b = 11;
705 
706         foo35(a<b, a, b) = 42;
707         printf("a = %d and b = %d\n", a, b); // a = 42 and b = 11
708         assert(a == 42 && b == 11);
709 
710         bar35(a<b, a, b) = 52;
711         printf("a = %d and b = %d\n", a, b);
712         assert(a == 42 && b == 52);
713 }
714 
715 /***************************************************/
716 
717 int foo36(T...)(T ts)
718 if (T.length > 1)
719 {
720     return T.length;
721 }
722 
723 int foo36(T...)(T ts)
724 if (T.length <= 1)
725 {
726     return T.length * 7;
727 }
728 
test36()729 void test36()
730 {
731     auto i = foo36!(int,int)(1, 2);
732     assert(i == 2);
733     i = foo36(1, 2, 3);
734     assert(i == 3);
735     i = foo36(1);
736     assert(i == 7);
737     i = foo36();
738     assert(i == 0);
739 }
740 
741 
742 /***************************************************/
743 
test6685()744 void test6685()
745 {
746     struct S { int x; }
747     with({ return S(); }())
748     {
749         x++;
750     }
751 }
752 
753 /***************************************************/
754 
A37(alias T)755 struct A37(alias T)
756 {
757 }
758 
759 void foo37(X)(X x) if (is(X Y == A37!(U), alias U))
760 {
761 }
762 
bar37()763 void bar37() {}
764 
test37()765 void test37()
766 {
767     A37!(bar37) a2;
768     foo37(a2);
769     foo37!(A37!bar37)(a2);
770 }
771 
772 /***************************************************/
773 
774 struct A38
775 {
thisA38776     this(this)
777     {
778         printf("B's copy\n");
779     }
emptyA38780     bool empty() {return false;}
popFrontA38781     void popFront() {}
frontA38782     int front() { return 1; }
783 //    ref A38 opSlice() { return this; }
784 }
785 
test38()786 void test38()
787 {
788     A38 a;
789     int i;
790     foreach (e; a) { if (++i == 100) break; }
791 }
792 
793 /***************************************************/
794 
795 alias int function() Fun39;
796 alias ref int function() Gun39;
797 static assert(!is(Fun39 == Gun39));
798 
test39()799 void test39()
800 {
801 }
802 
803 /***************************************************/
804 
805 int x40;
806 
807 struct Proxy
808 {
atProxy809     ref int at(int i)() { return x40; }
810 }
811 
test40()812 void test40()
813 {
814     Proxy p;
815     auto x = p.at!(1);
816 }
817 
818 /***************************************************/
819 
Foo41(TList...)820 template Foo41(TList...)
821 {
822     alias TList Foo41;
823 }
824 
825 alias Foo41!(immutable(ubyte)[], ubyte[]) X41;
826 
test41()827 void test41()
828 {
829 }
830 
831 
832 /***************************************************/
833 
endsWith(A1,A2)834 bool endsWith(A1, A2)(A1 longer, A2 shorter)
835 {
836     static if (is(typeof(longer[0 .. 0] == shorter)))
837     {
838     }
839     else
840     {
841     }
842     return false;
843 }
844 
test42()845 void test42()
846 {
847     char[] a;
848     byte[] b;
849     endsWith(a, b);
850 }
851 
852 /***************************************************/
853 
854 void f43(S...)(S s) if (S.length > 3)
855 {
856 }
857 
test43()858 void test43()
859 {
860     f43(1, 2, 3, 4);
861 }
862 
863 
864 /***************************************************/
865 
866 struct S44(int x = 1){}
867 
fun()868 void fun()(S44!(1) b) { }
869 
test44()870 void test44()
871 {
872     S44!() s;
873     fun(s);
874 }
875 
876 /***************************************************/
877 // 2006
878 
test2006()879 void test2006()
880 {
881     string [][] aas = [];
882     assert(aas.length == 0);
883     aas ~= cast (string []) [];
884     assert(aas.length == 1);
885     aas = aas ~ cast (string []) [];
886     assert(aas.length == 2);
887 }
888 
889 /***************************************************/
890 // 8442
891 
test8442()892 void test8442()
893 {
894     enum int[] fooEnum = [];
895     immutable fooImmutable = fooEnum;
896 }
897 
898 /***************************************************/
899 
900 class A45
901 {
902   int x;
f()903   int f()
904   {
905     printf("A\n");
906     return 1;
907   }
908 }
909 
910 class B45 : A45
911 {
f()912   override const int f()
913   {
914     printf("B\n");
915     return 2;
916   }
917 }
918 
test45()919 void test45()
920 {
921     A45 y = new B45;
922     int i = y.f;
923     assert(i == 2);
924 }
925 
926 /***************************************************/
927 
text10682()928 void text10682()
929 {
930     ulong x = 1;
931     ulong y = 2 ^^ x;
932 }
933 
934 /***************************************************/
935 
936 struct Test46
937 {
938  int foo;
939 }
940 
test46()941 void test46()
942 {
943     enum Test46 test = {};
944     enum q = test.foo;
945 }
946 
947 /***************************************************/
948 
double_sqr(int x)949 pure int double_sqr(int x) {
950     int y = x;
951     void do_sqr() { y *= y; }
952     do_sqr();
953     return y;
954 }
955 
test47()956 void test47()
957 {
958    assert(double_sqr(10) == 100);
959 }
960 
961 /***************************************************/
962 
sort(alias less)963 void sort(alias less)(string[] r)
964 {
965             bool pred()
966             {
967                 return less("a", "a");
968             }
969             .sort!(less)(r);
970 }
971 
foo48()972 void foo48()
973 {
974     int[string] freqs;
975     string[] words;
976 
977 sort!((a, b) { return freqs[a] > freqs[b]; })(words);
978 sort!((string a, string b) { return freqs[a] > freqs[b]; })(words);
979 //sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words);
980 //sort!(function (a, b) { return freqs[a] > freqs[b]; })(words);
981 //sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words);
982 sort!(delegate bool(string a, string b) { return freqs[a] > freqs[b]; })(words);
983 
984 }
985 
test48()986 void test48()
987 {
988 }
989 
990 /***************************************************/
991 // 6408
992 
993 static assert(!is(typeof(string[0..1].init)));
994 static assert(is(typeof(string[].init) == string[]));
995 static assert(is(typeof(string[][].init) == string[][]));
996 static assert(is(typeof(string[][][].init) == string[][][]));
997 
998 static assert(is(typeof(string[1].init) == string[1]));
999 static assert(is(typeof(string[1][1].init) == string[1][1]));
1000 static assert(is(typeof(string[1][1][1].init) == string[1][1][1]));
1001 
1002 static assert(is(typeof(string[string].init) == string[string]));
1003 static assert(is(typeof(string[string][string].init) == string[string][string]));
1004 static assert(is(typeof(string[string][string][string].init) == string[string][string][string]));
1005 
TT6408(T...)1006 template TT6408(T...) { alias T TT6408; }
1007 static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int)));
1008 static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int)));
1009 static assert(is(typeof(TT6408!(int, int)[$-1].init) == int));
1010 
1011 /***************************************************/
1012 // 9409
1013 
TT9409(T...)1014 template TT9409(T...) { alias T TT9409; }
1015 
idxTypes9409(Prefix...)1016 template idxTypes9409(Prefix...)
1017 {
1018     TT9409!((Prefix[$-1])) idxTypes9409;
1019 }
1020 
1021 alias idxTypes9409!(int) Types9409;
1022 
1023 /***************************************************/
1024 
1025 struct S49
1026 {
1027     static void* p;
1028 
thisS491029     this( string name )
1030     {
1031         printf( "(ctor) &%.*s.x = %p\n", name.length, name.ptr, &x );
1032         p = cast(void*)&x;
1033     }
1034 
invariantS491035     invariant() {}
1036 
1037     int x;
1038 }
1039 
test49()1040 void test49()
1041 {
1042     auto s = new S49("s2");
1043 
1044     printf( "&s2.x = %p\n", &s.x );
1045     assert(cast(void*)&s.x == S49.p);
1046 }
1047 
1048 /***************************************************/
1049 
1050 auto max50(Ts...)(Ts args)
1051   if (Ts.length >= 2
1052         && is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init)))
1053 {
1054     static if (Ts.length == 2)
1055         return args[1] > args[0] ? args[1] : args[0];
1056     else
1057         return max50(max50(args[0], args[1]), args[2 .. $]);
1058 }
1059 
test50()1060 void test50()
1061 {
1062    assert(max50(4, 5) == 5);
1063    assert(max50(2.2, 4.5) == 4.5);
1064    assert(max50("Little", "Big") == "Little");
1065 
1066    assert(max50(4, 5.5) == 5.5);
1067    assert(max50(5.5, 4) == 5.5);
1068 }
1069 
1070 /***************************************************/
1071 
test51()1072 void test51()
1073 {
1074     static immutable int[2] array = [ 42 ];
1075     enum e = array[1];
1076     static immutable int[1] array2 = [ 0: 42 ];
1077     enum e2 = array2[0];
1078     assert(e == 0);
1079     assert(e2 == 42);
1080 }
1081 
1082 /***************************************************/
1083 
1084 enum ubyte[4] a52 = [5,6,7,8];
1085 
test52()1086 void test52()
1087 {
1088   int x=3;
1089   assert(a52[x]==8);
1090 }
1091 
1092 /***************************************************/
1093 
test53()1094 void test53()
1095 {
1096     size_t func2(immutable(void)[] t)
1097     {
1098         return 0;
1099     }
1100 }
1101 
1102 /***************************************************/
1103 
foo54(void delegate (void[])dg)1104 void foo54(void delegate(void[]) dg) { }
1105 
test54()1106 void test54()
1107 {
1108     void func(void[] t) pure { }
1109     foo54(&func);
1110 
1111 //    void func2(const(void)[] t) { }
1112 //    foo54(&func2);
1113 }
1114 
1115 /***************************************************/
1116 
1117 class Foo55
1118 {
noop1()1119     synchronized void noop1() { }
noop2()1120     void noop2() shared { }
1121 }
1122 
test55()1123 void test55()
1124 {
1125     auto foo = new shared(Foo55);
1126     foo.noop1();
1127     foo.noop2();
1128 }
1129 
1130 /***************************************************/
1131 
1132 enum float one56 = 1 * 1;
X56(float E)1133 template X56(float E) { int X56 = 2; }
1134 alias X56!(one56 * one56) Y56;
1135 
test56()1136 void test56()
1137 {
1138     assert(Y56 == 2);
1139 }
1140 
1141 /***************************************************/
1142 
test57()1143 void test57()
1144 {
1145     alias shared(int) T;
1146     assert (is(T == shared));
1147 }
1148 
1149 /***************************************************/
1150 
1151 struct A58
1152 {
1153   int a,b;
1154 }
1155 
test58()1156 void test58()
1157 {
1158   A58[2] rg=[{1,2},{5,6}];
1159   assert(rg[0].a == 1);
1160   assert(rg[0].b == 2);
1161   assert(rg[1].a == 5);
1162   assert(rg[1].b == 6);
1163 }
1164 
1165 /***************************************************/
1166 
1167 class A59 {
foo(int i)1168     const foo(int i)  { return i; }
1169 }
1170 
1171 /***************************************************/
1172 
test60()1173 void test60()
1174 {
1175     enum real ONE = 1.0;
1176     real x;
1177     for (x=0.0; x<10.0; x+=ONE)
1178         printf("%Lg\n", x);
1179     printf("%Lg\n", x);
1180     assert(x == 10);
1181 }
1182 
1183 /***************************************************/
1184 
immutable(T)1185 pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){
1186 
1187   immutable(T)[] fooState;
1188 
1189   immutable(T)[] bar(immutable(T)[] x){
1190     fooState = "hello ";
1191     return x ~ y;
1192   }
1193 
1194   return fooState ~ bar(x);
1195 
1196 }
1197 
1198 
test61()1199 void test61()
1200 {
1201   writeln(fooPT("p", "c"));
1202 }
1203 
1204 /***************************************************/
1205 
test9577()1206 void test9577()
1207 {
1208     static int function(int)[] foo = [x => x];
1209     foo[0](0);
1210 }
1211 
1212 /***************************************************/
1213 
foo62(int[3]a)1214 int[3] foo62(int[3] a)
1215 {
1216     a[1]++;
1217     return a;
1218 }
1219 
test62()1220 void test62()
1221 {
1222     int[3] b;
1223     b[0] = 1;
1224     b[1] = 2;
1225     b[2] = 3;
1226     auto c = foo62(b);
1227     assert(b[0] == 1);
1228     assert(b[1] == 2);
1229     assert(b[2] == 3);
1230 
1231     assert(c[0] == 1);
1232     assert(c[1] == 3);
1233     assert(c[2] == 3);
1234 }
1235 
1236 /***************************************************/
1237 
test3927()1238 void test3927()
1239 {
1240     int[] array;
1241     assert(array.length++ == 0);
1242     assert(array.length == 1);
1243     assert(array.length-- == 1);
1244     assert(array.length == 0);
1245 }
1246 
1247 /***************************************************/
1248 
test63()1249 void test63()
1250 {
1251     int[3] b;
1252     b[0] = 1;
1253     b[1] = 2;
1254     b[2] = 3;
1255     auto c = b;
1256     b[1]++;
1257     assert(b[0] == 1);
1258     assert(b[1] == 3);
1259     assert(b[2] == 3);
1260 
1261     assert(c[0] == 1);
1262     assert(c[1] == 2);
1263     assert(c[2] == 3);
1264 }
1265 
1266 /***************************************************/
1267 
test64()1268 void test64()
1269 {
1270     int[3] b;
1271     b[0] = 1;
1272     b[1] = 2;
1273     b[2] = 3;
1274     int[3] c;
1275     c = b;
1276     b[1]++;
1277     assert(b[0] == 1);
1278     assert(b[1] == 3);
1279     assert(b[2] == 3);
1280 
1281     assert(c[0] == 1);
1282     assert(c[1] == 2);
1283     assert(c[2] == 3);
1284 }
1285 
1286 /***************************************************/
1287 
foo65(int[2]a)1288 int[2] foo65(int[2] a)
1289 {
1290     a[1]++;
1291     return a;
1292 }
1293 
test65()1294 void test65()
1295 {
1296     int[2] b;
1297     b[0] = 1;
1298     b[1] = 2;
1299     int[2] c = foo65(b);
1300     assert(b[0] == 1);
1301     assert(b[1] == 2);
1302 
1303     assert(c[0] == 1);
1304     assert(c[1] == 3);
1305 }
1306 
1307 /***************************************************/
1308 
foo66(int[1]a)1309 int[1] foo66(int[1] a)
1310 {
1311     a[0]++;
1312     return a;
1313 }
1314 
test66()1315 void test66()
1316 {
1317     int[1] b;
1318     b[0] = 1;
1319     int[1] c = foo66(b);
1320     assert(b[0] == 1);
1321     assert(c[0] == 2);
1322 }
1323 
1324 /***************************************************/
1325 
foo67(out int[2]a)1326 int[2] foo67(out int[2] a)
1327 {
1328     a[0] = 5;
1329     a[1] = 6;
1330     return a;
1331 }
1332 
test67()1333 void test67()
1334 {
1335     int[2] b;
1336     b[0] = 1;
1337     b[1] = 2;
1338     int[2] c = foo67(b);
1339     assert(b[0] == 5);
1340     assert(b[1] == 6);
1341 
1342     assert(c[0] == 5);
1343     assert(c[1] == 6);
1344 }
1345 
1346 /***************************************************/
1347 
test68()1348 void test68()
1349 {
1350     digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b");
1351 }
1352 
digestToString(const ubyte[16]digest)1353 void digestToString(const ubyte[16] digest)
1354 {
1355     assert(digest[0] == 0xc3);
1356     assert(digest[15] == 0x3b);
1357 }
1358 
1359 /***************************************************/
1360 
test69()1361 void test69()
1362 {
1363     digestToString69(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b");
1364 }
1365 
digestToString69(ref const ubyte[16]digest)1366 void digestToString69(ref const ubyte[16] digest)
1367 {
1368     assert(digest[0] == 0xc3);
1369     assert(digest[15] == 0x3b);
1370 }
1371 
1372 /***************************************************/
1373 
test70()1374 void test70()
1375 {
1376     digestToString70("1234567890123456");
1377 }
1378 
digestToString70(ref const char[16]digest)1379 void digestToString70(ref const char[16] digest)
1380 {
1381     assert(digest[0] == '1');
1382     assert(digest[15] == '6');
1383 }
1384 
1385 /***************************************************/
1386 
foo71(out shared int o)1387 void foo71(out shared int o) {}
1388 
1389 /***************************************************/
1390 
1391 struct foo72
1392 {
barfoo721393   int bar() shared { return 1; }
1394 }
1395 
test72()1396 void test72()
1397 {
1398   shared foo72 f;
1399   auto x = f.bar;
1400 }
1401 
1402 /***************************************************/
1403 
1404 class Foo73
1405 {
1406   static if (is(typeof(this) T : shared T))
1407     static assert(0);
1408   static if (is(typeof(this) U == shared U))
1409     static assert(0);
1410   static if (is(typeof(this) U == const U))
1411     static assert(0);
1412   static if (is(typeof(this) U == immutable U))
1413     static assert(0);
1414   static if (is(typeof(this) U == const shared U))
1415     static assert(0);
1416 
1417   static assert(!is(int == const));
1418   static assert(!is(int == immutable));
1419   static assert(!is(int == shared));
1420 
1421   static assert(is(int == int));
1422   static assert(is(const(int) == const));
1423   static assert(is(immutable(int) == immutable));
1424   static assert(is(shared(int) == shared));
1425   static assert(is(const(shared(int)) == shared));
1426   static assert(is(const(shared(int)) == const));
1427 
1428   static assert(!is(const(shared(int)) == immutable));
1429   static assert(!is(const(int) == immutable));
1430   static assert(!is(const(int) == shared));
1431   static assert(!is(shared(int) == const));
1432   static assert(!is(shared(int) == immutable));
1433   static assert(!is(immutable(int) == const));
1434   static assert(!is(immutable(int) == shared));
1435 }
1436 
1437 template Bar(T : T)
1438 {
1439     alias T Bar;
1440 }
1441 
1442 template Barc(T : const(T))
1443 {
1444     alias T Barc;
1445 }
1446 
1447 template Bari(T : immutable(T))
1448 {
1449     alias T Bari;
1450 }
1451 
1452 template Bars(T : shared(T))
1453 {
1454     alias T Bars;
1455 }
1456 
1457 template Barsc(T : shared(const(T)))
1458 {
1459     alias T Barsc;
1460 }
1461 
1462 
test73()1463 void test73()
1464 {
1465     auto f = new Foo73;
1466 
1467     alias int T;
1468 
1469     // 5*5 == 25 combinations, plus 2 for swapping const and shared
1470 
1471     static assert(is(Bar!(T) == T));
1472     static assert(is(Bar!(const(T)) == const(T)));
1473     static assert(is(Bar!(immutable(T)) == immutable(T)));
1474     static assert(is(Bar!(shared(T)) == shared(T)));
1475     static assert(is(Bar!(shared(const(T))) == shared(const(T))));
1476 
1477     static assert(is(Barc!(const(T)) == T));
1478     static assert(is(Bari!(immutable(T)) == T));
1479     static assert(is(Bars!(shared(T)) == T));
1480     static assert(is(Barsc!(shared(const(T))) == T));
1481 
1482     static assert(is(Barc!(T) == T));
1483     static assert(is(Barc!(immutable(T)) == T));
1484     static assert(is(Barc!(const(shared(T))) == shared(T)));
1485     static assert(is(Barsc!(immutable(T)) == T));
1486 
1487     static assert(is(Bars!(const(shared(T))) == const(T)));
1488     static assert(is(Barsc!(shared(T)) == T));
1489 
1490     Bars!(shared(const(T))) b;
1491     pragma(msg, typeof(b));
1492 
1493     static assert(is(Bars!(shared(const(T))) == const(T)));
1494     static assert(is(Barc!(shared(const(T))) == shared(T)));
1495 
1496     static assert(!is(Bari!(T)));
1497     static assert(!is(Bari!(const(T))));
1498     static assert(!is(Bari!(shared(T))));
1499     static assert(!is(Bari!(const(shared(T)))));
1500 
1501     static assert(is(Barc!(shared(T))));
1502 
1503     static assert(!is(Bars!(T)));
1504     static assert(!is(Bars!(const(T))));
1505     static assert(!is(Bars!(immutable(T))));
1506     static assert(!is(Barsc!(T)));
1507     static assert(!is(Barsc!(const(T))));
1508 }
1509 
1510 /***************************************************/
1511 
1512 pure nothrow {
1513   alias void function(int) A74;
1514 }
1515 
1516 alias void function(int) pure nothrow B74;
1517 alias pure nothrow void function(int) C74;
1518 
test74()1519 void test74()
1520 {
1521     A74 a = null;
1522     B74 b = null;
1523     C74 c = null;
1524     a = b;
1525     a = c;
1526 }
1527 
1528 /***************************************************/
1529 
test9212()1530 void test9212()
1531 {
1532     int[int] aa;
1533     foreach (const key, const val; aa) {}
1534     foreach (size_t key, size_t val; aa) {}
1535 }
1536 
1537 /***************************************************/
1538 
1539 class A75
1540 {
raise(string s)1541     pure static void raise(string s)
1542     {
1543         throw new Exception(s);
1544     }
1545 }
1546 
test75()1547 void test75()
1548 {   int x = 0;
1549     try
1550     {
1551         A75.raise("a");
1552     } catch (Exception e)
1553     {
1554         x = 1;
1555     }
1556     assert(x == 1);
1557 }
1558 
1559 /***************************************************/
1560 
test76()1561 void test76()
1562 {
1563     int x, y;
1564     bool which;
1565     (which ? x : y) += 5;
1566     assert(y == 5);
1567 }
1568 
1569 /***************************************************/
1570 
test77()1571 void test77()
1572 {
1573     auto a = ["hello", "world"];
1574     pragma(msg, typeof(a));
1575     auto b = a;
1576     assert(a is b);
1577     assert(a == b);
1578     b = a.dup;
1579     assert(a == b);
1580     assert(a !is b);
1581 }
1582 
1583 /***************************************************/
1584 
test78()1585 void test78()
1586 {
1587     auto array = [0, 2, 4, 6, 8, 10];
1588     array = array[0 .. $ - 2];         // Right-shrink by two elements
1589     assert(array == [0, 2, 4, 6]);
1590     array = array[1 .. $];             // Left-shrink by one element
1591     assert(array == [2, 4, 6]);
1592     array = array[1 .. $ - 1];         // Shrink from both sides
1593     assert(array == [4]);
1594 }
1595 
1596 /***************************************************/
1597 
test79()1598 void test79()
1599 {
1600     auto a = [87, 40, 10];
1601     a ~= 42;
1602     assert(a == [87, 40, 10, 42]);
1603     a ~= [5, 17];
1604     assert(a == [87, 40, 10, 42, 5, 17]);
1605 }
1606 
1607 /***************************************************/
1608 
test6317()1609 void test6317()
1610 {
1611     int b = 12345;
1612     struct nested { int a; int fun() { return b; } }
1613     static assert(!__traits(compiles, { nested x = { 3, null }; }));
1614     nested g = { 7 };
1615     auto h = nested(7);
1616     assert(g.fun() == 12345);
1617     assert(h.fun() == 12345);
1618 }
1619 
1620 /***************************************************/
1621 
test80()1622 void test80()
1623 {
1624     auto array = new int[10];
1625     array.length += 1000;
1626     assert(array.length == 1010);
1627     array.length /= 10;
1628     assert(array.length == 101);
1629     array.length -= 1;
1630     assert(array.length == 100);
1631     array.length |= 1;
1632     assert(array.length == 101);
1633     array.length ^= 3;
1634     assert(array.length == 102);
1635     array.length &= 2;
1636     assert(array.length == 2);
1637     array.length *= 2;
1638     assert(array.length == 4);
1639     array.length <<= 1;
1640     assert(array.length == 8);
1641     array.length >>= 1;
1642     assert(array.length == 4);
1643     array.length >>>= 1;
1644     assert(array.length == 2);
1645     array.length %= 2;
1646     assert(array.length == 0);
1647 
1648     int[]* foo()
1649     {
1650         static int x;
1651         x++;
1652         assert(x == 1);
1653         auto p = &array;
1654         return p;
1655     }
1656 
1657     (*foo()).length += 2;
1658     assert(array.length == 2);
1659 }
1660 
1661 /***************************************************/
1662 
test81()1663 void test81()
1664 {
1665     int[3] a = [1, 2, 3];
1666     int[3] b = a;
1667     a[1] = 42;
1668     assert(b[1] == 2); // b is an independent copy of a
1669     int[3] fun(int[3] x, int[3] y) {
1670        // x and y are copies of the arguments
1671        x[0] = y[0] = 100;
1672        return x;
1673     }
1674     auto c = fun(a, b);         // c has type int[3]
1675     assert(c == [100, 42, 3]);
1676     assert(b == [1, 2, 3]);     // b is unaffected by fun
1677 }
1678 
1679 /***************************************************/
1680 
test82()1681 void test82()
1682 {
1683     auto a1 = [ "Jane":10.0, "Jack":20, "Bob":15 ];
1684     auto a2 = a1;                    // a1 and a2 refer to the same data
1685     a1["Bob"] = 100;                 // Changing a1
1686     assert(a2["Bob"] == 100);        //is same as changing a2
1687     a2["Sam"] = 3.5;                 //and vice
1688     assert(a2["Sam"] == 3.5);        //    versa
1689 }
1690 
1691 /***************************************************/
1692 
test7942()1693 void test7942()
1694 {
1695     string a = "a";
1696     wstring b = "b";
1697     dstring c = "c";
1698 
1699     a ~= "a"c;
1700     static assert(!is(typeof(a ~= "b"w)));
1701     static assert(!is(typeof(a ~= "c"d)));
1702     static assert(!is(typeof(b ~= "a"c)));
1703     b ~= "b"w;
1704     static assert(!is(typeof(b ~= "c"d)));
1705     static assert(!is(typeof(c ~= "a"c)));
1706     static assert(!is(typeof(c ~= "b"w)));
1707     c ~= "c"d;
1708 
1709     assert(a == "aa");
1710     assert(b == "bb");
1711     assert(c == "cc");
1712 }
1713 
1714 /***************************************************/
1715 
bump(ref int x)1716 void bump(ref int x) { ++x; }
1717 
test83()1718 void test83()
1719 {
1720    int x = 1;
1721    bump(x);
1722    assert(x == 2);
1723 }
1724 
1725 /***************************************************/
1726 
1727 interface Test4174
1728 {
func(T)1729     void func(T)() {}
1730 }
1731 
1732 /***************************************************/
1733 
1734 auto foo84 = [1, 2.4];
1735 
test84()1736 void test84()
1737 {
1738     pragma(msg, typeof([1, 2.4]));
1739     static assert(is(typeof([1, 2.4]) == double[]));
1740 
1741     pragma(msg, typeof(foo84));
1742     static assert(is(typeof(foo84) == double[]));
1743 }
1744 
1745 /***************************************************/
1746 
test85()1747 void test85()
1748 {
1749     dstring c = "V\u00E4rld";
1750     c = c ~ '!';
1751     assert(c == "V\u00E4rld!");
1752     c = '@' ~ c;
1753     assert(c == "@V\u00E4rld!");
1754 
1755     wstring w = "V\u00E4rld";
1756     w = w ~ '!';
1757     assert(w == "V\u00E4rld!");
1758     w = '@' ~ w;
1759     assert(w == "@V\u00E4rld!");
1760 
1761     string s = "V\u00E4rld";
1762     s = s ~ '!';
1763     assert(s == "V\u00E4rld!");
1764     s = '@' ~ s;
1765     assert(s == "@V\u00E4rld!");
1766 }
1767 
1768 /***************************************************/
1769 
test86()1770 void test86()
1771 {
1772     int[][] a = [ [1], [2,3], [4] ];
1773     int[][] w = [ [1, 2], [3], [4, 5], [] ];
1774     int[][] x = [ [], [1, 2], [3], [4, 5], [] ];
1775 }
1776 
1777 /***************************************************/
1778 
1779 // Bugzilla 3379
1780 
1781 T1[] find(T1, T2)(T1[] longer, T2[] shorter)
1782    if (is(typeof(longer[0 .. 1] == shorter) : bool))
1783 {
1784    while (longer.length >= shorter.length) {
1785       if (longer[0 .. shorter.length] == shorter) break;
1786       longer = longer[1 .. $];
1787    }
1788    return longer;
1789 }
1790 
1791 auto max(T...)(T a)
1792       if (T.length == 2
1793          && is(typeof(a[1] > a[0] ? a[1] : a[0]))
1794        || T.length > 2
1795          && is(typeof(max(max(a[0], a[1]), a[2 .. $])))) {
1796    static if (T.length == 2) {
1797       return a[1] > a[0] ? a[1] : a[0];
1798    } else {
1799       return max(max(a[0], a[1]), a[2 .. $]);
1800    }
1801 }
1802 
1803 // Cases which would ICE or segfault
Bulldog(T)1804 struct Bulldog(T){
1805     static void cat(Frog)(Frog f) if (true)
1806     {    }
1807 }
1808 
mouse()1809 void mouse(){
1810     Bulldog!(int).cat(0);
1811 }
1812 
test87()1813 void test87()
1814 {
1815     double[] d1 = [ 6.0, 1.5, 2.4, 3 ];
1816     double[] d2 = [ 1.5, 2.4 ];
1817     assert(find(d1, d2) == d1[1 .. $]);
1818     assert(find(d1, d2) == d1[1 .. $]); // Check for memory corruption
1819     assert(max(4, 5) == 5);
1820     assert(max(3, 4, 5) == 5);
1821 }
1822 
1823 /***************************************************/
1824 
test4284(alias v)1825 template test4284(alias v) { enum test4284 = v.length == 0; }
1826 static assert(test4284!(cast(string)null));
1827 static assert(test4284!(cast(string[])null));
1828 
1829 /***************************************************/
1830 
1831 struct S88
1832 {
opDispatchS881833     void opDispatch(string s, T)(T i)
1834     {
1835         printf("S.opDispatch('%.*s', %d)\n", s.length, s.ptr, i);
1836     }
1837 }
1838 
1839 class C88
1840 {
opDispatch(string s)1841     void opDispatch(string s)(int i)
1842     {
1843         printf("C.opDispatch('%.*s', %d)\n", s.length, s.ptr, i);
1844     }
1845 }
1846 
1847 struct D88
1848 {
opDispatchD881849     template opDispatch(string s)
1850     {
1851         enum int opDispatch = 8;
1852     }
1853 }
1854 
test88()1855 void test88()
1856 {
1857     S88 s;
1858     s.opDispatch!("hello")(7);
1859     s.foo(7);
1860 
1861     auto c = new C88();
1862     c.foo(8);
1863 
1864     D88 d;
1865     printf("d.foo = %d\n", d.foo);
1866     assert(d.foo == 8);
1867 }
1868 
1869 /***************************************************/
1870 
test89()1871 void test89() {
1872     static struct X {
1873         int x;
1874         int bar() { return x; }
1875     }
1876     X s;
1877     printf("%d\n", s.sizeof);
1878     assert(s.sizeof == 4);
1879 }
1880 
1881 /***************************************************/
1882 
1883 struct S90
1884 {
opDispatchS901885     void opDispatch( string name, T... )( T values )
1886     {
1887         assert(values[0] == 3.14);
1888     }
1889 }
1890 
test90()1891 void test90( )
1892 {   S90 s;
1893     s.opDispatch!("foo")( 3.14 );
1894     s.foo( 3.14 );
1895 }
1896 
1897 /***************************************************/
1898 
A7439(int r,int c)1899 struct A7439(int r, int c)
1900 {
1901     alias r R;
1902     alias c C;
1903     alias float[R * C] Data;
1904     Data _data;
1905     alias _data this;
1906 
1907     this(Data ar){ _data = ar; }
1908 
1909     pure ref float opIndex(size_t rr, size_t cc){ return _data[cc + rr * C]; }
1910 }
1911 
test7439()1912 void test7439()
1913 {
1914     A7439!(2, 2) a = A7439!(2, 2)([8, 3, 2, 9]);
1915     a[0,0] -= a[0,0] * 2.0;
1916 }
1917 
1918 /***************************************************/
1919 
1920 void foo91(uint line = __LINE__) { printf("%d\n", line); }
1921 
test91()1922 void test91()
1923 {
1924     foo91();
1925     printf("%d\n", __LINE__);
1926 }
1927 
1928 /***************************************************/
1929 
fun13468(Object e,typeof (null)needle)1930 bool fun13468(Object e, typeof(null) needle)
1931 {
1932     return (e == needle);
1933 }
1934 
test13468()1935 void test13468()
1936 {
1937     assert(fun13468(null, null));
1938 }
1939 
1940 /***************************************************/
1941 
foo92(ref int x)1942 auto ref foo92(ref int x) { return x; }
bar92(ref int x)1943 int bar92(ref int x) { return x; }
1944 
test92()1945 void test92()
1946 {
1947     int x = 3;
1948     int i = bar92(foo92(x));
1949     assert(i == 3);
1950 }
1951 
1952 /***************************************************/
1953 
1954 struct Foo93
1955 {
fooFoo931956     public int foo() const
1957     {
1958         return 2;
1959     }
1960 }
1961 
test93()1962 void test93()
1963 {
1964     const Foo93 bar = Foo93();
1965     enum bla = bar.foo();
1966     assert(bla == 2);
1967 }
1968 
1969 /***************************************************/
1970 
1971 
1972 extern(C++) class C1687
1973 {
func()1974     void func() {}
1975 }
1976 
test1687()1977 void test1687()
1978 {
1979     auto c = new C1687();
1980     assert(c.__vptr[0] == (&c.func).funcptr);
1981 }
1982 
1983 /***************************************************/
1984 
1985 struct Foo94
1986 {
1987     int x, y;
1988     real z;
1989 }
1990 
makeFoo(const int x,const int y)1991 pure nothrow Foo94 makeFoo(const int x, const int y)
1992 {
1993     return Foo94(x, y, 3.0);
1994 }
1995 
test94()1996 void test94()
1997 {
1998     auto f = makeFoo(1, 2);
1999     assert(f.x==1);
2000     assert(f.y==2);
2001     assert(f.z==3);
2002 }
2003 
2004 /***************************************************/
2005 
2006 struct T95
2007 {
thisT952008     @disable this(this)
2009     {
2010     }
2011 }
2012 
2013 struct S95
2014 {
2015     T95 t;
2016 }
2017 
foo95()2018 @disable void foo95() { }
2019 
2020 struct T95A
2021 {
2022     @disable this(this);
2023 }
2024 
2025 struct S95A
2026 {
2027     T95A t;
2028 }
2029 
foo95A()2030 @disable void foo95A() { }
2031 
test95()2032 void test95()
2033 {
2034     S95 s;
2035     S95 t;
2036     static assert(!__traits(compiles, t = s));
2037     static assert(!__traits(compiles, foo95()));
2038 
2039     S95A u;
2040     S95A v;
2041     static assert(!__traits(compiles, v = u));
2042     static assert(!__traits(compiles, foo95A()));
2043 }
2044 
2045 /***************************************************/
2046 
S96(alias init)2047 struct S96(alias init)
2048 {
2049     int[] content = init;
2050 }
2051 
test96()2052 void test96()
2053 {
2054     S96!([12, 3]) s1;
2055     S96!([1, 23]) s2;
2056     writeln(s1.content);
2057     writeln(s2.content);
2058     assert(!is(typeof(s1) == typeof(s2)));
2059 }
2060 
2061 /***************************************************/
2062 
2063 struct A97
2064 {
opEqualsA972065     const bool opEquals(ref const A97) { return true; }
2066     ref A97 opUnary(string op)() if (op == "++")
2067     {
2068         return this;
2069     }
2070 }
2071 
test97()2072 void test97()
2073 {
2074     A97 a, b;
2075     foreach (e; a .. b) {
2076     }
2077 }
2078 
2079 /***************************************************/
2080 
test98()2081 void test98()
2082 {
2083     auto a = new int[2];
2084     // the name "length" should not pop up in an index expression
2085     static assert(!is(typeof(a[length - 1])));
2086 }
2087 
2088 /***************************************************/
2089 
2090 string s99;
2091 
bar99(string i)2092 void bar99(string i)
2093 {
2094 }
2095 
function(string)2096 void function(string) foo99(string i)
2097 {
2098     return &bar99;
2099 }
2100 
test99()2101 void test99()
2102 {
2103     foo99 (s99 ~= "a") (s99 ~= "b");
2104     assert(s99 == "ab");
2105 }
2106 
2107 /***************************************************/
2108 // 5081
2109 
test5081()2110 void test5081()
2111 {
2112     static pure immutable(int[]) x1()
2113     {
2114         int[] a = new int[](10);
2115         return a;
2116     }
2117     static pure immutable(int[]) x2(int len)
2118     {
2119         int[] a = new int[](len);
2120         return a;
2121     }
2122     static pure immutable(int[]) x3(immutable(int[]) org)
2123     {
2124         int[] a = new int[](org.length);
2125         return a;
2126     }
2127 
2128     immutable a1 = x1();
2129     immutable a2 = x2(10);
2130     immutable a3 = x3([1,2]);
2131 
2132     static pure int[] y1()
2133     {
2134         return new int[](10);
2135     }
2136 
2137     immutable b1 = y1();
2138 }
2139 
2140 /***************************************************/
2141 
test100()2142 void test100()
2143 {
2144    string s;
2145 
2146    /* Testing order of evaluation */
2147    void delegate(string, string) fun(string) {
2148       s ~= "b";
2149       return delegate void(string x, string y) { s ~= "e"; };
2150    }
2151    fun(s ~= "a")(s ~= "c", s ~= "d");
2152    assert(s == "abcde", s);
2153 }
2154 
2155 /***************************************************/
2156 
test101()2157 void test101()
2158 {
2159    int[] d1 = [ 6, 1, 2 ];
2160    byte[] d2 = [ 6, 1, 2 ];
2161    assert(d1 == d2);
2162    d2 ~= [ 6, 1, 2 ];
2163    assert(d1 != d2);
2164 }
2165 
2166 /***************************************************/
2167 
2168 
test5403()2169 void test5403()
2170 {
2171     struct S
2172     {
2173         static int front;
2174         enum back = "yes!";
2175         bool empty;
2176         void popAny() { empty = true; }
2177         alias popAny popFront;
2178         alias popAny popBack;
2179     }
2180     S.front = 7;
2181     foreach(int i; S()) assert(i == 7);
2182     S.front = 2;
2183     foreach(i; S()) assert(i == 2);
2184     foreach_reverse(i; S()) assert(i == "yes!");
2185 }
2186 
2187 /***************************************************/
2188 
2189 static assert([1,2,3] == [1.0,2,3]);
2190 
2191 /***************************************************/
2192 
transmogrify(uint)2193 int transmogrify(uint) { return 1; }
transmogrify(long)2194 int transmogrify(long) { return 2; }
2195 
test103()2196 void test103()
2197 {
2198     assert(transmogrify(42) == 1);
2199 }
2200 
2201 /***************************************************/
2202 
foo104(int x)2203 int foo104(int x)
2204 {
2205     int* p = &(x += 1);
2206     return *p;
2207 }
2208 
bar104(int * x)2209 int bar104(int *x)
2210 {
2211     int* p = &(*x += 1);
2212     return *p;
2213 }
2214 
test104()2215 void test104()
2216 {
2217     auto i = foo104(1);
2218     assert(i == 2);
2219     i = bar104(&i);
2220     assert(i == 3);
2221 }
2222 
2223 /***************************************************/
2224 
bump105(ref int x)2225 ref int bump105(ref int x) { return ++x; }
2226 
test105()2227 void test105()
2228 {
2229    int x = 1;
2230    bump105(bump105(x)); // two increments
2231    assert(x == 3);
2232 }
2233 
2234 /***************************************************/
2235 
genFactorials(int n)2236 pure int genFactorials(int n) {
2237     static pure int factorial(int n) {
2238       if (n==2) return 1;
2239       return factorial(2);
2240     }
2241     return factorial(n);
2242 }
2243 
2244 /***************************************************/
2245 
test107()2246 void test107()
2247 {
2248     int[6] a;
2249     writeln(a);
2250     writeln(a.init);
2251     assert(a.init == [0,0,0,0,0,0]);
2252 }
2253 
2254 /***************************************************/
2255 
2256 class A109 {}
2257 
test109()2258 void test109()
2259 {
2260     immutable(A109) b;
2261     A109 c;
2262     auto z = true ? b : c;
2263     //writeln(typeof(z).stringof);
2264     static assert(is(typeof(z) == const(A109)));
2265 }
2266 
2267 /***************************************************/
2268 
Boo(T)2269 template Boo(T) {}
2270 struct Foo110(T, alias V = Boo!T)
2271 {
2272     pragma(msg, V.stringof);
2273     static const s = V.stringof;
2274 }
2275 alias Foo110!double B110;
2276 alias Foo110!int A110;
2277 
2278 static assert(B110.s == "Boo!double");
2279 static assert(A110.s == "Boo!int");
2280 
2281 /***************************************************/
2282 
test11247()2283 int test11247()
2284 {
2285     static assert(is(byte[typeof(int.init).sizeof] == byte[4]));
2286     static assert(is(byte[typeof(return).sizeof] == byte[4]));
2287     return 0;
2288 }
2289 
2290 /***************************************************/
2291 
2292 // 3716
test111()2293 void test111()
2294 {
2295     auto k1 = true ? [1,2] : []; // OK
2296     auto k2 = true ? [[1,2]] : [[]];
2297     auto k3 = true ? [] : [[1,2]];
2298     auto k4 = true ? [[[]]] : [[[1,2]]];
2299     auto k5 = true ? [[[1,2]]] : [[[]]];
2300     auto k6 = true ? [] : [[[]]];
2301     static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail
2302 }
2303 
2304 /***************************************************/
2305 // 658
2306 
test658()2307 void test658()
2308 {
2309     struct S { int i; }
2310     class C { int i; }
2311 
2312     S s;
2313     S* sp = &s;
2314     with (sp) i = 42;
2315     assert(s.i == 42);
2316     with (&s) i = 43;
2317     assert(s.i == 43);
2318 
2319     C c = new C;
2320     C* cp = &c;
2321     with (cp) i = 42;
2322     assert(c.i == 42);
2323     with (&c) i = 43;
2324     assert(c.i == 43);
2325 }
2326 
2327 /***************************************************/
2328 
test3069()2329 void test3069()
2330 {
2331     ubyte id = 0;
2332     void[] v = [id] ~ [id];
2333 }
2334 
2335 /***************************************************/
2336 // 4303
2337 
2338 template foo112() if (__traits(compiles,undefined))
2339 {
2340     enum foo112 = false;
2341 }
2342 
2343 template foo112() if (true)
2344 {
2345     enum foo112 = true;
2346 }
2347 
2348 pragma(msg,__traits(compiles,foo112!()));
2349 static assert(__traits(compiles,foo112!()));
2350 
2351 const bool bar112 = foo112!();
2352 
2353 
2354 /***************************************************/
2355 
2356 struct File113
2357 {
thisFile1132358     this(int name) { }
2359 
~thisFile1132360     ~this() { }
2361 
opAssignFile1132362     void opAssign(File113 rhs) { }
2363 
2364     struct ByLine
2365     {
2366         File113 file;
2367 
thisFile113::ByLine2368         this(int) { }
2369 
2370     }
2371 
byLineFile1132372     ByLine byLine()
2373     {
2374         return ByLine(1);
2375     }
2376 }
2377 
2378 auto filter113(File113.ByLine rs)
2379 {
2380     struct Filter
2381     {
2382         this(File113.ByLine r) { }
2383     }
2384 
2385     return Filter(rs);
2386 }
2387 
test113()2388 void test113()
2389 {
2390     auto f = File113(1);
2391     auto rx = f.byLine();
2392     auto file = filter113(rx);
2393 }
2394 
2395 /***************************************************/
2396 
foo114(fun...)2397 template foo114(fun...)
2398 {
2399     auto foo114(int[] args)
2400     {
2401         return 1;
2402     }
2403 }
2404 
2405 pragma(msg, typeof(foo114!"a + b"([1,2,3])));
2406 
2407 /***************************************************/
2408 // Bugzilla 3935
2409 
2410 struct Foo115 {
opBinaryFoo1152411     void opBinary(string op)(Foo other) {
2412         pragma(msg, "op: " ~ op);
2413         assert(0);
2414     }
2415 }
2416 
test115()2417 void test115()
2418 {
2419     Foo115 f;
2420     f = f;
2421 }
2422 
2423 /***************************************************/
2424 // Bugzilla 2477
2425 
2426 void foo116(T,)(T t) { T x; }
2427 
test116()2428 void test116()
2429 {
2430     int[] data = [1,2,3,];  // OK
2431 
2432     data = [ 1,2,3, ];  // fails
2433     auto i = data[1,];
2434     foo116!(int)(3);
2435     foo116!(int,)(3);
2436     foo116!(int,)(3,);
2437 }
2438 
2439 /***************************************************/
2440 
test1891()2441 void test1891()
2442 {
2443     struct C {
2444         char[8] x = "helloabc";
2445     }
2446 
2447     int main()
2448     {
2449         C* a = new C;
2450         C*[] b;
2451         b ~= new C;
2452 
2453         auto g = a ~ b;
2454         assert(g[0] && g[1] && g[0].x == g[1].x);
2455 
2456         return 0;
2457     }
2458 }
2459 
2460 /***************************************************/
2461 // Bugzilla 4291
2462 
test117()2463 void test117() pure
2464 {
2465     mixin declareVariable;
2466     var = 42;
2467     mixin declareFunction;
2468     readVar();
2469 }
declareVariable()2470 template declareVariable() { int var; }
declareFunction()2471 template declareFunction()
2472 {
2473     int readVar() { return var; }
2474 }
2475 
2476 /***************************************************/
2477 // Bugzilla 4177
2478 
log118(real x)2479 pure real log118(real x) {
2480     if (__ctfe)
2481         return 0.0;
2482     else
2483         return 1.0;
2484 }
2485 
2486 enum x118 = log118(4.0);
2487 
test118()2488 void test118() {}
2489 
2490 /***************************************************/
2491 
bug4465()2492 void bug4465()
2493 {
2494     const a = 2 ^^ 2;
2495     int b = a;
2496 }
2497 
2498 /***************************************************/
2499 
foo(int * p)2500 pure void foo(int *p)
2501 {
2502     *p = 3;
2503 }
2504 
test120()2505 pure void test120()
2506 {
2507     int i;
2508     foo(&i);
2509     assert(i == 3);
2510 }
2511 
2512 /***************************************************/
2513 // 4866
2514 
2515 immutable int[3] statik = [ 1, 2, 3 ];
2516 enum immutable(int)[] dynamic = statik;
2517 
2518 static assert(is(typeof(dynamic) == immutable(int)[]));
2519 static if (! is(typeof(dynamic) == immutable(int)[]))
2520 {
2521     static assert(0);   // (7)
2522 }
2523 pragma(msg, "!! ", typeof(dynamic));
2524 
2525 /***************************************************/
2526 // 2943
2527 
2528 struct Foo2943
2529 {
2530     int a;
2531     int b;
2532     alias b this;
2533 }
2534 
test122()2535 void test122()
2536 {
2537     Foo2943 foo, foo2;
2538     foo.a = 1;
2539     foo.b = 2;
2540     foo2.a = 3;
2541     foo2.b = 4;
2542 
2543     foo2 = foo;
2544     assert(foo2.a == foo.a);
2545 }
2546 
2547 /***************************************************/
2548 // 4641
2549 
2550 struct S123 {
2551     int i;
2552     alias i this;
2553 }
2554 
test123()2555 void test123() {
2556     S123[int] ss;
2557     ss[0] = S123.init; // This line causes Range Violation.
2558 }
2559 
2560 /***************************************************/
2561 // 2451
2562 
2563 struct Foo124 {
2564     int z = 3;
opAssignFoo1242565     void opAssign(Foo124 x) { z= 2;}
2566 }
2567 
2568 struct Bar124 {
2569     int z = 3;
this(this)2570     this(this){ z = 17; }
2571 }
2572 
test124()2573 void test124() {
2574     Foo124[string] stuff;
2575     stuff["foo"] = Foo124.init;
2576     assert(stuff["foo"].z == 3);
2577     stuff["foo"] = Foo124.init;
2578     assert(stuff["foo"].z == 2);
2579 
2580     Bar124[string] stuff2;
2581     Bar124 q;
2582     stuff2["dog"] = q;
2583     assert(stuff2["dog"].z == 17);
2584 }
2585 
2586 /***************************************************/
2587 
test3022()2588 void test3022()
2589 {
2590     static class Foo3022
2591     {
2592         new(size_t)
2593         {
2594             assert(0);
2595         }
2596     }
2597 
2598     scope x = new Foo3022;
2599 }
2600 
2601 /***************************************************/
2602 
doNothing()2603 void doNothing() {}
2604 
bug5071(short d,ref short c)2605 void bug5071(short d, ref short c) {
2606    assert(c==0x76);
2607 
2608     void closure() {
2609         auto c2 = c;
2610         auto d2 = d;
2611         doNothing();
2612     }
2613     auto useless = &closure;
2614 }
2615 
test125()2616 void test125()
2617 {
2618    short c = 0x76;
2619    bug5071(7, c);
2620 }
2621 
2622 /***************************************************/
2623 
2624 struct Foo126
2625 {
opCallFoo1262626    static Foo126 opCall(in Foo126 _f) pure
2627    {
2628        return _f;
2629    }
2630 }
2631 
2632 /***************************************************/
2633 
test796()2634 void test796()
2635 {
2636     struct S { invariant() { throw new Exception(""); } }
2637     S* s;
2638     try {
2639         assert(s);
2640     } catch (Error) {
2641     }
2642 }
2643 
2644 /***************************************************/
2645 
test7077()2646 void test7077()
2647 {
2648     if(0) mixin("auto x = 2;");
2649     auto x = 1;
2650 }
2651 
2652 /***************************************************/
2653 
Tuple127(S...)2654 struct Tuple127(S...)
2655 {
2656     S expand;
2657     alias expand this;
2658 }
2659 
2660 alias Tuple127!(int, int) Foo127;
2661 
test127()2662 void test127()
2663 {
2664     Foo127[] m_array;
2665     Foo127 f;
2666     m_array ~= f;
2667 }
2668 
2669 /***************************************************/
2670 
2671 struct Bug4434 {}
2672 alias const Bug4434* IceConst4434;
2673 alias shared Bug4434* IceShared4434;
2674 alias shared Bug4434[] IceSharedArray4434;
2675 alias immutable Bug4434* IceImmutable4434;
2676 alias shared const Bug4434* IceSharedConst4434;
2677 
2678 alias int MyInt4434;
2679 alias const MyInt4434[3] IceConstInt4434;
2680 
2681 alias immutable string[] Bug4830;
2682 
2683 /***************************************************/
2684 // 4254
2685 
bub(const inout int other)2686 void bub(const inout int other) {}
2687 
test128()2688 void test128()
2689 {
2690     bub(1);
2691 }
2692 
2693 
2694 /***************************************************/
2695 
bug4915a()2696 pure nothrow @safe auto bug4915a() {  return 0; }
bug4915b()2697 pure nothrow @safe int  bug4915b() { return bug4915a(); }
2698 
bug4915c()2699 void bug4915c()
2700 {
2701     pure nothrow @safe int d() { return 0; }
2702     int e() pure nothrow @safe { return d(); }
2703 }
2704 
2705 /***************************************************/
2706 // 5164
2707 
2708 static if (is(int Q == int, Z...))  { }
2709 
2710 /***************************************************/
2711 // 5195
2712 
2713 alias typeof(foo5195) food5195;
2714 const int * foo5195 = null;
2715 alias typeof(foo5195) good5195;
2716 static assert( is (food5195 == good5195));
2717 
2718 /***************************************************/
2719 
version(Windows)2720 version (Windows)
2721 {
2722 }
2723 else
2724 {
2725 int[0] var5332;
test5332()2726 void test5332() { auto x = var5332; }
2727 }
2728 
2729 /***************************************************/
2730 // 5191
2731 
2732 struct Foo129
2733 {
addFoo1292734     void add(T)(T value) nothrow
2735     {
2736         this.value += value;
2737     }
2738 
thisFoo1292739     this(int value)
2740     {
2741         this.value = value;
2742     }
2743 
2744     int value;
2745 }
2746 
test129()2747 void test129()
2748 {
2749     auto foo = Foo129(5);
2750     assert(foo.value == 5);
2751 
2752     foo.add(2);
2753     writeln(foo.value);
2754     assert(foo.value == 7);
2755 
2756     foo.add(3);
2757     writeln(foo.value);
2758     assert(foo.value == 10);
2759 
2760     foo.add(3);
2761     writeln(foo.value);
2762     assert(foo.value == 13);
2763 
2764     void delegate (int) nothrow dg = &foo.add!(int);
2765     dg(7);
2766     assert(foo.value == 20);
2767 }
2768 
2769 /***************************************************/
2770 // 6169
2771 
ctfefunc6169()2772 auto ctfefunc6169() { return "{}"; }
2773 enum ctfefptr6169 = &ctfefunc6169;
ctfefunc6169a()2774 int ctfefunc6169a() { return 1; }
x6169(string c)2775 template x6169(string c) { alias int x6169; }
TT6169(T...)2776 template TT6169(T...) { alias T TT6169; }
ctfeprop6169()2777 @property ctfeprop6169() { return "g"; }
2778 
test6169()2779 void test6169() pure @safe
2780 {
2781     enum a = ctfefunc6169();
2782     static b = ctfefunc6169();
2783     x6169!(ctfefunc6169()) tt;
2784     mixin(ctfefunc6169());
2785     static if(ctfefunc6169()) {}
2786     pragma(msg, ctfefunc6169());
2787     enum xx
2788     {
2789         k = 0,
2790         j = ctfefunc6169a()
2791     }
2792     auto g = mixin('"' ~ ctfefunc6169() ~ '"');
2793     //auto h = import("testx.d" ~ false ? ctfefunc() : "");
2794     alias TT6169!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i;
2795     alias TT6169!(int, int)[ctfefunc6169a()] j;
2796     int[ctfefunc6169a()+1] k;
2797     alias int[ctfefunc6169a()] l;
2798     switch(1)
2799     {
2800     //case ctfefunc6169a(): // Can't do this because of case variables
2801     case ctfefunc6169a()+1:
2802         ..
2803     case ctfefunc6169a()+2:
2804     default:
2805         break;
2806     }
2807     static assert(ctfefunc6169a());
2808     void fun(int i : ctfefunc6169a() = ctfefunc6169a(), alias j)() if (ctfefunc6169a()) {}
2809     fun!(ctfefunc6169a(), ctfefunc6169())();
2810     enum z = ctfefptr6169();
2811 
2812     auto p = mixin(ctfeprop6169);
2813 }
2814 
2815 /***************************************************/
2816 // 10506
2817 
impureFunc10506()2818 void impureFunc10506() {}
join10506(RoR)2819 string join10506(RoR)(RoR ror)
2820 {
2821     impureFunc10506();
2822     return ror[0] ~ ror[1];
2823 }
2824 
test10506()2825 void test10506() pure
2826 {
2827     void foobar() {}
2828 
2829     mixin(["foo", "bar"].join10506()~";");
2830 }
2831 
2832 /***************************************************/
2833 
2834 const shared class C5107
2835 {
2836     int x;
2837 }
2838 
2839 static assert(is(typeof(C5107.x) ==  const)); // okay
2840 static assert(is(typeof(C5107.x) == shared)); // fails!
2841 
2842 /***************************************************/
2843 
2844 immutable struct S3598
2845 {
funkcjaS35982846     static void funkcja() { }
2847 }
2848 
2849 /***************************************************/
2850 // 4211
2851 
2852 @safe struct X130
2853 {
func()2854     void func() {  }
2855 }
2856 
2857 @safe class Y130
2858 {
func()2859     void func() {  }
2860 }
2861 
test130()2862 @safe void test130()
2863 {
2864     X130 x;
2865     x.func();
2866     auto y = new Y130;
2867     y.func();
2868 }
2869 
2870 /***************************************************/
2871 
Return(alias fun)2872 template Return(alias fun)
2873 {
2874     static if (is(typeof(fun) R == return)) alias R Return;
2875 }
2876 
2877 interface I4217
2878 {
2879     int  square(int  n);
2880     real square(real n);
2881 }
2882 alias Return!( __traits(getOverloads, I4217, "square")[0] ) R4217;
2883 alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217;
2884 
2885 static assert(! is(R4217 == S4217));
2886 
2887 /***************************************************/
2888 // 5094
2889 
test131()2890 void test131()
2891 {
2892     S131 s;
2893     int[] conv = s;
2894 }
2895 
2896 struct S131
2897 {
getS1312898     @property int[] get() { return [1,2,3]; }
2899     alias get this;
2900 }
2901 
2902 /***************************************************/
2903 
2904 struct S7545
2905 {
2906     uint id;
2907     alias id this;
2908 }
2909 
test7545()2910 void test7545()
2911 {
2912     auto id = 0 ? S7545() : -1;
2913 }
2914 
2915 /***************************************************/
2916 // 5020
2917 
test132()2918 void test132()
2919 {
2920     S132 s;
2921     if (!s) {}
2922 }
2923 
2924 struct S132
2925 {
2926     bool cond;
2927     alias cond this;
2928 }
2929 
2930 /***************************************************/
2931 // 5343
2932 
Tuple5343(Specs...)2933 struct Tuple5343(Specs...)
2934 {
2935     Specs[0] field;
2936 }
2937 
S5343(E)2938 struct S5343(E)
2939 {
2940     immutable E x;
2941 }
2942 enum A5343{a,b,c}
2943 alias Tuple5343!(A5343) TA5343;
2944 alias S5343!(A5343) SA5343;
2945 
2946 /***************************************************/
2947 // 5365
2948 
2949 interface IFactory
2950 {
2951     void foo();
2952 }
2953 
2954 class A133
2955 {
2956     protected static class Factory : IFactory
2957     {
foo()2958         void foo()
2959         {
2960         }
2961     }
2962 
this()2963     this()
2964     {
2965         _factory = createFactory();
2966     }
2967 
createFactory()2968     protected IFactory createFactory()
2969     {
2970         return new Factory;
2971     }
2972 
2973     private IFactory _factory;
factory()2974     @property final IFactory factory()
2975     {
2976         return _factory;
2977     }
2978 
2979     alias factory this;
2980 }
2981 
test133()2982 void test133()
2983 {
2984 
2985     IFactory f = new A133;
2986     f.foo(); // segfault
2987 }
2988 
2989 /***************************************************/
2990 // 5365
2991 
2992 class B134
2993 {
2994 }
2995 
2996 class A134
2997 {
2998 
2999     B134 _b;
3000 
this()3001     this()
3002     {
3003         _b = new B134;
3004     }
3005 
b()3006     B134 b()
3007     {
3008         return _b;
3009     }
3010 
3011     alias b this;
3012 }
3013 
test134()3014 void test134()
3015 {
3016 
3017     auto a = new A134;
3018     B134 b = a; // b is null
3019     assert(a._b is b); // fails
3020 }
3021 
3022 /***************************************************/
3023 // 5025
3024 
3025 struct S135 {
3026   void delegate() d;
3027 }
3028 
test135()3029 void test135()
3030 {
3031   shared S135[] s;
3032   if (0)
3033     s[0] = S135();
3034 }
3035 
3036 /***************************************************/
3037 // 5545
3038 
3039 bool enforce136(bool value, lazy const(char)[] msg = null) {
3040     if(!value) {
3041         return false;
3042     }
3043 
3044     return value;
3045 }
3046 
3047 struct Perm {
3048     byte[3] perm;
3049     ubyte i;
3050 
thisPerm3051     this(byte[] input) {
3052         foreach(elem; input) {
3053             enforce136(i < 3);
3054             perm[i++] = elem;
3055             std.stdio.stderr.writeln(i);  // Never gets incremented.  Stays at 0.
3056         }
3057     }
3058 }
3059 
test136()3060 void test136() {
3061     byte[] stuff = [0, 1, 2];
3062     auto perm2 = Perm(stuff);
3063     writeln(perm2.perm);  // Prints [2, 0, 0]
3064     assert(perm2.perm[] == [0, 1, 2]);
3065 }
3066 
3067 /***************************************************/
3068 // 4097
3069 
foo4097()3070 void foo4097() { }
3071 alias typeof(&foo4097) T4097;
3072 static assert(is(T4097 X : X*) && is(X == function));
3073 
3074 static assert(!is(X));
3075 
3076 /***************************************************/
3077 // 5798
3078 
assign9(ref int lhs)3079 void assign9(ref int lhs) pure {
3080     lhs = 9;
3081 }
3082 
assign8(ref int rhs)3083 void assign8(ref int rhs) pure {
3084     rhs = 8;
3085 }
3086 
test137()3087 int test137(){
3088     int a=1,b=2;
3089     assign8(b),assign9(a);
3090     assert(a == 9);
3091     assert(b == 8);   // <-- fail
3092 
3093     assign9(b),assign8(a);
3094     assert(a == 8);
3095     assert(b == 9);   // <-- fail
3096 
3097     return 0;
3098 }
3099 
3100 /***************************************************/
3101 
3102 // 9366
3103 static assert(!is(typeof((void[]).init ~ cast(void)0)));
3104 static assert(!is(typeof(cast(void)0 ~ (void[]).init)));
3105 
3106 /***************************************************/
3107 
3108 struct Size138
3109 {
3110     union
3111     {
3112         struct
3113         {
3114             int width;
3115             int height;
3116         }
3117 
3118         long size;
3119     }
3120 }
3121 
3122 enum Size138 foo138 = {2 ,5};
3123 
3124 Size138 bar138 = foo138;
3125 
3126 void test138()
3127 {
3128     assert(bar138.width == 2);
3129     assert(bar138.height == 5);
3130 }
3131 
3132 /***************************************************/
3133 
3134 void test3822()
3135 {
3136     import core.stdc.stdlib;
3137     int i = 0;
3138     void* ptr;
3139     while(i++ != 2)
3140     {
3141         auto p = alloca(2);
3142         assert(p != ptr);
3143         ptr = p;
3144     }
3145 }
3146 
3147 /***************************************************/
3148 
3149 // 5939, 5940
3150 
3151 template map(fun...)
3152 {
3153     auto map(double[] r)
3154     {
3155         struct Result
3156         {
3157             this(double[] input)
3158             {
3159             }
3160         }
3161 
3162         return Result(r);
3163     }
3164 }
3165 
3166 
3167 void test139()
3168 {
3169     double[] x;
3170     alias typeof(map!"a"(x)) T;
3171     T a = void;
3172     auto b = map!"a"(x);
3173     auto c = [map!"a"(x)];
3174     T[3] d = void;
3175 }
3176 
3177 
3178 /***************************************************/
3179 // 5966
3180 
3181 string[] foo5966(string[] a)
3182 {
3183     a[0] = a[0][0..$];
3184     return a;
3185 }
3186 
3187 enum var5966 = foo5966([""]);
3188 
3189 /***************************************************/
3190 // 5975
3191 
3192 int foo5975(wstring replace)
3193 {
3194   wstring value = "";
3195   value ~= replace;
3196   return 1;
3197 }
3198 
3199 enum X5975 = foo5975("X"w);
3200 
3201 /***************************************************/
3202 // 5965
3203 
3204 template mapx(fun...) if (fun.length >= 1)
3205 {
3206     int mapx(Range)(Range r)
3207     {
3208         return 1;
3209     }
3210 }
3211 
3212 void test140()
3213 {
3214    int foo(int i) { return i; }
3215 
3216    int[] arr;
3217    auto x = mapx!( (int a){return foo(a);} )(arr);
3218 }
3219 
3220 /***************************************************/
3221 
3222 void bug5976()
3223 {
3224     int[] barr;
3225     int * k;
3226     foreach (ref b; barr)
3227     {
3228         scope(failure)
3229             k = &b;
3230         k = &b;
3231     }
3232 }
3233 
3234 /***************************************************/
3235 // 5771
3236 
3237 struct S141
3238 {
3239     this(A)(auto ref A a){}
3240 }
3241 
3242 void test141()
3243 {
3244     S141 s = S141(10);
3245 }
3246 
3247 /***************************************************/
3248 
3249 class test5498_A {}
3250 class test5498_B : test5498_A {}
3251 class test5498_C : test5498_A {}
3252 
3253 static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[]));
3254 
3255 /***************************************************/
3256 // 3688
3257 
3258 struct S142
3259 {
3260     int v;
3261     this(int n) pure { v = n; }
3262     const bool opCast(T:bool)() { return true; }
3263 }
3264 
3265 void test142()
3266 {
3267     if (int a = 1)
3268         assert(a == 1);
3269     else assert(0);
3270 
3271     if (const int a = 2)
3272         assert(a == 2);
3273     else assert(0);
3274 
3275     if (immutable int a = 3)
3276         assert(a == 3);
3277     else assert(0);
3278 
3279     if (auto s = S142(10))
3280         assert(s.v == 10);
3281     else assert(0);
3282 
3283     if (auto s = const(S142)(20))
3284         assert(s.v == 20);
3285     else assert(0);
3286 
3287     if (auto s = immutable(S142)(30))
3288         assert(s.v == 30);
3289     else assert(0);
3290 }
3291 
3292 /***************************************************/
3293 // 6072
3294 
3295 static assert({
3296     if (int x = 5) {}
3297     return true;
3298 }());
3299 
3300 /***************************************************/
3301 // 5959
3302 
3303 int n;
3304 
3305 void test143()
3306 {
3307     ref int f(){ return n; }            // NG
3308     f() = 1;
3309     assert(n == 1);
3310 
3311     nothrow ref int f1(){ return n; }    // OK
3312     f1() = 2;
3313     assert(n == 2);
3314 
3315     auto ref int f2(){ return n; }       // OK
3316     f2() = 3;
3317     assert(n == 3);
3318 }
3319 
3320 /***************************************************/
3321 // 6119
3322 
3323 void startsWith(alias pred) ()   if (is(typeof(pred('c', 'd')) : bool))
3324 {
3325 }
3326 
3327 void startsWith(alias pred) ()   if (is(typeof(pred('c', "abc")) : bool))
3328 {
3329 }
3330 
3331 void test144()
3332 {
3333     startsWith!((a, b) { return a == b; })();
3334 }
3335 
3336 /***************************************************/
3337 
3338 void test145()
3339 {
3340     import core.stdc.stdio;
3341     printf("hello world 145\n");
3342 }
3343 
3344 void test146()
3345 {
3346     test1();
3347     static import core.stdc.stdio;
3348     core.stdc.stdio.printf("hello world 146\n");
3349 }
3350 
3351 /***************************************************/
3352 // 5856
3353 
3354 struct X147
3355 {
3356     void f()       { writeln("X.f mutable"); }
3357     void f() const { writeln("X.f const"); }
3358 
3359     void g()()       { writeln("X.g mutable"); }
3360     void g()() const { writeln("X.g const"); }
3361 
3362     void opOpAssign(string op)(int n)       { writeln("X+= mutable"); }
3363     void opOpAssign(string op)(int n) const { writeln("X+= const"); }
3364 }
3365 
3366 void test147()
3367 {
3368     X147 xm;
3369     xm.f();     // prints "X.f mutable"
3370     xm.g();     // prints "X.g mutable"
3371     xm += 10;   // should print "X+= mutable" (1)
3372 
3373     const(X147) xc;
3374     xc.f();     // prints "X.f const"
3375     xc.g();     // prints "X.g const"
3376     xc += 10;   // should print "X+= const" (2)
3377 }
3378 
3379 
3380 /***************************************************/
3381 
3382 void test3559()
3383 {
3384     static class A
3385     {
3386         int foo(int a)   { return 0; }
3387         int foo(float a) { return 1; }
3388 
3389         int bar(float a) { return 1; }
3390         int bar(int a) { return 0; }
3391     }
3392 
3393     static class B : A
3394     {
3395         override int foo(float a) { return 2; }
3396         alias A.foo foo;
3397 
3398         alias A.bar bar;
3399         override int bar(float a) { return 2; }
3400     }
3401 
3402     {
3403         auto x = new A;
3404         auto f1 = cast(int delegate(int))&x.foo;
3405         auto f2 = cast(int delegate(float))&x.foo;
3406         int delegate(int) f3 = &x.foo;
3407         int delegate(float) f4 = &x.foo;
3408 
3409         assert(f1(0) == 0);
3410         assert(f2(0) == 1);
3411         assert(f3(0) == 0);
3412         assert(f4(0) == 1);
3413     }
3414 
3415     {
3416         auto x = new B;
3417         auto f1 = cast(int delegate(int))&x.foo;
3418         auto f2 = cast(int delegate(float))&x.foo;
3419         int delegate(int) f3 = &x.foo;
3420         int delegate(float) f4 = &x.foo;
3421 
3422         assert(f1(0) == 0);
3423         assert(f2(0) == 2);
3424         assert(f3(0) == 0);
3425         assert(f4(0) == 2);
3426     }
3427 
3428     {
3429         auto x = new A;
3430         auto f1 = cast(int delegate(int))&x.bar;
3431         auto f2 = cast(int delegate(float))&x.bar;
3432         int delegate(int) f3 = &x.bar;
3433         int delegate(float) f4 = &x.bar;
3434 
3435         assert(f1(0) == 0);
3436         assert(f2(0) == 1);
3437         assert(f3(0) == 0);
3438         assert(f4(0) == 1);
3439     }
3440 
3441     {
3442         auto x = new B;
3443         auto f1 = cast(int delegate(int))&x.bar;
3444         auto f2 = cast(int delegate(float))&x.bar;
3445         int delegate(int) f3 = &x.bar;
3446         int delegate(float) f4 = &x.bar;
3447 
3448         assert(f1(0) == 0);
3449         assert(f2(0) == 2);
3450         assert(f3(0) == 0);
3451         assert(f4(0) == 2);
3452     }
3453 }
3454 
3455 /***************************************************/
3456 
3457 extern(C++)
3458 class C13182
3459 {
3460 }
3461 
3462 void test13182()
3463 {
3464     scope C13182 c = new C13182();
3465 }
3466 
3467 /***************************************************/
3468 // 5897
3469 
3470 struct A148{ int n; }
3471 struct B148{
3472     int n, m;
3473     this(A148 a){ n = a.n, m = a.n*2; }
3474 }
3475 
3476 struct C148{
3477     int n, m;
3478     static C148 opCall(A148 a)
3479     {
3480         C148 b;
3481         b.n = a.n, b.m = a.n*2;
3482         return b;
3483     }
3484 }
3485 
3486 void test148()
3487 {
3488     auto a = A148(10);
3489     auto b = cast(B148)a;
3490     assert(b.n == 10 && b.m == 20);
3491     auto c = cast(C148)a;
3492     assert(c.n == 10 && c.m == 20);
3493 }
3494 
3495 /***************************************************/
3496 // 4969
3497 
3498 class MyException : Exception
3499 {
3500     this()
3501     {
3502         super("An exception!");
3503     }
3504 }
3505 
3506 void throwAway()
3507 {
3508     throw new MyException;
3509 }
3510 
3511 void cantthrow() nothrow
3512 {
3513     try
3514         throwAway();
3515     catch(MyException me)
3516         assert(0);
3517     catch(Exception e)
3518         assert(0);
3519 }
3520 
3521 /***************************************************/
3522 // 2356
3523 
3524 void test2356()
3525 {
3526     int[3] x = [1,2,3];
3527     printf("x[] = [%d %d %d]\n", x[0], x[1], x[2]);
3528     assert(x[0] == 1 && x[1] == 2 && x[2] == 3);
3529 
3530     struct S
3531     {
3532         static int pblit;
3533         int n;
3534         this(this) { ++pblit; printf("postblit: %d\n", n); }
3535     }
3536     S s2 = S(2);
3537     S[3] s = [S(1), s2, S(3)];
3538     assert(s[0].n == 1 && s[1].n == 2 && s[2].n == 3);
3539     printf("s[].n = [%d %d %d]\n", s[0].n, s[1].n, s[2].n);
3540     assert(S.pblit == 1);
3541 
3542     ubyte[1024] v;
3543     v = typeof(v).init;
3544     printf("v[] = [%d %d %d, ..., %d]\n", v[0], v[1], v[2], v[$-1]);
3545     foreach (ref a; v) assert(a == 0);
3546 
3547     int n = 5;
3548     int[3] y = [n, n, n];
3549     printf("y[] = [%d %d %d]\n", y[0], y[1], y[2]);
3550     assert(y[0] == 5 && y[1] == 5 && y[2] == 5);
3551 
3552     S[3] z = [s2, s2, s2];
3553     assert(z[0].n == 2 && z[1].n == 2 && z[2].n == 2);
3554     printf("z[].n = [%d %d %d]\n", z[0].n, z[1].n, z[2].n);
3555     assert(S.pblit == 1 + 3);
3556 
3557     int[0] nsa0 = [];
3558     void[0] vsa0 = [];
3559 
3560     void foo(T)(T){}
3561     foo(vsa0);
3562 
3563     ref int[0] bar() { static int[1] sa; return *cast(int[0]*)&sa; }
3564     bar() = [];
3565 }
3566 
3567 /***************************************************/
3568 // 13652
3569 
3570 void test13652()
3571 {
3572     // reduced case
3573     uint[9][5] arr =
3574         [[0, 0, 0,  0, 1, 5,  8, 0, 7],
3575          [0, 3, 8,  0, 2, 0,  0, 6, 0],
3576          [0, 0, 7,  0, 6, 8,  9, 4, 0],
3577          [0, 0, 0,  0, 0, 1,  2, 9, 0],
3578          [9, 7, 0,  0, 0, 0,  0, 8, 3]];
3579     assert(arr[0][0] == 0 && arr[0][1] == 0 && arr[0][2] == 0 &&
3580            arr[0][3] == 0 && arr[0][4] == 1 && arr[0][5] == 5 &&
3581            arr[0][6] == 8 && arr[0][7] == 0 && arr[0][8] == 7);
3582     assert(arr[1][0] == 0 && arr[1][1] == 3 && arr[1][2] == 8 &&
3583            arr[1][3] == 0 && arr[1][4] == 2 && arr[1][5] == 0 &&
3584            arr[1][6] == 0 && arr[1][7] == 6 && arr[1][8] == 0);
3585     assert(arr[2][0] == 0 && arr[2][1] == 0 && arr[2][2] == 7 &&
3586            arr[2][3] == 0 && arr[2][4] == 6 && arr[2][5] == 8 &&
3587            arr[2][6] == 9 && arr[2][7] == 4 && arr[2][8] == 0);
3588     assert(arr[3][0] == 0 && arr[3][1] == 0 && arr[3][2] == 0 &&
3589            arr[3][3] == 0 && arr[3][4] == 0 && arr[3][5] == 1 &&
3590            arr[3][6] == 2 && arr[3][7] == 9 && arr[3][8] == 0);
3591     assert(arr[4][0] == 9 && arr[4][1] == 7 && arr[4][2] == 0 &&
3592            arr[4][3] == 0 && arr[4][4] == 0 && arr[4][5] == 0 &&
3593            arr[4][6] == 0 && arr[4][7] == 8 && arr[4][8] == 3);
3594 
3595     // original case
3596     uint[9][9] tbl =
3597         [[0, 0, 0,  0, 1, 5,  8, 0, 7],
3598          [0, 3, 8,  0, 2, 0,  0, 6, 0],
3599          [0, 0, 7,  0, 6, 8,  9, 4, 0],
3600          [0, 0, 0,  0, 0, 1,  2, 9, 0],
3601          [9, 7, 0,  0, 0, 0,  0, 8, 3],
3602          [0, 2, 1,  6, 0, 0,  0, 0, 0],
3603          [0, 6, 9,  5, 4, 0,  3, 0, 0],
3604          [0, 4, 0,  0, 8, 0,  6, 5, 0],
3605          [2, 0, 5,  9, 3, 0,  0, 0, 0]];
3606     assert(tbl[0][0] == 0 && tbl[0][1] == 0 && tbl[0][2] == 0 &&
3607            tbl[0][3] == 0 && tbl[0][4] == 1 && tbl[0][5] == 5 &&
3608            tbl[0][6] == 8 && tbl[0][7] == 0 && tbl[0][8] == 7);
3609     assert(tbl[1][0] == 0 && tbl[1][1] == 3 && tbl[1][2] == 8 &&
3610            tbl[1][3] == 0 && tbl[1][4] == 2 && tbl[1][5] == 0 &&
3611            tbl[1][6] == 0 && tbl[1][7] == 6 && tbl[1][8] == 0);
3612     assert(tbl[2][0] == 0 && tbl[2][1] == 0 && tbl[2][2] == 7 &&
3613            tbl[2][3] == 0 && tbl[2][4] == 6 && tbl[2][5] == 8 &&
3614            tbl[2][6] == 9 && tbl[2][7] == 4 && tbl[2][8] == 0);
3615     assert(tbl[3][0] == 0 && tbl[3][1] == 0 && tbl[3][2] == 0 &&
3616            tbl[3][3] == 0 && tbl[3][4] == 0 && tbl[3][5] == 1 &&
3617            tbl[3][6] == 2 && tbl[3][7] == 9 && tbl[3][8] == 0);
3618     assert(tbl[4][0] == 9 && tbl[4][1] == 7 && tbl[4][2] == 0 &&
3619            tbl[4][3] == 0 && tbl[4][4] == 0 && tbl[4][5] == 0 &&
3620            tbl[4][6] == 0 && tbl[4][7] == 8 && tbl[4][8] == 3);
3621     assert(tbl[5][0] == 0 && tbl[5][1] == 2 && tbl[5][2] == 1 &&
3622            tbl[5][3] == 6 && tbl[5][4] == 0 && tbl[5][5] == 0 &&
3623            tbl[5][6] == 0 && tbl[5][7] == 0 && tbl[5][8] == 0);
3624     assert(tbl[6][0] == 0 && tbl[6][1] == 6 && tbl[6][2] == 9 &&
3625            tbl[6][3] == 5 && tbl[6][4] == 4 && tbl[6][5] == 0 &&
3626            tbl[6][6] == 3 && tbl[6][7] == 0 && tbl[6][8] == 0);
3627     assert(tbl[7][0] == 0 && tbl[7][1] == 4 && tbl[7][2] == 0 &&
3628            tbl[7][3] == 0 && tbl[7][4] == 8 && tbl[7][5] == 0 &&
3629            tbl[7][6] == 6 && tbl[7][7] == 5 && tbl[7][8] == 0);
3630     assert(tbl[8][0] == 2 && tbl[8][1] == 0 && tbl[8][2] == 5 &&
3631            tbl[8][3] == 9 && tbl[8][4] == 3 && tbl[8][5] == 0 &&
3632            tbl[8][6] == 0 && tbl[8][6] == 0 && tbl[8][8] == 0);
3633 }
3634 
3635 /***************************************************/
3636 // 11238
3637 
3638 void test11238()
3639 {
3640     int[2] m;
3641     m[0] = 4,m[1] = 6;
3642     //printf("%d,%d\n", m[0], m[1]);
3643     assert(m[0] == 4 && m[1] == 6);
3644 
3645     m = [m[1], m[0]];   // swap
3646     assert(m[0] == 6 && m[1] == 4);
3647     //printf("%d,%d\n", m[0], m[1]);
3648 
3649     m = [m[1], m[0]];   // swap
3650     //printf("%d,%d\n", m[0], m[1]);
3651     assert(m[0] == 4 && m[1] == 6);
3652 }
3653 
3654 /***************************************************/
3655 
3656 void test11805()
3657 {
3658     int i;
3659 
3660     i = 47;
3661     i = 1 && i;
3662     assert(i == 1);
3663     i = 0 || i;
3664     assert(i == 1);
3665 }
3666 
3667 /***************************************************/
3668 
3669 class A2540
3670 {
3671     int a;
3672     int foo() { return 0; }
3673     alias int X;
3674 }
3675 
3676 class B2540 : A2540
3677 {
3678     int b;
3679     override super.X foo() { return 1; }
3680 
3681     alias this athis;
3682     alias this.b thisb;
3683     alias super.a supera;
3684     alias super.foo superfoo;
3685     alias this.foo thisfoo;
3686 }
3687 
3688 struct X2540
3689 {
3690     alias this athis;
3691 }
3692 
3693 void test2540()
3694 {
3695     auto x = X2540.athis.init;
3696     static assert(is(typeof(x) == X2540));
3697 
3698     B2540 b = new B2540();
3699 
3700     assert(&b.a == &b.supera);
3701     assert(&b.b == &b.thisb);
3702     assert(b.thisfoo() == 1);
3703 }
3704 
3705 /***************************************************/
3706 
3707 class B14348
3708 {
3709     int foo() { return 0; }
3710 }
3711 
3712 class C14348 : B14348
3713 {
3714     override int foo() { return 1; }
3715 
3716     alias superfoo = typeof(super).foo;
3717     alias thisfoo = typeof(this).foo;
3718 }
3719 
3720 B14348 test14348()
3721 {
3722     alias foo = typeof(return).foo;  // currently doesn't work.
3723     assert(&B14348.foo is &C14348.superfoo);
3724     assert(&C14348.foo is &C14348.thisfoo);
3725     return null;
3726 }
3727 
3728 /***************************************************/
3729 // 7295
3730 
3731 struct S7295
3732 {
3733     int member;
3734     @property ref int refCountedPayload() { return member; }
3735     alias refCountedPayload this;
3736 }
3737 
3738 void foo7295(S)(immutable S t, int qq) pure { }
3739 void foo7295(S)(S s) pure { }
3740 
3741 void bar7295() pure
3742 {
3743     S7295 b;
3744     foo7295(b);
3745 }
3746 
3747 /***************************************************/
3748 // 5659
3749 
3750 void test149()
3751 {
3752     import std.traits;
3753 
3754     char a;
3755     immutable(char) b;
3756 
3757     static assert(is(typeof(true ? a : b) == const(char)));
3758     static assert(is(typeof([a, b][0]) == const(char)));
3759 
3760     static assert(is(CommonType!(typeof(a), typeof(b)) == const(char)));
3761 }
3762 
3763 
3764 /***************************************************/
3765 // 1373
3766 
3767 void func1373a(){}
3768 
3769 static assert(typeof(func1373a).stringof == "void()");
3770 static assert(typeof(func1373a).mangleof == "FZv");
3771 static assert(!__traits(compiles, typeof(func1373a).alignof));
3772 static assert(!__traits(compiles, typeof(func1373a).init));
3773 static assert(!__traits(compiles, typeof(func1373a).offsetof));
3774 
3775 void func1373b(int n){}
3776 
3777 static assert(typeof(func1373b).stringof == "void(int n)");
3778 static assert(typeof(func1373b).mangleof == "FiZv");
3779 static assert(!__traits(compiles, typeof(func1373b).alignof));
3780 static assert(!__traits(compiles, typeof(func1373b).init));
3781 static assert(!__traits(compiles, typeof(func1373b).offsetof));
3782 
3783 /***************************************************/
3784 
3785 void bar150(T)(T n) {  }
3786 
3787 @safe void test150()
3788 {
3789     bar150(1);
3790 }
3791 
3792 /***************************************************/
3793 
3794 void test5785()
3795 {
3796     static struct x { static int y; }
3797     assert(x.y !is 1);
3798     assert(x.y !in [1:0]);
3799 }
3800 
3801 /***************************************************/
3802 
3803 void bar151(T)(T n) {  }
3804 
3805 nothrow void test151()
3806 {
3807     bar151(1);
3808 }
3809 
3810 /***************************************************/
3811 
3812 @property int coo() { return 1; }
3813 @property auto doo(int i) { return i; }
3814 
3815 @property int eoo() { return 1; }
3816 @property auto ref hoo(int i) { return i; }
3817 
3818 // 3359
3819 
3820 int goo(int i) pure { return i; }
3821 auto ioo(int i) pure { return i; }
3822 auto ref boo(int i) pure nothrow { return i; }
3823 
3824 class A152 {
3825     auto hoo(int i) pure  { return i; }
3826     const boo(int i) nothrow { return i; }
3827     auto coo(int i) const { return i; }
3828     auto doo(int i) immutable { return i; }
3829     auto eoo(int i) shared { return i; }
3830 }
3831 
3832 // 4706
3833 
3834 struct Foo152(T) {
3835     @property auto ref front() {
3836         return T.init;
3837     }
3838 
3839     @property void front(T num) {}
3840 }
3841 
3842 void test152() {
3843     Foo152!int foo;
3844     auto a = foo.front;
3845     foo.front = 2;
3846 }
3847 
3848 /***************************************************/
3849 // 6733
3850 
3851 void bug6733(int a, int b) pure nothrow { }
3852 void test6733() {
3853    int z = 1;
3854    bug6733(z++, z++);
3855    assert(z==3);
3856 }
3857 
3858 /***************************************************/
3859 // 3799
3860 
3861 void test153()
3862 {
3863     void bar()
3864     {
3865     }
3866 
3867     static assert(!__traits(isStaticFunction, bar));
3868 }
3869 
3870 /***************************************************/
3871 // 3632
3872 
3873 
3874 void test154() {
3875     float f;
3876     assert(f is float.init);
3877     double d;
3878     assert(d is double.init);
3879     real r;
3880     assert(r is real.init);
3881 
3882     assert(float.nan is float.nan);
3883     assert(double.nan is double.nan);
3884     assert(real.nan is real.nan);
3885 }
3886 
3887 /***************************************************/
3888 
3889 void test6545()
3890 {
3891     static int[] func()
3892     {
3893         auto a = [1, 2, 3];
3894         auto b = [2, 3, 4];
3895         auto c = [3, 4, 5];
3896 
3897         a[] = b[] + c[];
3898 
3899         return a;
3900     }
3901 
3902     auto a = func();
3903     enum b = func();
3904     assert(a == b);
3905 }
3906 
3907 /***************************************************/
3908 // 3147
3909 
3910 
3911 void test155()
3912 {
3913     byte b = 1;
3914     short s;
3915     int i;
3916     long l;
3917 
3918     s = b + b;
3919     b = s % b;
3920     s = s >> b;
3921     b = 1;
3922     b = i % b;
3923     b = b >> i;
3924 }
3925 
3926 /***************************************************/
3927 // 2486
3928 
3929 void test2486()
3930 {
3931     void foo(ref int[] arr) {}
3932 
3933     int[] arr = [1,2,3];
3934     foo(arr);   //OK
3935     static assert(!__traits(compiles, foo(arr[1..2]))); // should be NG
3936 
3937     struct S
3938     {
3939         int[] a;
3940         auto ref opSlice(){ return a[]; }  // line 4
3941     }
3942     S s;
3943     s[];
3944     // opSlice should return rvalue
3945     static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe));
3946     static assert(!__traits(compiles, foo(s[])));       // should be NG
3947 }
3948 
3949 /***************************************************/
3950 
3951 extern(C++) class C15080
3952 {
3953     uint x = 1;
3954     uint y = 2;
3955 }
3956 
3957 __gshared c15080 = new C15080();
3958 
3959 void test15080()
3960 {
3961     assert(c15080.x == 1);
3962     assert(c15080.y == 2);
3963 }
3964 
3965 /***************************************************/
3966 // 2521
3967 
3968 immutable int val = 23;
3969 const int val2 = 23;
3970 
3971 ref immutable(int) func2521_() {
3972     return val;
3973 }
3974 ref immutable(int) func2521_2() {
3975     return *&val;
3976 }
3977 ref immutable(int) func2521_3() {
3978     return func2521_;
3979 }
3980 ref const(int) func2521_4() {
3981     return val2;
3982 }
3983 ref const(int) func2521_5() {
3984     return val;
3985 }
3986 auto ref func2521_6() {
3987     return val;
3988 }
3989 ref func2521_7() {
3990     return val;
3991 }
3992 
3993 /***************************************************/
3994 
3995 void test5554()
3996 {
3997     class MA { }
3998     class MB : MA { }
3999     class MC : MB { }
4000 
4001     class A { abstract MA foo(); }
4002     interface I { MB foo(); }
4003     class B : A
4004     {
4005         override MC foo() { return null; }
4006     }
4007     class C : B, I
4008     {
4009         override MC foo() { return null; }
4010     }
4011 }
4012 
4013 /***************************************************/
4014 // 5962
4015 
4016 struct S156
4017 {
4018           auto g()(){ return 1; }
4019     const auto g()(){ return 2; }
4020 }
4021 
4022 void test156()
4023 {
4024     auto ms = S156();
4025     assert(ms.g() == 1);
4026     auto cs = const(S156)();
4027     assert(cs.g() == 2);
4028 }
4029 
4030 /***************************************************/
4031 
4032 void test10724()
4033 {
4034     const(char)* s = "abc"[0..$-1];
4035     assert(s[2] == '\0');
4036 }
4037 
4038 /***************************************************/
4039 
4040 void test6708(const ref int y)
4041 {
4042     immutable int x;
4043     test6708(x);
4044 }
4045 
4046 /***************************************************/
4047 // 4258
4048 
4049 struct Vec4258 {
4050     Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") {
4051         return this;
4052     }
4053     Vec4258 opBinary(string Op:"+")(Vec4258 other) {
4054         Vec4258 result;
4055         return result += other;
4056     }
4057 }
4058 void test4258() {
4059     Vec4258 v;
4060     v += Vec4258() + Vec4258(); // line 12
4061 }
4062 
4063 // regression fix test
4064 
4065 struct Foo4258 {
4066     // binary ++/--
4067     int opPostInc()() if (false) { return 0; }
4068 
4069     // binary 1st
4070     int opAdd(R)(R rhs) if (false) { return 0; }
4071     int opAdd_r(R)(R rhs) if (false) { return 0; }
4072 
4073     // compare
4074     int opCmp(R)(R rhs) if (false) { return 0; }
4075 
4076     // binary-op assign
4077     int opAddAssign(R)(R rhs) if (false) { return 0; }
4078 }
4079 struct Bar4258 {
4080     // binary commutive 1
4081     int opAdd_r(R)(R rhs) if (false) { return 0; }
4082 
4083     // binary-op assign
4084     int opOpAssign(string op, R)(R rhs) if (false) { return 0; }
4085 }
4086 struct Baz4258 {
4087     // binary commutive 2
4088     int opAdd(R)(R rhs) if (false) { return 0; }
4089 }
4090 static assert(!is(typeof(Foo4258.init++)));
4091 static assert(!is(typeof(Foo4258.init + 1)));
4092 static assert(!is(typeof(1 + Foo4258.init)));
4093 static assert(!is(typeof(Foo4258.init < Foo4258.init)));
4094 static assert(!is(typeof(Foo4258.init += 1)));
4095 static assert(!is(typeof(Bar4258.init + 1)));
4096 static assert(!is(typeof(Bar4258.init += 1)));
4097 static assert(!is(typeof(1 + Baz4258.init)));
4098 
4099 /***************************************************/
4100 // 4539
4101 
4102 void test4539()
4103 {
4104     static assert(!__traits(compiles, "hello" = "red"));
4105 
4106     void foo1(ref string s){}
4107     void foo2(ref const char[10] s){}
4108     void foo3(ref char[5] s){}
4109 
4110     void foo4(ref const char[5] s)
4111     {
4112         assert(s[0] == 'h');
4113         assert(s[4] == 'o');
4114     }
4115     void foo5(ref const ubyte[5] s)
4116     {
4117         assert(s[0] == 0xc3);
4118         assert(s[4] == 0x61);
4119     }
4120 
4121     static assert(!__traits(compiles, foo1("hello")));
4122     static assert(!__traits(compiles, foo2("hello")));
4123     static assert(!__traits(compiles, foo3("hello")));
4124 
4125     // same as test68, 69, 70
4126     foo4("hello");
4127     foo5(cast(ubyte[5])x"c3fcd3d761");
4128 
4129     //import std.conv;
4130     //static assert(!__traits(compiles, parse!int("10") == 10));
4131 }
4132 
4133 /***************************************************/
4134 // 1471
4135 
4136 void test1471()
4137 {
4138     int n;
4139     string bar = "BOOM"[n..$-1];
4140     assert(bar == "BOO");
4141 }
4142 
4143 /***************************************************/
4144 
4145 deprecated @disable int bug6389;
4146 static assert(!is(typeof(bug6389 = bug6389)));
4147 
4148 /***************************************************/
4149 
4150 void test10927()
4151 {
4152     static assert( (1+2i) ^^ 3 == -11 - 2i );
4153     auto a = (1+2i) ^^ 3;
4154 }
4155 
4156 /***************************************************/
4157 
4158 void test4963()
4159 {
4160     struct Value {
4161         byte a;
4162     }
4163     Value single()
4164     {
4165         return Value();
4166     }
4167 
4168     Value[] list;
4169     auto x = single() ~ list;
4170 }
4171 
4172 /***************************************************/
4173 
4174 pure int test4031()
4175 {
4176     static const int x = 8;
4177     return x;
4178 }
4179 
4180 /***************************************************/
4181 // 5437
4182 
4183 template EnumMembers5437(E)
4184 {
4185     template TypeTuple(T...){ alias T TypeTuple; }
4186 
4187     alias TypeTuple!("A", "B") EnumMembers5437;
4188 }
4189 template IntValue5437()
4190 {
4191     int IntValue5437 = 10;
4192 }
4193 
4194 void test5437()
4195 {
4196     enum Foo { A, B }
4197     alias EnumMembers5437!Foo members;      // OK
4198     enum n1 = members.length;               // OK
4199     enum n2 = (EnumMembers5437!Foo).length; // NG, type -> symbol
4200 
4201     enum s1 = IntValue5437!().sizeof;       // OK
4202     enum s2 = (IntValue5437!()).sizeof;     // NG, type -> expression
4203 }
4204 
4205 /***************************************************/
4206 // 1962
4207 
4208 
4209 void test1962()
4210 {
4211     class C { abstract void x(); }
4212     assert(C.classinfo.create() is null);
4213 }
4214 
4215 /***************************************************/
4216 // 6228
4217 
4218 
4219 void test6228()
4220 {
4221     const(int)* ptr;
4222     const(int)  temp;
4223     auto x = (*ptr) ^^ temp;
4224 }
4225 
4226 /***************************************************/
4227 
4228 int test7544()
4229 {
4230     try { throw new Exception(""); }
4231     catch (Exception e) static assert(1);
4232     return 1;
4233 }
4234 
4235 static assert(test7544());
4236 
4237 /***************************************************/
4238 
4239 struct S6230 {
4240     int p;
4241     int q() const pure {
4242         return p;
4243     }
4244     void r() pure {
4245         p = 231;
4246     }
4247 }
4248 class C6230 {
4249     int p;
4250     int q() const pure {
4251         return p;
4252     }
4253     void r() pure {
4254         p = 552;
4255     }
4256 }
4257 int q6230(ref const S6230 s) pure {    // <-- Currently OK
4258     return s.p;
4259 }
4260 int q6230(ref const C6230 c) pure {    // <-- Currently OK
4261     return c.p;
4262 }
4263 void r6230(ref S6230 s) pure {
4264     s.p = 244;
4265 }
4266 void r6230(ref C6230 c) pure {
4267     c.p = 156;
4268 }
4269 bool test6230pure() pure {
4270     auto s = S6230(4);
4271     assert(s.p == 4);
4272     assert(q6230(s) == 4);
4273     assert(s.q == 4);
4274 
4275     auto c = new C6230;
4276     c.p = 6;
4277     assert(q6230(c) == 6);
4278     assert(c.q == 6);
4279 
4280     r6230(s);
4281     assert(s.p == 244);
4282     s.r();
4283     assert(s.p == 231);
4284 
4285     r6230(c);
4286     assert(c.p == 156);
4287     c.r();
4288     assert(c.p == 552);
4289 
4290     return true;
4291 }
4292 void test6230() {
4293     assert(test6230pure());
4294 }
4295 
4296 /***************************************************/
4297 
4298 void test6264()
4299 {
4300     struct S { auto opSlice() { return this; } }
4301     int[] a;
4302     S s;
4303     static assert(!is(typeof(a[] = s[])));
4304     int*[] b;
4305     static assert(is(typeof(b[] = [new immutable(int)])));
4306     char[] c = new char[](5);
4307     c[] = "hello";
4308 }
4309 
4310 /***************************************************/
4311 // 5046
4312 
4313 void test5046()
4314 {
4315     auto va = S5046!("", int)();
4316     auto vb = makeS5046!("", int)();
4317 }
4318 
4319 struct S5046(alias p, T)
4320 {
4321     T s;
4322     T fun() { return s; }   // (10)
4323 }
4324 
4325 S5046!(p, T) makeS5046(alias p, T)()
4326 {
4327     return typeof(return)();
4328 }
4329 
4330 /***************************************************/
4331 // 6335
4332 
4333 struct S6335
4334 {
4335     const int value;
4336     this()(int n){ value = n; }
4337 }
4338 void test6335()
4339 {
4340     S6335 s = S6335(10);
4341 }
4342 
4343 /***************************************************/
4344 
4345 struct S6295(int N) {
4346     int[N] x;
4347     const nothrow pure @safe f() { return x.length; }
4348 }
4349 
4350 void test6295() {
4351     auto bar(T: S6295!(N), int N)(T x) {
4352         return x.f();
4353     }
4354     S6295!4 x;
4355     assert(bar(x) == 4);
4356 }
4357 
4358 /***************************************************/
4359 
4360 template TT4536(T...) { alias T TT4536; }
4361 
4362 void test4536()
4363 {
4364     auto x = TT4536!(int, long, [1, 2]).init;
4365     assert(x[0] is int.init);
4366     assert(x[1] is long.init);
4367     assert(x[2] is [1, 2].init);
4368 }
4369 
4370 /***************************************************/
4371 
4372 struct S6284 {
4373     int a;
4374 }
4375 class C6284 {
4376     int a;
4377 }
4378 pure int bug6284a() {
4379     S6284 s = {4};
4380     auto b = s.a;   // ok
4381     with (s) {
4382         b += a;     // should be ok.
4383     }
4384     return b;
4385 }
4386 pure int bug6284b() {
4387     auto s = new S6284;
4388     s.a = 4;
4389     auto b = s.a;
4390     with (*s) {
4391         b += a;
4392     }
4393     return b;
4394 }
4395 pure int bug6284c() {
4396     auto s = new C6284;
4397     s.a = 4;
4398     auto b = s.a;
4399     with (s) {
4400         b += a;
4401     }
4402     return b;
4403 }
4404 void test6284() {
4405     assert(bug6284a() == 8);
4406     assert(bug6284b() == 8);
4407     assert(bug6284c() == 8);
4408 }
4409 
4410 /***************************************************/
4411 
4412 class C6293 {
4413     C6293 token;
4414 }
4415 void f6293(in C6293[] a) pure {
4416     auto x0 = a[0].token;
4417     assert(x0 is a[0].token.token.token);
4418     assert(x0 is (&x0).token);
4419     auto p1 = &x0 + 1;
4420     assert(x0 is (p1 - 1).token);
4421     int c = 0;
4422     assert(x0 is a[c].token);
4423 }
4424 void test6293() {
4425     auto x = new C6293;
4426     x.token = x;
4427     f6293([x]);
4428 }
4429 
4430 /***************************************************/
4431 // 3733
4432 
4433 class C3733
4434 {
4435     int foo()        { return 1; }
4436     int foo() shared { return 2; }
4437 
4438     int bar()        { return foo(); }
4439 }
4440 void test3733()
4441 {
4442     auto c = new C3733();
4443     assert(c.bar() == 1);
4444 }
4445 
4446 /***************************************************/
4447 // 4392
4448 
4449 class C4392
4450 {
4451     int foo() const { return 1; }
4452     int foo()       { return 2; }
4453 
4454     int bar() const { return foo(); }
4455 }
4456 void test4392()
4457 {
4458     auto c = new C4392();
4459     assert(c.bar() == 1);
4460 }
4461 
4462 /***************************************************/
4463 // 6220
4464 
4465 void test6220() {
4466     struct Foobar { real x; real y; real z;}
4467     switch("x") {
4468         foreach(i,member; __traits(allMembers, Foobar)) {
4469             case member : break;
4470         }
4471     default : break;
4472     }
4473 }
4474 
4475 /***************************************************/
4476 // 5799
4477 
4478 void test5799()
4479 {
4480     int a;
4481     int *u = &(a ? a : (a ? a : a));
4482     assert(u == &a);
4483 }
4484 
4485 /***************************************************/
4486 // 6529
4487 
4488 enum Foo6529 : char { A='a' }
4489 ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; }
4490 
4491 /***************************************************/
4492 
4493 void test783()
4494 {
4495     const arr = [ 1,2,3 ];
4496     const i = 2;
4497     auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]"
4498 }
4499 
4500 /***************************************************/
4501 
4502 template X157(alias x)
4503 {
4504     alias x X157;
4505 }
4506 
4507 template Parent(alias foo)
4508 {
4509     alias X157!(__traits(parent, foo)) Parent;
4510 }
4511 
4512 template ParameterTypeTuple(alias foo)
4513 {
4514     static if (is(typeof(foo) P == function))
4515         alias P ParameterTypeTuple;
4516     else
4517         static assert(0, "argument has no parameters");
4518 }
4519 
4520 template Mfp(alias foo)
4521 {
4522     auto Mfp = function(Parent!foo self, ParameterTypeTuple!foo i) { return self.foo(i); };
4523 }
4524 
4525 class C157 {
4526  int a = 3;
4527  int foo(int i, int y) { return i + a + y; }
4528 }
4529 
4530 void test157()
4531 {
4532     auto c = new C157();
4533     auto mfp = Mfp!(C157.foo);
4534     auto i = mfp(c, 1, 7);
4535     assert(i == 11);
4536 }
4537 
4538 /***************************************************/
4539 // 6473
4540 
4541 struct Eins6473
4542 {
4543     ~this() {}
4544 }
4545 
4546 struct Zwei6473
4547 {
4548     void build(Eins6473 devices = Eins6473())
4549     {
4550     }
4551 }
4552 
4553 void build(Eins6473 devices = Eins6473())
4554 {}
4555 
4556 void test6473()
4557 {
4558     void build(Eins6473 devices = Eins6473())
4559     {}
4560 }
4561 
4562 /***************************************************/
4563 
4564 uint rol11417(uint n)(in uint x)
4565 {
4566     return x << n | x >> 32 - n;
4567 }
4568 
4569 uint ror11417(uint n)(in uint x)
4570 {
4571     return x >> n | x << 32 - n;
4572 }
4573 
4574 void test11417()
4575 {
4576     assert(rol11417!1(0x8000_0000) == 0x1);
4577     assert(ror11417!1(0x1) == 0x8000_0000);
4578 }
4579 
4580 /***************************************************/
4581 
4582 void test6578()
4583 {
4584     static struct Foo
4585     {
4586         this(int x) pure {}
4587     }
4588     auto f1 = new const(Foo)(1);
4589     auto f2 = new immutable(Foo)(1);
4590     auto f3 = new shared(Foo)(1);
4591     auto f4 = const(Foo)(1);
4592     auto f5 = immutable(Foo)(1);
4593     auto f6 = shared(Foo)(1);
4594     static assert(is(typeof(f1) == const(Foo)*));
4595     static assert(is(typeof(f2) == immutable(Foo)*));
4596     static assert(is(typeof(f3) == shared(Foo)*));
4597     static assert(is(typeof(f4) == const(Foo)));
4598     static assert(is(typeof(f5) == immutable(Foo)));
4599     static assert(is(typeof(f6) == shared(Foo)));
4600 
4601     static struct Bar
4602     {
4603         this(int x) const pure {}
4604     }
4605     auto g1 = new const(Bar)(1);
4606     auto g2 = new immutable(Bar)(1);
4607     auto g3 = new shared(Bar)(1);
4608     auto g4 = const(Bar)(1);
4609     auto g5 = immutable(Bar)(1);
4610     auto g6 = shared(Bar)(1);
4611     static assert(is(typeof(g1) == const(Bar)*));
4612     static assert(is(typeof(g2) == immutable(Bar)*));
4613     static assert(is(typeof(g3) == shared(Bar)*));
4614     static assert(is(typeof(g4) == const(Bar)));
4615     static assert(is(typeof(g5) == immutable(Bar)));
4616     static assert(is(typeof(g6) == shared(Bar)));
4617 
4618     static struct Baz
4619     {
4620         this()(int x) const pure {}
4621     }
4622     auto h1 = new const(Baz)(1);
4623     auto h2 = new immutable(Baz)(1);
4624     auto h3 = new shared(const(Baz))(1);
4625     auto h4 = const(Baz)(1);
4626     auto h5 = immutable(Baz)(1);
4627     auto h6 = shared(const(Baz))(1);
4628     static assert(is(typeof(h1) == const(Baz)*));
4629     static assert(is(typeof(h2) == immutable(Baz)*));
4630     static assert(is(typeof(h3) == shared(const(Baz))*));
4631     static assert(is(typeof(h4) == const(Baz)));
4632     static assert(is(typeof(h5) == immutable(Baz)));
4633     static assert(is(typeof(h6) == shared(const(Baz))));
4634 }
4635 
4636 /***************************************************/
4637 // 6630
4638 
4639 void test6630()
4640 {
4641     static class B {}
4642 
4643     static class A
4644     {
4645         this() { b = new B(); }
4646         B b;
4647         alias b this;
4648     }
4649 
4650     void fun(A a)
4651     {
4652         a = null;
4653         assert(a is null);
4654     }
4655 
4656     auto a = new A;
4657     assert(a.b !is null);
4658     fun(a);
4659     assert(a !is null);
4660     assert(a.b !is null);
4661 }
4662 
4663 /***************************************************/
4664 
4665 int i199 = 1;
4666 
4667 void test199()
4668 {
4669     label:
4670     {
4671         int i199 = 2;
4672     }
4673     assert(i199 == 1);
4674 }
4675 
4676 /***************************************************/
4677 // 6690
4678 
4679 T useLazy6690(T)(lazy T val)
4680 {
4681     return val;
4682     // val is converted to delegate call, but it is typed as int delegate() - not @safe!
4683 }
4684 void test6690() @safe
4685 {
4686     useLazy6690(0);
4687     // Error: safe function 'test6690' cannot call system function 'useLazy6690'
4688 }
4689 
4690 /***************************************************/
4691 
4692 template Hoge6691()
4693 {
4694     immutable static int[int] dict;
4695     immutable static int value;
4696 
4697     static this()
4698     {
4699         dict = [1:1, 2:2];
4700         value = 10;
4701     }
4702 }
4703 alias Hoge6691!() H6691;
4704 
4705 /***************************************************/
4706 
4707 void test10626()
4708 {
4709     double[2] v, x;
4710     struct Y { double u; }
4711     double z;
4712     Y y;
4713     double[2] r = v[] * x[0];
4714     //double[2] s = v[] * z++;
4715     //double[2] t = v[] * z--;
4716     double[2] a = v[] * ++z;
4717     double[2] b = v[] * --z;
4718     double[2] c = v[] * y.u;
4719     double[2] d = v[] * (x[] = 3, x[0]);
4720     double[2] e = v[] * (v[] ~ z)[0];
4721 }
4722 
4723 
4724 /***************************************************/
4725 // 2953
4726 
4727 template Tuple2953(T...)
4728 {
4729     alias T Tuple2953;
4730 }
4731 template Range2953(int b)
4732 {
4733     alias Tuple2953!(1) Range2953;
4734 }
4735 void foo2953()()
4736 {
4737     Tuple2953!(int, int) args;
4738     foreach( x ; Range2953!(args.length) ){ }
4739 }
4740 void test2953()
4741 {
4742     foo2953!()();
4743 }
4744 
4745 /***************************************************/
4746 // 2997
4747 
4748 abstract class B2997 { void foo(); }
4749 interface I2997 { void bar(); }
4750 abstract class C2997 : B2997, I2997 {}
4751 //pragma(msg, __traits(allMembers, C).stringof);
4752 
4753 void test2997()
4754 {
4755     enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
4756 
4757     static assert([__traits(allMembers, C2997)] == ["foo"] ~ ObjectMembers ~ ["bar"]);
4758 }
4759 
4760 /***************************************************/
4761 // 6596
4762 
4763 extern (C) int function() pfunc6596;
4764 extern (C) int cfunc6596(){ return 0; }
4765 static assert(typeof(pfunc6596).stringof == "extern (C) int function()");
4766 static assert(typeof(cfunc6596).stringof == "extern (C) int()");
4767 
4768 
4769 /***************************************************/
4770 // 4423
4771 
4772 struct S4423
4773 {
4774     this(string phrase, int num)
4775     {
4776         this.phrase = phrase;
4777         this.num = num;
4778     }
4779 
4780     int opCmp(const ref S4423 rhs)
4781     {
4782         if (phrase < rhs.phrase)
4783             return -1;
4784         else if (phrase > rhs.phrase)
4785             return 1;
4786 
4787         if (num < rhs.num)
4788             return -1;
4789         else if (num > rhs.num)
4790             return 1;
4791 
4792         return 0;
4793     }
4794 
4795     string phrase;
4796     int    num;
4797 }
4798 
4799 enum E4423 : S4423
4800 {
4801     a = S4423("hello", 1),
4802     b = S4423("goodbye", 45),
4803     c = S4423("world", 22),
4804 };
4805 
4806 void test4423()
4807 {
4808     E4423 e;
4809     assert(e.phrase == "hello");
4810 
4811     e = E4423.b;
4812     assert(e.phrase == "goodbye");
4813 }
4814 
4815 /***************************************************/
4816 // 4647
4817 
4818 interface Timer
4819 {
4820     final int run() { printf("Timer.run()\n"); fun(); return 1; };
4821     int fun();
4822 }
4823 
4824 interface Application
4825 {
4826     final int run() { printf("Application.run()\n"); fun(); return 2; };
4827     int fun();
4828 }
4829 
4830 class TimedApp : Timer, Application
4831 {
4832     int funCalls;
4833     override int fun()
4834     {
4835         printf("TimedApp.fun()\n");
4836         funCalls++;
4837         return 2;
4838     }
4839 }
4840 
4841 class SubTimedApp : TimedApp
4842 {
4843     int subFunCalls;
4844 
4845     override int fun()
4846     {
4847         printf("SubTimedApp.fun()\n");
4848         subFunCalls++;
4849         return 1;
4850     }
4851 }
4852 
4853 void test4647()
4854 {
4855     //Test access to TimedApps base interfaces
4856     auto app = new TimedApp();
4857     assert((cast(Application)app).run() == 2);
4858     assert((cast(Timer)app).run() == 1);
4859     assert(app.Timer.run() == 1); // error, no Timer property
4860     assert(app.Application.run() == 2); // error, no Application property
4861     assert(app.run() == 1);             // This would call Timer.run() if the two calls
4862                                         // above were commented out
4863     assert(app.funCalls == 5);
4864 
4865     assert(app.TimedApp.fun() == 2);
4866     assert(app.funCalls == 6);
4867 
4868     //Test direct access to SubTimedApp interfaces
4869     auto app2 = new SubTimedApp();
4870     assert((cast(Application)app2).run() == 2);
4871     assert((cast(Timer)app2).run() == 1);
4872     assert(app2.Application.run() == 2);
4873     assert(app2.Timer.run() == 1);
4874     assert(app2.funCalls == 0);
4875     assert(app2.subFunCalls == 4);
4876 
4877     assert(app2.fun() == 1);
4878     assert(app2.SubTimedApp.fun() == 1);
4879     assert(app2.funCalls == 0);
4880     assert(app2.subFunCalls == 6);
4881 
4882     //Test access to SubTimedApp interfaces via TimedApp
4883     auto app3 = new SubTimedApp();
4884     (cast(Timer)cast(TimedApp)app3).run();
4885     app3.TimedApp.Timer.run();
4886     assert((cast(Application)cast(TimedApp)app3).run() == 2);
4887     assert((cast(Timer)cast(TimedApp)app3).run() == 1);
4888     assert(app3.TimedApp.Application.run() == 2);
4889     assert(app3.TimedApp.Timer.run() == 1);
4890     assert(app3.funCalls == 0);
4891     assert(app3.subFunCalls == 6);
4892 }
4893 
4894 /***************************************************/
4895 
4896 template T1064(E...) { alias E T1064; }
4897 
4898 int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ];
4899 
4900 void test1064()
4901 {
4902     assert(var1064 == [1,2,3,4,5,6]);
4903 }
4904 
4905 /***************************************************/
4906 // 5696
4907 
4908 template Seq5696(T...){ alias T Seq5696; }
4909 template Pred5696(T) { alias T Pred5696; }  // TOKtemplate
4910 template Scope5696(int n){ template X(T) { alias T X; } }   // TOKimport
4911 T foo5696(T)(T x) { return x; }
4912 void test5696()
4913 {
4914     foreach (pred; Seq5696!(Pred5696, Pred5696))
4915     {
4916         static assert(is(pred!int == int));
4917     }
4918 
4919     foreach (scop; Seq5696!(Scope5696!0, Scope5696!1))
4920     {
4921         static assert(is(scop.X!int == int));
4922     }
4923 
4924     alias Seq5696!(foo5696, foo5696) funcs;
4925     assert(funcs[0](0) == 0);
4926     assert(funcs[1](1) == 1);
4927     foreach (i, fn; funcs)
4928     {
4929         assert(fn(i) == i);
4930     }
4931 }
4932 
4933 /***************************************************/
4934 // 5933
4935 
4936 int dummyfunc5933();
4937 alias typeof(dummyfunc5933) FuncType5933;
4938 
4939 struct S5933a { auto x() { return 0; } }
4940 static assert(is(typeof(&S5933a.init.x) == int delegate() pure nothrow @nogc @safe));
4941 
4942 struct S5933b { auto x() { return 0; } }
4943 //static assert(is(typeof(S5933b.init.x) == FuncType5933));
4944 
4945 struct S5933c { auto x() { return 0; } }
4946 static assert(is(typeof(&S5933c.x) == int function()));
4947 
4948 struct S5933d { auto x() { return 0; } }
4949 static assert(is(typeof(S5933d.x) == FuncType5933));
4950 
4951 
4952 class C5933a { auto x() { return 0; } }
4953 static assert(is(typeof(&(new C5933b()).x) == int delegate()));
4954 
4955 class C5933b { auto x() { return 0; } }
4956 //static assert(is(typeof((new C5933b()).x) == FuncType5933));
4957 
4958 class C5933c { auto x() { return 0; } }
4959 static assert(is(typeof(&C5933c.x) == int function()));
4960 
4961 class C5933d { auto x() { return 0; } }
4962 static assert(is(typeof(C5933d.x) == FuncType5933));
4963 
4964 /***************************************************/
4965 // 6084
4966 
4967 template TypeTuple6084(T...){ alias T TypeTuple6084; }
4968 void test6084()
4969 {
4970     int foo(int x)() { return x; }
4971     foreach(i; TypeTuple6084!(0))
4972         foo!(i);
4973 }
4974 
4975 /***************************************************/
4976 // 6763
4977 
4978 template TypeTuple6763(TList...)
4979 {
4980     alias TList TypeTuple6763;
4981 }
4982 
4983 alias TypeTuple6763!(int) T6763;
4984 
4985 void f6763(      T6763) { } ///
4986 void c6763(const T6763) { } ///T now is (const int)
4987 void r6763(ref   T6763) { } ///T now is(ref const int)
4988 void i6763(in    T6763) { } ///Uncomment to get an Assertion failure in 'mtype.c'
4989 void o6763(out   T6763) { } ///ditto
4990 
4991 void test6763()
4992 {
4993     int n;
4994 
4995     f6763(0);   //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int)
4996     c6763(0);
4997     r6763(n);   static assert(!__traits(compiles, r6763(0)));
4998     i6763(0);
4999     o6763(n);   static assert(!__traits(compiles, o6763(0)));
5000 
5001     // 6755
5002     static assert(typeof(f6763).stringof == "void(int _param_0)");
5003     static assert(typeof(c6763).stringof == "void(const(int) _param_0)");
5004     static assert(typeof(r6763).stringof == "void(ref int _param_0)");
5005     static assert(typeof(i6763).stringof == "void(const(int) _param_0)");
5006     static assert(typeof(o6763).stringof == "void(out int _param_0)");
5007 }
5008 
5009 /***************************************************/
5010 // 6695
5011 
5012 struct X6695
5013 {
5014     void mfunc()
5015     {
5016         static assert(is(typeof(this) == X6695));
5017     }
5018     void cfunc() const
5019     {
5020         static assert(is(typeof(this) == const(X6695)));
5021     }
5022     void ifunc() immutable
5023     {
5024         static assert(is(typeof(this) == immutable(X6695)));
5025     }
5026     void sfunc() shared
5027     {
5028         static assert(is(typeof(this) == shared(X6695)));
5029     }
5030     void scfunc() shared const
5031     {
5032         static assert(is(typeof(this) == shared(const(X6695))));
5033     }
5034     void wfunc() inout
5035     {
5036         static assert(is(typeof(this) == inout(X6695)));
5037     }
5038     void swfunc() shared inout
5039     {
5040         static assert(is(typeof(this) == shared(inout(X6695))));
5041     }
5042 
5043     static assert(is(typeof(this) == X6695));
5044 }
5045 
5046 /***************************************************/
5047 // 6087
5048 
5049 template True6087(T)
5050 {
5051     immutable True6087 = true;
5052 }
5053 struct Foo6087
5054 {
5055     static assert( True6087!(typeof(this)) );
5056 }
5057 
5058 struct Bar6087
5059 {
5060     static assert( is(typeof(this) == Bar6087) );
5061 }
5062 
5063 /***************************************************/
5064 // 6848
5065 
5066 class Foo6848 {}
5067 
5068 class Bar6848 : Foo6848
5069 {
5070     void func() immutable
5071     {
5072         static assert(is(typeof(this) == immutable(Bar6848)));  // immutable(Bar6848)
5073         auto t = this;
5074         static assert(is(typeof(t) == immutable(Bar6848)));     // immutable(Bar6848)
5075 
5076         static assert(is(typeof(super) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848)
5077         auto s = super;
5078         static assert(is(typeof(s) == immutable(Foo6848)));     // Foo6848 instead of immutable(Foo6848)
5079     }
5080 }
5081 
5082 /***************************************************/
5083 
5084 version(none)
5085 {
5086     cent issue785;
5087     ucent issue785;
5088 }
5089 
5090 static assert(is(cent) && is(ucent) || !is(cent) && !is(ucent));
5091 static if (is(cent))
5092   static assert(__traits(compiles, { cent x; }));
5093 else
5094   static assert(!__traits(compiles, { cent x; }));
5095 
5096 /***************************************************/
5097 // 6847
5098 
5099 template True6847(T)
5100 {
5101     immutable True6847 = true;
5102 }
5103 class Foo6847
5104 {}
5105 
5106 class Bar6847 : Foo6847
5107 {
5108     static assert( True6847!(typeof(super)) );
5109     static assert( is(typeof(super) == Foo6847) );
5110 }
5111 
5112 /***************************************************/
5113 // http://d.puremagic.com/issues/show_bug.cgi?id=6488
5114 
5115 struct TickDuration
5116 {
5117     template to(T) if (__traits(isIntegral,T))
5118     {
5119         const T to()
5120         {
5121             return 1;
5122         }
5123     }
5124 
5125     template to(T) if (__traits(isFloating,T))
5126     {
5127         const T to()
5128         {
5129             return 0;
5130         }
5131     }
5132 
5133     const long seconds()
5134     {
5135         return to!(long)();
5136     }
5137 
5138 }
5139 
5140 void test6488()
5141 {
5142     TickDuration d;
5143     d.seconds();
5144 }
5145 
5146 /***************************************************/
5147 // 6565
5148 
5149 void foo6565(out int[2][2] m) {}
5150 
5151 void test6565()
5152 {
5153     int[2][2] mat = [[1, 2], [3, 4]];
5154     foo6565(mat);
5155     assert(mat == [[0, 0], [0, 0]]);
5156 }
5157 
5158 /***************************************************/
5159 // 6836
5160 
5161 template map6836(fun...) if (fun.length >= 1)
5162 {
5163     auto map6836(Range)(Range r)
5164     {
5165     }
5166 }
5167 void test6836()
5168 {
5169     [1].map6836!"a"();
5170 }
5171 
5172 /***************************************************/
5173 
5174 string func12864() { return ['a', 'b', 'c']; }
5175 
5176 void test12864(string s)
5177 {
5178     switch (s)
5179     {
5180     case func12864():
5181         break;
5182 
5183     default:
5184         break;
5185     }
5186 }
5187 
5188 /***************************************************/
5189 
5190 void test5448()
5191 {
5192     int[int][] aaa = [[1: 2]];
5193     int[string][] a2 = [["cc":0], ["DD":10]];
5194 }
5195 
5196 /***************************************************/
5197 // 6837
5198 
5199 struct Ref6837a(T)
5200 {
5201     T storage;
5202     alias storage this;
5203 }
5204 
5205 struct Ref6837b(T)
5206 {
5207     T storage;
5208     @property ref T get(){ return storage; }
5209     alias get this;
5210 }
5211 
5212 int front6837(int[] arr){ return arr[0]; }
5213 
5214 void popFront6837(ref int[] arr){ arr = arr[1..$]; }
5215 
5216 void test6837()
5217 {
5218     assert([1,2,3].front6837 == 1);
5219 
5220     auto r1 = Ref6837a!(int[])([1,2,3]);
5221     assert(r1.front6837() == 1);    // ng
5222     assert(r1.front6837 == 1);      // ok
5223     r1.popFront6837();              // ng
5224     r1.storage.popFront6837();      // ok
5225 
5226     auto r2 = Ref6837b!(int[])([1,2,3]);
5227     assert(r2.front6837() == 1);    // ng
5228     assert(r2.front6837 == 1);      // ok
5229     r2.popFront6837();              // ng
5230     r2.get.popFront6837();          // ng
5231     r2.get().popFront6837();        // ok
5232 }
5233 
5234 /***************************************************/
5235 // 6927
5236 
5237 @property int[] foo6927()
5238 {
5239     return [1, 2];
5240 }
5241 int[] bar6927(int[] a)
5242 {
5243     return a;
5244 }
5245 void test6927()
5246 {
5247     bar6927(foo6927); // OK
5248     foo6927.bar6927(); // line 9, Error
5249 }
5250 
5251 /***************************************************/
5252 
5253 struct Foo6813(T)
5254 {
5255     Foo6813 Bar()
5256     {
5257         return Foo6813(_indices.abc());
5258     }
5259 
5260     T _indices;
5261 }
5262 
5263 struct SortedRange(alias pred)
5264 {
5265     SortedRange abc()
5266     {
5267         return SortedRange();
5268     }
5269 }
5270 
5271 void test6813() {
5272     auto ind = SortedRange!({ })();
5273     auto a = Foo6813!(typeof(ind))();
5274 }
5275 
5276 /***************************************************/
5277 
5278 struct Interval6753{ int a,b; }
5279 @safe struct S6753
5280 {
5281     int[] arr;
5282     @trusted @property auto byInterval() const
5283     {
5284         return cast(const(Interval6753)[])arr;
5285     }
5286 }
5287 
5288 /***************************************************/
5289 // 6859
5290 
5291 class Parent6859
5292 {
5293 public:
5294     bool isHage() const @property;
5295 
5296 public:
5297     abstract void fuga()
5298     out
5299     {
5300         assert(isHage);
5301     }
5302     body { }
5303 }
5304 
5305 class Child6859 : Parent6859
5306 {
5307     override bool isHage() const @property
5308     {
5309         return true;
5310     }
5311     override void fuga()
5312     {
5313         //nop
5314     }
5315 }
5316 
5317 void test6859()
5318 {
5319     auto t = new Child6859;
5320     t.fuga();
5321     printf("done.\n");
5322 }
5323 
5324 /***************************************************/
5325 // 6910
5326 
5327 template Test6910(alias i, B)
5328 {
5329     void fn()
5330     {
5331         foreach(t; B.Types)
5332         {
5333             switch(i)
5334             {
5335                 case 0://IndexOf!(t, B.Types):
5336                 {
5337                     pragma(msg, __traits(allMembers, t));
5338                     pragma(msg, __traits(hasMember, t, "m"));
5339                     static assert(__traits(hasMember, t, "m")); // test
5340                     break;
5341                 }
5342                 default: {}
5343             }
5344         }
5345     }
5346 }
5347 void test6910()
5348 {
5349     static struct Bag(S...)
5350     {
5351         alias S Types;
5352     }
5353     static struct A
5354     {
5355         int m;
5356     }
5357 
5358     int i;
5359     alias Test6910!(i, Bag!(A)).fn func;
5360 }
5361 
5362 /***************************************************/
5363 
5364 void fun12503()
5365 {
5366     string b = "abc";
5367     try
5368     {
5369         try
5370         {
5371             b = null;
5372             return;
5373         }
5374         catch
5375         {
5376         }
5377     }
5378     finally
5379     {
5380         assert("abc" !is b);
5381     }
5382 }
5383 
5384 void test12503()
5385 {
5386     fun12503();
5387 }
5388 
5389 /***************************************************/
5390 // 6902
5391 
5392 void test6902()
5393 {
5394     static assert(is(typeof({
5395         return int.init; // int, long, real, etc.
5396     })));
5397 
5398     int f() pure nothrow { assert(0); }
5399     alias int T() pure nothrow @safe @nogc;
5400     static if(is(typeof(&f) DT == delegate))
5401     {
5402         static assert(is(DT* == T*));  // ok
5403 
5404         // Error: static assert  (is(pure nothrow int() == pure nothrow int())) is false
5405         static assert(is(DT == T));
5406     }
5407 }
5408 
5409 /***************************************************/
5410 // 6330
5411 
5412 struct S6330
5413 {
5414     void opAssign(S6330 s) @disable
5415     {
5416         assert(0);  // This fails.
5417     }
5418 }
5419 
5420 void test6330()
5421 {
5422     S6330 s;
5423     S6330 s2;
5424     static assert(!is(typeof({ s2 = s; })));
5425 }
5426 
5427 /***************************************************/
5428 
5429 struct S8269
5430 {
5431     bool dtor = false;
5432     ~this()
5433     {
5434         dtor = true;
5435     }
5436 }
5437 
5438 void test8269()
5439 {
5440     with(S8269())
5441     {
5442         assert(!dtor);
5443     }
5444 }
5445 
5446 /***************************************************/
5447 // 5311
5448 
5449 class C5311
5450 {
5451     private static int globalData;
5452 
5453     void breaksPure() pure const
5454     {
5455         static assert(!__traits(compiles, { globalData++; }));      // SHOULD BE ERROR
5456         static assert(!__traits(compiles, { C5311.globalData++; }));// SHOULD BE ERROR
5457         static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5458 
5459         static assert(!__traits(compiles, { int a = this.globalData; }));
5460     }
5461 }
5462 static void breaksPure5311a(C5311 x) pure
5463 {
5464     static assert(!__traits(compiles, { x.globalData++; }));        // SHOULD BE ERROR
5465 
5466     static assert(!__traits(compiles, { int a = x.globalData; }));
5467 }
5468 
5469 struct S5311
5470 {
5471     private static int globalData;
5472 
5473     void breaksPure() pure const
5474     {
5475         static assert(!__traits(compiles, { globalData++; }));      // SHOULD BE ERROR
5476         static assert(!__traits(compiles, { S5311.globalData++; }));// SHOULD BE ERROR
5477         static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5478 
5479         static assert(!__traits(compiles, { int a = this.globalData; }));
5480     }
5481 }
5482 static void breaksPure5311b(S5311 x) pure
5483 {
5484     static assert(!__traits(compiles, { x.globalData++; }));        // SHOULD BE ERROR
5485 
5486     static assert(!__traits(compiles, { int a = x.globalData; }));
5487 }
5488 
5489 /***************************************************/
5490 // 6868
5491 
5492 @property bool empty6868(T)(in T[] a) @safe pure nothrow
5493 {
5494     return !a.length;
5495 }
5496 
5497 void test6868()
5498 {
5499     alias int[] Range;
5500     static if (is(char[1 + Range.empty6868]))  // Line 9
5501         enum bool isInfinite = true;
5502 
5503     char[0] s;  // need
5504 }
5505 
5506 /***************************************************/
5507 // 2856
5508 
5509 struct foo2856    { static void opIndex(int i) { printf("foo\n"); } }
5510 struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } }
5511 
5512 void test2856()
5513 {
5514     foo2856[1];
5515     bar2856!(float)[1];     // Error (# = __LINE__)
5516     alias bar2856!(float) B;
5517     B[1];                   // Okay
5518 }
5519 
5520 /***************************************************/
5521 
5522 void test13947()
5523 {
5524     struct S {}
5525     static assert(S.sizeof == 1);
5526 
5527     S a;
5528     S b;
5529     *cast(ubyte*)&a = 1;
5530     *cast(ubyte*)&b = 2;
5531     assert(a == b);
5532     assert(a is b);
5533     assert(!(a != b));
5534     assert(!(a !is b));
5535     static assert(S() == S());
5536     static assert(S() is S());
5537     static assert(!(S() != S()));
5538     static assert(!(S() !is S()));
5539 }
5540 
5541 /***************************************************/
5542 // 3091
5543 
5544 void test3091(inout int = 0)
5545 {
5546     struct Foo {}
5547 
5548     auto  pm = new Foo;                 static assert(is( typeof( pm) ==              Foo  * ));
5549     auto  pc = new const Foo;           static assert(is( typeof( pc) ==        const(Foo) * ));
5550     auto  pw = new inout Foo;           static assert(is( typeof( pw) ==        inout(Foo) * ));
5551     auto psm = new shared Foo;          static assert(is( typeof(psm) ==       shared(Foo) * ));
5552     auto psc = new shared const Foo;    static assert(is( typeof(psc) == shared(const(Foo))* ));
5553     auto psw = new shared inout Foo;    static assert(is( typeof(psw) == shared(inout(Foo))* ));
5554     auto  pi = new immutable Foo;       static assert(is( typeof( pi) ==    immutable(Foo) * ));
5555 
5556     auto  m = Foo();                    static assert(is( typeof( m) ==              Foo   ));
5557     auto  c = const Foo();              static assert(is( typeof( c) ==        const(Foo)  ));
5558     auto  w = inout Foo();              static assert(is( typeof( w) ==        inout(Foo)  ));
5559     auto sm = shared Foo();             static assert(is( typeof(sm) ==       shared(Foo)  ));
5560     auto sc = shared const Foo();       static assert(is( typeof(sc) == shared(const(Foo)) ));
5561     auto sw = shared inout Foo();       static assert(is( typeof(sw) == shared(inout(Foo)) ));
5562     auto  i = immutable Foo();          static assert(is( typeof( i) ==    immutable(Foo)  ));
5563 }
5564 
5565 /***************************************************/
5566 // 6837
5567 
5568 template Id6837(T)
5569 {
5570     alias T Id6837;
5571 }
5572 static assert(is(Id6837!(shared const int) == shared const int));
5573 static assert(is(Id6837!(shared inout int) == shared inout int));
5574 
5575 /***************************************************/
5576 // 6056 fixup
5577 
5578 template ParameterTypeTuple6056(func)
5579 {
5580     static if (is(func Fptr : Fptr*) && is(Fptr P == function))
5581         alias P ParameterTypeTuple6056;
5582     else
5583         static assert(0, "argument has no parameters");
5584 }
5585 
5586 extern(C) alias void function() fpw_t;
5587 
5588 alias void function(fpw_t fp) cb_t;
5589 
5590 void bar6056(ParameterTypeTuple6056!(cb_t) args) {
5591       pragma (msg, "TFunction1: " ~ typeof(args[0]).stringof);
5592 }
5593 
5594 extern(C) void foo6056() { }
5595 
5596 void test6056()
5597 {
5598     bar6056(&foo6056);
5599 }
5600 
5601 /***************************************************/
5602 // 6356
5603 
5604 int f6356()(int a)
5605 {
5606     return a*a;
5607 }
5608 
5609 alias f6356!() g6356;     // comment this out to eliminate the errors
5610 
5611 pure nothrow @safe int i6356()
5612 {
5613     return f6356(1);
5614 }
5615 
5616 void test6356()
5617 {
5618     assert(i6356() == 1);
5619 }
5620 
5621 /***************************************************/
5622 // 7108
5623 
5624 static assert(!__traits(hasMember, int, "x"));
5625 static assert( __traits(hasMember, int, "init"));
5626 
5627 /***************************************************/
5628 // 7073
5629 
5630 void test7073()
5631 {
5632     string f(int[] arr...)
5633     {
5634         return "";
5635     }
5636 }
5637 
5638 /***************************************************/
5639 // 7104
5640 
5641 void test7104()
5642 {
5643     typeof(new class {}) c;
5644     c = new typeof(c);
5645 }
5646 
5647 /***************************************************/
5648 // 7150
5649 
5650 struct A7150
5651 {
5652     static int cnt;
5653 
5654     this(T)(T thing, int i)
5655     {
5656         this(thing, i > 0); // Error: constructor call must be in a constructor
5657         ++cnt;
5658     }
5659     this(T)(T thing, bool b)
5660     {
5661         ++cnt;
5662     }
5663 }
5664 
5665 void test7150()
5666 {
5667     auto a = A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating
5668     assert(A7150.cnt == 2);
5669 }
5670 
5671 /***************************************************/
5672 // 7159
5673 
5674 alias void delegate()  Void7159;
5675 
5676 class HomeController7159 {
5677     Void7159 foo() {
5678         return cast(Void7159)&HomeController7159.displayDefault;
5679     }
5680     auto displayDefault() {
5681         return 1;
5682     }
5683 }
5684 
5685 /***************************************************/
5686 // 7160
5687 
5688 class HomeController {
5689     static if (false) {
5690         mixin(q{ int a; });
5691     }
5692     void foo() {
5693         foreach (m; __traits(derivedMembers, HomeController)) {
5694         }
5695     }
5696 }
5697 
5698 void test7160()
5699 {}
5700 
5701 /***************************************************/
5702 // 7168
5703 
5704 void test7168()
5705 {
5706     static class X
5707     {
5708         void foo(){}
5709     }
5710     static class Y : X
5711     {
5712         void bar(){}
5713     }
5714 
5715     enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
5716 
5717     static assert([__traits(allMembers, X)] == ["foo"]~ObjectMembers);          // pass
5718     static assert([__traits(allMembers, Y)] == ["bar", "foo"]~ObjectMembers);   // fail
5719     static assert([__traits(allMembers, Y)] != ["bar", "foo"]);                 // fail
5720 }
5721 
5722 /***************************************************/
5723 // 7170
5724 
5725 T to7170(T)(string x) { return 1; }
5726 void test7170()
5727 {
5728 //  auto i = to7170!int("1");   // OK
5729     auto j = "1".to7170!int();  // NG, Internal error: e2ir.c 683
5730 }
5731 
5732 /***************************************************/
5733 // 7196
5734 
5735 auto foo7196(int x){return x;}
5736 auto foo7196(double x){return x;}
5737 
5738 void test7196()
5739 {
5740     auto x = (&foo7196)(1);   // ok
5741     auto y = (&foo7196)(1.0); // fail
5742 }
5743 
5744 /***************************************************/
5745 // 7285
5746 
5747 int[2] spam7285()
5748 {
5749     int[2] ab;
5750     if (true)
5751         return (true) ? ab : [0, 0]; // Error
5752     else
5753         return (true) ? [0, 0] : ab; // OK
5754 }
5755 
5756 void test7285()
5757 {
5758     auto sa = spam7285();
5759 }
5760 
5761 /***************************************************/
5762 // 14737
5763 
5764 void test14737()
5765 {
5766     // compile-time
5767     enum string[2] a1 = ["d", "e"];
5768     enum b1x = ["a", "b", "c"] ~ a1;        // Tarray vs Tsarray
5769     enum b1y = a1 ~ ["a", "b", "c"];        // Tsarray vs Tarray
5770     static assert(is(typeof(b1x) == string[]));
5771     static assert(is(typeof(b1y) == string[]));
5772     static assert(b1x == ["a", "b", "c", "d", "e"]);
5773     static assert(b1y == ["d", "e", "a", "b", "c"]);
5774 
5775     // runtime
5776     string[2] a2 = ["d", "e"];
5777     auto b2x = ["a", "b", "c"] ~ a2;        // Tarray vs Tsarray
5778     auto b2y = a2 ~ ["a", "b", "c"];        // Tsarray vs Tarray
5779     static assert(is(typeof(b2x) == string[]));
5780     static assert(is(typeof(b2y) == string[]));
5781     assert(b2x == ["a", "b", "c", "d", "e"]);
5782     assert(b2y == ["d", "e", "a", "b", "c"]);
5783 }
5784 
5785 /***************************************************/
5786 // 7321
5787 
5788 void test7321()
5789 {
5790     static assert(is(typeof((){})==void function()pure nothrow @nogc @safe));         // ok
5791     static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe));  // fail
5792 }
5793 
5794 /***************************************************/
5795 
5796 class A158
5797 {
5798     pure void foo1() { }
5799     const void foo2() { }
5800     nothrow void foo3() { }
5801     @safe void foo4() { }
5802 }
5803 
5804 class B158 : A158
5805 {
5806     override void foo1() { }
5807     override void foo2() const { }
5808     override void foo3() { }
5809     override void foo4() { }
5810 }
5811 
5812 /***************************************************/
5813 // 9231
5814 
5815 class B9231 { void foo() inout pure {} }
5816 class D9231 : B9231 { override void foo() inout {} }
5817 
5818 /***************************************************/
5819 // 3282
5820 
5821 class Base3282
5822 {
5823     string f()
5824     {
5825         return "Base.f()";
5826     }
5827 }
5828 class Derived3282 : Base3282
5829 {
5830     override string f()
5831     {
5832         return "Derived.f()";
5833     }
5834   /*override*/ string f() const
5835     {
5836         return "Derived.f() const";
5837     }
5838 }
5839 
5840 void test3282()
5841 {
5842     auto x = new Base3282;
5843     assert(x.f() == "Base.f()");
5844     auto y = new Derived3282;
5845     assert(y.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const.
5846     auto z = new const(Derived3282);
5847     assert(z.f() == "Derived.f() const");
5848 }
5849 
5850 /***************************************************/
5851 // 7534
5852 
5853 class C7534
5854 {
5855     int foo(){ return 1; }
5856 }
5857 class D7534 : C7534
5858 {
5859     override int foo(){ return 2; }
5860   /*override*/ int foo() const { return 3; }
5861     // Error: D.foo multiple overrides of same function
5862 }
5863 void test7534()
5864 {
5865     C7534 mc = new C7534();
5866     assert(mc.foo() == 1);
5867 
5868     D7534 md = new D7534();
5869     assert(md.foo() == 2);
5870     mc = md;
5871     assert(mc.foo() == 2);
5872 
5873     const(D7534) cd = new const(D7534)();
5874     assert(cd.foo() == 3);
5875     md = cast()cd;
5876     assert(md.foo() == 2);
5877 }
5878 
5879 /***************************************************/
5880 // 7534 + return type covariance
5881 
5882 class X7534 {}
5883 class Y7534 : X7534
5884 {
5885     int value; this(int n){ value = n; }
5886 }
5887 
5888 class V7534
5889 {
5890     X7534 foo(){ return new X7534(); }
5891 }
5892 class W7534 : V7534
5893 {
5894     override Y7534 foo(){ return new Y7534(1); }
5895   /*override*/ Y7534 foo() const { return new Y7534(2); }
5896 }
5897 
5898 void test7534cov()
5899 {
5900     auto mv = new V7534();
5901     assert(typeid(mv.foo()) == typeid(X7534));
5902 
5903     auto mw = new W7534();
5904     assert(typeid(mw.foo()) == typeid(Y7534));
5905     assert(mw.foo().value == 1);
5906     mv = mw;
5907     assert(typeid(mv.foo()) == typeid(Y7534));
5908     assert((cast(Y7534)mv.foo()).value == 1);
5909 
5910     auto cw = new const(W7534)();
5911     assert(typeid(cw.foo()) == typeid(Y7534));
5912     assert(cw.foo().value == 2);
5913 }
5914 
5915 /***************************************************/
5916 // 7562
5917 
5918 static struct MyInt
5919 {
5920     private int value;
5921     mixin ProxyOf!value;
5922 }
5923 mixin template ProxyOf(alias a)
5924 {
5925     template X1(){}
5926     template X2(){}
5927     template X3(){}
5928     template X4(){}
5929     template X5(){}
5930     template X6(){}
5931     template X7(){}
5932     template X8(){}
5933     template X9(){}
5934     template X10(){}
5935 
5936     void test1(this X)(){}
5937     void test2(this Y)(){}
5938 }
5939 
5940 /***************************************************/
5941 
5942 import core.stdc.stdlib;
5943 
5944 void test13427(void* buffer = alloca(100))
5945 {
5946 }
5947 
5948 /***************************************************/
5949 // 7583
5950 
5951 template Tup7583(E...) { alias E Tup7583; }
5952 
5953 struct S7583
5954 {
5955     Tup7583!(float, char) field;
5956     alias field this;
5957     this(int x) {    }
5958 }
5959 
5960 int bug7583() {
5961     S7583[] arr;
5962     arr ~= S7583(0);
5963     return 1;
5964 }
5965 
5966 static assert (bug7583());
5967 
5968 /***************************************************/
5969 // 7618
5970 
5971 void test7618(const int x = 1)
5972 {
5973     int func(ref int x) { return 1; }
5974     static assert(!__traits(compiles, func(x)));
5975     // Error: function test.foo.func (ref int _param_0) is not callable using argument types (const(int))
5976 
5977     int delegate(ref int) dg = (ref int x) => 1;
5978     static assert(!__traits(compiles, dg(x)));
5979     // --> no error, bad!
5980 
5981     int function(ref int) fp = (ref int x) => 1;
5982     static assert(!__traits(compiles, fp(x)));
5983     // --> no error, bad!
5984 }
5985 
5986 /***************************************************/
5987 // 7621
5988 
5989 void test7621()
5990 {
5991     enum uint N = 4u;
5992     char[] A = "hello".dup;
5993     uint[immutable char[4u]] dict;
5994     dict[*cast(immutable char[4]*)(A[0 .. N].ptr)] = 0; // OK
5995     dict[*cast(immutable char[N]*)(A[0 .. N].ptr)] = 0; // line 6, error
5996 }
5997 
5998 /***************************************************/
5999 // 7682
6000 
6001 template ConstOf7682(T)
6002 {
6003     alias const(T) ConstOf7682;
6004 }
6005 bool pointsTo7682(S)(ref const S source) @trusted pure nothrow
6006 {
6007     return true;
6008 }
6009 void test7682()
6010 {
6011     shared(ConstOf7682!(int[])) x;  // line A
6012 
6013     struct S3 { int[10] a; }
6014     shared(S3) sh3;
6015     shared(int[]) sh3sub = sh3.a[];
6016     assert(pointsTo7682(sh3sub));   // line B
6017 }
6018 
6019 /***************************************************/
6020 // 7735
6021 
6022 void a7735(void[][] data...)
6023 {
6024     //writeln(data);
6025     assert(data.length == 1);
6026     b7735(data);
6027 }
6028 
6029 void b7735(void[][] data...)
6030 {
6031     //writeln(data);
6032     assert(data.length == 1);
6033     c7735(data);
6034 }
6035 
6036 void c7735(void[][] data...)
6037 {
6038     //writeln(data);
6039     assert(data.length == 1);
6040 }
6041 
6042 void test7735()
6043 {
6044     a7735([]);
6045     a7735([]);
6046 }
6047 
6048 /***************************************************/
6049 
6050 struct A7823 {
6051     long a;
6052     enum A7823 b = {0};
6053 }
6054 
6055 void test7823(A7823 a = A7823.b) { }
6056 
6057 /***************************************************/
6058 // 7871
6059 
6060 struct Tuple7871
6061 {
6062     string field;
6063     alias field this;
6064 }
6065 
6066 //auto findSplitBefore(R1)(R1 haystack)
6067 auto findSplitBefore7871(string haystack)
6068 {
6069     return Tuple7871(haystack);
6070 }
6071 
6072 void test7871()
6073 {
6074     string line = `<bookmark href="https://stuff">`;
6075     auto a = findSplitBefore7871(line[0 .. $])[0];
6076 }
6077 
6078 /***************************************************/
6079 // 7906
6080 
6081 void test7906()
6082 {
6083     static assert(!__traits(compiles, { enum s = [string.min]; }));
6084 }
6085 
6086 /***************************************************/
6087 // 7907
6088 
6089 template Id7907(E)
6090 {
6091     alias E Id7907;
6092 }
6093 template Id7907(alias E)
6094 {
6095     alias E Id7907;
6096 }
6097 
6098 void test7907()
6099 {
6100     static assert(!__traits(compiles, { alias Id7907!([string.min]) X; }));
6101 }
6102 
6103 /***************************************************/
6104 // 1175
6105 
6106 class A1175
6107 {
6108     class I1 { }
6109 }
6110 
6111 class B1175 : A1175
6112 {
6113     class I2 : I1 { }
6114 
6115     I1 getI() { return new I2; }
6116 }
6117 
6118 /***************************************************/
6119 // 7983
6120 
6121 class A7983 {
6122         void f() {
6123                 g7983(this);
6124         }
6125         unittest {
6126         }
6127 }
6128 
6129 void g7983(T)(T a)
6130 {
6131         foreach (name; __traits(allMembers, T)) {
6132                 pragma(msg, name);
6133                 static if (__traits(compiles, &__traits(getMember, a, name)))
6134                 {
6135                 }
6136         }
6137 }
6138 
6139 /***************************************************/
6140 // 8004
6141 
6142 void test8004()
6143 {
6144     auto n = (int n = 10){ return n; }();
6145     assert(n == 10);
6146 }
6147 
6148 /***************************************************/
6149 // 8064
6150 
6151 void test8064()
6152 {
6153     uint[5] arry;
6154     ref uint acc(size_t i) {
6155         return arry[i];
6156     }
6157     auto arryacc = &acc;
6158     arryacc(3) = 5; // same error
6159 }
6160 
6161 /***************************************************/
6162 // 8220
6163 
6164 void foo8220(int){}
6165 static assert(!__traits(compiles, foo8220(typeof(0)))); // fail
6166 
6167 /***************************************************/
6168 
6169 void func8105(in ref int x) { }
6170 
6171 void test8105()
6172 {
6173 }
6174 
6175 /***************************************************/
6176 
6177 template ParameterTypeTuple159(alias foo)
6178 {
6179     static if (is(typeof(foo) P == __parameters))
6180         alias P ParameterTypeTuple159;
6181     else
6182         static assert(0, "argument has no parameters");
6183 }
6184 
6185 int func159(int i, long j = 7) { return 3; }
6186 
6187 alias ParameterTypeTuple159!func159 PT;
6188 
6189 int bar159(PT) { return 4; }
6190 
6191 pragma(msg, typeof(bar159));
6192 pragma(msg, PT[1]);
6193 
6194 PT[1] boo159(PT[1..2] a) { return a[0]; }
6195 
6196 void test159()
6197 {
6198     assert(bar159(1) == 4);
6199     assert(boo159() == 7);
6200 }
6201 
6202 /***************************************************/
6203 // 8283
6204 
6205 struct Foo8283 {
6206     this(long) { }
6207 }
6208 
6209 struct FooContainer {
6210     Foo8283 value;
6211 }
6212 
6213 auto get8283() {
6214     union Buf { FooContainer result; }
6215     Buf buf = {};
6216     return buf.result;
6217 }
6218 
6219 void test8283() {
6220     auto a = get8283();
6221 }
6222 
6223 
6224 /***************************************************/
6225 // 8395
6226 
6227 struct S8395
6228 {
6229     int v;
6230     this(T : long)(T x) { v = x * 2; }
6231 }
6232 void test8395()
6233 {
6234     S8395 ms = 6;
6235     assert(ms.v == 12);
6236     const S8395 cs = 7;
6237     assert(cs.v == 14);
6238 }
6239 
6240 /***************************************************/
6241 // 5749
6242 
6243 void test5749()
6244 {
6245     static struct A
6246     {
6247         A foo(int x, int i)
6248         {
6249             //printf("this = %p, %d: i=%d\n", &this, x, i);
6250             assert(i == x);
6251             return this;
6252         }
6253         A bar(int x, ref int i)
6254         {
6255             //printf("this = %p, %d: i=%d\n", &this, x, i);
6256             assert(i == x);
6257             return this;
6258         }
6259     }
6260 
6261     static     int inc1(ref int i) { return ++i; }
6262     static ref int inc2(ref int i) { return ++i; }
6263 
6264     int i;
6265     A a;
6266     //printf("&a = %p\n", &a);
6267 
6268     i = 0;  a.foo(1, ++i).foo(2, ++i);          // OK <-- 2 1
6269     i = 0;  a.bar(1, ++i).bar(2, ++i);          // OK <-- 2 2
6270     i = 0;  a.foo(1, inc1(i)).foo(2, inc1(i));  // OK <-- 2 1
6271     i = 0;  a.bar(1, inc2(i)).bar(2, inc2(i));  // OK <-- 2 2
6272     //printf("\n");
6273 
6274     A getVal() { static A a; return a; }
6275     i = 0;  getVal().foo(1, ++i).foo(2, ++i);           // OK <-- 2 1
6276     i = 0;  getVal().bar(1, ++i).bar(2, ++i);           // OK <-- 2 2
6277     i = 0;  getVal().foo(1, inc1(i)).foo(2, inc1(i));   // OK <-- 2 1
6278     i = 0;  getVal().bar(1, inc2(i)).bar(2, inc2(i));   // OK <-- 2 2
6279     //printf("\n");
6280 
6281     ref A getRef() { static A a; return a; }
6282     i = 0;  getRef().foo(1, ++i).foo(2, ++i);           // OK <-- 2 1
6283     i = 0;  getRef().bar(1, ++i).bar(2, ++i);           // OK <-- 2 2
6284     i = 0;  getRef().foo(1, inc1(i)).foo(2, inc1(i));   // OK <-- 2 1
6285     i = 0;  getRef().bar(1, inc2(i)).bar(2, inc2(i));   // OK <-- 2 2
6286 }
6287 
6288 /***************************************************/
6289 // 8396
6290 
6291 void test8396()
6292 {
6293     static int g;
6294 
6295     static extern(C) int bar(int a, int b)
6296     {
6297         //printf("a = %d, b = %d\n", a, b);
6298         assert(b - a == 1);
6299         return ++g;
6300     }
6301     static auto getFunc(int n)
6302     {
6303         assert(++g == n);
6304         return &bar;
6305     }
6306 
6307     static struct Tuple { int _a, _b; }
6308     static Tuple foo(int n)
6309     {
6310         assert(++g == n);
6311         return Tuple(1, 2);
6312     }
6313 
6314     g = 0;
6315     assert(bar(foo(1).tupleof) == 2);
6316 
6317     g = 0;
6318     assert(getFunc(1)(foo(2).tupleof) == 3);
6319 }
6320 
6321 /***************************************************/
6322 
6323 enum E160 : ubyte { jan = 1 }
6324 
6325 struct D160
6326 {
6327     short _year  = 1;
6328     E160 _month = E160.jan;
6329     ubyte _day   = 1;
6330 
6331     this(int year, int month, int day) pure
6332     {
6333         _year  = cast(short)year;
6334         _month = cast(E160)month;
6335         _day   = cast(ubyte)day;
6336     }
6337 }
6338 
6339 struct T160
6340 {
6341     ubyte _hour;
6342     ubyte _minute;
6343     ubyte _second;
6344 
6345     this(int hour, int minute, int second = 0) pure
6346     {
6347         _hour   = cast(ubyte)hour;
6348         _minute = cast(ubyte)minute;
6349         _second = cast(ubyte)second;
6350     }
6351 }
6352 
6353 struct DT160
6354 {
6355     D160 _date;
6356     T160 _tod;
6357 
6358     this(int year, int month, int day,
6359          int hour = 0, int minute = 0, int second = 0) pure
6360     {
6361         _date = D160(year, month, day);
6362         _tod = T160(hour, minute, second);
6363     }
6364 }
6365 
6366 void foo160(DT160 dateTime)
6367 {
6368     printf("test7 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6369     assert(dateTime._date._year == 1999);
6370     assert(dateTime._date._day == 6);
6371 }
6372 
6373 void test160()
6374 {
6375     auto dateTime = DT160(1999, 7, 6, 12, 30, 33);
6376     printf("test5 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6377     assert(dateTime._date._year == 1999);
6378     assert(dateTime._date._day == 6);
6379     foo160(DT160(1999, 7, 6, 12, 30, 33));
6380 }
6381 
6382 /***************************************************/
6383 // 8437
6384 
6385 class Cgi8437
6386 {
6387     struct PostParserState {
6388         UploadedFile piece;
6389     }
6390 
6391     static struct UploadedFile {
6392         string contentFilename;
6393     }
6394 }
6395 
6396 /***************************************************/
6397 // 8665
6398 
6399 auto foo8665a(bool val)
6400 {
6401     if (val)
6402         return 42;
6403     else
6404         return 1.5;
6405 }
6406 auto foo8665b(bool val)
6407 {
6408     if (!val)
6409         return 1.5;
6410     else
6411         return 42;
6412 }
6413 
6414 void test8665()
6415 {
6416     static assert(is(typeof(foo8665a(true))  == double));
6417     static assert(is(typeof(foo8665b(false)) == double));
6418     assert(foo8665a(true) == 42); // assertion failure
6419     assert(foo8665b(true) == 42); // assertion failure
6420     assert(foo8665a(false) == 1.5);
6421     assert(foo8665b(false) == 1.5);
6422 
6423     static assert(foo8665a(true) == 42);
6424     static assert(foo8665b(true) == 42);
6425     static assert(foo8665a(false) == 1.5);
6426     static assert(foo8665b(false) == 1.5);
6427 }
6428 
6429 /***************************************************/
6430 
6431 int foo8108(int, int);
6432 
6433 int foo8108(int a, int b)
6434 {
6435     return a + b;
6436 }
6437 
6438 void test8108()
6439 {
6440     foo8108(1,2);
6441 }
6442 
6443 /***************************************************/
6444 // 8360
6445 
6446 struct Foo8360
6447 {
6448     int value = 0;
6449     int check = 1337;
6450 
6451     this(int value)
6452     {
6453         assert(0);
6454         this.value = value;
6455     }
6456 
6457     ~this()
6458     {
6459         assert(0);
6460         assert(check == 1337);
6461     }
6462 
6463     string str()
6464     {
6465         assert(0);
6466         return "Foo";
6467     }
6468 }
6469 
6470 Foo8360 makeFoo8360()
6471 {
6472     assert(0);
6473     return Foo8360(2);
6474 }
6475 
6476 void test8360()
6477 {
6478     size_t length = 0;
6479 
6480     // The message part 'makeFoo().str()' should not be evaluated at all.
6481     assert(length < 5, makeFoo8360().str());
6482 }
6483 
6484 /***************************************************/
6485 // 8361
6486 
6487 struct Foo8361
6488 {
6489     string bar = "hello";
6490     ~this() {}
6491 }
6492 
6493 void test8361()
6494 {
6495     assert(true, Foo8361().bar);
6496 }
6497 
6498 /***************************************************/
6499 // 6141 + 8526
6500 
6501 void test6141()
6502 {
6503     static void takeADelegate(void delegate()) {}
6504     auto items = new int[1];
6505     items[0] = 17;
6506     foreach (ref item; items)
6507     {
6508         // both asserts fail
6509         assert(item == 17);
6510         assert(&item == items.ptr);
6511 
6512         takeADelegate({ auto x = &item; });
6513     }
6514 
6515     foreach(ref val; [3])
6516     {
6517         auto dg = { int j = val; };
6518         assert(&val != null); // Assertion failure
6519         assert(val == 3);
6520     }
6521 
6522     static void f(lazy int) {}
6523     int i = 0;
6524     auto dg = { int j = i; };
6525     foreach(ref val; [3])
6526     {
6527         f(val);
6528         assert(&val != null); // Assertion failure
6529         assert(val == 3);
6530     }
6531 }
6532 
6533 void test8526()
6534 {
6535     static void call(void delegate() dg) { dg(); }
6536 
6537     foreach (i, j; [0])
6538     {
6539         call({
6540             assert(i == 0); // fails, i is corrupted
6541         });
6542     }
6543 
6544     foreach (n; 0..1)
6545     {
6546         call({
6547             assert(n == 0); // fails, n is corrupted
6548         });
6549     }
6550 }
6551 
6552 /***************************************************/
6553 
6554 template ParameterTuple(alias func)
6555 {
6556     static if(is(typeof(func) P == __parameters))
6557         alias P ParameterTuple;
6558     else
6559         static assert(0);
6560 }
6561 
6562 int foo161(ref float y);
6563 
6564 void test161()
6565 {
6566     alias PT = ParameterTuple!foo161;
6567     auto x = __traits(identifier, PT);
6568     assert(x == "y");
6569 }
6570 
6571 /***************************************************/
6572 // 7175
6573 
6574 void test7175()
6575 {
6576     struct S { ubyte[0] arr; }
6577     S s;
6578     assert(s.arr.ptr !is null);
6579     assert(cast(void*)s.arr.ptr is cast(void*)&s);
6580 }
6581 
6582 /***************************************************/
6583 // 8819
6584 
6585 void test8819()
6586 {
6587     void[1] sa1 = (void[1]).init;
6588     assert((cast(ubyte*)sa1.ptr)[0] == 0);
6589 
6590     void[4] sa4 = [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4];
6591     assert((cast(ubyte*)sa4.ptr)[0] == 1);
6592     assert((cast(ubyte*)sa4.ptr)[1] == 2);
6593     assert((cast(ubyte*)sa4.ptr)[2] == 3);
6594     assert((cast(ubyte*)sa4.ptr)[3] == 4);
6595 
6596     auto sa22 = (void[2][2]).init;
6597     static assert(sa22.sizeof == ubyte.sizeof * 2 * 2);
6598     ubyte[4]* psa22 = cast(ubyte[4]*)sa22.ptr;
6599     assert((*psa22)[0] == 0);
6600     assert((*psa22)[1] == 0);
6601     assert((*psa22)[2] == 0);
6602     assert((*psa22)[3] == 0);
6603 }
6604 
6605 /***************************************************/
6606 // 8897
6607 
6608 class C8897
6609 {
6610     static mixin M8897!(int);
6611     static class causesAnError  {}
6612 }
6613 
6614 template M8897 ( E ) { }
6615 
6616 /***************************************************/
6617 // 8917
6618 
6619 void test8917()
6620 {
6621     int[3] a;
6622     int[3] a2;
6623     int[3] b = a[] + a2[];
6624 }
6625 
6626 /***************************************************/
6627 // 8945
6628 
6629 struct S8945 // or `class`, or `union`
6630 {
6631     struct S0(T) { int i; }
6632     struct S1(T) { this(int){} }
6633 }
6634 
6635 void test8945()
6636 {
6637     auto cs0a = const S8945.S0!int();  // ok
6638     auto cs0b = const S8945.S0!int(1); // ok
6639     auto cs1  = const S8945.S1!int(1); // ok
6640 
6641     auto s0a = S8945.S0!int();  // Error: struct S0 does not overload ()
6642     auto s0b = S8945.S0!int(1); // Error: struct S0 does not overload ()
6643     auto s1  = S8945.S1!int(1); // Error: struct S1 does not overload ()
6644 }
6645 
6646 /***************************************************/
6647 
6648 struct S162
6649 {
6650     static int generateMethodStubs( Class )()
6651     {
6652         int text;
6653 
6654         foreach( m; __traits( allMembers, Class ) )
6655         {
6656             static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) == function ) )
6657             {
6658                 pragma(msg, __traits( getOverloads, Class, m ));
6659             }
6660         }
6661 
6662         return text;
6663     }
6664 
6665     enum int ttt = generateMethodStubs!( S162 )();
6666 
6667     float height();
6668     int get( int );
6669     int get( long );
6670     void clear();
6671 
6672     void draw( int );
6673     void draw( long );
6674 }
6675 
6676 /***************************************************/
6677 
6678 void test163() {
6679     static class C { int x; int y; }
6680 
6681     immutable C c = new C();
6682     shared C c2 = new C();
6683     shared const C c3 = new C();
6684 
6685     class D { int x; int y; }
6686     immutable D d;
6687     assert(!__traits(compiles, d = new D()));
6688 
6689     static struct S { int x; int y; }
6690 
6691     immutable S* s = new S();
6692     shared S* s2 = new S();
6693     shared const S* s3 = new S();
6694 
6695     shared S* s4;
6696     assert(__traits(compiles, s4 = new immutable(S)()));
6697 
6698     struct T { int x; int y; }
6699     immutable T* t;
6700     assert(!__traits(compiles, t = new T()));
6701 
6702     immutable int* pi = new int();
6703     immutable void* pv = new int();
6704 
6705     immutable int[] ai = new int[1];
6706     immutable void[] av = new int[2];
6707 }
6708 
6709 /***************************************************/
6710 struct S9000
6711 { ubyte i = ubyte.max; }
6712 
6713 enum E9000 = S9000.init;
6714 
6715 /***************************************************/
6716 
6717 mixin template DefineCoreType(string type)
6718 {
6719     struct Faulty
6720     {
6721         static int x;
6722 
6723         static void instance()
6724         {
6725             x = 3;
6726         }
6727 
6728         X164!() xxx;
6729     }
6730 }
6731 
6732 mixin DefineCoreType!("");
6733 
6734 
6735 mixin template A164()
6736 {
6737     static this()
6738     {
6739     }
6740 }
6741 
6742 struct X164()
6743 {
6744     mixin A164!();
6745 }
6746 
6747 
6748 /***************************************************/
6749 // 9428
6750 
6751 void test9428()
6752 {
6753     int[2][] items = [[1, 2]];
6754     int[2] x = [3, 4];
6755 
6756     auto r1 = items ~ [x];
6757     assert(r1.length == 2);
6758     assert(r1[0][0] == 1);
6759     assert(r1[0][1] == 2);
6760     assert(r1[1][0] == 3);
6761     assert(r1[1][1] == 4);
6762 
6763     auto r2 = items ~ x;
6764     assert(r2.length == 2);
6765     assert(r2[0][0] == 1);
6766     assert(r2[0][1] == 2);
6767     assert(r2[1][0] == 3);
6768     assert(r2[1][1] == 4);
6769 
6770     auto r3 = [x] ~ items;
6771     assert(r3.length == 2);
6772     assert(r3[0][0] == 3);
6773     assert(r3[0][1] == 4);
6774     assert(r3[1][0] == 1);
6775     assert(r3[1][1] == 2);
6776 
6777     auto r4 = x ~ items;
6778     assert(r4.length == 2);
6779     assert(r4[0][0] == 3);
6780     assert(r4[0][1] == 4);
6781     assert(r4[1][0] == 1);
6782     assert(r4[1][1] == 2);
6783 }
6784 
6785 /***************************************************/
6786 // 9477
6787 
6788 template Tuple9477(T...) { alias T Tuple9477; }
6789 template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; }
6790 
6791 void test9477()
6792 {
6793     static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; }
6794     static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; }
6795 
6796     // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9748
6797     int order;
6798     // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9756
6799     auto checkOrder(bool dyn, uint expected)()
6800     {
6801         assert(order==expected);
6802         order++;
6803         // Use temporary ("v") to work around http://d.puremagic.com/issues/show_bug.cgi?id=9402
6804         auto v = cast(Select9477!(dyn, string, char[1]))"a";
6805         return v;
6806     }
6807 
6808     foreach (b1; Tuple9477!(false, true))
6809         foreach (b2; Tuple9477!(false, true))
6810         {
6811             version (D_PIC) {} else // Work around http://d.puremagic.com/issues/show_bug.cgi?id=9754
6812             {
6813                 assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))""  ));
6814                 assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))""  ));
6815 
6816                 assert(!isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6817                 assert( isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6818             }
6819 
6820             assert( isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6821             assert(!isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6822 
6823             assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6824             assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6825 
6826             assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6827             assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6828 
6829             // Note: order of evaluation was not followed before this patch
6830             // (thus, the test below will fail without the patch).
6831             // Although the specification mentions that as implementation-defined behavior,
6832             // I understand that this isn't by design, but rather an inconvenient aspect of DMD
6833             // that has been moved to the specification.
6834             order = 0;
6835             bool result = checkOrder!(b1, 0)() == checkOrder!(b2, 1)();
6836             assert(result);
6837             assert(order == 2);
6838         }
6839 
6840     // need largest natural alignment to avoid unaligned access on
6841     // some architectures, double in this case.
6842     align(8) ubyte[64] a1, a2;
6843     foreach (T; Tuple9477!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double))
6844     {
6845         auto s1 = cast(T[])(a1[]);
6846         auto s2 = cast(T[])(a2[]);
6847         assert(s1 == s2);
6848         a2[$-1]++;
6849         assert(s1 != s2);
6850         assert(s1[0..$-1]==s2[0..$-1]);
6851         a2[$-1]--;
6852     }
6853 }
6854 
6855 /***************************************************/
6856 // 9504
6857 
6858 struct Bar9504
6859 {
6860     template Abc(T)
6861     {
6862         T y;
6863     }
6864 
6865     enum size_t num = 123;
6866 
6867     class Def {}
6868 }
6869 
6870 template GetSym9504(alias sym) { static assert(__traits(isSame, sym, Bar9504.Abc)); }
6871 template GetExp9504(size_t n) { static assert(n == Bar9504.num); }
6872 template GetTyp9504(T) { static assert(is(T == Bar9504.Def)); }
6873 
6874 alias GetSym9504!(typeof(Bar9504.init).Abc) X9504; // NG
6875 alias GetExp9504!(typeof(Bar9504.init).num) Y9504; // NG
6876 alias GetTyp9504!(typeof(Bar9504.init).Def) Z9504;
6877 
6878 Bar9504 test9504()
6879 {
6880     alias GetSym9504!(typeof(return).Abc) V9504; // NG
6881     alias GetExp9504!(typeof(return).num) W9504; // NG
6882     alias GetTyp9504!(typeof(return).Def) X9504;
6883     return Bar9504();
6884 }
6885 
6886 /***************************************************/
6887 // 9538
6888 
6889 void test9538()
6890 {
6891     void*[1] x;
6892     auto ti = typeid(x.ptr);
6893 }
6894 
6895 /***************************************************/
6896 // 9539
6897 
6898 void test9539()
6899 {
6900     void f(int** ptr)
6901     {
6902         assert(**ptr == 10);
6903     }
6904     int* p = new int;
6905     *p = 10;
6906     int*[1] x = [p];
6907     f(&x[0]);
6908 
6909     int*[] arr = [null];
6910     static assert(!__traits(compiles, p = arr));    // bad!
6911 }
6912 
6913 /***************************************************/
6914 // 9700
6915 
6916 mixin template Proxy9700(alias a)
6917 {
6918     auto ref opOpAssign(string op, V)(V v) { return a += v; }  // NG
6919   //auto ref opOpAssign(string op, V)(V v) { a += v; } // OK
6920 }
6921 struct MyInt9700
6922 {
6923     int value;
6924     invariant() { assert(value >= 0); }
6925     mixin Proxy9700!value;
6926 }
6927 void test9700()
6928 {
6929     MyInt9700 a = { 2 };
6930     a *= 3;   // object.Error: Access Violation
6931 }
6932 
6933 /***************************************************/
6934 // 9834
6935 
6936 struct Event9834
6937 {
6938     void delegate() dg;
6939     void set(void delegate() h) pure { dg = h; }  // AV occurs
6940     void call() { dg(); }
6941 }
6942 void test9834()
6943 {
6944     Event9834 ev;
6945     auto a = new class
6946     {
6947         Object o;
6948         this()
6949         {
6950             o = new Object;
6951             ev.set((){ o.toString(); });
6952         }
6953     };
6954     ev.call();
6955 }
6956 
6957 /***************************************************/
6958 // 9859
6959 
6960 void test9859(inout int[] arr)
6961 {
6962     auto dg1 = { foreach (i, e; arr) { } };
6963     dg1();
6964 
6965     void foo() { auto v = arr; auto w = arr[0]; }
6966     void bar(inout int i) { auto v = arr[i]; }
6967 
6968     auto dg2 =
6969     {
6970         auto dg =
6971         {
6972             void foo(T)()
6973             {
6974                 auto dg =
6975                 {
6976                     auto dg =
6977                     {
6978                         auto v = arr;
6979                     };
6980                 };
6981             }
6982             foo!int;
6983         };
6984     };
6985 
6986     void qux(T)()
6987     {
6988         auto v = arr;
6989         auto dg1 = { auto v = arr; };
6990         auto dg2 =
6991         {
6992             auto dg =
6993             {
6994                 auto v = arr;
6995             };
6996         };
6997     }
6998     qux!int;
6999 }
7000 
7001 /***************************************************/
7002 // 9912
7003 
7004 template TypeTuple9912(Stuff...)
7005 {
7006     alias Stuff TypeTuple9912;
7007 }
7008 
7009 struct S9912
7010 {
7011     int i;
7012     alias TypeTuple9912!i t;
7013 
7014     void testA() {
7015         auto x = t;
7016     }
7017 
7018     void testB() {
7019         auto x = t;
7020     }
7021 }
7022 
7023 /***************************************************/
7024 // 9883
7025 
7026 struct S9883
7027 {
7028     @property size_t p9883(T)() { return 0; }
7029 }
7030 
7031 @property size_t p9883(T)() { return 0; }
7032 
7033 void test9883()
7034 {
7035     S9883 s;
7036     auto n1 = p9883!int; // OK
7037     auto n2 = s.p9883!int; // OK
7038     auto a1 = new int[p9883!int]; // Error: need size of rightmost array, not type p!(int)
7039     auto a2 = new int[s.p9883!int]; // Error: no property 'p!(int)' for type 'S'
7040 }
7041 
7042 
7043 /***************************************************/
7044 // 10091
7045 
7046 struct S10091
7047 {
7048     enum e = "a";
7049 }
7050 
7051 void test10091()
7052 {
7053     auto arr = cast(ubyte[1]) S10091.e;
7054 }
7055 
7056 /***************************************************/
7057 
7058 void test12824()
7059 {
7060 label:
7061     static if (0)
7062     {
7063     }
7064 }
7065 
7066 /***************************************************/
7067 // 9130
7068 
7069 class S9130 { void bar() { } }
7070 
7071 import core.stdc.stdio : printf;
7072 
7073 struct Function
7074 {
7075     int[] ai = [1,2,3];
7076 }
7077 
7078 @property void meta(alias m)()
7079 {
7080     static Function md;
7081     printf("length = %d\n", md.ai.length);
7082     printf("ptr = %p\n", md.ai.ptr);
7083     md.ai[0] = 0;
7084 }
7085 
7086 void test9130()
7087 {
7088     meta!(__traits(getOverloads, S9130, "bar")[0]);
7089     meta!(S9130.bar);
7090 }
7091 
7092 /***************************************************/
7093 // 10390
7094 
7095 class C10390 { this() { this.c = this; } C10390 c; }
7096 const c10390 = new C10390();
7097 pragma(msg, c10390);
7098 
7099 /***************************************************/
7100 // 10542
7101 
7102 class B10542
7103 {
7104     this() nothrow pure @safe { }
7105 }
7106 
7107 class D10542 : B10542
7108 {
7109 }
7110 
7111 void test10542() nothrow pure @safe
7112 {
7113     new D10542;
7114 }
7115 
7116 /***************************************************/
7117 // 10539
7118 
7119 void test10539()
7120 {
7121     int[2][2] a;
7122     int* p1 = a.ptr.ptr;    // OK <- error
7123     int* p2 = (*a.ptr).ptr; // OK
7124     assert(p1 is p2);
7125 }
7126 
7127 /***************************************************/
7128 
7129 struct TimeOfDay
7130 {
7131     ubyte h, m, s;
7132 }
7133 
7134 __gshared byte glob;
7135 
7136 struct DateTime
7137 {
7138     this(ubyte _d, ubyte _m, ubyte _y, TimeOfDay _tod = TimeOfDay.init)
7139     {
7140         d = _d;
7141         m = _m;
7142         y = _y;
7143         tod = _tod;
7144     }
7145     TimeOfDay tod;
7146     ubyte d, m, y;
7147 }
7148 
7149 
7150 void test10634()
7151 {
7152     glob = 123;
7153     DateTime date1 = DateTime(0, 0, 0);
7154     DateTime date2;
7155     assert(date1 == date2);
7156 }
7157 
7158 /***************************************************/
7159 
7160 immutable(char)[4] bar7254(int i)
7161 {
7162     if (i)
7163     {
7164         immutable(char)[4] r; return r;
7165     }
7166     else
7167         return "1234";
7168 }
7169 
7170 void test7254()
7171 {
7172     assert(bar7254(0) == "1234");
7173 }
7174 
7175 /***************************************************/
7176 
7177 struct S11075() { int x = undefined_expr; }
7178 
7179 class C11075() { int x = undefined_expr; }
7180 
7181 interface I11075() { enum int x = undefined_expr; }
7182 
7183 void test11075()
7184 {
7185     static assert(!is(typeof(S11075!().x)));
7186     static assert(!is(typeof(S11075!().x)));
7187 
7188     static assert(!is(typeof(C11075!().x)));
7189     static assert(!is(typeof(C11075!().x)));
7190 
7191     static assert(!is(typeof(I11075!().x)));
7192     static assert(!is(typeof(I11075!().x)));
7193 }
7194 
7195 /***************************************************/
7196 // 11181
7197 
7198 void test11181()
7199 {
7200     auto a = ["a", "b"];
7201 
7202     static assert(!is(typeof([a, "x"])));
7203     static assert(!is(typeof(true ? a : "x")));
7204 
7205     static assert(!is(typeof(true ? a[0 .. $] : "x")));
7206     static assert(!is(typeof([a[0 .. $], "x"])));
7207 }
7208 
7209 /***************************************************/
7210 // 11317
7211 
7212 void test11317()
7213 {
7214     auto ref uint fun()
7215     {
7216         return 0;
7217     }
7218 
7219     void test(ref uint x) {}
7220     static assert(!__traits(compiles, test(fun())));
7221 
7222     assert(fun() == 0);
7223 }
7224 
7225 /***************************************************/
7226 // 11888
7227 
7228 void test11888()
7229 {
7230     static long val;
7231 
7232     static ubyte* foo(size_t* len)
7233     {
7234         *len = val.sizeof;
7235         return cast(ubyte*)&val;
7236     }
7237 
7238     size_t size;
7239     ubyte[] t = foo(&size)[0..size];
7240     assert(t.ptr is cast(void*)&val);
7241     assert(t.length == 8);
7242 
7243     // regression test
7244     int[3] sa1 = [1,2,3];
7245     int[1] sa2 = sa1[1..2]; // convert slice to Tsarray
7246     assert(sa2.length == 1);
7247     assert(sa2[0] == 2);
7248 }
7249 
7250 /***************************************************/
7251 // 12036
7252 
7253 template T12036(alias a)
7254 {
7255     string value;
7256 }
7257 
7258 struct S12036
7259 {
7260     auto fun() { }
7261     mixin T12036!fun;
7262 }
7263 
7264 void test12036()
7265 {
7266     S12036 s;
7267     assert(s.value == "");
7268 }
7269 
7270 /***************************************************/
7271 // 12153
7272 
7273 void test12153()
7274 {
7275     int[1] i, j;
7276     bool b = true;
7277     (b ? i : j)[] = [4];
7278     assert(i == [4]);
7279 
7280     // regression test
7281     int[1][1] k, l;
7282     (b ? k : l)[0..1][0..1] = [4];
7283     assert(k == [[4]]);
7284 }
7285 
7286 /***************************************************/
7287 // 12498
7288 
7289 string a12498()
7290 {
7291     string b;
7292     while (b) { }
7293     for (; b; ) { }
7294     return "";
7295 }
7296 
7297 void test12498()
7298 {
7299     enum t = a12498();
7300     string x = t;
7301 }
7302 
7303 /***************************************************/
7304 // 12900
7305 
7306 struct A12900
7307 {
7308     char[1] b;
7309 }
7310 
7311 void test12900()
7312 {
7313     A12900 c;
7314     if (*c.b.ptr)
7315         return;
7316 }
7317 
7318 /***************************************************/
7319 // 12937
7320 
7321 void test12937()
7322 {
7323     void[1] sa2 = cast(void[])[cast(ubyte)1];   // ICE!
7324     assert((cast(ubyte[])sa2[])[0] == 1);
7325 }
7326 
7327 /***************************************************/
7328 // 13154
7329 
7330 void test13154()
7331 {
7332     int[3] ints      = [2   , 1   , 0   , 1   ][0..3];
7333     float[3] floats0 = [2f  , 1f  , 0f  , 1f  ][0..3];
7334     float[3] floats1 = [2.0 , 1.0 , 0.0 , 1.0 ][0..3];  // fails!
7335     float[3] floats2 = [2.0f, 1.0f, 0.0f, 1.0f][0..3];
7336     assert(ints == [2, 1, 0]);
7337     assert(floats0 == [2, 1, 0]);
7338     assert(floats1 == [2, 1, 0]); // fail!
7339     assert(floats1 != [0, 0, 0]); // fail!
7340     assert(floats2 == [2, 1, 0]);
7341 }
7342 
7343 /***************************************************/
7344 // 13437
7345 
7346 ubyte[4] foo13437() { return [1,2,3,4]; }
7347 
7348 void test13437()
7349 {
7350     auto n = cast(ubyte[4])foo13437()[];  // OK <- ICE: e2ir.c 4616
7351     static assert(is(typeof(n) == ubyte[4]));
7352     assert(n == [1,2,3,4]);
7353 }
7354 
7355 /***************************************************/
7356 // 13472
7357 
7358 class A13472
7359 {
7360     int a;
7361 }
7362 
7363 void test13472()
7364 {
7365     A13472[] test;
7366     test.length = 4;
7367     auto b = test[0..2] ~ null ~ test[2..$];
7368     assert(b.length == 5);
7369 }
7370 
7371 /***************************************************/
7372 // 13476
7373 
7374 template ParameterTypeTuple13476(func...)
7375 {
7376     static if (is(typeof(*func[0]) P == function))
7377         alias ParameterTypeTuple13476 = P;
7378     else
7379         static assert(0, "argument has no parameters");
7380 }
7381 
7382 int flag13476;
7383 
7384 __gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476;
7385 
7386 extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args)
7387 {
7388     ++flag13476;
7389     extern(C) void function(int) nothrow impl = (i) { };
7390     return (func = impl)(args);
7391 }
7392 
7393 __gshared extern(C) void function(int) nothrow  someFunc13476Alt = &Stub13476Alt!someFunc13476AltP;
7394 __gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt;
7395 
7396 extern(C) auto Stub13476Alt(alias func)(int args) nothrow
7397 {
7398     ++flag13476;
7399     extern(C) void function(int) nothrow impl = (i) {};
7400     return (*func = impl)(args);
7401 }
7402 
7403 void test13476()
7404 {
7405     assert(flag13476 == 0);
7406 
7407     someFunc13476(42);
7408     assert(flag13476 == 1);
7409     someFunc13476(43);
7410     assert(flag13476 == 1);
7411 
7412     someFunc13476Alt(42);
7413     assert(flag13476 == 2);
7414     someFunc13476Alt(43);
7415     assert(flag13476 == 2);
7416 }
7417 
7418 /***************************************************/
7419 // 14038
7420 
7421 static immutable ubyte[string] wordsAA14038;
7422 static this()
7423 {
7424     wordsAA14038["zero"] = 0;
7425 }
7426 
7427 /***************************************************/
7428 // 14192
7429 
7430 void test14192()
7431 {
7432     shared int[int] map;
7433     map[1] = 1;
7434 }
7435 
7436 /***************************************************/
7437 // 13720
7438 
7439 struct FracSec13720
7440 {
7441     this(int hnsecs) {}
7442 }
7443 
7444 struct SysTime13720
7445 {
7446     this(TimeOfDay13720 dateTime, FracSec13720 fracSec)
7447     {
7448     }
7449 }
7450 
7451 struct TimeOfDay13720
7452 {
7453     ~this() { }
7454 }
7455 
7456 void assertThrown13720(T)(lazy T) {}
7457 
7458 void test13720()
7459 {
7460     assertThrown13720(SysTime13720(TimeOfDay13720.init, FracSec13720(-1)));
7461 }
7462 
7463 /***************************************************/
7464 // 13952
7465 
7466 struct Reg13952
7467 {
7468     ubyte type;
7469     ubyte regNo;
7470     ushort size;
7471 }
7472 
7473 struct Imm13952
7474 {
7475     ulong imm;
7476 }
7477 
7478 struct Opnd13952
7479 {
7480     union
7481     {
7482         Reg13952 reg; // size == 4
7483         Imm13952 imm; // size == 8
7484     }
7485     ubyte tag;
7486 
7487     this(Reg13952 r) { reg = r; }
7488 }
7489 
7490 Opnd13952 opnd13952(Reg13952 reg)
7491 {
7492     return Opnd13952(reg);
7493 }
7494 
7495 void test13952()
7496 {
7497     Reg13952 reg;
7498     auto op = opnd13952(reg);
7499     auto buf = (cast(ubyte*)&op)[0 .. op.sizeof];
7500     //debug
7501     //{
7502     //    import std.stdio;
7503     //    writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]);
7504     //    writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]);
7505     //}
7506     foreach (e; buf) assert(e == 0);
7507 }
7508 
7509 /***************************************************/
7510 // 14165
7511 
7512 class Foo14165
7513 {
7514     @disable this();
7515     this(int i) {}
7516 }
7517 
7518 /***************************************************/
7519 // 13985
7520 
7521 interface I13985
7522 {
7523     void m1();
7524     void m2();
7525     void m3();
7526 
7527     final void mf()
7528     {
7529         m3();
7530     }
7531 }
7532 
7533 class C13985 : I13985
7534 {
7535     void m1() {}
7536     void m2() {}
7537     void m3() {}
7538 }
7539 
7540 class D13985 : C13985
7541 {
7542     void ml()
7543     {
7544         super.mf();
7545     }
7546 }
7547 
7548 void test13985()
7549 {
7550     auto d = new D13985();
7551     d.ml();
7552 }
7553 
7554 /***************************************************/
7555 // 14211
7556 
7557 extern(C++) // all derived classes won't have invariants
7558 class B14211
7559 {
7560     void func()
7561     {
7562     }
7563 }
7564 
7565 final class C14211 : B14211
7566 {
7567 }
7568 
7569 void test14211()
7570 {
7571     auto c = new C14211();
7572     *cast(void**)c = null;
7573     c.func();   // called without vtbl access
7574 }
7575 
7576 /***************************************************/
7577 // 14552
7578 
7579 template map14552(fun...)
7580 {
7581     template AppliedReturnType(alias f)
7582     {
7583         alias typeof(f(0)) AppliedReturnType;
7584     }
7585 
7586     auto map14552(int[] r)
7587     {
7588         assert(!is(AppliedReturnType!fun));
7589         return MapResult14552!fun();
7590     }
7591 }
7592 
7593 struct MapResult14552(alias fun)
7594 {
7595     @property front()
7596     {
7597         fun(0);
7598     }
7599 }
7600 
7601 class Outer14552
7602 {
7603     auto test()
7604     {
7605         [1].map14552!(j => new Inner);
7606     }
7607     class Inner {}
7608 }
7609 
7610 /***************************************************/
7611 // 14853
7612 
7613 struct Queue14853(T)
7614 {
7615     struct Node
7616     {
7617         T mfPayload = T.init;
7618         union
7619         {
7620                    typeof(this)*  mfPrev;
7621             shared(typeof(this)*) mfShPrev;
7622         }
7623         union
7624         {
7625                    typeof(this)*  mfNext;
7626             shared(typeof(this)*) mfShNext;
7627         }
7628     }
7629 
7630     Node root;
7631 
7632     void pfPut(T v, Node* r = null)
7633     {
7634         shared n = new Node(v);    // problem!
7635     }
7636 }
7637 
7638 void test14853()
7639 {
7640     auto b1 = new Queue14853!uint;
7641 }
7642 
7643 /********************************************************/
7644 // 15045
7645 
7646 void test15045()
7647 {
7648     void testName(T, bool r, string name)()
7649     {
7650         T t;
7651 
7652         static assert(r ==          is(typeof(mixin("T."~name))));
7653         static assert(r ==          is(typeof(mixin("t."~name))));
7654         static assert(r == __traits(compiles, mixin("T."~name)));
7655         static assert(r == __traits(compiles, mixin("t."~name)));
7656         static assert(r == mixin("__traits(compiles, T."~name~")"));
7657         static assert(r == mixin("__traits(compiles, t."~name~")"));
7658 
7659         static assert(r ==                       __traits(hasMember, T, name) );
7660         static assert(r ==                       __traits(hasMember, t, name) );
7661         static assert(r == __traits(compiles,    __traits(getMember, T, name) ));
7662         static assert(r == __traits(compiles,    __traits(getMember, t, name) ));
7663         static assert(r == __traits(compiles, __traits(getOverloads, T, name) ));
7664         static assert(r == __traits(compiles, __traits(getOverloads, t, name) ));
7665     }
7666     void test(T, bool r)()
7667     {
7668         testName!(T, r, "__ctor")();
7669         testName!(T, r, "__dtor")();
7670         testName!(T, r, "__xdtor")();
7671         testName!(T, r, "__postblit")();
7672         testName!(T, r, "__xpostblit")();
7673     }
7674 
7675     static struct X
7676     {
7677         this(int) {}
7678         this(this) {}
7679         ~this() {}
7680     }
7681 
7682     static struct S1
7683     {
7684         auto opDispatch(string name, A...)(A args) { }
7685     }
7686     static struct S2
7687     {
7688         X get() { return X(); };
7689         alias get this;
7690     }
7691     static struct S3
7692     {
7693         X opDot() { return X(); };
7694     }
7695 
7696     test!(X, true)();
7697     test!(S1, false)();
7698     test!(S2, false)();
7699     test!(S3, false)();
7700 }
7701 
7702 /***************************************************/
7703 // 15116
7704 
7705 alias TypeTuple15116(T...) = T;
7706 
7707 template Mix15116()
7708 {
7709     TypeTuple15116!(int, int) tup;
7710 }
7711 
7712 struct S15116
7713 {
7714     mixin Mix15116 mix;
7715 }
7716 
7717 void test15116()
7718 {
7719     S15116 s;
7720     auto x1 = s.tup;        // OK
7721     auto x2 = s.mix.tup;    // OK <- NG
7722 }
7723 
7724 /***************************************************/
7725 // 15117
7726 
7727 template Mix15117()
7728 {
7729     int y = { typeof(this)* s; return s ? s.mix.y : 0; }();
7730 }
7731 
7732 struct S15117
7733 {
7734     int x = { typeof(this)* s; return s ? s.x : 0; }(); // OK
7735 
7736     mixin Mix15117 mix;     // OK <- NG
7737 }
7738 
7739 /***************************************************/
7740 // 15126
7741 
7742 struct Json15126
7743 {
7744     ubyte[16] m_data;
7745     int opDispatch(string prop)() const { return 0; }
7746     int opDispatch(string prop)() { return 0; }
7747 }
7748 
7749 template isCustomSerializable15126(T)
7750 {
7751     enum isCustomSerializable15126 = T.init.toRepresentation();
7752 }
7753 
7754 alias bug15126 = isCustomSerializable15126!Json15126;
7755 
7756 /***************************************************/
7757 // 15141
7758 
7759 class A15141
7760 {
7761     abstract void method();
7762 }
7763 
7764 class B15141 : A15141 { }
7765 
7766 void test15141()
7767 {
7768     auto a = Object.factory(__MODULE__ ~ ".A15141");
7769     assert(a is null);
7770     auto b = Object.factory(__MODULE__ ~ ".B15141");
7771     assert(b is null); // OK <- oops
7772 }
7773 
7774 /***************************************************/
7775 // 15366
7776 
7777 enum E15366 : bool { A, B };
7778 
7779 struct S15366
7780 {
7781     void func1(E15366 e) {}
7782 
7783     void func2(E15366 a, E15366 b)
7784     {
7785         func1(cast(E15366)(a && b));
7786         func1(cast(E15366)(a || b));
7787 
7788         auto x1 = cast(E15366)(a && b);
7789         auto x2 = cast(E15366)(a || b);
7790     }
7791 }
7792 
7793 /***************************************************/
7794 // 15369
7795 
7796 struct MsgTable15369
7797 {
7798     const(char)[] ident;
7799     const(char)* name;
7800 };
7801 
7802 MsgTable15369[] msgTable15369 =
7803 [
7804     { "empty", "" },
7805 ];
7806 
7807 void test15369()
7808 {
7809     auto id = msgTable15369[0].ident;
7810     auto p = msgTable15369[0].name;
7811 
7812     // a string literal "" should be zero-terminated
7813     assert(*p == '\0');
7814 }
7815 
7816 void test15638()
7817 {
7818     class A {}
7819     class B : A {}
7820     class C : A {}
7821 
7822     B b;
7823     C c;
7824     const(B) cb;
7825     const(C) cc;
7826     immutable(B) ib;
7827     immutable(C) ic;
7828 
7829     // Common type for const derived classes
7830     auto constCommon = true ? cb : cc;
7831     static assert(is(typeof(constCommon) == const(A)));
7832 
7833     // Common type for immutable derived classes
7834     auto immutableCommon = true ? ib : ic;
7835     static assert(is(typeof(immutableCommon) == immutable(A)));
7836 
7837     // Common type for mixed const/immutable derived classes
7838     auto mixed1 = true ? cb : ic;
7839     static assert(is(typeof(mixed1) == const(A)));
7840     auto mixed2 = true ? ib : cc;
7841     static assert(is(typeof(mixed2) == const(A)));
7842 
7843     // Common type for mixed mutable/immutable derived classes
7844     auto mixed3 = true ? b : ic;
7845     static assert(is(typeof(mixed3) == const(A)));
7846     auto mixed4 = true ? ib : c;
7847     static assert(is(typeof(mixed4) == const(A)));
7848 
7849     // Array literal type deduction
7850     auto arr1 = [ new immutable(B), new C ];
7851     auto arr2 = [ new B,            new const(C) ];
7852     auto arr3 = [ new immutable(B), new immutable(C) ];
7853     static assert(is(typeof(arr1) == const(A)[]));
7854     static assert(is(typeof(arr2) == const(A)[]));
7855     static assert(is(typeof(arr3) == immutable(A)[]));
7856 }
7857 
7858 /***************************************************/
7859 // 15961
7860 
7861 struct SliceOverIndexed15961(T)
7862 {
7863     enum assignableIndex = T.init;
7864 }
7865 
7866 struct Grapheme15961
7867 {
7868     SliceOverIndexed15961!Grapheme15961 opSlice()
7869     {
7870         assert(0);
7871     }
7872 
7873     struct
7874     {
7875         ubyte* ptr_;
7876     }
7877 }
7878 
7879 /***************************************************/
7880 // 16022
7881 
7882 bool test16022()
7883 {
7884     enum Type { Colon, Comma }
7885     Type type;
7886     return type == Type.Colon, type == Type.Comma;
7887 }
7888 
7889 /***************************************************/
7890 // https://issues.dlang.org/show_bug.cgi?id=16233
7891 
7892 enum valueConvertible(T1, T2) = blah;
7893 
7894 struct Checked(T, Hook)
7895 {
7896     bool opEquals(U)(Checked!(U, Hook) rhs)
7897     {
7898         alias R = typeof(payload + rhs.payload);
7899         static if (valueConvertible!(T, R))
7900         {
7901         }
7902         return false;
7903     }
7904 }
7905 
7906 void test16233()
7907 {
7908     Checked!(Checked!(int, void), void) x1;
7909 }
7910 
7911 /***************************************************/
7912 // https://issues.dlang.org/show_bug.cgi?id=16466
7913 
7914 void test16466()
7915 {
7916     static struct S
7917     {
7918         real r;
7919     }
7920     real r;
7921     printf("S.alignof: %x, r.alignof: %x\n", S.alignof, r.alignof);
7922     assert(S.alignof == r.alignof);
7923 }
7924 
7925 /***************************************************/
7926 
7927 // https://issues.dlang.org/show_bug.cgi?id=16408
7928 
7929 char[1] SDL_GetKeyName_buffer;
7930 
7931 const(char)[] SDL_GetKeyName(char k)
7932 {
7933     pragma(inline, false);
7934     SDL_GetKeyName_buffer[0] = k;
7935     return SDL_GetKeyName_buffer[];
7936 }
7937 
7938 void formattedWrite(const(char)[] strW, const(char)[] strA, const(char)[] strC)
7939 {
7940     pragma(inline, false);
7941 
7942     assert(strW == "W");
7943     assert(strA == "A");
7944     assert(strC == "C");
7945 }
7946 
7947 void test16408()
7948 {
7949     pragma(inline, false);
7950     formattedWrite(
7951         SDL_GetKeyName('W').idup,
7952         SDL_GetKeyName('A').idup,
7953         SDL_GetKeyName('C').idup
7954     );
7955 }
7956 
7957 /***************************************************/
7958 // https://issues.dlang.org/show_bug.cgi?id=17349
7959 
7960 void test17349()
7961 {
7962     static struct S
7963     {
7964         int bar(void delegate(ref int*)) { return 1; }
7965         int bar(void delegate(ref const int*)) const { return 2; }
7966     }
7967 
7968     void dg1(ref int*) { }
7969     void dg2(ref const int*) { }
7970     S s;
7971     int i;
7972     i = s.bar(&dg1);
7973     assert(i == 1);
7974     i = s.bar(&dg2);
7975     assert(i == 2);
7976 }
7977 
7978 /***************************************************/
7979 // https://issues.dlang.org/show_bug.cgi?id=17915
7980 
7981 void test17915()
7982 {
7983     static class MyClass
7984     {
7985         S17915!MyClass m_member;
7986     }
7987 }
7988 
7989 struct S17915(T)
7990 {
7991     T owner;
7992 }
7993 
7994 /***************************************************/
7995 
7996 int main()
7997 {
7998     test1();
7999     test2();
8000     test3();
8001     test4();
8002     test5();
8003     test6();
8004     test7();
8005     test8();
8006     test9();
8007     test10();
8008     test11();
8009     test12();
8010     test13();
8011     test14();
8012     test15();
8013     test16();
8014     test17();
8015     test18();
8016     test19();
8017     test20();
8018     test21();
8019     test22();
8020     test23();
8021     test24();
8022     test25();
8023     test26();
8024     test27();
8025     test28();
8026     test29();
8027     test30();
8028     test31();
8029     test32();
8030     test33();
8031     test34();
8032     test35();
8033     test36();
8034     test37();
8035     test38();
8036     test39();
8037     test40();
8038     test41();
8039     test42();
8040     test43();
8041     test44();
8042     test45();
8043     test46();
8044     test47();
8045     test48();
8046     test49();
8047     test796();
8048     test50();
8049     test51();
8050     test52();
8051     test53();
8052     test54();
8053     test55();
8054     test56();
8055     test57();
8056     test58();
8057 
8058     test60();
8059     test61();
8060     test62();
8061     test63();
8062     test64();
8063     test65();
8064     test66();
8065     test67();
8066     test68();
8067     test69();
8068     test70();
8069 
8070     test5785();
8071     test72();
8072     test73();
8073     test74();
8074     test75();
8075     test76();
8076     test77();
8077     test78();
8078     test79();
8079     test80();
8080     test81();
8081     test82();
8082     test83();
8083     test3559();
8084     test84();
8085     test85();
8086     test2006();
8087     test8442();
8088     test86();
8089     test87();
8090     test2486();
8091     test5554();
8092     test88();
8093     test7545();
8094     test89();
8095     test90();
8096     test91();
8097     test92();
8098     test4536();
8099     test93();
8100     test94();
8101     test95();
8102     test5403();
8103     test96();
8104     test97();
8105     test98();
8106     test99();
8107     test100();
8108     test101();
8109 
8110     test103();
8111     test104();
8112     test105();
8113     test3927();
8114     test107();
8115 
8116     test109();
8117 
8118     test111();
8119 
8120     test113();
8121 
8122     test115();
8123     test116();
8124     test117();
8125     test3822();
8126     test6545();
8127     test118();
8128     test5081();
8129 
8130     test120();
8131     test10724();
8132     test122();
8133     test123();
8134     test124();
8135     test125();
8136     test6763();
8137 
8138     test127();
8139     test128();
8140     test1891();
8141     test129();
8142     test130();
8143     test1064();
8144     test131();
8145     test132();
8146     test133();
8147     test134();
8148     test135();
8149     test136();
8150     test137();
8151     test138();
8152     test1962();
8153     test139();
8154     test140();
8155     test141();
8156     test6317();
8157     test142();
8158     test143();
8159     test144();
8160     test145();
8161     test146();
8162     test147();
8163     test6685();
8164     test148();
8165     test149();
8166     test2356();
8167     test13652();
8168     test11238();
8169     test2540();
8170     test14348();
8171     test150();
8172     test151();
8173     test152();
8174     test153();
8175     test154();
8176     test155();
8177     test156();
8178     test658();
8179     test4258();
8180     test4539();
8181     test4963();
8182     test4031();
8183     test5437();
8184     test6230();
8185     test6264();
8186     test6284();
8187     test6295();
8188     test6293();
8189     test5046();
8190     test1471();
8191     test6335();
8192     test1687();
8193     test6228();
8194     test3733();
8195     test4392();
8196     test7942();
8197     test6220();
8198     test5799();
8199     test157();
8200     test6473();
8201     test6630();
8202     test6690();
8203     test2953();
8204     test2997();
8205     test4423();
8206     test4647();
8207     test5696();
8208     test6084();
8209     test6488();
8210     test6565();
8211     test6836();
8212     test6837();
8213     test6927();
8214     test6733();
8215     test6813();
8216     test6859();
8217     test3022();
8218     test6910();
8219     test6902();
8220     test6330();
8221     test6868();
8222     test2856();
8223     test3091();
8224     test6056();
8225     test6356();
8226     test7073();
8227     test7104();
8228     test7150();
8229     test7160();
8230     test7168();
8231     test7170();
8232     test7196();
8233     test7285();
8234     test14737();
8235     test7321();
8236     test3282();
8237     test7534();
8238     test7534cov();
8239     test7618();
8240     test7621();
8241     test11417();
8242     test7682();
8243     test7735();
8244     test7823();
8245     test7871();
8246     test7906();
8247     test7907();
8248     test12503();
8249     test8004();
8250     test8064();
8251     test8105();
8252     test159();
8253     test12824();
8254     test8283();
8255     test13182();
8256     test8269();
8257     test8395();
8258     test13427();
8259     test5749();
8260     test8396();
8261     test160();
8262     test8665();
8263     test8108();
8264     test8360();
8265     test9577();
8266     test6141();
8267     test199();
8268     test8526();
8269     test161();
8270     test7175();
8271     test8819();
8272     test8917();
8273     test8945();
8274     test11805();
8275     test14192();
8276     test163();
8277     test9428();
8278     test9477();
8279     test9538();
8280     test9700();
8281     test9834();
8282     test13947();
8283     test9883();
8284     test10091();
8285     test9130();
8286     test10542();
8287     test10539();
8288     test10634();
8289     test15080();
8290     test7254();
8291     test13468();
8292     test11075();
8293     test11181();
8294     test11317();
8295     test11888();
8296     test12036();
8297     test12153();
8298     test12937();
8299     test13154();
8300     test13437();
8301     test13472();
8302     test13476();
8303     test13720();
8304     test13952();
8305     test13985();
8306     test14211();
8307     test15141();
8308     test15369();
8309     test15638();
8310     test16233();
8311     test16466();
8312     test16408();
8313     test17349();
8314     test17915();
8315 
8316     printf("Success\n");
8317     return 0;
8318 }
8319