1 // RUNNABLE_PHOBOS_TEST
2 /*
3 TEST_OUTPUT:
4 ---
5 Object
6 ---
7 */
8 
9 module test34;
10 
11 import std.stdio;
12 import std.string;
13 import std.format;
14 import core.exception;
15 
16 
17 /************************************************/
18 
19 class Foo {}
20 class Bar {}
21 
test1()22 void test1()
23 {
24     TypeInfo ti_foo = typeid(Foo);
25     TypeInfo ti_bar = typeid(Bar);
26 
27     auto hfoo = ti_foo.toHash();
28     auto hbar = ti_bar.toHash();
29     writefln("typeid(Foo).toHash: ", hfoo);
30     writefln("typeid(Bar).toHash: ", hbar);
31     assert(hfoo != hbar);
32 
33     auto e = (ti_foo == ti_bar);
34     writefln("opEquals: ", e ? "equal" : "not equal");
35     assert(!e);
36 
37     auto c = (ti_foo.opCmp(ti_bar) == 0);
38     writefln("opCmp: ", c ? "equal" : "not equal");
39     assert(!c);
40 }
41 
42 
43 /************************************************/
44 
test2()45 void test2()
46 {
47   assert( [2,3]!=[2,4] );
48   assert( [3,2]!=[4,2] );
49   assert( !([2,3]==[2,4]) );
50   assert( ([2,3]==[2,3]) );
51 }
52 
53 /************************************************/
54 
55 struct Struct
56 {
57     int langID;
58     long _force_nrvo;
59 }
60 
61 Struct[1] table;
62 
getfirst()63 Struct getfirst()
64 {
65     foreach(v; table) {
66         writeln(v.langID);
67         assert(v.langID == 1);
68         return v;
69     }
70     assert(0);
71 }
72 
getsecond()73 Struct getsecond()
74 {
75     foreach(ref v; table) {
76         writeln(v.langID);
77         assert(v.langID == 1);
78         return v;
79     }
80     assert(0);
81 }
82 
test3()83 void test3()
84 {
85     table[0].langID = 1;
86 
87     auto v = getfirst();
88     writeln(v.langID);
89     assert(v.langID == 1);
90 
91     v = getsecond();
92     writeln(v.langID);
93     assert(v.langID == 1);
94 }
95 
96 /************************************************/
97 
98 class ExOuter
99 {
100     class ExInner
101     {
this()102         this()
103         {
104             typeof(this.outer) X;
105             static assert(is(typeof(X) == ExOuter));
106         }
107     }
108 }
109 
test4()110 void test4()
111 {
112 }
113 
114 /************************************************/
115 
116 int status5;
117 
118 struct MyStruct5
119 {
120 }
121 
rec5(int i,MyStruct5 s)122 void rec5(int i, MyStruct5 s)
123 {
124     if( i > 0 )
125     {
126         status5++;
127         rec5(i-1, s);
128     }
129 }
130 
test5()131 void test5()
132 {
133     assert(status5==0);
134     MyStruct5 st;
135     rec5(1030, st);
136     assert(status5==1030);
137 }
138 
139 /************************************************/
140 
141 class C6
142 {
143     const int a;
144 
this()145     this()
146     {
147         a = 3;
148     }
149 
this(int x)150     this(int x)
151     {
152         this();
153     }
154 }
155 
test6()156 void test6()
157 {
158 }
159 
160 /************************************************/
161 
parseUinteger(string s)162 template parseUinteger(string s)
163 {
164     static if (s.length == 0)
165     {   const char[] value = "";
166         const char[] rest = "";
167     }
168     else static if (s[0] >= '0' && s[0] <= '9')
169     {   const char[] value = s[0] ~ parseUinteger!(s[1..$]).value;
170         const char[] rest = parseUinteger!(s[1..$]).rest;
171     }
172     else
173     {   const char[] value = "";
174         const char[] rest = s;
175     }
176 }
177 
parseInteger(string s)178 template parseInteger(string s)
179 {
180     static if (s.length == 0)
181     {   const char[] value = "";
182         const char[] rest = "";
183     }
184     else static if (s[0] >= '0' && s[0] <= '9')
185     {   const char[] value = s[0] ~ parseUinteger!(s[1..$]).value;
186         const char[] rest = parseUinteger!(s[1..$]).rest;
187     }
188     else static if (s.length >= 2 &&
189                 s[0] == '-' && s[1] >= '0' && s[1] <= '9')
190     {   const char[] value = s[0..2] ~ parseUinteger!(s[2..$]).value;
191         const char[] rest = parseUinteger!(s[2..$]).rest;
192     }
193     else
194     {   const char[] value = "";
195         const char[] rest = s;
196     }
197 }
198 
test7()199 void test7()
200 {
201     writeln(parseUinteger!("1234abc").value);
202     writeln(parseUinteger!("1234abc").rest);
203     writeln(parseInteger!("-1234abc").value);
204     writeln(parseInteger!("-1234abc").rest);
205 
206     assert(parseUinteger!("1234abc").value == "1234");
207     assert(parseUinteger!("1234abc").rest == "abc");
208     assert(parseInteger!("-1234abc").value == "-1234");
209     assert(parseInteger!("-1234abc").rest == "abc");
210 }
211 
212 /************************************************/
213 
214 struct Foo8 { }
215 
216 enum Enum { RED }
217 
218 //typedef int myint;
219 
220 alias int myalias;
221 
test8()222 void test8()
223 {
224 /+
225     assert((1+2).stringof == "1 + 2");
226     assert(Foo8.stringof == "Foo8");
227     assert(test.Foo8.stringof == "test.Foo8");
228     assert(int.stringof == "int");
229     assert((int*[5][]).stringof == "int*[5][]");
230     assert(Enum.RED.stringof == "Enum.RED");
231     assert(test.myint.stringof == "test.myint");
232     assert(myalias.stringof == "myalias");
233     assert((5).stringof == "5");
234     assert(typeof(5).stringof == "typeof(5)");
235 +/
236 }
237 
238 /************************************************/
239 
240 /+
241 class Base9 {
242     public void fnc(){
243     }
244 }
245 
246 class Foo9 : Base9 {
247     alias Base9.fnc fnc;
248     public void fnc(){
249     }
250     static this(){
251         alias void function() T;
252         T ptr = & fnc;
253     }
254 }
255 +/
256 
test9()257 void test9()
258 {
259 }
260 
261 /************************************************/
262 
isalnum(dchar c)263 bool isalnum(dchar c) { return c>='0' && c >= '9'; }
264 
toHtmlFilename(char[]fname)265 char[] toHtmlFilename(char[] fname)
266 {
267     foreach (ref c; fname)
268     {
269         if (!isalnum(c) && c != '.' && c != '-')
270             c = '_';
271     }
272     return fname;
273 }
274 
test10()275 void test10()
276 {
277 }
278 
279 /************************************************/
280 
281 class A34 { }
282 class B34 : A34 { }
283 
test11()284 void test11()
285 {
286   A34 test=new B34;
287   writefln("Test is ", test.toString);
288   assert(test.toString == "test34.B34");
289   A34 test_2=cast(A34)(new B34);
290   writefln("Test 2 is ", test_2.toString);
291   assert(test_2.toString == "test34.B34");
292 }
293 
294 /************************************************/
295 
296 template Foo12(T: T[U], U)
297 {
298     alias int Foo12;
299 }
300 
test12()301 void test12()
302 {
303     Foo12!(int[long]) x;
304     assert(is(typeof(x) == int));
305 }
306 
307 /************************************************/
308 
309 class C13
310 {
311     int a = 4;
this()312     this()
313     {
314         printf("C13.this()\n");
315         assert(a == 4);
316         a = 5;
317     }
318 }
319 
test13()320 void test13()
321 {
322     C13 c = cast(C13)Object.factory("test34.C13");
323     assert(c.a == 5);
324     Object o = Object.factory("test35.C13");
325     assert(o is null);
326 }
327 
328 /************************************************/
329 
330 class Base15 {
func(int a)331         int func(int a) { return 1; }
332 }
333 
334 
335 class Foo15 : Base15 {
336         alias Base15.func func;
337 }
338 
339 
340 class Bar15 : Foo15 {
341         alias Foo15.func func;
func(string a)342         int func(string a) { return 2; }
343 }
344 
test15()345 void test15()
346 {
347     Bar15 b = new Bar15();
348     assert(b.func("hello") == 2);
349     assert(b.func(5) == 1);
350 }
351 
352 /************************************************/
353 
Basic16(T,U)354 struct Basic16(T, U) {}
355 
356 struct Iterator16(T : Basic16!(T, U), U)
357 {
FooIterator16358     static void Foo()
359     {
360         writeln(typeid(T), typeid(U));
361         assert(is(T == int));
362         assert(is(U == float));
363     }
364 }
365 
test16()366 void test16()
367 {
368     Iterator16!(Basic16!(int, float)).Foo();
369 }
370 
371 /************************************************/
372 
S17(T)373 struct S17(T)
374 {
375     struct iterator {}
376 }
377 
378 int insert17(T) (S17!(T) lst, S17!(T).iterator i)
379 {
380     return 3;
381 }
382 
383 void test17()
384 {
385     S17!(int) a;
386     S17!(int).iterator i;
387     auto x = insert17(a, i);
388     assert(x == 3);
389 }
390 
391 /************************************************/
392 
393 void test18()
394 {
395     real t = 0.;
396     for(int i=0; i<10; i++)
397     {
398         t += 1.;
399         real r =  (2*t);
400         printf("%Lg  %Lg  %Lg\n", t, r, 2*t);
401         assert(2*t == (i+1)*2);
402     }
403 }
404 
405 /************************************************/
406 
407 void test19()
408 {
409     char c = '3';
410     void[] ca = cast(void[])[c];
411     char[] x = cast(char[])ca;
412     assert(x[0] == '3');
413 }
414 
415 /************************************************/
416 
417 enum type20
418 {
419     a,
420     b,
421 }
422 
423 class myclass20
424 {
425     template XX(uint a, uint c)
426     {
427         static uint XX(){ return (a*256+c);}
428     }
429     void testcase()
430     {
431         switch (cast(uint)type20.a)
432         {
433             case XX!(cast(uint)type20.a,cast(uint)type20.b)():
434                 break;
435             default: assert(0);
436         }
437     }
438 }
439 
440 void test20()
441 {
442 }
443 
444 /************************************************/
445 
446 struct S21
447 {
448     alias int Foo;
449     int x;
450 }
451 
452 void test21()
453 {
454     S21 s;
455     typeof(s).Foo j;
456     assert(is(typeof(j) == int));
457 }
458 
459 /************************************************/
460 
461 void test22()
462 {
463     auto i = 3, j = 4;
464     assert(is(typeof(i) == int));
465     assert(is(typeof(j) == int));
466 }
467 
468 /************************************************/
469 
470 static m23 = 5, n23 = 6;
471 
472 void test23()
473 {
474     auto i = 3, j = 4;
475     assert(is(typeof(i) == int));
476     assert(is(typeof(j) == int));
477     assert(is(typeof(m23) == int));
478     assert(is(typeof(n23) == int));
479 }
480 
481 /************************************************/
482 
483 const int a24 = 0;
484 const int foo24 = 4;
485 const int[1] bar24 = [foo24 * 2];
486 const int zap24 = (1 << bar24[a24]);
487 
488 void test24()
489 {
490     assert(zap24 == 256);
491 }
492 
493 /************************************************/
494 
495 struct List25(T) {  }
496 struct CircularQueue25(T) {  }
497 
498 void front25(T)(ref List25!(T) list) {  }
499 void front25(T)(ref CircularQueue25!(T) queue) {  }
500 
501 void test25()
502 {
503     List25!(int) x;
504     front25(x);
505 }
506 
507 /************************************************/
508 
509 struct Foo26
510 {
511     const string x;
512 }
513 
514 static Foo26 foo26 = {"something"};
515 
516 void test26()
517 {
518     assert(foo26.x == "something");
519 }
520 
521 /************************************************/
522 
523 template Mang(alias F)
524 {
525     class G { }
526     alias void function (G ) H;
527     const string mangledname = H.mangleof;
528 }
529 
530 template moo(alias A)
531 {
532     pragma(msg,"   ");
533     const string a = Mang!(A).mangledname;
534     pragma(msg,"   ");
535     static assert(Mang!(A).mangledname == a); // FAILS !!!
536     pragma(msg,"   ");
537 }
538 
539 void test27()
540 {
541     int q;
542     string b = moo!(q).a;
543 }
544 
545 /************************************************/
546 
547 struct Color
548 {
549     static void fromRgb(uint rgb)
550     {
551     }
552 
553     static void fromRgb(ubyte alpha, uint rgb)
554     {
555     }
556 }
557 
558 void test28()
559 {
560     Color.fromRgb(0);
561     Color.fromRgb(cast(uint)0);
562 }
563 
564 /************************************************/
565 
566 void test29()
567 {
568   const char[] t="abcd";
569   const ubyte[] t2=cast(ubyte[])t;
570   const char[] t3=['a','b','c','d'];
571   const ubyte[] t4=cast(ubyte[])t3;
572   assert(t4[1] == 'b');
573 }
574 
575 /************************************************/
576 
577 void test30()
578 {
579   const char[] test = "" ~ 'a' ~ 'b' ~ 'c';
580   char[] test2 = (cast(char[])null)~'a'~'b'~'c';
581   const char[] test3 = (cast(char[])null)~'a'~'b'~'c';
582   char[] test4 = (cast(char[])[])~'a'~'b'~'c';
583   const char[] test5 = (cast(char[])[])~'a'~'b'~'c';
584   const char[] test6 = null;
585   const char[] test7 = test6~'a'~'b'~'c';
586 }
587 
588 /************************************************/
589 
590 class C31
591 {
592     synchronized invariant() { int x; }
593 }
594 
595 void test31()
596 {
597 }
598 
599 /************************************************/
600 
601 ulong foo32()
602 {
603         return cast(ulong) (cast(ulong) 1176576512 + cast(float) -2);
604 }
605 
606 void test32()
607 {
608         assert(foo32()==1176576510);
609 }
610 
611 /************************************************/
612 
613 class RangeCoder
614 {
615     uint[258] cumCount; // 256 + end + total
616     uint lower;
617     uint upper;
618     ulong range;
619 
620     this() {
621         for (int i=0; i<cumCount.length; i++)
622             cumCount[i] = i;
623         lower = 0;
624         upper = 0xffffffff;
625         range = 0x100000000;
626     }
627 
628     void encode(uint symbol) {
629         uint total = cumCount[$ - 1];
630         // "Error: Access Violation" in following line
631         upper = lower + cast(uint)((cumCount[symbol+1] * range) / total) - 1;
632         lower = lower + cast(uint)((cumCount[symbol]   * range) / total);
633     }
634 }
635 
636 void test33()
637 {
638     RangeCoder rc = new RangeCoder();
639     rc.encode(77);
640 }
641 
642 /************************************************/
643 
644 struct Vector34
645 {
646     float x, y, z;
647 
648     public static Vector34 opCall(float x = 0, float y = 0, float z = 0)
649     {
650         Vector34 v;
651 
652         v.x = x;
653         v.y = y;
654         v.z = z;
655 
656         return v;
657     }
658 
659     public string toString()
660     {
661         return std.string.format("<%f, %f, %f>", x, y, z);
662     }
663 }
664 
665 class Foo34
666 {
667     private Vector34 v;
668 
669     public this()
670     {
671         v = Vector34(1, 0, 0);
672     }
673 
674     public void foo()
675     {
676         bar();
677     }
678 
679     private void bar()
680     {
681         auto s = foobar();
682         writef("Returned: %s\n", s);
683         assert(std.string.format("%s", s) == "<1.000000, 0.000000, 0.000000>");
684     }
685 
686     public Vector34 foobar()
687     {
688         writef("Returning %s\n", v);
689 
690         return v;
691         Vector34 b = Vector34();
692         return b;
693     }
694 }
695 
696 void test34()
697 {
698     Foo34 f = new Foo34();
699     f.foo();
700 }
701 
702 
703 /************************************************/
704 
705 void foo35()
706 {
707         uint a;
708         uint b;
709         uint c;
710         extern (Windows) int function(int i, int j, int k) xxx;
711 
712         a = 1;
713         b = 2;
714         c = 3;
715 
716         xxx = cast(typeof(xxx))(a + b);
717         throw new Exception("xxx");
718         xxx( 4, 5, 6 );
719 }
720 
721 void test35()
722 {
723 }
724 
725 /************************************************/
726 
727 void test36()
728 {
729     int* p = void, c = void;
730 }
731 
732 /************************************************/
733 
734 void test37()
735 {
736     synchronized
737     {
738         synchronized
739         {
740             writefln("Hello world!");
741         }
742     }
743 }
744 
745 /************************************************/
746 
747 struct Rect {
748     int left, top, right, bottom;
749 }
750 
751 void test38()
752 {
753     print38(sizeTest(false));
754     print38(sizeTest(true));
755     print38(defaultRect);
756 }
757 
758 static Rect sizeTest(bool empty) {
759     if (empty) {
760         Rect result;
761         return result;
762         //return Rect.init;
763     } else {
764         return defaultRect;
765         /+Rect result = defaultRect;
766         return result;+/
767     }
768 }
769 
770 void print38(Rect r) {
771     writefln("(%d, %d)-(%d, %d)", r.left, r.top, r.right, r.bottom);
772     assert(r.left == 0);
773     assert(r.right == 0);
774     assert(r.top == 0);
775     assert(r.bottom == 0);
776 }
777 
778 Rect defaultRect() {
779     return Rect.init;
780 }
781 
782 /************************************************/
783 
784 void test39()
785 {
786    double[][] foo = [[1.0],[2.0]];
787 
788    writeln(foo[0]); // --> [1] , ok
789    writeln(foo[1]); // --> [2] , ok
790 
791    writeln(foo);       // --> [[1],4.63919e-306]  ack!
792    writefln("%s", foo); // --> ditto
793    auto f = std.string.format("%s", foo);
794    assert(f == "[[1], [2]]");
795 
796    double[1][2] bar;
797    bar[0][0] = 1.0;
798    bar[1][0] = 2.0;
799 
800    writeln(bar);       // Error: Access violation
801    auto r = std.string.format("%s", bar);
802    assert(r == "[[1], [2]]");
803 }
804 
805 /************************************************/
806 
807 void test40()
808 {
809     int[char] x;
810     x['b'] = 123;
811     writeln(x);
812     auto r = std.string.format("%s", x);
813     assert(r == "['b':123]");
814     writeln(x['b']);
815 }
816 
817 /************************************************/
818 
819 void test41()
820 {
821 }
822 
823 /************************************************/
824 
825 enum Enum42 {
826         A = 1
827 }
828 
829 void test42() {
830         Enum42[] enums = new Enum42[1];
831         assert(enums[0] == Enum42.A);
832 }
833 
834 
835 /************************************************/
836 
837 struct A43 {}
838 
839 struct B43(L) {
840   A43 l;
841 }
842 
843 void test43()
844 {
845   A43 a;
846   auto b = B43!(A43)(a);
847 }
848 
849 /************************************************/
850 
851 void test44()
852 {
853     int[ const char[] ] a = ["abc":3, "def":4];
854 }
855 
856 /************************************************/
857 
858 void test45()
859 {
860     //char[3][] a = ["abc", "def"];
861     //writefln(a);
862     //char[][2] b = ["abc", "def"];
863     //writefln(b);
864 }
865 
866 /************************************************/
867 
868 struct bignum
869 {
870     bool smaller()
871     {
872         if (true) return false;
873         else      return false;
874         assert(0);
875     }
876 
877     void equal()
878     {
879         if (!smaller)
880             return;
881     }
882 }
883 
884 void test46()
885 {
886 }
887 
888 /************************************************/
889 
890 static size_t myfind(string haystack, char needle) {
891   foreach (i, c ; haystack) {
892     if (c == needle) return i;
893   }
894   return size_t.max;
895 }
896 
897 static size_t skip_digits(string s) {
898   foreach (i, c ; s) {
899     if (c < '0' || c > '9') return i;
900   }
901   return s.length;
902 }
903 
904 static uint matoi(string s) {
905   uint result = 0;
906   foreach (c ; s) {
907     if (c < '0' || c > '9') break;
908     result = result * 10 + (c - '0');
909   }
910   return result;
911 }
912 
913 enum { leading, skip, width, modifier, format, fmt_length, extra };
914 
915 static string GetFormat(string s) {
916   uint pos = 0;
917   string result;
918   // find the percent sign
919   while (pos < s.length && s[pos] != '%') {
920     ++pos;
921   }
922   const leading_chars = pos;
923   result ~= cast(char) pos;
924   if (pos < s.length) ++pos; // go right after the '%'
925   // skip?
926   if (pos < s.length && s[pos] == '*') {
927     result ~= 1;
928     ++pos;
929   } else {
930     result ~= 0;
931   }
932   // width?
933   result ~= cast(char) matoi(s);
934   pos += skip_digits(s[pos .. $]);
935   // modifier?
936   if (pos < s.length && myfind("hjlLqtz", s[pos]) != size_t.max) {
937     // @@@@@@@@@@@@@@@@@@@@@@@@@@@@
938     static if (true) {
939       result ~= s[pos++];
940     } else {
941       result ~= s[pos];
942       ++pos;
943     }
944     // @@@@@@@@@@@@@@@@@@@@@@@@@@@@
945   } else {
946     result ~= '\0';
947   }
948   return result;
949 }
950 
951 void test47()
952 {
953   static string test = GetFormat(" %*Lf");
954   assert(test[modifier] == 'L', "`" ~ test[modifier] ~ "'");
955 }
956 
957 /************************************************/
958 
959 class B48() {}
960 class C48   {}
961 
962 int foo48()(B48!()) { return 1; }
963 int foo48()(C48 c) { return 2; }
964 
965 void test48()
966 {
967     auto i = foo48(new B48!());
968     assert(i == 1);
969 
970     i = foo48(new C48);
971     assert(i == 2);
972 }
973 
974 /************************************************/
975 
976 void test49()
977 {
978     struct A { int v; }
979 
980     A a = A(10);
981 
982   version (all)
983   {
984     writefln("Before test 1: ", a.v);
985     if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); }
986     else { writeln(a.v,"(a!=a.init)"); assert(a.v == 10); }
987   }
988   else
989   {
990     writefln("Before test 1: ", a.v);
991     if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(a.v == 10); }
992     else { writeln(a.v,"(a!=a.init)"); assert(0); }
993   }
994 
995     a.v = 100;
996     writefln("Before test 2: ", a.v);
997     if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); }
998     else { writeln(a.v,"(a!=a.init)"); assert(a.v == 100); }
999 
1000     a = A(1000);
1001     writefln("Before test 3: ", a.v);
1002     if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); }
1003     else { writeln(a.v,"(a!=a.init)"); assert(a.v == 1000); }
1004 
1005   version (all)
1006     assert(a.init.v == 0);
1007   else
1008     assert(a.init.v == 10);
1009 }
1010 
1011 /************************************************/
1012 
1013 struct S51
1014 {
1015     int i = 3;
1016     void div() { assert(i == 3); }
1017 }
1018 
1019 void test51()
1020 {
1021     S51().div();
1022 }
1023 
1024 /************************************************/
1025 
1026 void test52()
1027 {
1028     struct Foo {
1029         alias int Y;
1030     }
1031     with (Foo) {
1032          Y y;
1033     }
1034 }
1035 
1036 /************************************************/
1037 
1038 struct TestStruct
1039 {
1040     int dummy0 = 0;
1041     int dummy1 = 1;
1042     int dummy2 = 2;
1043 }
1044 
1045 void func53(TestStruct[2] testarg)
1046 {
1047     writeln(testarg[0].dummy0);
1048     writeln(testarg[0].dummy1);
1049     writeln(testarg[0].dummy2);
1050 
1051     writeln(testarg[1].dummy0);
1052     writeln(testarg[1].dummy1);
1053     writeln(testarg[1].dummy2);
1054 
1055     assert(testarg[0].dummy0 == 0);
1056     assert(testarg[0].dummy1 == 1);
1057     assert(testarg[0].dummy2 == 2);
1058 
1059     assert(testarg[1].dummy0 == 0);
1060     assert(testarg[1].dummy1 == 1);
1061     assert(testarg[1].dummy2 == 2);
1062 }
1063 
1064 TestStruct m53[2];
1065 
1066 void test53()
1067 {
1068     writeln(&m53);
1069     func53(m53);
1070 }
1071 
1072 /************************************************/
1073 
1074 void test54()
1075 {
1076     double a = 0;
1077     double b = 1;
1078     // Internal error: ..\ztc\cg87.c 3233
1079 //    a += (1? b: 1+1i)*1i;
1080     writeln(a);
1081 //    assert(a == 0);
1082     // Internal error: ..\ztc\cod2.c 1680
1083 //    a += (b?1:b-1i)*1i;
1084     writeln(a);
1085 //    assert(a == 0);
1086 }
1087 
1088 /************************************************/
1089 
1090 class B55 {}
1091 class D55 : B55 {}
1092 
1093 template foo55(S, T : S) { }    // doesn't work
1094 
1095 alias foo55!(B55, D55) bar55;
1096 
1097 void test55()
1098 {
1099 }
1100 
1101 /************************************************/
1102 
1103 template t56() { alias Object t56; }
1104 pragma(msg, t56!().stringof);
1105 
1106 void test56()
1107 {
1108 }
1109 
1110 /************************************************/
1111 
1112 void test57()
1113 {
1114     alias long[char[]] AA;
1115 
1116     static if (is(AA T : T[U], U : const char[]))
1117     {
1118         writeln(typeid(T));
1119         writeln(typeid(U));
1120 
1121         assert(is(T == long));
1122         assert(is(U == const(char)[]));
1123     }
1124 
1125     static if (is(AA A : A[B], B : int))
1126     {
1127         assert(0);
1128     }
1129 
1130     static if (is(int[10] W : W[V], int V))
1131     {
1132         writeln(typeid(W));
1133         assert(is(W == int));
1134         writeln(V);
1135         assert(V == 10);
1136     }
1137 
1138     static if (is(int[10] X : X[Y], int Y : 5))
1139     {
1140         assert(0);
1141     }
1142 }
1143 
1144 /************************************************/
1145 
1146 static this()
1147 {
1148    printf("one\n");
1149 }
1150 
1151 static this()
1152 {
1153    printf("two\n");
1154 }
1155 
1156 static ~this()
1157 {
1158    printf("~two\n");
1159 }
1160 
1161 static ~this()
1162 {
1163    printf("~one\n");
1164 }
1165 
1166 
1167 void test59()
1168 {
1169 }
1170 
1171 /************************************************/
1172 
1173 class C60
1174 {
1175     extern (C++) int bar60(int i, int j, int k)
1176     {
1177         printf("this = %p\n", this);
1178         printf("i = %d\n", i);
1179         printf("j = %d\n", j);
1180         printf("k = %d\n", k);
1181         assert(i == 4);
1182         assert(j == 5);
1183         assert(k == 6);
1184         return 1;
1185     }
1186 }
1187 
1188 
1189 extern (C++)
1190         int foo60(int i, int j, int k)
1191 {
1192     printf("i = %d\n", i);
1193     printf("j = %d\n", j);
1194     printf("k = %d\n", k);
1195     assert(i == 1);
1196     assert(j == 2);
1197     assert(k == 3);
1198     return 1;
1199 }
1200 
1201 void test60()
1202 {
1203     foo60(1, 2, 3);
1204 
1205     C60 c = new C60();
1206     c.bar60(4, 5, 6);
1207 }
1208 
1209 /***************************************************/
1210 
1211 template Foo61(alias a) {}
1212 
1213 struct Bar61 {}
1214 const Bar61 bar61 = {};
1215 
1216 alias Foo61!(bar61) baz61;
1217 
1218 void test61()
1219 {
1220 }
1221 
1222 /************************************************/
1223 
1224 T foo62(T)(lazy T value)
1225 {
1226     return value;
1227 }
1228 
1229 void test62()
1230 {
1231     foo62(new float[1]);
1232 }
1233 
1234 /************************************************/
1235 
1236 void main()
1237 {
1238     test1();
1239     test2();
1240     test3();
1241     test4();
1242     test5();
1243     test6();
1244     test7();
1245     test8();
1246     test9();
1247     test10();
1248     test11();
1249     test12();
1250     test13();
1251     test15();
1252     test16();
1253     test17();
1254     test18();
1255     test19();
1256     test20();
1257     test21();
1258     test22();
1259     test23();
1260     test24();
1261     test25();
1262     test26();
1263     test27();
1264     test28();
1265     test29();
1266     test30();
1267     test31();
1268     test32();
1269     test33();
1270     test34();
1271     test35();
1272     test36();
1273     test37();
1274     test38();
1275     test39();
1276     test40();
1277     test41();
1278     test42();
1279     test43();
1280     test44();
1281     test45();
1282     test46();
1283     test47();
1284     test48();
1285     test49();
1286     test51();
1287     test52();
1288     test53();
1289     test54();
1290     test55();
1291     test56();
1292     test57();
1293     test59();
1294     test60();
1295     test61();
1296     test62();
1297 
1298     writefln("Success");
1299 }
1300 
1301 
1302