1 // RUNNABLE_PHOBOS_TEST
2 // REQUIRED_ARGS:
3 
4 module test;
5 
6 import core.vararg;
7 import core.stdc.stdlib;
8 import std.stdio;
9 import std.string;
10 import core.stdc.stdlib;
11 
12 
13 /*******************************************/
14 
15 struct S
16 {
opSliceAssignS17     int opSliceAssign(int v, size_t i, size_t j)
18     {
19         assert(v == 5);
20         assert(i == 9);
21         assert(j == 10);
22         return 3;
23     }
24 
opSliceAssignS25     int opSliceAssign(int v)
26     {
27         assert(v == 6);
28         return 11;
29     }
30 }
31 
test1()32 void test1()
33 {
34     S s;
35 
36     assert((s[9 .. 10] = 5) == 3);
37     assert((s[] = 6) == 11);
38 }
39 
40 /*******************************************/
41 
42 static int i2 = 1;
43 
test2()44 void test2()
45 {
46     synchronized { int i2 = 2; }
47     assert(i2 == 1);
48 }
49 
50 /*******************************************/
51 
test3()52 void test3()
53 {
54     size_t border = 8;
55 
56     for(ulong i = 0; i < border; i++)
57     {
58         ulong test = 1;
59         test <<= i;
60         double r = test;
61         ulong result = cast(ulong)r;
62 
63         if (result != test)
64         {
65             assert(0);
66         }
67     }
68 }
69 
70 /*******************************************/
71 
test4()72 void test4()
73 {
74     writeln("",true);
75 }
76 
77 /*******************************************/
78 
test5()79 void test5()
80 {
81     int[] qwert = new int[6];
82     int[] yuiop;
83     yuiop = qwert[2..5] = 3;
84     assert(yuiop.length == 3);
85     assert(yuiop[0] == 3);
86     assert(yuiop[1] == 3);
87     assert(yuiop[2] == 3);
88 }
89 
90 /*******************************************/
91 
92 struct Foo6
93 {
94     static int x;
95 
farrayFoo696     static int[] farray()
97     {
98         printf("farray\n");
99         assert(x == 0);
100         x++;
101         return new int[6];
102     }
103 
flwrFoo6104     static int flwr()
105     {
106         printf("flwr\n");
107         assert(x == 1);
108         x++;
109         return 2;
110     }
111 
fuprFoo6112     static int fupr()
113     {
114         printf("fupr\n");
115         assert(x == 2);
116         x++;
117         return 1;
118     }
119 }
120 
test6()121 void test6()
122 {
123     int[] yuiop;
124     yuiop =
125         Foo6.farray()[Foo6.flwr() .. $ - Foo6.fupr()] = 3;
126     assert(Foo6.x == 3);
127     assert(yuiop.length == 3);
128     assert(yuiop[0] == 3);
129     assert(yuiop[1] == 3);
130     assert(yuiop[2] == 3);
131 }
132 
133 /*******************************************/
134 
test7()135 void test7()
136 {
137     real a = 3.40483; // this is treated as 3.40483L
138     real b;
139     b = 3.40483;
140     assert(a==b);
141     assert(a==3.40483);
142     assert(a==3.40483L);
143     assert(a==3.40483F);
144 }
145 
146 /*******************************************/
147 
test8()148 void test8()
149 {
150    real [5][5] m = 1;
151    m[1][1..3] = 2;
152 
153    for (size_t i = 0; i < 5; i++)
154         for (size_t j = 0; j < 5; j++)
155         {
156             if (i == 1 && (j >= 1 && j < 3))
157                 assert(m[i][j] == 2);
158             else
159                 assert(m[i][j] == 1);
160         }
161 }
162 
163 /*******************************************/
164 
ClassOf(Type)165 class ClassOf(Type)
166 {
167     Type val;
168 
169     template refx()
170     {
171         alias val refx;
172     }
173 }
174 
175 struct StructOf
176 {
177     int val;
178 
refxStructOf179     template refx()
180     {
181         alias val refx;
182     }
183 }
184 
test9()185 void test9()
186 {
187     ClassOf!(int)  c = new ClassOf!(int)();
188     StructOf s;
189     int x = 10;
190 
191     c.refx!() = x;
192     x = c.refx!();
193     assert(x == 10);
194 
195     x = 11;
196     s.refx!() = x;
197     x = s.refx!();
198     assert(x == 11);
199 }
200 
201 
202 /*******************************************/
203 
test10()204 void test10()
205 {
206     static if( int.mangleof.length > 1 && int.mangleof[1] == 'x' )
207         printf("'x' as second char\n");
208 }
209 
210 /*******************************************/
211 
212 class Foo11 : Bar11 { }
213 
Foo11T(V)214 class Foo11T(V)
215 {
216     public void foo() {}
217 }
218 
219 class Bar11
220 {
this()221     public this(){
222         f = new Foo11T!(int);
223     }
224     Foo11T!(int) f;
225 }
226 
test11()227 void test11()
228 {
229     Foo11 fooIt = new Foo11();
230     if (fooIt !is null)
231         writefln("fooIt should be valid");
232     fooIt.f.foo();
233     writefln("it worked");
234 }
235 
236 /*******************************************/
237 
238 struct A12 {
239         int a;
240         union {
241                 int c;
242                 B12 b;
243         }
244 }
245 
246 struct B12 {
247         int b1;
248         int b2;
249 }
250 
251 void test12()
252 {
253         A12 a;
254         printf("%d\n", A12.sizeof);
255         assert(A12.sizeof == 12);
256 }
257 
258 /*******************************************/
259 
260 template declare13(X) { X declare13; }
261 
262 typeof(declare13!(int[0]).ptr[0]) x13;
263 typeof(declare13!(typeof(""))[0..$]) y13;
264 
265 void test13()
266 {
267 }
268 
269 /*******************************************/
270 
271 interface Father {}
272 
273 class Mother {
274      Father test() {
275          writefln("Called Mother.test!");
276          return new Child(42);
277      }
278 }
279 
280 class Child : Mother, Father {
281      int data;
282 
283      this(int d) { data = d; }
284 
285      override Child test() {
286          writefln("Called Child.test!");
287          return new Child(69);
288      }
289 }
290 
291 void test14()
292 {
293      Child aChild = new Child(105);
294      Mother childsMum = aChild;
295      Child childsChild = aChild.test();
296      Child mumsChild = cast(Child) childsMum.test();
297      writefln("Success2");
298 }
299 
300 
301 /*******************************************/
302 
303 class A15
304 {
305         int a = 3;
306 
307         class B
308         {
309             void bar()
310             {
311                 assert(a == 3);
312             }
313         }
314 
315         void fork()
316         {
317                 assert(a == 3);
318                 B b = new B();  // This is okay
319                 b.bar();
320 
321                 void knife()
322                 {
323                         assert(a == 3);
324                         B b = new B();  // No 'this' for nested class B
325                         b.bar();
326                 }
327         }
328 }
329 
330 void test15()
331 {
332     A15 a = new A15();
333     a.fork();
334 }
335 
336 /*******************************************/
337 
338 creal x16;
339 
340 void foo16()
341 {
342         x16 = -x16;
343 }
344 
345 void bar16()
346 {
347         return foo16();
348 }
349 
350 void test16()
351 {
352         x16 = 2.0L + 0.0Li;
353         bar16();
354         assert(x16 == -2.0L + 0.0Li);
355 }
356 
357 /*******************************************/
358 
359 void test17()
360 {
361     version(D_InlineAsm_X86_64)
362         enum AsmX86 = true;
363     else version(D_InlineAsm_X86)
364         enum AsmX86 = true;
365     else
366         enum AsmX86 = false;
367 
368     version (OSX)
369     {
370     }
371     else
372     {
373         const f = 1.2f;
374         float g = void;
375 
376         static if (AsmX86)
377         {
378             asm
379             {
380                 fld f;  // doesn't work with PIC
381                 fstp g;
382             }
383         }
384         else
385         {
386             g = f;
387         }
388         assert(g == 1.2f);
389     }
390 }
391 
392 /*******************************************/
393 
394 class Foo18 : Bar18 {}
395 class FooT18(V){}
396 class Bar18 : FooT18!(int) {}
397 
398 void test18()
399 {
400 }
401 
402 /*******************************************/
403 
404 struct STRUCTA19
405 {
406   union {
407     int a;
408     long b;
409   }
410   STRUCTB19 c;
411 }
412 
413 struct STRUCTB19
414 {
415   int a;
416 }
417 
418 void test19()
419 {
420 }
421 
422 /*******************************************/
423 
424 class Foo20
425 {
426         void bar (void * src)
427         {
428                 void baz (void function (void *, size_t) xyz)
429                 {
430                         size_t foo (void [] dst)
431                         {
432                                 size_t len = dst.length;
433                                 dst [0 .. len] = src [0 .. len];
434                                 xyz (dst.ptr, len);
435                                 return len;
436                         }
437                 }
438         }
439 }
440 
441 void test20()
442 {
443 }
444 
445 /*******************************************/
446 
447 class Baz21
448 {
449         int opApply (int delegate(ref int) dg)
450         {
451                 int i;
452                 return dg(i);
453         }
454 }
455 
456 class Foo21
457 {
458         Baz21    baz;
459 
460         int foo (int delegate() dg)
461         {
462                 foreach (b; baz)
463                          if (bar ())
464                             if (dg ())
465                                 break;
466                 return 0;
467         }
468 
469         bool bar ()
470         { return true; }
471 }
472 
473 void test21()
474 {
475 }
476 
477 /*******************************************/
478 
479 struct Bar22 {
480     union {
481         struct {
482             union {
483                 Foo22 A;
484             }
485         }
486     }
487 }
488 
489 struct Foo22 {
490     double d = 3;
491 }
492 
493 void test22()
494 {
495     printf("Bar22.sizeof = %zd, double.sizeof = %zd\n", Bar22.sizeof, double.sizeof);
496     assert(Bar22.sizeof == double.sizeof);
497     Bar22 b;
498     assert(b.A.d == 3);
499 }
500 
501 /*******************************************/
502 
503 struct Ag
504 {
505     static void func(){}
506 
507     static void foo()
508     {
509         void function() fnp;
510         Ag a;
511 
512         fnp = &func;
513         fnp = &Ag.func;
514         with(a)    fnp = &Ag.func;
515 
516         with(a) fnp = &func;
517     }
518 }
519 
520 class Ah
521 {
522     static void func(){}
523 
524     static void foo()
525     {
526         void function() fnp;
527         Ah a;
528 
529         fnp = &func;
530         fnp = &Ah.func;
531         with(a)    fnp = &Ah.func;
532 
533         with(a) fnp = &func;
534     }
535 }
536 
537 void test23()
538 {
539 }
540 
541 /*******************************************/
542 
543 void test24()
544 {
545     uint[10] arr1;
546     ulong idx = 3;
547     uint[] arr3 = arr1[ cast(int)(idx) .. (cast(int) idx) + 3  ]; // OK
548     uint[] arr4 = arr1[ cast(int) idx  ..  cast(int) idx  + 3  ]; // OK
549     uint[] arr5 = arr1[ cast(int)(idx) ..  cast(int)(idx) + 3  ]; // C style cast illegal, use cast(idx)+3
550     uint[] arr6 = arr1[ cast(int)(idx) ..  cast(int)(idx  + 3) ]; // OK
551 }
552 
553 /*******************************************/
554 
555 void test25()
556 {
557     char[6] cstr = "123456"c;
558     auto str1 = cast(wchar[3])(cstr);
559 
560     writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1));
561     assert(cast(char[])str1 == "123456"c);
562 
563     auto str2 = cast(wchar[3])("789abc"c);
564     writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2));
565     assert(cast(char[])str2 == "789abc"c);
566 
567     auto str3 = cast(wchar[3])("defghi");
568     writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3));
569     version (LittleEndian)
570         assert(cast(char[])str3 == "d\000e\000f\000"c);
571     version (BigEndian)
572         assert(cast(char[])str3 == "\000d\000e\000f"c);
573 }
574 
575 /*******************************************/
576 
577 void test26()
578 {
579     assert(foo26(5) == 25);
580 }
581 
582 int foo26(int i)
583 {
584     if (auto j = i * i)
585       return j;
586     else
587       return 10;
588 }
589 
590 /*******************************************/
591 
592 class A27
593 {
594     int am;
595 
596     class B
597     {
598         this()
599         {
600             assert(am == 3);
601         }
602     }
603 
604     void fork()
605     {
606         B b = new B();  // This is okay
607 
608         void knife()
609         {
610                 B b = new B();  // No 'this' for nested class B
611                 assert(am == 3);
612         }
613     }
614 }
615 
616 
617 void test27()
618 {
619     A27 a = new A27();
620     a.am = 3;
621 
622     a.fork();
623 }
624 
625 /*******************************************/
626 
627 uint intRes()
628 {
629         return 4;
630 }
631 
632 void test28()
633 {
634         auto s = std.string.format("%s", "abc123"[intRes() % $] );
635         writefln( "%s", s );
636         assert(s == "2");
637 
638         static const char[] foo = "abc123";
639         s = std.string.format("%s", foo[intRes() % $] );
640         assert(s == "2");
641 
642 
643         static string bar = "abc123";
644         s = std.string.format("%s", bar[intRes() % $] );
645         assert(s == "2");
646 
647         const char[] abc = "abc123";
648         s = std.string.format("%s", abc[intRes() % $] );
649         assert(s == "2");
650 
651         string def = "abc123";
652         s = std.string.format("%s", def[intRes() % $] );
653         assert(s == "2");
654 }
655 
656 /*******************************************/
657 
658 class UA {
659     A29 f() { return null; }
660 }
661 
662 class UB : UA {
663     override B29 f() { return null; }
664 }
665 
666 class A29
667 {
668 }
669 
670 class B29 : A29
671 {
672 }
673 
674 void test29()
675 {
676 }
677 
678 /*******************************************/
679 
680 class Foo30 : Bar30 {}
681 
682 class FooT30(V) {}
683 
684 class Bar30 : FooT30!(int) {}
685 
686 void test30()
687 {
688 }
689 
690 
691 /*******************************************/
692 
693 int y31;
694 
695 struct X31 { static void opCall() { y31 = 3; } }
696 
697 void test31()
698 {
699     X31 x;
700     typeof(x)();
701     assert(y31 == 3);
702 }
703 
704 /*******************************************/
705 
706 class Foo32
707 {
708     static void* ps;
709 
710     new (size_t sz)
711     {
712         void* p = core.stdc.stdlib.malloc(sz);
713         printf("new(sz = %d) = %p\n", sz, p);
714         ps = p;
715         return p;
716     }
717 
718     delete(void* p)
719     {
720         printf("delete(p = %p)\n", p);
721         assert(p == ps);
722         if (p) core.stdc.stdlib.free(p);
723     }
724 }
725 
726 void test32()
727 {
728     Foo32 f = new Foo32;
729     delete f;
730 }
731 
732 /*******************************************/
733 
734 class Foo33
735 {
736 //    this() { printf("this()\n"); }
737 //    ~this() { printf("~this()\n"); }
738 
739     static void* ps;
740     static int del;
741 
742     new (size_t sz, int i)
743     {
744         void* p = core.stdc.stdlib.malloc(sz);
745         printf("new(sz = %d) = %p\n", sz, p);
746         ps = p;
747         return p;
748     }
749 
750     delete(void* p)
751     {
752         printf("delete(p = %p)\n", p);
753         assert(p == ps);
754         if (p) core.stdc.stdlib.free(p);
755         del += 1;
756     }
757 }
758 
759 void foo33()
760 {
761     scope Foo33 f = new(3) Foo33;
762 }
763 
764 void test33()
765 {
766     foo33();
767     assert(Foo33.del == 1);
768 }
769 
770 /*******************************************/
771 
772 struct o_O { int a; }
773 union  O_O { int a; }
774 class  O_o { int a; }
775 
776 struct Foo34
777 {
778     int ok;
779     o_O foo;
780     O_O bar;
781     O_o baz;
782 }
783 
784 void test34()
785 {
786     int o1 = Foo34.ok.offsetof;
787     assert(o1 == 0);
788     int o2 = Foo34.foo.offsetof;
789     assert(o2 == 4);
790     int o3 = Foo34.bar.offsetof;
791     assert(o3 == 8);
792     int o4 = Foo34.baz.offsetof;
793     assert((o4 % (void*).sizeof) == 0);
794     assert(o4 > o3);
795 }
796 
797 /*******************************************/
798 
799 class Foo37
800 {
801     float[4] array = 1.0;
802     int count = 10;
803 }
804 
805 void test37()
806 {
807     Foo37 f = new Foo37();
808 
809     writefln("Foo.array[0] = %s", f.array[0] );
810     writefln("Foo.array[1] = %s", f.array[1] );
811     writefln("Foo.array[2] = %s", f.array[2] );
812     writefln("Foo.array[3] = %s", f.array[3] );
813     writefln("Foo.count = %s", f.count );
814 
815     assert(f.array[0] == 1.0);
816     assert(f.array[1] == 1.0);
817     assert(f.array[2] == 1.0);
818     assert(f.array[3] == 1.0);
819     assert(f.count == 10);
820 }
821 
822 /*******************************************/
823 
824 void test38()
825 in
826 {
827     static void checkParameters()
828     {
829         return;
830     }
831 
832     checkParameters();
833 }
834 body
835 {
836 }
837 
838 /*******************************************/
839 
840 void delegate() foo39()
841 {
842         return &(new class
843         {
844 
845                 int a;
846 
847                 this() { a = 3; }
848 
849                 void dg()
850                 {
851                         writefln("delegate!");
852                         assert(a == 3);
853                 }
854         }).dg;
855 }
856 
857 void test39()
858 {
859     void delegate() dg = foo39();
860 
861     dg();
862 }
863 
864 /*******************************************/
865 
866 void test40()
867 {
868     assert( typeid(int) == typeid(int) );
869     assert( (typeid(int) != typeid(int)) == false );
870 
871     int x;
872 
873     bool b1 = (typeid(typeof(x)) != typeid(int));
874 
875     TypeInfo t1 = typeid(typeof(x));
876     TypeInfo t2 = typeid(int);
877 
878     bool b2 = (t1 != t2);
879 
880     assert(b1 == b2);
881 }
882 
883 /*******************************************/
884 
885 int foo41(string s)
886 {
887         short shift = cast(short)(s.length * 3);
888         int answer;
889 
890         for (size_t i = 0; i < s.length; i++){
891                 answer = s[i] << shift;
892         }
893 
894         return answer;
895 }
896 
897 void test41()
898 {
899         if(foo41("\u0001") != 8){
900                 assert(0);
901         }
902 }
903 
904 /*******************************************/
905 
906 struct S42
907 {
908         int i;
909 
910         static S42 foo(int x){
911                 S42 s;
912 
913                 s.i = x;
914 
915                 return s;
916         }
917 }
918 
919 void test42()
920 {
921         S42[] s;
922 
923         s = s ~ S42.foo(6);
924         s = s ~ S42.foo(1);
925 
926         if(s.length != 2){
927                 assert(0);
928         }
929         if(s[0].i != 6){
930                 assert(0);
931         }
932         if(s[1].i != 1){
933                 assert(0);
934         }
935 }
936 
937 /*******************************************/
938 
939 struct S43
940 {
941         int i,j;
942 
943         static S43 foo(int x){
944                 S43 s;
945 
946                 s.i = x;
947 
948                 return s;
949         }
950 }
951 
952 void test43()
953 {
954         S43[] s;
955 
956         s = s ~ S43.foo(6);
957         s = s ~ S43.foo(1);
958 
959         if(s.length != 2){
960                 assert(0);
961         }
962         if(s[0].i != 6){
963                 assert(0);
964         }
965         if(s[1].i != 1){
966                 assert(0);
967         }
968 }
969 
970 /*******************************************/
971 
972 struct S44
973 {
974         int i,j,k;
975 
976         static S44 foo(int x){
977                 S44 s;
978 
979                 s.i = x;
980 
981                 return s;
982         }
983 }
984 
985 void test44()
986 {
987         S44[] s;
988 
989         s = s ~ S44.foo(6);
990         s = s ~ S44.foo(1);
991 
992         if(s.length != 2){
993                 assert(0);
994         }
995         if(s[0].i != 6){
996                 assert(0);
997         }
998         if(s[1].i != 1){
999                 assert(0);
1000         }
1001 }
1002 
1003 /*******************************************/
1004 
1005 void test45()
1006 {
1007    char[] buffer = "abcdefghijklmnopqrstuvwxyz".dup;
1008    foreach(ref char c; buffer)
1009    {
1010        if('a' <= c && c <= 'z')
1011        {
1012            c -= cast(char)'a' - 'A'; // segfault here
1013        }
1014    }
1015    for(int i = 0; i < buffer.length; i++)
1016    {
1017        if('a' <= buffer[i] && buffer[i] <= 'z')
1018        {
1019            buffer[i] -= cast(char)'a' - 'A'; // segfault here
1020        }
1021    }
1022    writeln(buffer);
1023 }
1024 
1025 /*******************************************/
1026 
1027 struct st46
1028 {
1029     template t1()
1030     {
1031         template t2(int n2) { }
1032     }
1033 }
1034 
1035 alias st46.t1!().t2 a46;
1036 
1037 void test46()
1038 {
1039 }
1040 
1041 /*******************************************/
1042 
1043 struct A47
1044 {
1045     static int y;
1046     void opSliceAssign(int x)
1047     {
1048         printf("x = %d\n", x);
1049         y = x;
1050     }
1051     A47 d() { return this; }
1052 }
1053 
1054 void test47()
1055 {
1056     A47 a;
1057     a[] = 3;
1058     printf("y = %d\n", a.y);
1059     a.d()[] = 5;
1060     printf("y = %d\n", a.y);
1061     assert(a.y == 5);
1062     a.d[] = 6;
1063     printf("y = %d\n", a.y);
1064     assert(a.y == 6);
1065 }
1066 
1067 /*******************************************/
1068 
1069 static uint[] sarray48 = void;
1070 
1071 void test48()
1072 {
1073     static uint[] array = void;
1074 
1075     assert(sarray48 == null);
1076     assert(array == null);
1077 }
1078 
1079 /*******************************************/
1080 
1081 int x = 2, y = 1;
1082 
1083 void foo50(int z)
1084 {
1085     static int t;
1086     t++;
1087     assert(t == z);
1088 }
1089 
1090 void test50()
1091 {
1092     printf("test50()\n");
1093     int res = 0;
1094     for(int i = 0; i < 10; i++)
1095     {
1096         res = res + x - y;
1097         foo50(res);
1098     }
1099 }
1100 
1101 /*******************************************/
1102 
1103 void test52()
1104 {
1105     printf("test52()\n");
1106     char[] s;
1107     s = ['a', 'b', 'c'];
1108     assert(s == "abc");
1109 
1110     int[] x;
1111     x = [17, 18u, 29, 33];
1112     assert(x.length == 4);
1113     assert(x[0] == 17);
1114     assert(x[1] == 18);
1115     assert(x[2] == 29);
1116     assert(x[3] == 33);
1117     assert(x == [17, 18, 29, 33]);
1118 }
1119 
1120 /*******************************************/
1121 
1122 void test54()
1123 {
1124     printf("test54()\n");
1125     uint[500][] data;
1126 
1127     data.length = 1;
1128     assert(data.length == 1);
1129     foreach (ref foo; data)
1130     {
1131         assert(foo.length == 500);
1132         foreach (ref u; foo)
1133         {   //printf("u = %u\n", u);
1134             assert(u == 0);
1135             u = 23;
1136         }
1137     }
1138     foreach (ref foo; data)
1139     {
1140         assert(foo.length == 500);
1141         foreach (u; foo)
1142         {   assert(u == 23);
1143             auto v = u;
1144             v = 23;
1145         }
1146     }
1147 }
1148 
1149 /*******************************************/
1150 
1151 class Base56
1152 {
1153         private string myfoo;
1154         private string mybar;
1155 
1156         // Get/set properties that will be overridden.
1157         void foo(string s) { myfoo = s; }
1158         string foo() { return myfoo; }
1159 
1160         // Get/set properties that will not be overridden.
1161         void bar(string s) { mybar = s; }
1162         string bar() { return mybar; }
1163 }
1164 
1165 class Derived56: Base56
1166 {
1167         alias Base56.foo foo; // Bring in Base56's foo getter.
1168         override void foo(string s) { super.foo = s; } // Override foo setter.
1169 }
1170 
1171 void test56()
1172 {
1173         Derived56 d = new Derived56;
1174         with (d)
1175         {
1176                 foo = "hi";
1177                 d.foo = "hi";
1178                 bar = "hi";
1179                 assert(foo == "hi");
1180                 assert(d.foo == "hi");
1181                 assert(bar == "hi");
1182         }
1183 }
1184 
1185 /*******************************************/
1186 
1187 bool[void[]] reg57;
1188 
1189 void addToReg57(const(void)[] a, int b, bool v)
1190 {
1191     if (!v)
1192         writefln("X");
1193     auto key = a~(cast(void*)&b)[0..4];
1194     reg57[cast(immutable(void)[])key] = v;
1195     writefln("OK");
1196 }
1197 
1198 void test57()
1199 {
1200         addToReg57("test", 1024, true);
1201 }
1202 
1203 /*******************************************/
1204 
1205 int bar58( string msg ){
1206     return 1;
1207 }
1208 
1209 int foo58( lazy string dg ){
1210     return bar58( dg() );
1211 }
1212 
1213 void test58()
1214 {
1215     printf("test58()\n");
1216     try{
1217     }
1218     finally{
1219         foo58("");
1220     }
1221 }
1222 
1223 /*******************************************/
1224 
1225 struct S59
1226 {
1227     string toString()
1228     {
1229         return "foo";
1230     }
1231 }
1232 
1233 void test59()
1234 {   S59 s;
1235     writefln("s = %s", s);
1236 
1237     string p;
1238     p = std.string.format("s = %s", s);
1239     assert(p == "s = foo");
1240 }
1241 
1242 /*******************************************/
1243 
1244 void test60()
1245 {
1246     int[2][] a;
1247     a = [ [-1,2], [3,4] ];
1248     assert(a[0][0] == -1);
1249     assert(a[0][1] == 2);
1250     assert(a[1][0] == 3);
1251     assert(a[1][1] == 4);
1252 
1253     int[][] b;
1254     b = [ [-1,2], [3,4] ];
1255     assert(b[0][0] == -1);
1256     assert(b[0][1] == 2);
1257     assert(b[1][0] == 3);
1258     assert(b[1][1] == 4);
1259 }
1260 
1261 /*******************************************/
1262 
1263 void test61()
1264 {
1265     int[][] f = [[1,2],[3,4]];
1266     assert(f[0][0] == 1);
1267     assert(f[0][1] == 2);
1268     assert(f[1][0] == 3);
1269     assert(f[1][1] == 4);
1270     writeln(f);
1271 }
1272 
1273 /*******************************************/
1274 
1275 struct List62 {
1276         void get() {}
1277 }
1278 struct Array62 {
1279         interface Model {
1280                 List62 list();
1281         }
1282         List62 list() {
1283                 return model ? model.list() : List62.init;
1284         }
1285         void item() {
1286                 list.get();
1287         }
1288         private Model model;
1289 }
1290 
1291 void test62()
1292 {
1293 }
1294 
1295 /*******************************************/
1296 
1297 void foo63(...)
1298 {
1299 }
1300 
1301 void test63()
1302 {
1303         int[] arr;
1304         arr = [1] ~ 2;
1305 
1306         // runtime crash, the length == 1
1307         printf("%d\n", arr.length);
1308         assert (arr.length == 2);
1309         assert(arr[0] == 1);
1310         assert(arr[1] == 2);
1311 
1312         arr = 2 ~ [1];
1313         assert(arr.length == 2);
1314         assert(arr[0] == 2);
1315         assert(arr[1] == 1);
1316 
1317         arr = [2, 3] ~ [1];
1318         assert(arr.length == 3);
1319         assert(arr[0] == 2);
1320         assert(arr[1] == 3);
1321         assert(arr[2] == 1);
1322 
1323         foo63([1] ~ 2, 2 ~ [1], [1,2] ~ [3,4,5]);
1324 }
1325 
1326 /*******************************************/
1327 
1328 void test64()
1329 {
1330     printf("test64()\n");
1331     int[] x = [1,2,3,4];
1332     int j = 4;
1333 
1334     foreach_reverse(v; x)
1335     {
1336         writeln(v);
1337         assert(j == v);
1338         j--;
1339     }
1340     assert(j == 0);
1341 
1342     j = 4;
1343     foreach_reverse(i, v; x)
1344     {
1345         writefln("[%s] = %s", i, v);
1346         assert(i + 1 == j);
1347         assert(j == v);
1348         j--;
1349     }
1350     assert(j == 0);
1351     printf("-test64()\n");
1352 }
1353 
1354 /*******************************************/
1355 
1356 void test65()
1357 {
1358     // Bugzilla Issue 407.
1359     int i = *cast(int*)cast(char[4])['0', '0', '0', '0']; // compiler seg-fault
1360     printf("i = %x\n", i);
1361 }
1362 
1363 /*******************************************/
1364 
1365 void test66()
1366 {
1367     int[]  ia;
1368     ia ~= 3;
1369     byte[] data = new byte[ia[0]];
1370     byte[] data2 = new byte[ cast(int)(ia[0])];
1371 }
1372 
1373 /*******************************************/
1374 
1375 class C68
1376 {
1377     static int value;
1378 }
1379 
1380 void test68()
1381 {
1382     auto v1 = test.C68.value;
1383     auto v2 = C68.classinfo;
1384     auto v3 = test.C68.classinfo;
1385     assert(v2 == v3);
1386 }
1387 
1388 /*******************************************/
1389 
1390 void test69()
1391 {
1392     class Bug
1393     {
1394       char[12] str = "";
1395       uint t = 1;
1396     }
1397 
1398     class NoBug
1399     {
1400       uint t = 2;
1401       char[12] str = "";
1402     }
1403 
1404     class NoBug2
1405     {
1406       char[12] str;
1407       uint t = 3;
1408     }
1409 
1410     auto b = new Bug;
1411     auto n = new NoBug;
1412     auto n2 = new NoBug2;
1413 
1414     writefln("bug %d", b.t);
1415     assert(b.t == 1);
1416     writefln("nobug %d", n.t);
1417     assert(n.t == 2);
1418     writefln("nobug2 %d", n2.t);
1419     assert(n2.t == 3);
1420 }
1421 
1422 /*******************************************/
1423 
1424 void test70()
1425 {
1426     void foo(char[0] p)
1427     {
1428     }
1429 
1430     static const char[0] altsep;
1431     string s = std.string.format("test%spath", altsep);
1432     assert(s == "testpath");
1433     foo(altsep);
1434 }
1435 
1436 /*******************************************/
1437 
1438 
1439 class C71
1440 {
1441     static int cnt;
1442     this() { printf("C()\n"); cnt++; }
1443     ~this() { printf("~C()\n"); cnt--; }
1444 }
1445 
1446 class D71
1447 {
1448     static int cnt;
1449     this() { printf("D()\n"); cnt++; }
1450     ~this() { printf("~D()\n"); cnt--; }
1451 }
1452 
1453 class E71
1454 {
1455     static int cnt;
1456     this() { printf("E()\n"); cnt++; }
1457     ~this() { printf("~E()\n"); cnt--; }
1458 }
1459 
1460 void test71()
1461 {
1462   {
1463     int i = 0;
1464     printf("start\n");
1465     scope D71 d = new D71();
1466     assert(D71.cnt == 1);
1467     for (scope E71 e = new E71(); i < 5; i++)
1468     {
1469         assert(D71.cnt == 1);
1470         assert(E71.cnt == 1);
1471         scope c = new C71();
1472         assert(C71.cnt == 1);
1473     }
1474     assert(C71.cnt == 0);
1475     assert(E71.cnt == 0);
1476     assert(D71.cnt == 1);
1477     printf("finish\n");
1478   }
1479   assert(D71.cnt == 0);
1480 }
1481 
1482 /*******************************************/
1483 
1484 size_t getLength(int[] arr) { return arr.length; }
1485 
1486 void test13237()
1487 {
1488         int[] arr = [0];
1489         immutable size_t len = getLength(arr);
1490 
1491         arr.length--;
1492 
1493         assert(len == 1); // ok
1494         if (len) { auto l = len; }
1495         assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline"
1496 }
1497 
1498 /*******************************************/
1499 
1500 void main()
1501 {
1502     test1();
1503     test2();
1504     test3();
1505     test4();
1506     test5();
1507     test6();
1508     test7();
1509     test8();
1510     test9();
1511     test10();
1512     test11();
1513     test12();
1514     test13();
1515     test14();
1516     test15();
1517     test16();
1518     test17();
1519     test18();
1520     test19();
1521     test20();
1522     test21();
1523     test22();
1524     test23();
1525     test24();
1526     test25();
1527     test26();
1528     test27();
1529     test28();
1530     test29();
1531     test30();
1532     test31();
1533     test32();
1534     test33();
1535     test34();
1536     test37();
1537     test38();
1538     test39();
1539     test40();
1540     test41();
1541     test42();
1542     test43();
1543     test44();
1544     test45();
1545     test46();
1546     test47();
1547     test48();
1548     test50();
1549     test52();
1550     test54();
1551     test56();
1552     test57();
1553     test58();
1554     test59();
1555     test60();
1556     test61();
1557     test62();
1558     test63();
1559     test64();
1560     test65();
1561     test66();
1562     test68();
1563     test69();
1564     test70();
1565     test71();
1566     test13237();
1567 
1568     printf("Success\n");
1569 }
1570