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