1 // REQUIRED_ARGS:
2 
3 module test42;
4 
5 import std.stdio;
6 import core.stdc.stdio;
7 import std..string;
8 import core.memory;
9 
10 /***************************************************/
11 
12 class Foo {
13     template myCast(T) {
14         T myCast(U)(U val) {
15             return cast(T) val;
16         }
17     }
18 }
19 
20 void test1()
21 {
22   Foo foo = new Foo;
23   int i = foo.myCast!(int)(1.0);
24 }
25 
26 /***************************************************/
27 
28 template A()
29 {
30   static T foo(T)(T t) { return 7 + t; }
31 }
32 
33 struct Bar
34 {
35   mixin A!() a;
36 }
37 
38 void test2()
39 {
40   auto i = A!().foo(1);
41   assert(i == 8);
42   i = Bar.a.foo!(int)(2);
43   assert(i == 9);
44   i = Bar.a.foo(3);
45   assert(i == 10);
46 }
47 
48 /***************************************************/
49 
50 void test3()
51 {
52     auto i = mixin("__LINE__");
53     writefln("%d", i);
54     assert(i == 52);
55 }
56 
57 /***************************************************/
58 
59 class C4
60 {
61     void Stamp(){}
62 
63     this() { }
64 
65     S4 cursor;
66 }
67 
68 struct S4
69 {
70 }
71 
72 void test4()
73 {
74 }
75 
76 /***************************************************/
77 
78 char a5 = (cast(char[])['a']) [$-1];
79 
80 void test5()
81 {
82     assert(a5 == 'a');
83 }
84 
85 /***************************************************/
86 // Bug 1200. One case moved to deprecate1.d
87 
88 void foo6a() {
89         do
90                 debug {}
91         while (true);
92 }
93 
94 void foo6b() {
95         while (true)
96                 debug {}
97 }
98 
99 void foo6c() {
100         with (Object.init)
101                 debug {}
102 }
103 
104 void foo6d() {
105         synchronized debug {}
106 }
107 
108 void foo6e() {
109 //        volatile debug {}
110 }
111 
112 void test6()
113 {
114 }
115 
116 /***************************************************/
117 
118 class C7 {
119     public this(){
120     }
121 }
122 
123 interface I7 {
124     void fnc();
125 }
126 
127 void test7()
128 {
129     char[][] t;
130     foreach( char[] c; t ){
131         new class( c ) C7, I7 {
132             public this( char[] c ){
133                 super();
134             }
135             void fnc(){
136             }
137         };
138     }
139 }
140 
141 /***************************************************/
142 
143 const ulong[] A8 = ([1LU])[0..$];
144 
145 void test8()
146 {
147     assert(A8[0] == 1);
148 }
149 
150 /***************************************************/
151 
152 void test9()
153 {
154     writeln(long.max.stringof);
155     writeln(ulong.max.stringof);
156     assert(long.max.stringof == "9223372036854775807L");
157     assert(ulong.max.stringof == "18446744073709551615LU");
158 }
159 
160 /***************************************************/
161 
162 const ulong[] A10 = [1UL];
163 const ulong[] B10 = A10 ~ [1UL];
164 
165 void test10()
166 {
167 }
168 
169 /***************************************************/
170 
171 class Base11 {
172         private final void foo() {}
173 }
174 
175 class Derived11 : Base11 {
176         void foo() {}
177 }
178 
179 void test11()
180 {
181 }
182 
183 /***************************************************/
184 
185 void test12()
186 {
187     int[] bar;
188     assert((bar ~ 1).length == bar.length + 1);
189 
190     int[][] baz;
191     assert((baz ~ cast(int[])[1]).length == baz.length + 1);
192 
193     char[][] foo;
194     assert((foo ~ cast(char[])"foo").length == foo.length + 1);
195     assert((cast(char[])"foo" ~ foo).length == foo.length + 1);
196 
197     printf("%d\n", (foo ~ cast(char[])"foo")[0].length);
198 
199     assert((foo ~ [cast(char[])"foo"]).length == foo.length + 1);
200 
201     char[] qux;
202     assert(([qux] ~ cast(char[])"foo").length == [qux].length + 1);
203 
204     assert(([cast(dchar[])"asdf"] ~ cast(dchar[])"foo").length == [cast(dchar[])"asdf"].length + 1);
205 
206     string[] quux;
207     auto quuux = quux.dup;
208     quuux ~= "foo";
209     assert (quuux.length == quux.length + 1);
210 }
211 
212 /***************************************************/
213 
214 int prop() { return 3; }
215 
216 void test13()
217 {
218   auto x = prop;
219   assert(x == 3);
220 }
221 
222 /***************************************************/
223 
224 void recurse(ref int i)
225 {
226     int j = i;
227     recurse(j);
228 }
229 
230 void test14()
231 {
232 }
233 
234 /***************************************************/
235 
236 void bar15(void delegate(int) dg)
237 {
238     dg(7);
239 }
240 
241 class C15
242 {
243     int x;
244 
245     private void callback(int i)
246     {
247 	x = i + 3;
248     }
249 
250     void foo()
251     {
252 	bar15(&callback);
253 	assert(x == 10);
254     }
255 }
256 
257 void test15()
258 {
259     C15 c = new C15();
260 
261     c.foo();
262 }
263 
264 /***************************************************/
265 
266 void bar16(int i, ...) { }
267 
268 void foo16() { }
269 void foo16(int) { }
270 
271 void test16()
272 {
273     bar16(1, cast(void function())&foo16);
274 }
275 
276 /***************************************************/
277 
278 void foo17(char[4] buf, dchar c) { }
279 void foo17(string s) { }
280 void foo17(wstring s) { }
281 
282 
283 void test17()
284 {
285     wstring w;
286     .foo17(w);
287 }
288 
289 /***************************************************/
290 
291 struct S18
292 {
293   version (Dversion2)
294   {
295     static void opCall(string msg) { assert(0); }
296   }
297     static void opCall() { }
298 }
299 
300 void test18()
301 {
302     S18();
303 }
304 
305 /***************************************************/
306 
307 class C19
308 {
309   version (Dversion2)
310   {
311     static void opCall(string msg) { assert(0); }
312   }
313     static void opCall() { }
314 }
315 
316 void test19()
317 {
318     C19();
319 }
320 
321 /***************************************************/
322 
323 extern (System) void test20()
324 {
325 }
326 
327 /***************************************************/
328 
329 void func21()
330 {
331 }
332 
333 int foo21()
334 {
335    return *cast(int*)&func21;
336 }
337 
338 void test21()
339 {
340     foo21();
341 }
342 
343 /***************************************************/
344 
345 void bar22(alias T)()
346 {
347 	assert(3 == T);
348 }
349 
350 class Test22
351 {
352 	int a;
353 	mixin bar22!(a);
354 }
355 
356 void test22()
357 {
358 	Test22 t = new Test22();
359 	t.a = 3;
360 	t.bar22();
361 }
362 
363 /***************************************************/
364 
365 static this()
366 {
367    printf("one\n");
368 }
369 
370 static this()
371 {
372    printf("two\n");
373 }
374 
375 static ~this()
376 {
377    printf("~two\n");
378 }
379 
380 static ~this()
381 {
382    printf("~one\n");
383 }
384 
385 void test23()
386 {
387 }
388 
389 /***************************************************/
390 
391 class Foo24
392 {
393     static string gen()
394     {
395         return "abc";
396     }
397 }
398 
399 auto s24 = Foo24.gen();
400 
401 void test24()
402 {
403     assert(s24 == "abc");
404 }
405 
406 /***************************************************/
407 
408 void test25()
409 {
410     int[10] arrayA = [0,1,2,3,4,5,6,7,8,9];
411     foreach(int i; arrayA)
412     {
413         writeln(i);
414     }
415 }
416 
417 /************************************/
418 
419 const char[][7] DAY_NAME = [
420         DAY.SUN: "sunday", "monday", "tuesday", "wednesday",
421           "thursday", "friday", "saturday"
422 ];
423 
424 enum DAY { SUN, MON, TUE, WED, THU, FRI, SAT }
425 
426 void test27()
427 {
428     assert(DAY_NAME[DAY.SUN] == "sunday");
429     assert(DAY_NAME[DAY.MON] == "monday");
430     assert(DAY_NAME[DAY.TUE] == "tuesday");
431     assert(DAY_NAME[DAY.WED] == "wednesday");
432     assert(DAY_NAME[DAY.THU] == "thursday");
433     assert(DAY_NAME[DAY.FRI] == "friday");
434     assert(DAY_NAME[DAY.SAT] == "saturday");
435 }
436 
437 /***************************************************/
438 
439 void test28()
440 {
441 }
442 
443 /***************************************************/
444 
445 struct C29 {
446 
447     C29 copy() { return this; }
448 }
449 
450 void foo29(C29 _c) {
451 
452     foo29( _c.copy() );
453 }
454 
455 void test29() {
456 
457     C29 c;
458 
459     //foo(c);
460 }
461 
462 /***************************************************/
463 
464 template Tuple31(T...) { alias T Tuple31; }
465 alias Tuple31!(int,int) TType31;
466 
467 void bar31(TType31) {
468 }
469 
470 void test31()
471 {
472 }
473 
474 /***************************************************/
475 
476 template Foo32(T : S!(T), alias S)
477 {
478     alias int Foo32;
479 }
480 
481 struct Struct32(T)
482 {
483 }
484 
485 void test32()
486 {
487     Foo32!(Struct32!(int)) f;
488 }
489 
490 /***************************************************/
491 
492 void test33()
493 {
494     string a = "a";
495     string b = "b";
496     string c = a ~ b;
497     assert(c == "ab");
498 }
499 
500 /***************************************************/
501 
502 void foo34(in string s)
503 {
504     string t = s;
505 }
506 
507 void test34()
508 {
509 }
510 
511 /***************************************************/
512 
513 struct S35
514 {
515    string toString()
516    {
517        return "foo";
518    }
519 }
520 
521 void test35()
522 {   S35 s;
523     auto t = typeid(S35);
524     writefln("s = %s", s);
525     writefln("s = %s", t);
526     auto tis = cast(TypeInfo_Struct)t;
527     writefln("s = %s", tis);
528     writefln("s = %s", tis.xtoString);
529     assert(tis.xtoString != null);
530 }
531 
532 /***************************************************/
533 
534 void test36()
535 {
536     void[0] x;
537     auto y = x;
538     alias x z;
539 }
540 
541 /***************************************************/
542 
543 template isStaticArray(T : U[], U)
544 {
545     const bool isStaticArray = is(typeof(U) == typeof(T.init));
546 }
547 
548 template isStaticArray(T, U = void)
549 {
550     const bool isStaticArray = false;
551 }
552 
553 template isStaticArray(T : T[N], size_t N)
554 {
555     const bool isStaticArray = true;
556 }
557 
558 static assert (isStaticArray!(int[51]));
559 static assert (isStaticArray!(int[][2]));
560 static assert (isStaticArray!(char[][int][11]));
561 static assert (!isStaticArray!(int[]));
562 static assert (!isStaticArray!(int[char]));
563 static assert (!isStaticArray!(int[1][]));
564 
565 static assert(isStaticArray!(void[0]));
566 
567 void test37()
568 {
569 }
570 
571 /***************************************************/
572 
573 template Foo38(T)
574 {
575     const bool Foo38 = false;
576 }
577 
578 template Foo38(T : U[N], U, size_t N)
579 {
580     const bool Foo38 = true;
581 }
582 
583 void test38()
584 {
585     static assert (Foo38!(int[51]));
586 }
587 
588 /***************************************************/
589 
590 void test39()
591 {
592 }
593 
594 /***************************************************/
595 
596 void test40()
597 {
598     static x = [[1.0, 2.0], [3.0, 4.0]]; // works
599     assert(x[0][0] == 1.0);
600     assert(x[0][1] == 2.0);
601     assert(x[1][0] == 3.0);
602     assert(x[1][1] == 4.0);
603 
604     auto y = [[1.0, 2.0], [3.0, 4.0]]; // fails
605     assert(y[0][0] == 1.0);
606     assert(y[0][1] == 2.0);
607     assert(y[1][0] == 3.0);
608     assert(y[1][1] == 4.0);
609 }
610 
611 /***************************************************/
612 
613 align(16) struct S41
614 {
615     int[4] a;
616 }
617 
618 shared int x41;
619 shared S41 s41;
620 
621 void test41()
622 {
623     printf("&x = %p\n", &x41);
624     printf("&s = %p\n", &s41);
625     assert((cast(int)&s41 & 0xF) == 0);
626 }
627 
628 /***************************************************/
629 
630 int test42(string[] args = null)
631 {
632    foreach(p; args){
633       version(dummy) int i;
634    }
635    return 0;
636 }
637 
638 
639 /***************************************************/
640 
641 void foo43(float length, byte b)
642 {
643 //    b /= cast(cfloat) length;
644 }
645 
646 void test43()
647 {
648 }
649 
650 /***************************************************/
651 
652 void test44()
653 {
654     ifloat f = 1.0fi;
655 //    f *= 2.0fi; // illegal but compiles
656     writefln("%s", f);
657 //    assert(f == 0i);
658 }
659 
660 /***************************************************/
661 
662 int foo45(int i)
663 {
664    if(i==0){
665       return 2;
666    }
667    assert(0);
668 }
669 
670 void test45()
671 {
672    version (Win32)  // this test fails in -release because asserts will be removed
673    {
674    assert(foo45(0)==2);
675    try{
676       foo45(1);
677    }catch{
678       return cast(void)0;
679    }
680    assert(0);
681    }
682 }
683 
684 /***************************************************/
685 
686 
687 void va_copy46(out void* dest, void* src)
688 {
689     dest = src;
690 }
691 
692 void test46()
693 {
694 }
695 
696 /***************************************************/
697 
698 void test47()
699 {
700     enum { _P_WAIT, _P_NOWAIT, _P_OVERLAY };
701 
702     alias _P_WAIT P_WAIT;
703     alias _P_NOWAIT P_NOWAIT;
704 }
705 
706 /***************************************************/
707 
708 void f48(int x)
709 {
710     const(char)[] blah = (x == 1 ? "hello".dup : "world");
711 }
712 
713 void test48()
714 {
715     f48(1);
716 }
717 
718 /***************************************************/
719 
720 void test49()
721 {
722     assert((25.5).stringof ~ (3.01).stringof == "25.53.01");
723     assert(25.5.stringof ~ 3.01.stringof == "25.53.01");
724 }
725 
726 /***************************************************/
727 
728 class Ap50
729 {
730     ulong size;
731     static uint valuex;
732 
733     void update(ubyte input, int i)
734     {
735 	valuex =
736 	    (((size + i) & 1) == 0) ?
737 		    0 :
738 		    input;
739     }
740 }
741 
742 void test50()
743 {
744 }
745 
746 /***************************************************/
747 
748 int* foo51()
749 {
750     assert(is(typeof(return) == int*));
751     return null;
752 }
753 
754 void test51()
755 {
756     foo51();
757 }
758 
759 /***************************************************/
760 
761 template Foo52(ulong U)
762 {
763     int Foo52 = 1;
764 }
765 
766 template Foo52(uint U)
767 {
768     int Foo52 = 2;
769 }
770 
771 template Foo52(ubyte U)
772 {
773     int Foo52 = 3;
774 }
775 
776 
777 void test52()
778 {
779     const uint u = 3;
780     auto s = Foo52!(u);
781     assert(s == 2);
782 }
783 
784 /***************************************************/
785 
786 void test53()
787 {
788     extern int x;
789 }
790 
791 /***************************************************/
792 
793 void func54(string delegate() dg)
794 {
795         dg();
796 }
797 
798 void test54()
799 {
800     string[] k=["adf","AsdfadSF","dfdsfassdf"];
801     foreach(d;k)
802     {
803 	printf("%.*s\n", d.length, d.ptr);
804 	string foo() {assert(d!="");return d;}
805 	func54(&foo);
806 	func54(delegate string() {assert(d!="");return d;});
807     }
808 }
809 
810 /***************************************************/
811 // bug 1767
812 
813 class DebugInfo
814 {
815     alias int CVHeaderType ;
816     enum anon:CVHeaderType{ CV_NONE, CV_DOS, CV_NT, CV_DBG }
817 }
818 
819 void test55()
820 {
821 }
822 
823 /***************************************************/
824 
825 template T56() { int i; }
826 
827 struct S56 {
828     alias T56!() data;
829 }
830 
831 class C56 {
832     alias T56!() data;
833 }
834 
835 void test56()
836 {
837     S56.data.i = 3;
838     C56.data.i = 4;
839     assert(S56.data.i == 4);
840 }
841 
842 /***************************************************/
843 
844 void writecrossing(bool goal)
845 {
846   writeln(goal?"escape":"return");
847 }
848 
849 void test57()
850 {
851     writecrossing(true);
852     writecrossing(false);
853 }
854 
855 /***************************************************/
856 
857 void f58(int n) {}
858 void g58(char[] s) {}
859 
860 char[][] a58;
861 
862 class bar58
863 {
864         int i;
865 
866         void func() {
867                 f58(i);
868 
869                 foreach (s; a58) {
870                         if (s == s){}
871                         if (s[0..0] == "" && s[0..0])
872                                 g58(s);
873                 }
874 
875                 f58(i);
876         }
877 }
878 
879 void test58()
880 {
881 }
882 
883 /***************************************************/
884 
885 void test59()
886 {
887     int[] array = new int[5];
888     uint check = 0;
889     foreach (it; array.ptr .. array.ptr + array.length) {
890         ++check;
891     }
892     assert(check == array.length);
893 }
894 
895 /***************************************************/
896 
897 final class Foo60()
898 {
899     void bar()
900     {
901         int baz;
902         baz = 1;
903     }
904 }
905 
906 void test60()
907 {
908     auto foo = new Foo60!();
909 }
910 
911 /***************************************************/
912 
913 class ZipEntry61
914 {
915     ZipEntryInfo61 info;
916     this() {}
917 }
918 struct ZipEntryInfo61 {}
919 
920 void test61()
921 {
922 }
923 
924 /***************************************************/
925 
926 void test62()
927 {
928    int foo() { return 0; }
929    int bar() { return 0; }
930 
931    auto t1 = typeid(typeof(foo));
932    auto t2 = typeid(typeof(bar));
933 
934    t1.tsize();
935 }
936 
937 /***************************************************/
938 
939 struct S63
940 {
941     int a;
942     static int foo()
943     {
944 	return a.sizeof;
945     }
946 }
947 
948 void test63()
949 {
950     int x = S63.a.sizeof;
951     assert(x == 4);
952     assert(S63.foo() == 4);
953 }
954 
955 /***************************************************/
956 
957 string[] foo64()
958 {
959     return [[]];
960 }
961 
962 void test64()
963 {
964     auto a = foo64();
965     assert(a.length == 1);
966     assert(a[0].length == 0);
967 }
968 
969 /***************************************************/
970 
971 string[][] foo65()
972 {
973     string[][] result = [];
974     string[] s = [];
975     result ~= [s];
976     return result;
977 }
978 
979 void test65()
980 {
981     auto s = foo65();
982     assert(s.length == 1);
983     assert(s[0].length == 0);
984 }
985 
986 /***************************************************/
987 
988 string[][] foo66()
989 {
990     string[] strings = ["a","bc"];
991     string [][] result = [];
992     foreach (s; strings)
993     {
994         result ~= [s];
995     }
996     return result;
997 }
998 
999 void test66()
1000 {
1001     auto s = foo66();
1002     assert(s.length == 2);
1003     assert(s[0].length == 1);
1004     assert(s[0][0].length == 1);
1005     assert(s[1].length == 1);
1006     assert(s[1][0].length == 2);
1007 }
1008 
1009 /***************************************************/
1010 
1011 template Tuple67(A...)
1012 {
1013     alias A Tuple67;
1014 }
1015 
1016 template Bar67()
1017 {
1018     const s = "a bar";
1019 }
1020 
1021 void test67()
1022 {
1023     alias Tuple67!(Bar67!()) tuple;
1024     static const i = 0;
1025     alias tuple[0] bara;
1026     alias tuple[i] barb;
1027 
1028     static assert(bara.s == "a bar");
1029     static assert(barb.s == "a bar");
1030 }
1031 
1032 /***************************************************/
1033 
1034 template Tuple68(A...)
1035 {
1036     alias A Tuple68;
1037 }
1038 
1039 size_t foo68()
1040 {
1041     return 1;
1042 }
1043 
1044 void test68()
1045 {
1046     alias Tuple68!("one", "two") tuple;
1047     static assert(tuple[foo68()] == "two");
1048 }
1049 
1050 /***************************************************/
1051 
1052 class Base69 {}
1053 
1054 class Da69 : Base69 {}
1055 class Db69 : Base69 {}
1056 
1057 void test69()
1058 {   int i;
1059     auto b = i ? new Da69 : new Db69;
1060     assert(is(typeof(b) == Base69));
1061 }
1062 
1063 /***************************************************/
1064 
1065 struct Bar70
1066 {
1067         Bar70[] bars;
1068 }
1069 
1070 void test70()
1071 {
1072         Bar70 node;
1073 }
1074 
1075 /***************************************************/
1076 
1077 template Foo71(string s)
1078 {
1079     string b = s;
1080 }
1081 
1082 void test71()
1083 {
1084     size_t s = Foo71!(
1085 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1086 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1087 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1088 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1089 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1090 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1091 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1092 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1093 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1094 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1095 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1096 "When dealing with complex template tuples, it's very easy to overflow the
1097 maximum symbol length allowed by OPTLINK.  This is, simply put, a damn shame,
1098 because it prevents otherwise completely legal code from compiling and linking
1099 with DMDWin, whereas it works perfectly fine when using DMDNix or GDC.
1100 I know that this is neither a simple nor a small issue to fix: either the
1101 ancient, nearly-immutable OPTLINK would have to be modified, or DMDWin would
1102 have to be changed to output a more reasonable format, in which case a new
1103 linker would probably have to be written.  Until then, this issue should stand
1104 as a reminder that DMDWin is inherently limited.
1105 Oplink isn't the issue. The OMF file format has a hard limit. This results in
1106 the only solutions being: convert DMD to use some other .obj format or have DMD
1107 do something else for name mangling.
1108 In talking to Walter, the issue is that it's easy to get symbols that have more
1109 info in them than can be fit into the limit. (the limit has already stretched
1110 by gziping the symbols.)
1111 The simple solution I have proposed is to just MD5 (or what not) the symbols.
1112 The only issue (besides a vanishingly small chance of a hash collision) is that
1113 this looses information so you can't look at a symbol and directly determine
1114 what it was. My answer to that is, who cares? The only place where hashing
1115 provides less info than compressing is in a debugger and it can grab the full
1116 symbol from a table in the static data segment.
1117 I suppose as a stopgap measure that'd work fine, and might even be controlled
1118 by a compiler switch, so that in the general case debugger info wouldn't be
1119 affected.  And what's more -- the only time these issues come up is with
1120 templates, which a lot of debuggers have serious problems with anyway, so..
1121 I would set it up as a method of last resort. It wouldn't be used unless the
1122 symbol can't be used any other way.
1123 "
1124 	).b.length;
1125 }
1126 
1127 /***************************************************/
1128 
1129 class B72 { this(bool b, string c){} }
1130 
1131 class C72 : B72
1132 {
1133         this()
1134         {
1135                 alias typeof(super(false,"hello")) foo;
1136                 super(false,"hello");
1137         }
1138 }
1139 
1140 void test72()
1141 {
1142 }
1143 
1144 /***************************************************/
1145 
1146 template Foo73()
1147 {
1148     mixin ("const int x = 3;");
1149     //const int x = 3;
1150 
1151     static if (x == 3)
1152     {
1153 	pragma(msg, "success");
1154     }
1155 }
1156 
1157 alias Foo73!() foo73;
1158 
1159 void test73()
1160 {
1161 }
1162 
1163 /***************************************************/
1164 
1165 alias uint foo74;
1166 
1167 void simple_func_t(T)(T s, foo74 i)
1168 {
1169     assert(s == "hello");
1170     assert(i == 3);
1171 }
1172 
1173 void test74()
1174 {
1175     simple_func_t("hello", 3);
1176 }
1177 
1178 /***************************************************/
1179 
1180 void foo75(T)(T[] x ...)
1181 {
1182     assert(x.length == 3);
1183     assert(x[0] == 2);
1184     assert(x[1] == 3);
1185     assert(x[2] == 4);
1186     assert(is(T == int));
1187 }
1188 
1189 void test75()
1190 {
1191     foo75(2,3,4);
1192 }
1193 
1194 /***************************************************/
1195 
1196 void delegate(U) Curry(A, U...)(void delegate(A,U) dg,A arg)
1197 {
1198   struct ArgRecord {
1199     A arg;
1200     typeof(dg) callback;
1201 
1202     void OpCall(U args) { callback(arg,args); }
1203   }
1204   auto temp = new ArgRecord;
1205   temp.arg = arg;
1206   temp.callback = dg;
1207   return &temp.OpCall;
1208 }
1209 
1210 void delegate(A) Seq(A...)(void delegate(A)[] dgs...)
1211 {
1212   return Curry(delegate void(void delegate(A)[] dgs1,A args)
1213                {
1214                  foreach(dg; dgs1)
1215                    dg(args);
1216                },
1217                dgs);
1218 }
1219 
1220 struct Foo76
1221 {
1222   void fred(int i) {}
1223 }
1224 
1225 void test76()
1226 {
1227   void delegate(int) tmp;
1228   auto bob = new Foo76;
1229   auto dan = new Foo76;
1230 
1231   tmp = Seq!(int)(&bob.fred);             // this works
1232   tmp = Seq!(int)(&bob.fred, &dan.fred);  // this works
1233   tmp = Seq      (&bob.fred);             // this doesn't
1234   tmp = Seq      (&bob.fred, &dan.fred);  // neither does this
1235 }
1236 
1237 /***************************************************/
1238 
1239 int x77;
1240 
1241 void foo77()
1242 {
1243     x77 = 1;
1244 
1245     static if(true)
1246     {
1247     }
1248     else
1249     {
1250     }
1251 }
1252 
1253 void test77()
1254 {
1255     foo77();
1256     assert(x77 == 1);
1257 }
1258 
1259 /***************************************************/
1260 
1261 class Foo78
1262 {
1263   template TBar(T)
1264   {
1265     T x;                   // Compiles, but is implicitly static
1266     void func(T t)   // Ok, non-static member template function
1267     { assert(t == 2); assert(this.bar == 42); }
1268   }
1269   int bar = 42;
1270 }
1271 
1272 void test78()
1273 {
1274   alias Foo78 Foo;
1275   Foo.TBar!(int).x = 2;
1276   //Foo.TBar!(int).func(2); // error, since funcx is not static
1277 
1278   Foo f = new Foo;
1279   Foo g = new Foo;
1280 
1281   f.TBar!(int).func(2); // works
1282 
1283   f.TBar!(int).x = 10;
1284   g.TBar!(int).x = 20;
1285   assert(f.TBar!(int).x == 20); // prints 20
1286 }
1287 
1288 /***************************************************/
1289 
1290 class C79
1291 {
1292 }
1293 
1294 void test79()
1295 {
1296     C79 c = new C79();
1297     writeln(c.__vptr);
1298     writeln(c.__vptr[0]);
1299     writeln(cast(void*)c.classinfo);
1300     assert(c.__vptr[0] == cast(void*)c.classinfo);
1301     writeln(c.__monitor);
1302     assert(c.__monitor == null);
1303     synchronized (c)
1304     {
1305 	writeln(c.__monitor);
1306 	assert(c.__monitor !is null);
1307     }
1308 }
1309 
1310 /***************************************************/
1311 
1312 class Test80{
1313   template test(){
1314     enum int test=1;
1315   }
1316 }
1317 
1318 void test80()
1319 {
1320   assert(Test80.test!()==1);
1321   assert((new Test80).test!()==1);
1322 }
1323 
1324 /***************************************************/
1325 
1326 class Test81
1327 {
1328   static const test2=1;
1329   template test(){
1330     static const int test=1;
1331   }
1332 }
1333 
1334 void test81()
1335 {
1336   auto a=new Test81;
1337   static assert(typeof(a).test2==1);//ok
1338   alias typeof(a) t;
1339   static assert(t.test!()==1);//ok
1340   static assert(typeof(a).test!()==1);//syntax error
1341 }
1342 
1343 /***************************************************/
1344 
1345 deprecated
1346 {
1347     alias real A82;
1348     void foo82(A82 x) {    }
1349 }
1350 
1351 void test82()
1352 {
1353 }
1354 
1355 /***************************************************/
1356 
1357 class Bar83
1358 {
1359     deprecated void foo(int param)
1360     {
1361     }
1362 
1363     void foo(string param)
1364     {
1365     }
1366 }
1367 
1368 void test83()
1369 {
1370     Bar83 b = new Bar83;
1371     string str = "bar";
1372     b.foo(str);
1373 }
1374 
1375 /***************************************************/
1376 
1377 void test84()
1378 {
1379     int[0][10] arr;
1380     printf("%u\n", &arr[9] - &arr[0]);
1381     auto i = &arr[9] - &arr[0];
1382     assert(i == 0);
1383 }
1384 
1385 /***************************************************/
1386 
1387 class myid
1388 {
1389     string buf;
1390     this(string str )
1391     {
1392 	    buf = str;
1393     }
1394 }
1395 struct Lex
1396 {
1397     static myid myidinst;
1398     static void Init()
1399     {
1400 	    myidinst = new myid("abc");
1401     }
1402 }
1403 
1404 void test85()
1405 {
1406     Lex.Init();
1407     assert(cast(myid)(Lex.myidinst) !is null);
1408 }
1409 
1410 /***************************************************/
1411 
1412 struct Time
1413 {
1414   long ticks;
1415 }
1416 
1417 struct Stamps
1418 {
1419     Time    created,        /// time created
1420             accessed,       /// last time accessed
1421             modified;       /// last time modified
1422 }
1423 
1424 Stamps getTimeStamps()
1425 {
1426     foreach(i; 0..10) { }
1427     Stamps                    time = void;
1428 
1429     time.modified = Time(20);
1430     time.accessed = Time(20);
1431     time.created  = Time(20);
1432     return time;
1433 }
1434 
1435 Time accessed ()
1436 {
1437     foreach(i; 0..10) { }
1438     return timeStamps(4).accessed;
1439 }
1440 
1441 Stamps timeStamps (int name)
1442 {
1443   return getTimeStamps();
1444 }
1445 
1446 void test86()
1447 {
1448 
1449   assert(accessed().ticks == 20);
1450 }
1451 
1452 /***************************************************/
1453 
1454 const bool foo87 = is(typeof(function void() { }));
1455 const bar87      = is(typeof(function void() { }));
1456 
1457 void test87()
1458 {
1459     assert(foo87 == true);
1460     assert(bar87 == true);
1461 }
1462 
1463 /***************************************************/
1464 
1465 int function() wrap88(void function()) { return null; }
1466 
1467 void test88()
1468 {
1469 	printf("test88\n");
1470 	if (0)
1471 	    wrap88(&test88)();
1472 }
1473 
1474 /***************************************************/
1475 
1476 struct S89
1477 {
1478         static const float[2] z = 3;
1479 }
1480 
1481 class C89
1482 {
1483         static const float[2] z = 3;
1484 }
1485 
1486 void bar89(float f) { assert(f == 3); }
1487 
1488 void test89()
1489 {
1490 	printf("test89\n");
1491         bar89(S89.z[0]);
1492         bar89(S89.z[1]);
1493         bar89(C89.z[0]);
1494         bar89(C89.z[1]);
1495 }
1496 
1497 /***************************************************/
1498 
1499 void trigger(char[] txt)
1500 {
1501         txt[0] = 'x';
1502 
1503         scope(exit)
1504         {
1505                 txt[0] = 'x';
1506         }
1507 
1508         return;
1509 }
1510 
1511 void test90()
1512 {
1513 }
1514 
1515 /***************************************************/
1516 
1517 void test91()
1518 {
1519     enum ABC { a, b, c }
1520     assert(ABC.stringof == "ABC");
1521 }
1522 
1523 /***************************************************/
1524 
1525 int x92;
1526 
1527 int f92() {
1528     x92++;
1529     return 0;
1530 }
1531 
1532 void test92()
1533 {
1534     int[1] a;
1535     a[f92()] += 42L;
1536     assert(x92 == 1);
1537 }
1538 
1539 /***************************************************/
1540 
1541 void test93()
1542 {
1543     void foo() { }
1544     static assert(is(typeof(1 || foo()) == void));
1545     static assert(is(typeof(1 && foo()) == void));
1546 }
1547 
1548 /***************************************************/
1549 
1550 void foo94(T)()
1551 {
1552 }
1553 
1554 struct f94(alias func=foo94!(int))
1555 {
1556 }
1557 
1558 void test94()
1559 {
1560     f94!() myf;
1561 }
1562 
1563 /***************************************************/
1564 
1565 struct X95
1566 {
1567    import core.stdc.stdio;
1568 }
1569 
1570 void test95()
1571 {
1572    X95.core.stdc.stdio.printf("hello\n");
1573 }
1574 
1575 /***************************************************/
1576 
1577 template foo96(alias bar)
1578 {
1579     pragma(msg, bar.stringof ~ " " ~ typeof(bar).stringof);
1580     static assert((bar.stringof ~ " " ~ typeof(bar).stringof) == "myInt int" ||
1581 	(bar.stringof ~ " " ~ typeof(bar).stringof) == "myBool bool");
1582     void foo96() {}
1583 }
1584 
1585 void test96()
1586 {
1587     int myInt;
1588     bool myBool;
1589 
1590     foo96!(myInt)();
1591     foo96!(myBool)();
1592 }
1593 
1594 /***************************************************/
1595 
1596 void test97()
1597 {
1598     const short[] ct = cast(short[]) [cast(byte)1, 1];
1599     writeln(ct);
1600     assert(ct.length == 2 && ct[0] == 1 && ct[1] == 1);
1601 
1602     short[] rt = cast(short[]) [cast(byte)1, cast(byte)1].dup;
1603     writeln(rt);
1604     assert(rt.length == 1 && rt[0] == 257);
1605 }
1606 
1607 /***************************************************/
1608 
1609 class Foo98
1610 {
1611     string foo = "abc";
1612     size_t i = 0;
1613 
1614     void bar()
1615     {
1616 	printf("%c\n", foo[i]);
1617 	i++;
1618 	printf("%c\n", foo[i]);
1619 	assert(foo[i] == 'b');
1620     }
1621 }
1622 
1623 void test98()
1624 {
1625     auto f = new Foo98();
1626     f.bar();
1627 }
1628 
1629 /***************************************************/
1630 
1631 template implicitlyConverts99(S, T)
1632 {
1633     enum bool implicitlyConverts99 = T.sizeof >= S.sizeof
1634         && is(typeof({S s; T t = s;}()));
1635 }
1636 
1637 static assert(!implicitlyConverts99!(long, short));
1638 
1639 void test99()
1640 {
1641 }
1642 
1643 /***************************************************/
1644 
1645 void test100()
1646 {
1647     static void check(ulong value)
1648     {
1649         real r = value;
1650         ulong d = cast(ulong)r;
1651         printf("ulong: %llu => real: %Lg => ulong: %llu\n", value, r, d);
1652         assert(d == value);
1653     }
1654 
1655     // check biggest power of 2 representable in ulong: 2^63
1656     check(1L << 63);
1657 
1658     // check biggest representable uneven number
1659     static if (real.mant_dig >= 64) // > 64: limited by ulong precision
1660         check(ulong.max); // 2^64-1
1661     else
1662         check((1L << real.mant_dig) - 1);
1663 }
1664 
1665 /***************************************************/
1666 
1667 auto e101(int x) { return 5; }
1668 
1669 void test101()
1670 {
1671     assert(is(typeof(e101(3)) == int));
1672 }
1673 
1674 /***************************************************/
1675 
1676 version(X86)
1677 {
1678 int x103;
1679 
1680 void external(...)
1681 {
1682     printf("external: %d\n", *cast (int *) _argptr);
1683     x103 = *cast (int *) _argptr;
1684 }
1685 
1686 class C103
1687 {
1688     void method ()
1689     {
1690 	void internal (...)
1691 	{
1692 	    printf("internal: %d\n", *cast (int *)_argptr);
1693 	    x103 = *cast (int *) _argptr;
1694 	}
1695 
1696 	internal (43);
1697 	assert(x103 == 43);
1698     }
1699 }
1700 
1701 void test103()
1702 {
1703     external(42);
1704     assert(x103 == 42);
1705     (new C103).method ();
1706 }
1707 }
1708 else version(X86_64)
1709 {
1710     pragma(msg, "Not ported to x86-64 compatible varargs, yet.");
1711     void test103() {}
1712 }
1713 else
1714     static assert(false, "Unknown platform");
1715 
1716 /***************************************************/
1717 
1718 class C104
1719 {
1720     template Bar()
1721     {
1722     }
1723 }
1724 
1725 static assert(!is(typeof(C104.Bar.foo)));
1726 
1727 void test104()
1728 {
1729 }
1730 
1731 /***************************************************/
1732 
1733 template Templ(T)
1734 {
1735     const char [] XXX = Type.mangleof;
1736     alias T Type;
1737 }
1738 
1739 void test105()
1740 {
1741     Templ!(int).Type x;
1742     auto s = Templ!(int).XXX;
1743     writeln(s);
1744     assert(s == "i");
1745 }
1746 
1747 /***************************************************/
1748 // rejects-valid 2.012.
1749 
1750 class foo107 {}
1751 alias foo107 bar107;
1752 void x107()
1753 {
1754    bar107 a = new bar107();
1755    bar107 b = new bar107();
1756    bool c = (a == b);
1757 }
1758 
1759 void test107()
1760 {
1761 }
1762 
1763 /***************************************************/
1764 
1765 struct Foo108
1766 {
1767     char[] byLine()()
1768     {
1769 	return null;
1770     }
1771 }
1772 
1773 void test108()
1774 {   Foo108 foo;
1775 
1776     foreach (char c; foo.byLine)
1777     {
1778     }
1779 }
1780 
1781 /***************************************************/
1782 
1783 void test109()
1784 {
1785     double x[] = new double[1];
1786     assert(x[0] != 0);
1787 }
1788 
1789 /***************************************************/
1790 
1791 void test110()
1792 {
1793     struct C {
1794 	int[0] b;
1795     }
1796     static C g_c2_ = {  };
1797 }
1798 
1799 /***************************************************/
1800 
1801 template Foo111(T...) {
1802     alias T Foo111;
1803 }
1804 
1805 void test111()
1806 {
1807     auto y = (Foo111!(int) x){ return 0; };
1808 }
1809 
1810 /***************************************************/
1811 
1812 bool isNull(string str) {
1813         return str is null;
1814 }
1815 
1816 const bool foo112 = isNull("hello!");
1817 
1818 void test112()
1819 {
1820     assert(!foo112);
1821 }
1822 
1823 /***************************************************/
1824 
1825 void test113()
1826 {
1827   for (int j=1; j<2; j++) {
1828     int x = (j<0) ? -j : j;
1829     int q=0;
1830     for (int i=0; i<x; i++) ++q;
1831     assert(q!=0);
1832   }
1833 }
1834 
1835 /***************************************************/
1836 
1837 struct VariantN
1838 {
1839     static int opCall(int value)
1840     {
1841         return 0;
1842     }
1843 
1844     void foo()
1845     {
1846         VariantN v;
1847 	v.bar(42, 5);
1848     }
1849 
1850     void bar(int value, int i)
1851     {
1852         int args[2] = [ VariantN(value), VariantN(i) ];
1853     }
1854 }
1855 
1856 void test114()
1857 {
1858 }
1859 
1860 /***************************************************/
1861 
1862 class B115 : A115!(B115) { }
1863 class A115(T) { }
1864 
1865 void test115()
1866 {
1867 }
1868 
1869 /***************************************************/
1870 
1871 struct Foo116 {
1872     this(U...)(U values)  { }
1873 }
1874 
1875 void test116()
1876 {
1877   new Foo116;
1878 }
1879 
1880 /***************************************************/
1881 
1882 void test117()
1883 {
1884     float f = 7;
1885     f = f * 2;
1886     assert(f == 14);
1887 
1888     double d = 7;
1889     d = d * 2;
1890     assert(d == 14);
1891 
1892     real r = 7;
1893     r = r * 2;
1894     assert(r == 14);
1895 }
1896 
1897 /***************************************************/
1898 
1899 void test118()
1900 {
1901     int foo(real x)
1902     {
1903 	real y = -x*-x;
1904 	return cast(int)y;
1905     }
1906 
1907     auto i = foo(4.0);
1908     assert(i == 16);
1909 }
1910 
1911 /***************************************************/
1912 
1913 class A119
1914 {
1915     static class B119 : C119.D { }
1916 }
1917 
1918 abstract class C119
1919 {
1920     static class D { }
1921 }
1922 
1923 void test119()
1924 {
1925 }
1926 
1927 /***************************************************/
1928 
1929 class A120 {
1930     class B120 : C120.D { }
1931 }
1932 
1933 class C120 : E120 {
1934     static class D { }
1935 }
1936 
1937 interface E120 { }
1938 
1939 void test120()
1940 {
1941 }
1942 
1943 /***************************************************/
1944 
1945 void test121()
1946 {
1947     static assert(null is null);
1948 }
1949 
1950 /***************************************************/
1951 
1952 T[] find123(alias pred, T)(T[] input) {
1953    while (input.length > 0) {
1954       if (pred(input[0])) break;
1955       input = input[1 .. $];
1956    }
1957    return input;
1958 }
1959 
1960 void test123()
1961 {
1962     int[] a = [ 1, 2, 3, 4, -5, 3, -4 ];
1963     find123!(function bool(int i) { return i < 0; })(a);
1964 }
1965 
1966 
1967 /***************************************************/
1968 
1969 static assert(!is(typeof((){(){}
1970          ;-()
1971 {};})));
1972 
1973 /***************************************************/
1974 
1975 struct Foobar;
1976 
1977 /***************************************************/
1978 
1979 int test124()
1980 {   int result;
1981     dchar[] aa;
1982     alias uint foo_t;
1983 
1984     foreach (foo_t i, dchar d; aa)
1985     {
1986     }
1987     return result;
1988 }
1989 
1990 /***************************************************/
1991 
1992 int foo125(int x)
1993 {
1994     while (1)
1995     {
1996 	if (x)
1997 	    return 3;
1998 	x++;
1999     }
2000 }
2001 
2002 void test125()
2003 {
2004     foo125(4);
2005 }
2006 
2007 /***************************************************/
2008 
2009 int foo126(int x)
2010 {
2011     while (1)
2012     {
2013 	if (x)
2014 	    return 3;
2015 	x++;
2016     }
2017     assert(0);
2018 }
2019 
2020 void test126()
2021 {
2022     foo126(4);
2023 }
2024 
2025 /***************************************************/
2026 
2027 struct S127(T, int topology = 1)
2028 {
2029     this(T value) { }
2030 }
2031 
2032 void cons127(int t)(S127!(int, t) tail)
2033 {
2034 }
2035 
2036 void test127()
2037 {
2038     S127!(int)(1);
2039     S127!(int, 1) lst;
2040     cons127(lst);
2041 }
2042 
2043 /***************************************************/
2044 
2045 struct S128(T, int topology = 1)
2046 {
2047     this(T value) { }
2048 }
2049 
2050 void cons128(int t)(S128!(int, t) tail)
2051 {
2052 }
2053 
2054 void test128()
2055 {
2056     S128!(int, 1)(1);
2057     S128!(int) lst;
2058     cons128(lst);
2059 }
2060 
2061 /***************************************************/
2062 
2063 struct R129(R : E[], E)
2064 {
2065     E[] forward;
2066     static R129 opCall(E[] range)
2067     {
2068         R129 result = {};
2069         result.forward =  range;
2070         return result;
2071     }
2072 }
2073 
2074 R129!(E[]) retro129(E)(E[] r)
2075 {
2076     return R129!(E[])(r);
2077 }
2078 
2079 int begin129(F)(R129!(F) range)
2080 {
2081     return 0;
2082 }
2083 
2084 void test129()
2085 {
2086     int[] a = [ 1, 2, 3 ];
2087     auto r = retro129(a);
2088     auto i = begin129(r);
2089 }
2090 
2091 /***************************************************/
2092 // 12725
2093 
2094 struct R12725(R : E[], E)
2095 {
2096 }
2097 
2098 int begin12725(F)(R12725!(F) range)
2099 {
2100     return 0;
2101 }
2102 
2103 void test12725()
2104 {
2105     R12725!(int[], int) r;
2106     auto i = begin12725(r);
2107 }
2108 
2109 /***************************************************/
2110 // 12728
2111 
2112 struct Matrix12728(T, uint m, uint n = m, ubyte f = 0)
2113 {
2114     void foo(uint r)(auto ref in Matrix12728!(T, n, r) b)
2115     {
2116     }
2117 }
2118 
2119 void test12728()
2120 {
2121     alias Matrix4 = Matrix12728!(float, 4);
2122 
2123     Matrix4 m;
2124     m.foo(m);
2125 }
2126 
2127 /***************************************************/
2128 
2129 struct S130
2130 {
2131   byte[3] x;
2132 }
2133 
2134 __gshared S130 e130;
2135 
2136 const(S130) example130() { return e130; }
2137 
2138 void test130()
2139 {
2140 }
2141 
2142 /***************************************************/
2143 
2144 void foo131(real z) {}
2145 
2146 void test131()
2147 {
2148     real F = 1;
2149     foo131( 1 + (F*3*2.1) );
2150 }
2151 
2152 /***************************************************/
2153 
2154 float getFloat() {
2155     return 11468.78f;
2156 }
2157 
2158 void test132()
2159 {
2160     uint i = cast(uint) 11468.78f;
2161     assert(i == 11468);
2162 
2163     uint j = cast(uint) getFloat();
2164     assert(j == 11468);
2165 }
2166 
2167 /***************************************************/
2168 
2169 template T133(string s) {
2170     const string T133 = s;
2171 }
2172 
2173 string f133(string s) {
2174     return s;
2175 }
2176 
2177 void test133()
2178 {
2179     int foo;
2180     //writeln(foo.stringof);
2181     assert ("foo" == f133(foo.stringof));
2182     assert ("foo" == T133!(foo.stringof));
2183 }
2184 
2185 /***************************************************/
2186 
2187 public struct foo134
2188 {
2189     public this(real aleft)
2190     {
2191     }
2192 }
2193 
2194 class bar134
2195 {
2196     final void fun(foo134 arg = foo134(0.)) { }
2197 }
2198 
2199 /***************************************************/
2200 
2201 void test135()
2202 {
2203     char[char[3]] ac;
2204     char[3] c = "abc";
2205     ac["abc"]='a';
2206     assert(ac[c]=='a');
2207 
2208     char[dchar[3]] ad;
2209     dchar[3] d = "abc"d;
2210     ad["abc"d]='a';
2211     assert(ad[d]=='a');
2212 }
2213 
2214 /***************************************************/
2215 
2216 void test136()
2217 {
2218     struct S { int i[3]; }
2219     enum S s = S(8);
2220     const int i  = s.i[2];
2221     assert(i == 8);
2222 }
2223 
2224 /***************************************************/
2225 
2226 struct Particle {
2227     char[16] name;
2228 }
2229 
2230 class ReadSystem {
2231     size_t[char[16]] pKindsIdx;
2232 
2233     void t(Particle p)
2234     {   auto idx=p.name in pKindsIdx;
2235     }
2236 }
2237 
2238 void test137()
2239 {
2240     char[16] n;
2241     size_t[char[16]] aa;
2242     auto r=n in aa; // works
2243 }
2244 
2245 /***************************************************/
2246 
2247 long test138(int y)
2248 {
2249     return *cast(long*)(&y);
2250 }
2251 
2252 /***************************************************/
2253 
2254 void test139()
2255 {
2256    auto famousNamedConstants =
2257     [ "pi" : 3.14, "e" : 2.71, "moving sofa" : 2.22 ];
2258 
2259     assert(famousNamedConstants["e"]==2.71);
2260 }
2261 
2262 /***************************************************/
2263 
2264 int* get140()  {  return (new int[4]).ptr; }
2265 
2266 void test140()
2267 {
2268   int* p = get140();
2269   p[0..3] = 0;
2270   p[0] = 7;
2271 }
2272 
2273 /***************************************************/
2274 
2275 class Foo141 {
2276     Foo141 next;
2277     void start()
2278     in { assert (!next); } body
2279     {
2280         void* p = cast(void*)this;
2281     }
2282 }
2283 
2284 /***************************************************/
2285 
2286 void a142(int b = 1+2)(){};
2287 
2288 void test142()
2289 {
2290     a142!(1+2)();
2291     a142();
2292 }
2293 
2294 /***************************************************/
2295 
2296 class A143
2297 {
2298     invariant() { }
2299     void fill() { }
2300 }
2301 
2302 
2303 class B143 : A143
2304 {
2305     override void fill() { }
2306 }
2307 
2308 void test143()
2309 {
2310     auto b = new B143();
2311     b.fill();
2312 }
2313 
2314 /***************************************************/
2315 
2316 struct Pair
2317 {
2318     static Pair opCall(uint a, uint b) { return Pair.init; }
2319 }
2320 
2321 struct Stack
2322 {
2323     Pair pop() { return Pair.init; }
2324 }
2325 
2326 void test144()
2327 {
2328     Stack stack;
2329     Pair item = stack.pop;
2330 }
2331 
2332 /***************************************************/
2333 
2334 struct Ashes {
2335     int ashes = cast(int)0;
2336 }
2337 void funky (Ashes s = Ashes()) { }
2338 
2339 struct S145 {
2340     real a = 0, b = 0;
2341 }
2342 
2343 void func145(S145 s = S145()) { }
2344 
2345 void test145()
2346 {
2347     funky();
2348     func145();
2349 }
2350 
2351 /***************************************************/
2352 
2353 string foo146(T...)(T args)
2354 {
2355     string ret;
2356 
2357     foreach(arg; args) {
2358         ret = arg;
2359     }
2360 
2361     assert(ret=="b"); // passes
2362     return ret;
2363 }
2364 
2365 void test146()
2366 {
2367     string s = foo146("b");
2368     assert(s == "b"); // fails
2369 }
2370 
2371 /***************************************************/
2372 
2373 void test147()
2374 {
2375     string s = "foo";
2376     dchar c = 'x';
2377     s ~= c;
2378     assert(s == "foox");
2379 
2380     wstring ws = "foo";
2381     ws ~= c;
2382     assert(ws == "foox");
2383 }
2384 
2385 /***************************************************/
2386 
2387 void test148()
2388 {
2389     string a = "\U00091234";
2390     string b;
2391 
2392     b ~= "\U00091234";
2393 
2394     if (a != b) {
2395 	    assert(0);
2396     }
2397 }
2398 
2399 /***************************************************/
2400 
2401 void test149()
2402 {
2403   long[1] b = void;
2404   b[0] = -1L;
2405   b[0] >>>= 2;
2406   assert( (b[0]) == 0x3FFFFFFFFFFFFFFFL);
2407 }
2408 
2409 /***************************************************/
2410 
2411 bool foo150()
2412 {
2413     int x;
2414     return cast(void*) (x & 1) == null;
2415 }
2416 
2417 /***************************************************/
2418 // 3521
2419 
2420 void crash(int x)
2421 {
2422   if (x==200) return;
2423    asm { int 3; }
2424 }
2425 
2426 void test151()
2427 {
2428    int x;
2429    bug3521(&x);
2430 }
2431 
2432 void bug3521(int *a){
2433     int c = 0;
2434     *a = 0;
2435     if ( *a || (*a != (c = 200)) )
2436        crash(c);
2437 }
2438 
2439 /***************************************************/
2440 
2441 string foo152(T...)() {
2442     return "";
2443 }
2444 
2445 void test152() {
2446     foo152!(int, char)();
2447 }
2448 
2449 /***************************************************/
2450 
2451 int get_value()
2452 {
2453     return 1;
2454 }
2455 
2456 int[2] array1;
2457 int[2] array2;
2458 
2459 int foo153(ulong a1, ulong extra, ulong extra2, ulong extra3)
2460 {
2461     if (!((a1 & 1) | (get_value() | array1[cast(uint)(a1^1)])))
2462         return 0;
2463 
2464     if (0 >= array2[cast(uint)(a1^1)])
2465         return 0;
2466 
2467     return 1;
2468 }
2469 
2470 void test153()
2471 {
2472     foo153(0, 0, 0, 0);
2473 }
2474 
2475 /***************************************************/
2476 
2477 class B154 : A154
2478 {
2479 }
2480 
2481 enum SomeEnum
2482 {
2483     EnumMember = 10
2484 }
2485 
2486 class A154
2487 {
2488     SomeEnum someEnum()
2489     {
2490         return SomeEnum.EnumMember;
2491     }
2492 }
2493 
2494 void test154()
2495 {
2496     auto b = new B154();
2497     assert(cast(int)b.someEnum == 10);
2498 }
2499 
2500 /***************************************************/
2501 
2502 struct Qwert {
2503     Yuiop.Asdfg hjkl;
2504 }
2505 
2506 struct Yuiop {
2507     struct Asdfg {
2508         int zxcvb;
2509     }
2510 }
2511 
2512 /***************************************************/
2513 
2514 void f156(Value156.Id t)
2515 {
2516     assert(cast(int)t == 1);
2517 }
2518 
2519 struct Value156 {
2520   public static enum Id {
2521     A,
2522     B
2523   }
2524 }
2525 
2526 void test156()
2527 {
2528   Value156.Id t = Value156.Id.B;
2529   f156(t);
2530 }
2531 
2532 /***************************************************/
2533 
2534 X157 x157;
2535 enum X157 { Y };
2536 
2537 interface Foo157 {
2538     Policy157 fn();
2539 }
2540 
2541 enum Policy157 {Default, Cached, Direct}
2542 
2543 void test157()
2544 {
2545 }
2546 
2547 /***************************************************/
2548 
2549 class X158 {
2550   Y158.NY t;
2551   enum NX { BLA, BLA1 }
2552 }
2553 
2554 class Y158 {
2555   enum NY { FOO, BAR }
2556   X158.NX nx;
2557 }
2558 
2559 /***************************************************/
2560 
2561 struct Foo159 {
2562     Bar.Baz x;
2563 
2564     struct Bar {
2565         struct Baz {}
2566     }
2567 }
2568 
2569 /***************************************************/
2570 
2571 void test160()
2572 {
2573   long[1] b = void;
2574   b[0] = -1L;
2575   b[0] >>>= 2;
2576   assert( (b[0]) == 0x3FFFFFFFFFFFFFFFL);
2577   int i = -1;
2578   assert(i >>>2 == 0x3FFFFFFF);
2579 }
2580 
2581 /***************************************************/
2582 
2583 class A161 {
2584     struct B {
2585         D161 x;
2586 
2587         struct C {}
2588     }
2589 }
2590 
2591 
2592 struct D161 {}
2593 
2594 class C161
2595 {
2596     A a;
2597 
2598     struct A
2599     {
2600         uint m;
2601     }
2602 
2603     enum
2604     {
2605         E = 0
2606     }
2607 }
2608 
2609 /***************************************************/
2610 
2611 interface A162
2612 {
2613     C162 foo();
2614     C162 foo() const;
2615 }
2616 
2617 class B162 : A162
2618 {
2619     C162 foo() { return null; }
2620     C162 foo() const { return null; }
2621 }
2622 
2623 abstract class C162 : A162
2624 {
2625     C162 foo() { return null; }
2626     C162 foo() const { return null; }
2627 }
2628 
2629 /***************************************************/
2630 
2631 void func163( A... )( string name, string v )
2632 {
2633 }
2634 
2635 void test163()
2636 {
2637     func163!( int, long, float )( "val", "10" );
2638     func163!()( "tmp", "77" );
2639     alias func163!() TMP; TMP( "tmp", "77" );
2640 }
2641 
2642 /***************************************************/
2643 
2644 class A164
2645 {
2646     B164 foo() { return null; }
2647     B164 foo() const { return null; }
2648 }
2649 
2650 abstract class B164 : A164
2651 {
2652     override final B164 foo() { return null; }
2653     override final B164 foo() const { return null; }
2654 }
2655 
2656 /***************************************************/
2657 
2658 class A165
2659 {
2660     B165 foo() { return null; }
2661     const(B165) foo() const { return null; }
2662 }
2663 
2664 abstract class B165 : A165
2665 {
2666     override final B165 foo() { return null; }
2667     override final const(B165) foo() const { return null; }
2668 }
2669 
2670 /***************************************************/
2671 
2672 struct A166 {
2673    B166  xxx;
2674    static this () { }
2675 }
2676 
2677 struct B166 {}
2678 
2679 /***************************************************/
2680 
2681 void x168(T)() {
2682     static assert(false);
2683 }
2684 
2685 template y168(T) {
2686     const bool y168 = is(typeof( { x168!(T)(); } ));
2687 }
2688 
2689 static assert(!y168!(int));
2690 
2691 /***************************************************/
2692 
2693 void test169()
2694 {
2695     int AssociativeArray;
2696     int[int] foo;
2697     foreach (x; foo)    {    }
2698 }
2699 
2700 /***************************************************/
2701 
2702 FwdEnum this_fails;
2703 
2704 enum : int
2705 {
2706         E170 =  2
2707 }
2708 
2709 enum FwdEnum : int
2710 {
2711         E2 =  E170
2712 }
2713 
2714 /***************************************************/
2715 // 3740
2716 
2717 abstract class Address {
2718     abstract int nameLen();
2719 }
2720 
2721 class Class171 : Address {
2722     FwdStruct z;
2723 
2724     struct FwdStruct  {  }
2725 
2726     override int nameLen()    { return 0; }
2727 }
2728 
2729 void test171 ()
2730 {
2731     Class171 xxx = new Class171;
2732     assert(typeid(Class171).vtbl.length - typeid(Object).vtbl.length == 1);
2733 }
2734 
2735 /***************************************************/
2736 
2737 struct Foo172
2738 {
2739     enum bool BAR = is (typeof({}()));
2740     static assert (BAR == is (typeof({}())));
2741 }
2742 
2743 /***************************************************/
2744 
2745 const char[][ 89 ] ENUM_NAME = [ 1:"N0" ];
2746 
2747 void test173()
2748 {
2749     switch(`Hi`.dup) {
2750         case ENUM_NAME[1]:
2751 	default:
2752 		break;
2753     }
2754 }
2755 
2756 /***************************************************/
2757 
2758 class A174 {
2759     void x() {  }
2760 }
2761 
2762 class B174 : A174 {
2763     override void x() {
2764         assert(0);
2765     }
2766     final void do_x() {
2767         super.x();
2768     }
2769 }
2770 
2771 void test174()
2772 {
2773     auto b = new B174();
2774     b.do_x();
2775 }
2776 
2777 /***************************************************/
2778 
2779 void badvariadic(...) {}
2780 
2781 static assert(!is(typeof(mixin(badvariadic()))));
2782 
2783 /***************************************************/
2784 
2785 struct Foo176
2786 {
2787     int x;
2788 }
2789 
2790 Foo176 getFoo(Foo176 irrelevant)
2791 {
2792     Foo176 p = Foo176(400);
2793     if ( p.x > p.x )
2794         return irrelevant;
2795     else
2796         return p;
2797 }
2798 
2799 void test176()
2800 {
2801    assert(getFoo( Foo176(0) ).x == 400);
2802 }
2803 
2804 /***************************************************/
2805 
2806 int test177()
2807 {
2808     long[1] c = [0]; // must be long
2809 
2810     int [1] d = [1];
2811     int k = 0;
2812     if (!d[0])
2813        k = 1;
2814     k = d[0] + k + k;
2815 
2816     if (c[0]) assert(c[0]);
2817 
2818     return k;
2819 }
2820 
2821 /***************************************************/
2822 
2823 struct S178 {
2824     int x;
2825 
2826     template T(int val) {
2827 	enum S178 T = { val };
2828     }
2829 }
2830 
2831 const x178 = S178.T!(0);
2832 
2833 /***************************************************/
2834 
2835 double[100_000] arr = 0.0;
2836 
2837 /***************************************************/
2838 
2839 alias ireal BUG3919;
2840 alias typeof(BUG3919.init*BUG3919.init) ICE3919;
2841 alias typeof(BUG3919.init/BUG3919.init) ICE3920;
2842 
2843 /***************************************************/
2844 
2845 struct S179 {
2846     char a, b, c, d;
2847 }
2848 
2849 void show(char[] args...) {
2850     assert(args[0]=='A');
2851     assert(args[1]=='L');
2852     assert(args[2]=='D');
2853     assert(args[3]=='O');
2854 }
2855 
2856 void A179( S179 ss ) {
2857     show( ss.a, ss.b, ss.c, ss.d );
2858 }
2859 
2860 void test179()
2861 {
2862     S179 ss3;
2863     ss3.a = 'A';
2864     ss3.b = 'L';
2865     ss3.c = 'D';
2866     ss3.d = 'O';
2867     A179( ss3 );
2868 }
2869 
2870 /***************************************************/
2871 
2872 struct XY { union { int x, y; } }
2873 struct AHolder {
2874     XY aa;
2875     void a(XY x) { aa = x; }
2876 }
2877 struct AB {
2878     AHolder aHolder;
2879     XY b;
2880     void a(XY x) { aHolder.a(x); }
2881 }
2882 struct Main {
2883     AB ab;
2884 
2885     void setB() { ab.b = XY(); }
2886     void f() {
2887         ab.a(XY.init);
2888         setB();
2889     }
2890 }
2891 
2892 /***************************************************/
2893 
2894 void fooa181(int x, int y, int[0] a, int z, int t)
2895 {
2896     if (!(x == 2 && y == 4 && z == 6 && t == 8))
2897 	assert(0);
2898 }
2899 
2900 void foob181(int x, int y, int[0] a)
2901 {
2902     if (!(x == 2 && y == 4))
2903 	assert(0);
2904 }
2905 
2906 void fooc181(int[0] a, int x, int y)
2907 {
2908     if (!(x == 2 && y == 4))
2909 	assert(0);
2910 }
2911 
2912 void food181(int[0] a)
2913 {
2914 }
2915 
2916 void test181()
2917 {
2918     int[0] arr = 0;
2919     fooa181(2, 4, arr, 6, 8);
2920     foob181(2, 4, arr);
2921     fooc181(arr, 2, 4);
2922     food181(arr);
2923 }
2924 
2925 /***************************************************/
2926 // 4042
2927 
2928 template isQObjectType(T)
2929 {
2930     enum isQObjectType = is(T.__isQObjectType);
2931 }
2932 
2933 template QTypeInfo(T)
2934 {
2935     static if (!isQObjectType!T)
2936     {
2937         enum size = T.sizeof;
2938     }
2939 }
2940 
2941 struct QList(T)
2942 {
2943     alias QTypeInfo!T TI;
2944     int x;
2945 
2946     void foo()
2947     {
2948         x++;
2949     }
2950 }
2951 
2952 void exec(QList!(QAction) actions) {}
2953 
2954 interface IQGraphicsItem
2955 {
2956 }
2957 
2958 abstract
2959 	class QGraphicsObject : IQGraphicsItem
2960 {
2961 }
2962 
2963 class QGraphicsWidget : QGraphicsObject
2964 {
2965 }
2966 
2967 class QAction
2968 {
2969     void associatedGraphicsWidgets(QList!(QGraphicsWidget) a)
2970     {
2971         QList!(QGraphicsWidget) x;
2972     }
2973 }
2974 
2975 void test182()
2976 {
2977 }
2978 
2979 /***************************************************/
2980 
2981 enum { a183 = b183() }
2982 
2983 int b183() { return 0; }
2984 
2985 /***************************************************/
2986 
2987 struct Z184 {
2988     int bar = 1;
2989     union { Foo184 foo; }
2990 }
2991 
2992 struct Foo184 { size_t offset = 0;}
2993 
2994 /***************************************************/
2995 
2996 struct BB185
2997 {
2998   Item185[1] aa;
2999 }
3000 
3001 struct CC185
3002 {
3003   Item185 aa;
3004 }
3005 
3006 struct Item185
3007 {
3008   byte data;
3009 }
3010 
3011 /***************************************************/
3012 
3013 const PM_QS_INPUT = QS_INPUT;
3014 const QS_INPUT = 2;
3015 
3016 /***************************************************/
3017 
3018 alias A187 B187;
3019 const int A187 = 1;
3020 
3021 /***************************************************/
3022 
3023 int foo188(int[3] s)
3024 {
3025     return s[0] + s[1] + s[2];
3026 }
3027 
3028 void test188()
3029 {
3030     int[3] t = [1,3,4];
3031     auto i = foo188(t);
3032     if (i != 8)
3033 	assert(0);
3034 }
3035 
3036 /***************************************************/
3037 
3038 template X189(alias fn) {
3039     alias typeof(fn) X189;
3040 }
3041 
3042 void a189()(T1189 x) {
3043     alias X189!(T1189.foo) P; //line 7
3044 
3045     x.foo();
3046 }
3047 
3048 class T1189 {
3049     void foo() {
3050 	printf("T1.foo()\n");
3051     }
3052 }
3053 
3054 class T2189 : T1189 {
3055     void bla() {
3056 	printf("T2.blah()\n");
3057         assert(false); //line 19
3058     }
3059 }
3060 
3061 void test189() {
3062     a189!()(new T2189());
3063 }
3064 
3065 /***************************************************/
3066 
3067 void test190()
3068 {
3069     string s;
3070 
3071     if (true) scope(exit) s ~= "a";
3072     if (false) { } else scope(exit) s ~= "b";
3073     if (true) scope(exit) scope(exit) s ~= "c";
3074     foreach(x; 1..2) scope(exit) s ~= "d";
3075     if (true) L1: scope(exit) s ~= "e";
3076     do scope(exit) s ~= "f"; while (false);
3077     int i; while (++i == 1) scope(exit) s ~= "g";
3078     try { } finally scope(exit) s ~= "h";
3079     assert(s == "abcdefgh");
3080 }
3081 
3082 /***************************************************/
3083 
3084 struct S191 {
3085   int last = 0;
3086   S191 opCall(int i) {
3087     printf("%d %d\n", last, i);
3088     assert(i == 1 && last == 0 || i == 2 && last == 1 || i == 3 && last == 1);
3089     last = i;
3090     return this;
3091   }
3092 }
3093 
3094 void test191()
3095 {
3096   S191 t;
3097   t(1)(2);
3098   t(3);
3099 }
3100 
3101 /***************************************************/
3102 
3103 enum foo192 {
3104     item,
3105 }
3106 
3107 //pragma(msg, foo.mangleof);
3108 static assert(foo192.mangleof == "E6test426foo192");
3109 
3110 /***************************************************/
3111 
3112 void test193()
3113 {
3114     enum Shapes
3115     {
3116 	Circle, Square
3117     }
3118 
3119     int i;
3120     Shapes s;
3121 
3122     pragma(msg, i.stringof);
3123     pragma(msg, s.stringof);
3124 
3125     static assert(i.stringof == "i");
3126     static assert(s.stringof == "s");
3127 }
3128 
3129 /***************************************************/
3130 
3131 void test194()
3132 {
3133     uint[][] b = [[ 1, 2, ]];
3134 }
3135 
3136 /***************************************************/
3137 
3138 alias int T195;
3139 
3140 class C195
3141 {
3142     int yum = x195;
3143 }
3144 
3145 const T195 x195 = 0;
3146 
3147 /***************************************************/
3148 
3149 union A196 {
3150     double[2] a;
3151     double[2] b;
3152 }
3153 
3154 union B196 {
3155 public:
3156      double[2] a;
3157      double[2] b;
3158 }
3159 
3160 static assert(A196.sizeof == B196.sizeof);
3161 
3162 /***************************************************/
3163 
3164 template Compileable(int z) { bool OK;}
3165 
3166 struct Bug3569 {
3167     int bar() { return 7; }
3168 }
3169 
3170 struct Bug3569b {
3171     Bug3569 foo;
3172     void crash() {
3173         static assert(!is(typeof(Compileable!(foo.bar()))));
3174         static assert(!is(typeof(Compileable!((foo = Bug3569.init).bar()))));
3175     }
3176 }
3177 
3178 void test197()
3179 {
3180 }
3181 
3182 /***************************************************/
3183 
3184 void test198()	// Bugzilla 4506
3185 {
3186     int c = 1;
3187     for (int k = 0; k < 2; k++) {
3188         assert((k == 0 && c == 1) || (k == 1 && c == -1));
3189         c *= -1;
3190     }
3191 }
3192 
3193 /***************************************************/
3194 
3195 // Bugzilla 4514
3196 void g199(void delegate(void*, void*) d) { }
3197 
3198 struct X199 {
3199     void f(void*, void*) {}
3200     void n()
3201     {
3202         g199(&f);
3203     }
3204 }
3205 
3206 /***************************************************/
3207 // Bugzilla 4443
3208 
3209 struct Struct4443
3210 {
3211     int x;
3212     char[5] unused;
3213 }
3214 
3215 void foo4443(Struct4443 *dest, Struct4443[] arr)
3216 {
3217     int junk = arr[$-1].x;
3218     if (dest || arr[$-1].x) {
3219         *dest = arr[$-1];
3220     }
3221 }
3222 
3223 void test200()
3224 {
3225     Struct4443[1] a;
3226     Struct4443 info;
3227     foo4443(&info, a);
3228 }
3229 
3230 /***************************************************/
3231 
3232 // Bugzilla 2931
3233 
3234 struct Bug2931 {
3235         int val[3][4];
3236 }
3237 
3238 struct Outer2931 {
3239         Bug2931 p = Bug2931(67);  // Applies to struct static initializers too
3240         int zoom = 2;
3241         int move = 3;
3242         int scale = 4;
3243 }
3244 
3245 int bug2931()
3246 {
3247   Outer2931 v;
3248   assert(v.move==3);
3249   assert(v.scale == 4);
3250   return v.zoom;
3251 }
3252 
3253 int bug2931_2()
3254 {
3255   Outer2931 v;
3256   Bug2931 w = Bug2931(68);
3257   assert(v.move==3);
3258   for (int i = 0; i < 4; i++)
3259   {
3260     for (int j = 0; j < 3; j++)
3261     {
3262         assert(w.val[j][i] == 68);
3263 	assert(v.p.val[j][i] == 67);
3264     }
3265   }
3266   assert(v.scale == 4);
3267   return v.zoom;
3268 }
3269 
3270 static assert(bug2931()==2);
3271 
3272 void test201() {
3273     assert(bug2931()==2);
3274     assert(bug2931_2()==2);
3275 }
3276 
3277 
3278 /***************************************************/
3279 // This was the original varargs example in std.vararg
3280 
3281 import core.vararg;
3282 
3283 void foo202(int x, ...) {
3284     printf("%d arguments\n", _arguments.length);
3285     for (int i = 0; i < _arguments.length; i++) {
3286         int j = va_arg!(int)(_argptr);
3287         printf("\t%d\n", j);
3288 	assert(j == i + 2);
3289     }
3290 }
3291 
3292 void fooRef202(ref int x, ...) {
3293     printf("%d arguments\n", _arguments.length);
3294     for (int i = 0; i < _arguments.length; i++) {
3295         int j = va_arg!(int)(_argptr);
3296         printf("\t%d\n", j);
3297 	assert(j == i + 2);
3298     }
3299 }
3300 
3301 void test202()
3302 {
3303     foo202(1, 2, 3, 4, 5);
3304 
3305     printf("---\n");
3306 
3307     int x = 1;
3308     fooRef202(x, 2, 3, 4, 5);
3309 }
3310 
3311 /***************************************************/
3312 // Bugzilla 1418
3313 
3314 class A203
3315 {
3316     char name = 'A';
3317     class B203
3318     {
3319         char name = 'B';
3320     }
3321 }
3322 
3323 void test203()
3324 {
3325     class C203
3326     {
3327     char name = 'C';
3328     }
3329 
3330     auto a = new A203;
3331     auto b = a..new B203;
3332     auto c = new C203;
3333 
3334     writeln(a.tupleof); // prints: A
3335     writeln(b.tupleof); // prints: B main.A
3336     writeln(c.tupleof); // prints: C 0000
3337     assert(a.tupleof.length == 1 && a.tupleof[0] == 'A');
3338     assert(b.tupleof.length == 1 && b.tupleof[0] == 'B');
3339     assert(c.tupleof.length == 1 && c.tupleof[0] == 'C');
3340 }
3341 
3342 /***************************************************/
3343 // Bugzilla 4516
3344 
3345 struct A204 { B204 b; }
3346 enum B204 { Z }
3347 
3348 /***************************************************/
3349 // Bugzilla 4503
3350 
3351 class Collection205(T) { }
3352 ICollection c;
3353 
3354 alias Collection205!int ICollection;
3355 
3356 /***************************************************/
3357 
3358 enum TaskStatus:int { Building=-1, }
3359 
3360 TaskStatus test206(char[] s){
3361     char[] t="TaskStatus".dup;
3362     if (s.length>t.length && s[0..t.length]==t){
3363         long res=0;
3364         if (s[t.length]=='-') res= -res;	// <= OPnegass
3365         return cast(TaskStatus)cast(int)res;
3366     }
3367     assert(0);
3368 }
3369 
3370 /***************************************************/
3371 
3372 struct UN {   double dd;    long ll; }
3373 bool cmp( UN * pU ) {   return pU.dd >= pU.ll ? true : false; }
3374 
3375 struct UN2 {  real dd; long ll; }
3376 bool cmp2( UN2 * pU ) {  return pU.dd >= pU.ll ? true : false; }
3377 
3378 struct UN3 {  double dd; int ll; }
3379 bool cmp3( UN3 * pU ) {  return pU.dd >= pU.ll ? true : false; }
3380 
3381 void test207()
3382 {
3383    static UN u = { 10.50, 10 };
3384    auto i = cmp(&u);
3385    printf( "%d\n", cmp( &u ) );
3386    assert(i);
3387 
3388    static UN2 u2 = { 10.50, 10 };
3389    i = cmp2(&u2);
3390    assert(i);
3391 
3392    static UN3 u3 = { 10.50, 10 };
3393    i = cmp3(&u3);
3394    assert(i);
3395 
3396    static UN3 u3_1 = { 9.50, 10 };
3397    i = cmp3(&u3_1);
3398    assert(!i);
3399 }
3400 
3401 /***************************************************/
3402 
3403 template fail4302() {
3404     static assert(0);
3405 }
3406 template bug4302() {
3407    alias fail4302!() bad;
3408 }
3409 static if (is(bug4302!())) {}
3410 
3411 /***************************************************/
3412 
3413 template tough4302()
3414 {
3415   template bar()
3416   {
3417      template far()
3418      {
3419          static assert(0);
3420      }
3421      alias far!() par;
3422   }
3423   static if (is(bar!())) {}
3424 }
3425 
3426 alias tough4302!() tougher;
3427 
3428 /***************************************************/
3429 
3430 template Bug6602A(T) {
3431   Bug6602B!(T).Result result;
3432 }
3433 
3434 template Bug6602B(U) {
3435   static assert(is(U == int));
3436   alias bool Result;
3437 }
3438 
3439 enum bug6602Compiles = __traits(compiles, Bug6602A!short);
3440 
3441 /***************************************************/
3442 // Bugzilla 3493
3443 
3444 const bar209 = foo209;
3445 const int * foo209 = null;
3446 
3447 /***************************************************/
3448 // 3418
3449 
3450 void test210()
3451 {
3452     ulong a = 1;
3453     a = cast(ulong)(a * 2.0L);
3454 }
3455 
3456 /***************************************************/
3457 
3458 static assert(!is(typeof(Object.tupleof[2000]=0)));
3459 
3460 /***************************************************/
3461 
3462 struct Ghost {}
3463 
3464 void bug4430(T)(int x)   {}
3465 void bug4430(T)(Ghost x) {}
3466 
3467 void test212()
3468 {
3469     bug4430!(char)( 777 );
3470 }
3471 
3472 /***************************************************/
3473 // 4768
3474 
3475 struct A213 { B213 b; }
3476 enum B213 { Z213 = 2 }
3477 
3478 void test213()
3479 {
3480    A213 x;
3481    assert(x.b == 2);
3482 }
3483 
3484 /***************************************************/
3485 
3486 void g214(int j) { }
3487 
3488 void test214()
3489 {
3490     struct S
3491     {
3492         int i;
3493         void f() { g214(i); }
3494     }
3495     auto s = S();
3496 }
3497 
3498 /***************************************************/
3499 
3500 template Q(s...) { alias s q; }
3501 
3502 void test215()
3503 {
3504     class C {}
3505     enum assocarrayliteral = Q!( [1:2] ).q.stringof;
3506     enum complex80 = Q!( 1+1.0i ).q.stringof;
3507     //enum dottype = Q!( C.Object.toString ).q.stringof;
3508     enum halt = (assert(0), 0).stringof;    // ICE w/ -release
3509     //enum remove = Q!( [1:2].remove(1) ).q.stringof;
3510     enum templat = Q!( Q ).q.stringof;
3511 }
3512 
3513 /***************************************************/
3514 // 4941
3515 
3516 template T216(_...) { alias _ T216; }
3517 size_t mid216(size_t n) { return n/2; }
3518 
3519 alias T216!(int, int)[0 .. mid216($)] A216;
3520 alias T216!(1, 2, 3)[0 .. mid216($)] B216;
3521 
3522 void test216()
3523 {
3524     T216!(int, int, int) values;
3525     auto slice = values[0 .. mid216($)];   // C
3526 }
3527 
3528 /***************************************************/
3529 
3530 int bug4529a() { return 0; }
3531 int function() bug4529b;
3532 auto ivorBomb1 = typeid(typeof(bug4529a));
3533 auto ivorBomb2 = typeid(typeof(bug4529b));
3534 
3535 /***************************************************/
3536 
3537 void bug5218c(char [3] s) {}
3538 void bug5218w(wchar [3] s) {}
3539 void bug5218d(dchar [3] s) {}
3540 
3541 void test217()
3542 {
3543     bug5218c("abc");
3544     bug5218w("abc"w);
3545     bug5218d("abc"d);
3546 }
3547 
3548 /***************************************************/
3549 // 2954
3550 
3551 void test218()
3552 {
3553     char[char[3]] ac;
3554     char[3] c = "abc";
3555     ac["abc"]='a';
3556     assert(ac[c]=='a');
3557 
3558     char[dchar[3]] ad;
3559     dchar[3] d = "abc"d;
3560     ad["abc"d]='a';
3561     assert(ad[d]=='a');
3562 }
3563 
3564 /***************************************************/
3565 // 2206
3566 
3567 template T219(U) {
3568   class C {}
3569 }
3570 
3571 void test219()
3572 {
3573   mixin T219!(int); // using a named mixin here fixes it
3574 
3575   pragma(msg, T219!(int).C.mangleof);
3576   pragma(msg, C.mangleof); // incorrectly outputs the same as above
3577 
3578   assert(T219!(int).C.classinfo !is C.classinfo); // fails
3579   assert(T219!(int).C.mangleof != C.mangleof); // fails
3580 }
3581 
3582 
3583 /***************************************************/
3584 // 2206
3585 
3586 class D220 {}
3587 
3588 template T220(U) {
3589   class C { this() { } }
3590 }
3591 
3592 void test220()
3593 {
3594   mixin T220!(int);
3595 
3596   // all print 8
3597   writeln(T220!(int).C.classinfo.init.length);
3598   writeln(C.classinfo.init.length);
3599   writeln(D220.classinfo.init.length);
3600 
3601   auto c = new C; // segfault in _d_newclass
3602 }
3603 
3604 /***************************************************/
3605 
3606 const struct S5110
3607 {
3608     static int value;
3609 }
3610 
3611 static assert(is(typeof(S5110.value) == int));
3612 
3613 /***************************************************/
3614 
3615 class C5110
3616 {
3617  override:
3618     string toString() { return ""; }
3619 
3620     class Nested
3621     {
3622         void gun() {}
3623     }
3624 }
3625 
3626 /***************************************************/
3627 
3628 immutable class Bug5504
3629 {
3630     void foo(T)(T a) {}
3631     template xx(X) {
3632         void hoo(T)(T a) {}
3633     }
3634 }
3635 
3636 shared class Bug5504b
3637 {
3638     void foo(T)(T a) {}
3639     template xx(X) {
3640         void hoo(T)(T a) {}
3641     }
3642 }
3643 
3644 void test5504()
3645 {
3646     immutable Bug5504 c;
3647     c.foo(10);
3648     c.xx!(int).hoo(10);
3649     shared Bug5504b d;
3650     d.foo(10);
3651     d.xx!(int).hoo(10);
3652 }
3653 
3654 /***************************************************/
3655 
3656 void bug5105() // compilation test -- don't need to run
3657 {
3658     auto c = new shared(C5105);
3659     c.foo(10);
3660 }
3661 
3662 synchronized shared class C5105
3663 {
3664     void foo(T)(T a) {}
3665 }
3666 
3667 /***************************************************/
3668 // 5145
3669 
3670 interface I221{
3671     void bla();
3672 }
3673 
3674 interface J221
3675 {
3676     I221 sync ();
3677 }
3678 
3679 class A221 : B221
3680 {
3681     final override I221 sync()
3682     in { assert( valid ); }
3683     body
3684     {
3685         return null;
3686     }
3687 }
3688 
3689 class B221 : J221
3690 {
3691     override I221 sync()
3692     in { assert( valid ); }
3693     body
3694     {
3695         return null;
3696     }
3697 
3698     final bool valid()
3699     {
3700         return true;
3701     }
3702 }
3703 
3704 /***************************************************/
3705 
3706 template Bug3276(bool B) {
3707    static if (B)
3708       alias Bug3276!(false) Bug3276;
3709    else
3710        alias double Bug3276;
3711 }
3712 
3713 template Bug3276_b(alias W) {
3714     alias W!(true) Bug3276_b;
3715 }
3716 
3717 alias Bug3276_b!(Bug3276) Bug3276_c;
3718 
3719 /***************************************************/
3720 // 5294
3721 
3722 void foo222(int) {}
3723 
3724 void test222()
3725 {
3726     int count;
3727     for (int i = 0; i < 2; i++) {
3728         count++;
3729         foo222(i * 5 - 6); // comment this out and it makes 2 loops
3730     }
3731     printf("%d\n", count); // compile with -O and it prints 1
3732     assert(count == 2);
3733 }
3734 
3735 /***************************************************/
3736 
3737 void foo223(long x,long a,long b,long c,long d,long e,long f)
3738 {
3739     assert(x == 0x123456789ABCDEF0);
3740 }
3741 
3742 void test223()
3743 {
3744     foo223(0x123456789ABCDEF0,2,3,4,5,6,7);
3745 }
3746 
3747 /***************************************************/
3748 // 4379
3749 
3750 template BigTuple(U...) {
3751     alias U BigTuple;
3752 }
3753 
3754 alias
3755 BigTuple!(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3756 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3757 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3758 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3759 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3760 1,1,1,1,1,1) Tuple4379;
3761 
3762 void test224()
3763 {
3764     foreach(x; Tuple4379) {    }
3765 }
3766 
3767 /***************************************************/
3768 // 3681
3769 
3770 public final class A3681 {
3771     private this() {
3772 	int i =0;
3773 	int j = i + 1;
3774  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3775  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3776  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3777  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3778  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3779  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3780  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3781  i = j * 15; j = i * 59; i = j * 15; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3782  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3783  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3784  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3785  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3786  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3787  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3788  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3789  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3790  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3791  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3792  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3793  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3794  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3795  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3796  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3797  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3798  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3799  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3800  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3801  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3802  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3803  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3804  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3805  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3806  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3807  j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; j = i * 59; i = j * 15; j = i * 59;
3808  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3809  i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3810     }
3811 }
3812 
3813 /***************************************************/
3814 
3815 int bug4389()
3816 {
3817     string s;
3818     dchar c = '\u2348';
3819     s ~= c;
3820     assert(s.length==3);
3821     dchar d = 'D';
3822     s ~= d;
3823     assert(s.length==4);
3824     s = "";
3825     s ~= c;
3826     assert(s.length==3);
3827     s ~= d;
3828     assert(s.length==4);
3829     string z;
3830     wchar w = '\u0300';
3831     z ~= w;
3832     assert(z.length==2);
3833     z = "";
3834     z ~= w;
3835     assert(z.length==2);
3836     return 1;
3837 }
3838 
3839 static assert(bug4389());
3840 
3841 // ICE(constfold.c)
3842 int ice4389()
3843 {
3844     string s;
3845     dchar c = '\u2348';
3846     s ~= c;
3847     s = s ~ "xxx";
3848    return 1;
3849 }
3850 
3851 static assert(ice4389());
3852 
3853 // ICE(expression.c)
3854 string ice4390()
3855 {
3856     string s;
3857     dchar c = '`';
3858     s ~= c;
3859     s ~= c;
3860    return s;
3861 }
3862 
3863 static assert(mixin(ice4390()) == ``);
3864 static assert(mixin(ice4390()) == ``);
3865 
3866 /***************************************************/
3867 // 190
3868 
3869 alias int avocado;
3870 void eat(avocado x225 = .x225);
3871 avocado x225;
3872 
3873 void test225()
3874 {
3875 }
3876 
3877 /***************************************************/
3878 // 5534
3879 
3880 void doStuff(byte start, byte end, uint increment = 1U) {
3881    auto output = new byte[3];
3882 
3883     size_t count = 0;
3884     for(byte i = start; i < end; i += increment) {
3885         output[count++] = i;
3886     }
3887 }
3888 
3889 void test226()  {
3890     doStuff(0, 3);
3891 }
3892 
3893 /***************************************************/
3894 // 5536
3895 
3896 void test227()
3897 {
3898   int[] as = [111, 666];
3899   as ~= as[$ - 2];
3900   assert(as.length == 3);
3901   assert(as[2] == 111);
3902 }
3903 
3904 /***************************************************/
3905 // 4017
3906 
3907 struct _A
3908 {
3909    uint data;
3910 }
3911 
3912 const A_SIZE =   (A4017.sizeof);
3913 
3914 alias _A A4017;
3915 
3916 /***************************************************/
3917 // 5455
3918 
3919 void thrw(Data *s) {
3920     throw new Exception("xxx");
3921 }
3922 
3923 struct Data {
3924     Rapper *w;
3925     uint n, m;
3926 }
3927 
3928 struct Rapper {
3929     ubyte * dat;
3930     ubyte[] con() {
3931         return dat[0..1];
3932     }
3933 }
3934 
3935 uint jaz(ubyte[] data) {
3936     return cast(uint)data.length;
3937 }
3938 
3939 struct Resp {
3940     void set(Data *data, string[] soup) {
3941         switch(soup[0]) {
3942             default:
3943         }
3944         uint[] f = [jaz(data.w ? data.w.con[data.n ..data.m] : null), data.m - data.n];
3945         thrw(data);
3946     }
3947 }
3948 
3949 /**************************************/
3950 // 5571
3951 
3952 void test228() {
3953     auto b = new bool;
3954     printf("%p\n", b);
3955     *b = false;
3956 }
3957 
3958 /***************************************************/
3959 // 5572
3960 
3961 void doSynchronized() {
3962     printf("In doSynchronized() 1:  %p\n", cast(void*) global229);
3963     synchronized {
3964         printf("In doSynchronized() 2:  %p\n", cast(void*) global229);
3965     }
3966 }
3967 
3968 __gshared Object global229;
3969 
3970 void test229() {
3971     auto local = new Object;
3972     global229 = local;
3973 
3974     printf("In main() 1:  %p\t%p\n",
3975         cast(void*) global229, cast(void*) local);
3976     doSynchronized();
3977     printf("In main() 1:  %p\t%p\n",
3978         cast(void*) global229, cast(void*) local);
3979 
3980     assert(cast(void*) global229 == cast(void*) local);
3981 }
3982 
3983 /***************************************************/
3984 
3985 static immutable real negtab[14] =
3986     [ 1e-4096L,1e-2048L,1e-1024L,1e-512L,1e-256L,1e-128L,1e-64L,1e-32L,
3987 	    1e-16L,1e-8L,1e-4L,1e-2L,1e-1L,1.0L ];
3988 static immutable real postab[13] =
3989     [ 1e+4096L,1e+2048L,1e+1024L,1e+512L,1e+256L,1e+128L,1e+64L,1e+32L,
3990 	    1e+16L,1e+8L,1e+4L,1e+2L,1e+1L ];
3991 
3992 float parse(ref string p)
3993 {
3994     printf("test1\n");
3995 
3996     real ldval = 0.0;
3997     int exp = 0;
3998     long msdec = 0;
3999 
4000     msdec = 123;
4001     exp = 2;
4002 
4003     ldval = msdec;
4004     printf("ldval = %Lg\n", ldval);
4005     if (ldval)
4006     {
4007         uint u = 0;
4008         int pow = 4096;
4009 
4010         while (exp > 0)
4011         {
4012             while (exp >= pow)
4013             {
4014                 ldval *= postab[u];
4015                 exp -= pow;
4016             }
4017             pow >>= 1;
4018             u++;
4019         }
4020         while (exp < 0)
4021         {
4022             while (exp <= -pow)
4023             {
4024                 ldval *= negtab[u];
4025                 exp += pow;
4026             }
4027             pow >>= 1;
4028             u++;
4029         }
4030     }
4031     return ldval;
4032 }
4033 
4034 void test230()
4035 {
4036     float f;
4037     string s = "123e+2";
4038     f = parse( s );
4039     //printf("f = %g\n", f);
4040     assert( f == 123e+2f );
4041 }
4042 
4043 /***************************************************/
4044 
4045 class Bug4033 {}
4046 
4047 class Template4033(T) {
4048     static assert(is(T : Bug4033));
4049 }
4050 
4051 alias Template4033!(Z4033) Bla;
4052 
4053 class Z4033 : Bug4033 { }
4054 
4055 /***************************************************/
4056 
4057 struct Bug4322 {
4058     int[1] a = void;
4059 }
4060 
4061 void bug4322() {
4062     Bug4322 f = Bug4322();
4063     Bug4322 g = Bug4322.init;
4064 }
4065 
4066 /***************************************************/
4067 
4068 bool bug5672(long v)
4069 {
4070     return  (v & 1) == 1;
4071     return  (v & 1) == 1;
4072 }
4073 
4074 /***************************************************/
4075 
4076 void bug5717()
4077 {
4078     string s, s2;
4079     s = "Привет";
4080     for (int i=0; i<s.length; i++)
4081         s2 ~= s[i];
4082     assert(s == s2);
4083 }
4084 
4085 /***************************************************/
4086 // 3086
4087 
4088 class X231 {
4089     void a() {}
4090     void b(int z, short c) {}
4091     void c(int z, short d) {}
4092 }
4093 
4094 void test231() {
4095     auto z = new X231();
4096     TypeInfo a = typeid(typeof(&z.a));
4097     TypeInfo b = typeid(typeof(&z.b));
4098     TypeInfo c = typeid(typeof(&z.c));
4099 
4100     assert(a !is b, "1");
4101     assert(a != b, "2");
4102     assert(b == c, "3");
4103 }
4104 
4105 /***************************************************/
4106 // 4140
4107 
4108 const A232 = [1,2,3];
4109 const B232 = A232[1..A232.length];
4110 const C232 = A232[1..$];
4111 
4112 void test232()
4113 {
4114     assert(A232[0] == 1);
4115     assert(A232[1] == 2);
4116     assert(A232[2] == 3);
4117     assert(B232[0] == 2);
4118     assert(B232[1] == 3);
4119     assert(C232[0] == 2);
4120     assert(C232[1] == 3);
4121 }
4122 
4123 /***************************************************/
4124 // 1389
4125 
4126 void test233()
4127 {
4128     int a;
4129     mixin("a") = 666;
4130 }
4131 
4132 /***************************************************/
4133 // 5735
4134 
4135 struct A234 {}
4136 
4137 void foo234(bool cond){}
4138 
4139 void test234()
4140 {
4141     A234 a;
4142     int i;
4143 
4144     static assert(!__traits(compiles, assert(a)));      // type A does not have a boolean value
4145     static assert(!__traits(compiles, assert(i || a))); // type A does not have a boolean value
4146     static assert(!__traits(compiles, assert(0 || a))); // OK
4147 
4148 //    if(a) {}        // type A does not have a boolean value
4149 //    if(i || a) {}   // type A does not have a boolean value
4150 //    if(0 || a) {}   // type A does not have a boolean value
4151 
4152     static assert(!__traits(compiles, foo234(a)));         // cannot implicitly convert type A to bool
4153     static assert(!__traits(compiles, foo234(i || a)));    // OK
4154     static assert(!__traits(compiles, foo234(0 || a)));    // OK
4155 }
4156 
4157 
4158 /***************************************************/
4159 
4160 int space() { return 4001; }
4161 
4162 void oddity4001()
4163 {
4164     const int bowie = space();
4165     static assert(space() == 4001); // OK
4166     static assert(bowie == 4001);   // doesn't compile
4167 }
4168 
4169 /***************************************************/
4170 
4171 int bug3809() { asm { nop; } return 0; }
4172 struct BUG3809 { int xx; }
4173 void bug3809b() {
4174 }
4175 
4176 /***************************************************/
4177 //
4178 
4179 void bug6184()
4180 {
4181     bool cmp(ref int[3] a, ref int[3] b)
4182     {
4183         return a is b;
4184     }
4185 
4186     static struct Ary
4187     {
4188         int[3] ary;
4189     }
4190 
4191     auto a = new Ary;
4192     auto b = new Ary;
4193     assert(!cmp(a.ary, b.ary));
4194     b = a;
4195     assert(cmp(a.ary, b.ary));
4196 
4197     // change high bit of ary address
4198     *(cast(size_t*)&b) ^= (1UL << (size_t.sizeof * 4));
4199     assert(!cmp(a.ary, b.ary));
4200 }
4201 
4202 /***************************************************/
4203 // 6229
4204 
4205 int test6229()
4206 {
4207   {
4208     ubyte a = 2;
4209     ubyte b = 4;
4210     b += a;
4211   }
4212 
4213     char a = 2;
4214     char b = 4;
4215     b += a;
4216 
4217     wchar c = 2;
4218     wchar d = 4;
4219     c /= d;
4220 
4221     return b;
4222 }
4223 
4224 /***************************************************/
4225 // XMMBug
4226 
4227 class XMMPainter
4228 {
4229   float call()
4230   {
4231     return sumFloats(0.0f, 0.0f);
4232   }
4233 
4234   static float sumFloats(float a, float b)
4235   {
4236     return a + b;
4237   }
4238 }
4239 
4240 void test6270()
4241 {
4242   auto painter = new XMMPainter;
4243   assert(XMMPainter.sumFloats(20, painter.call()) == 20.0f);
4244   auto dg = () { return XMMPainter.sumFloats(0.0f, 0.0f); };
4245   assert(XMMPainter.sumFloats(20, dg()) == 20.0f);
4246 }
4247 
4248 /***************************************************/
4249 
4250 void testrolror(int shift)
4251 {
4252     uint a = 7;
4253     uint r;
4254     r = (a >> shift) | (a << (int.sizeof * 8 - shift));
4255     assert(r == 0x8000_0003);
4256     r = (r << shift) | (r >> (int.sizeof * 8 - shift));
4257     assert(r == 7);
4258 }
4259 
4260 void test236()
4261 {
4262     testrolror(1);
4263 }
4264 
4265 
4266 /***************************************************/
4267 // 4460
4268 
4269 void test237()
4270 {
4271     foreach (s, i; [ "a":1, "b":2 ])
4272     {
4273         writeln(s, i);
4274     }
4275 }
4276 
4277 
4278 /***************************************************/
4279 
4280 void foo238(long a, long b)
4281 {
4282   while (1)		// prevent inlining
4283   {
4284     long x = a / b;
4285     long y = a % b;
4286     assert(x == 3);
4287     assert(y == 1);
4288     break;
4289   }
4290 }
4291 
4292 void test238()
4293 {
4294     long a, b;
4295     a = 10;
4296     b = 3;
4297     long x = a / b;
4298     long y = a % b;	// evaluate at compile time
4299     assert(x == 3);
4300     assert(y == 1);
4301 
4302     foo238(a, b);
4303 }
4304 
4305 /***************************************************/
4306 // 5239
4307 
4308 struct S239 { int x; }
4309 
4310 int test239()
4311 {
4312    S239[4] w = void;
4313    w[$-2].x = 217;
4314    return w[2].x;
4315 }
4316 
4317 
4318 /***************************************************/
4319 
4320 void enforce6506b(bool condition, void delegate() m) {
4321     assert(!condition);
4322 }
4323 void toImpl6506b(int value) {
4324     void f(){}
4325     enforce6506b(value >= 0, &f);
4326 }
4327 void test6506() {
4328     toImpl6506b(-112345);
4329 }
4330 
4331 /***************************************************/
4332 // 6505
4333 
4334 double foo240() {
4335     return 1.0;
4336 }
4337 
4338 void test240() {
4339     double a = foo240();
4340     double b = foo240();
4341     double x = a*a + a*a + a*a + a*a + a*a + a*a + a*a +
4342                a*b + a*b;
4343     assert(x > 0);
4344 }
4345 
4346 /***************************************************/
4347 // 6563
4348 
4349 int foo6563(float a, float b, float c, float d, float e, float f, float g, float h)
4350 {
4351     assert(a == 1);
4352     return 0; // return something to prevent folding
4353 }
4354 
4355 void test6563()
4356 {
4357     auto res = foo6563(1, 1, 1, 1, 1, 1, 1, 1);
4358 }
4359 
4360 /***************************************************/
4361 
4362 ubyte foo241(ubyte[] data)
4363 {
4364     ubyte a, b, c, d;
4365 
4366     a = data[0];
4367     b = data[1];
4368     c = data[2];
4369     d = data[3];
4370 
4371     c <<= 1;
4372     if (c & 0x80)
4373         c >>= 1;
4374     d <<= 1;
4375     if (d & 0x80)
4376         d >>= 1;
4377 
4378     return d;
4379 }
4380 
4381 void test241()
4382 {
4383     ubyte[4] data;
4384     data[3] = 0x40;
4385     assert(foo241(data[]) == 0x40);
4386     data[3] = 0x20;
4387     assert(foo241(data[]) == 0x40);
4388 }
4389 
4390 /***************************************************/
4391 
4392 struct Foo6665
4393 {
4394     double[2][2] dat;
4395 
4396     double foo(size_t i, size_t j)
4397     {
4398         return dat[i][j] = 0;
4399     }
4400 }
4401 
4402 void test6665()
4403 {
4404     Foo6665 a;
4405 }
4406 
4407 /***************************************************/
4408 
4409 double entropy(double[] probs) {
4410     double result = 0;
4411     foreach (p; probs) {
4412 	if (!p) continue;
4413 	result -= p;
4414     }
4415     return result;
4416 }
4417 
4418 /***************************************************/
4419 
4420 long b5364(long bmax){
4421     if(true){
4422     }
4423     if(bmax >= 0) bmax = -1;
4424     return bmax;
4425 }
4426 
4427 void test5364()
4428 {
4429     assert(b5364(0) == -1L);
4430 }
4431 
4432 
4433 /***************************************************/
4434 
4435 struct FPoint {
4436   float x, y;
4437 }
4438 
4439 void constructBezier(FPoint p0, FPoint p1, FPoint p2, ref FPoint[3] quad) {
4440   quad[0] = p0;
4441   quad[1] = FPoint(p1.x, p1.y);
4442   quad[$-1] = p2;
4443 }
4444 
4445 void test6189() {
4446   auto p0 = FPoint(0, 0);
4447   auto p1 = FPoint(1, 1);
4448   auto p2 = FPoint(2, 2);
4449 
4450   // avoid inline of call
4451   FPoint[3] quad;
4452   auto f = &constructBezier;
4453   f(p0, p1, p2, quad);
4454 
4455   assert(quad == [p0, p1, p2]);
4456 }
4457 
4458 /***************************************************/
4459 // 6997
4460 
4461 long fun6997(long a,long b,long c)
4462 {
4463     return a < b ? a < c ? a : b < c ? b : c : b;
4464 }
4465 
4466 long baz6997(long a, long b)
4467 {
4468     bool s = (a<0) != (b<0);
4469     a = a > 0 ? a : -a;
4470     return s ? a : a;
4471 }
4472 
4473 struct S6997
4474 {
4475     ulong bar, qux;
4476     bool c;
4477 
4478     S6997 foo()
4479     {
4480         if(!c)
4481         {
4482             long a = baz6997(bar, 0),
4483                 b = baz6997(bar, 0),
4484                 c = baz6997(bar, 0);
4485             return S6997(fun6997(a,b,c), fun6997(a,b,c));
4486         }
4487         return S6997();
4488     }
4489 }
4490 
4491 void test6997()
4492 {
4493     auto x = S6997().foo();
4494 }
4495 
4496 /***************************************************/
4497 
4498 ubyte foo7026(uint n) {
4499   ubyte[5] buf = void;
4500   ubyte wsize;
4501 
4502   while (true) {
4503     if ((n & ~0x7F) == 0) {
4504       buf[wsize++] = cast(ubyte)n;
4505       break;
4506     } else {
4507       buf[wsize++] = cast(ubyte)((n & 0x7F) | 0x80);
4508       n >>= 7;
4509     }
4510   }
4511 
4512   printf("%hhu\n", wsize);
4513   return buf[0];
4514 }
4515 
4516 void test7026() {
4517     if (foo7026(3) != 3)
4518 	assert(0);
4519 }
4520 
4521 
4522 /***************************************************/
4523 
4524 void test6354()
4525 {
4526     foreach(j; 0 .. 2)
4527     {
4528         scope(failure) int i = 0;
4529 
4530         ushort left = 0xffU;
4531         left <<= (ushort.sizeof - 1) * 8;
4532 
4533         assert((((left & 0xff00U) >> 8) | ((left & 0x00ffU) << 8)) == 0xffu);
4534     }
4535 }
4536 
4537 /***************************************************/
4538 
4539 struct S7072
4540 {
4541     this(A)(A args) { }
4542 }
4543 
4544 void test7072() {
4545    auto s = S7072( null );
4546 }
4547 
4548 /***************************************************/
4549 
4550 struct Point6881
4551 {
4552     float _x, _y;
4553 
4554     void rotateCCW()
4555     {
4556         float tmp = -_x;
4557         _x = _y;
4558         _y = tmp;
4559     }
4560 }
4561 
4562 /***************************************************/
4563 // 7212
4564 void foo7212(scope int delegate(int a) dg)
4565 {
4566 }
4567 
4568 void foo7212(bool a)
4569 {
4570 }
4571 
4572 void test7212()
4573 {
4574     foo7212((int a) => a);
4575 }
4576 
4577 /***************************************************/
4578 
4579 void test242()
4580 {
4581     foreach(v; long.max / 8 .. long.max / 8 + 1)
4582     {
4583         immutable long t1 = v;
4584         long t2 = t1 + t1;
4585         t2 *= 1L << 1;
4586         assert(t2 > long.max / 4);
4587     }
4588 }
4589 
4590 /***************************************************/
4591 // 7290
4592 
4593 void foo7290a(alias dg)()
4594 {
4595     assert(dg(5) == 7);
4596 }
4597 
4598 void foo7290b(scope int delegate(int a) dg)
4599 {
4600     assert(dg(5) == 7);
4601 }
4602 
4603 void foo7290c(int delegate(int a) dg)
4604 {
4605     assert(dg(5) == 7);
4606 }
4607 
4608 void test7290()
4609 {
4610     int add = 2;
4611     scope dg = (int a) => a + add;
4612 
4613     assert(GC.addrOf(dg.ptr) == null);
4614 
4615     foo7290a!dg();
4616     foo7290b(dg);
4617     foo7290c(dg);
4618 }
4619 
4620 /***************************************************/
4621 
4622 void test7367()
4623 {
4624     char a = '\x00';
4625     char b = '\xFF';
4626     assert(a < b);
4627 }
4628 
4629 /***************************************************/
4630 // 7375
4631 
4632 class A7375 {}
4633 class B7375(int i) : A7375 {}
4634 class C7375(int i) : B7375!i {}
4635 
4636 template DerivedAlias(int i)
4637 {
4638     alias B7375!i DerivedAlias;
4639 }
4640 
4641 alias DerivedAlias!22 X7375;
4642 
4643 void test7375()
4644 {
4645     A7375 foo = new C7375!11();
4646     assert(cast(B7375!22)foo is null);
4647 }
4648 
4649 /***************************************************/
4650 
4651 void test6504()
4652 {
4653     for (int i=0; i<3; ++i)
4654     {
4655 /+
4656 	char[] x2 = "xxx" ~ ['c'];
4657 	if (i == 0)
4658 	    assert(x2[1] == 'x');
4659 	x2[1] = 'q';
4660 +/
4661     }
4662 }
4663 
4664 /***************************************************/
4665 
4666 struct S7424a
4667 {
4668     @property inout(int) g()() inout { return 7424; }
4669     void test1()
4670     {
4671         int f = g;
4672         assert(f == 7424);
4673         assert(g == 7424);
4674     }
4675     void test2() const
4676     {
4677         int f = g;
4678         assert(f == 7424);
4679         assert(g == 7424);
4680     }
4681     void test3() immutable
4682     {
4683         int f = g;
4684         assert(f == 7424);
4685         assert(g == 7424);
4686     }
4687 }
4688 struct S7425
4689 {
4690     inout(T) g(T)(T x) inout
4691     {
4692         return x;
4693     }
4694     void test1()
4695     {
4696         int f = g(2);
4697         assert(f == 2);
4698     }
4699     void test2() const
4700     {
4701         double y = g(4.5);
4702         assert(y == 4.5);
4703     }
4704 }
4705 void test7424()
4706 {
4707     S7424a s1;
4708     s1.test1();
4709     s1.test2();
4710 
4711     immutable(S7424a) s2;
4712     s2.test2();
4713     s2.test3();
4714 
4715     const(S7424a) s3;
4716     s3.test2();
4717 
4718     S7425 s4;
4719     s4.test1();
4720     s4.test2();
4721 }
4722 
4723 /***************************************************/
4724 
4725 struct Logger {
4726     static bool info()() {
4727 	return false;
4728     }
4729 }
4730 
4731 void test7422() {
4732     if (Logger.info()) {
4733     }
4734 }
4735 
4736 /***************************************************/
4737 
4738 struct S7502
4739 {
4740     int[0x1000] arr;
4741 }
4742 
4743 S7502 s7502;
4744 
4745 void test7502()
4746 {
4747     s7502 = s7502.init;
4748 }
4749 
4750 /***************************************************/
4751 
4752 void nextis(void delegate() dg = {}) {}
4753 
4754 void test4820() {
4755     nextis();
4756 }
4757 
4758 /***************************************************/
4759 
4760 void test4820_2() {
4761 
4762 void nextis(void delegate() dg = {}) {}
4763     nextis();
4764 }
4765 
4766 /***************************************************/
4767 
4768 template T3509(bool b) { static assert (b); }
4769 
4770 template Mix3509() { void f() {} }
4771 
4772 class C3509 {
4773     alias T3509!(is(typeof(M.f))) U;
4774     mixin Mix3509!() M;
4775 }
4776 
4777 /***************************************************/
4778 
4779 struct S3510(int x) {}
4780 
4781 template Mix3510() { Sa s; }
4782 
4783 class C3510 {
4784     mixin Mix3510!();
4785     alias S3510!(0) Sa;
4786 }
4787 
4788 /***************************************************/
4789 
4790 struct Array243(T) if (is(T == bool))
4791 {
4792     struct Range
4793     {
4794         Array243!bool _outer;
4795         ulong _a, _b, _c;
4796 	ulong _d;
4797     }
4798 
4799     Range opSlice()
4800     {
4801         return Range(this, 0, 3);
4802     }
4803 
4804 }
4805 
4806 
4807 void test243() {
4808     Array243!bool a;
4809 }
4810 
4811 /***************************************************/
4812 // 7742
4813 
4814 struct Foo7742 {
4815     static immutable f = Foo7742(1, 2);
4816     int x, y;
4817 }
4818 
4819 struct Bar7742 {
4820     int x, y;
4821     static immutable f = Bar7742(1, 2);
4822 }
4823 
4824 void test7742()
4825 {
4826     assert(Foo7742.f.x == 1);
4827     assert(Foo7742.f.y == 2);
4828 
4829     assert(Bar7742.f.x == 1);
4830     assert(Bar7742.f.y == 2);
4831 }
4832 
4833 /***************************************************/
4834 // 7807
4835 
4836 interface Interface7807
4837 {
4838     Interface7807 getNext();
4839     const(Interface7807) getNext() const;
4840 }
4841 
4842 class Implementation7807 : Interface7807
4843 {
4844     Implementation7807 getNext()
4845     {
4846         return this;
4847     }
4848 
4849     const(Implementation7807) getNext() const
4850     {
4851         return null;
4852     }
4853 }
4854 
4855 void test7807()
4856 {
4857     auto mc = new Implementation7807();
4858     assert(mc.getNext() is mc);
4859     Interface7807 mi = mc;
4860     assert(mi.getNext() is mi);
4861 
4862     auto cc = new const(Implementation7807)();
4863     assert(cc.getNext() is null);
4864     const(Interface7807) ci = cc;
4865     assert(ci.getNext() is null);
4866 }
4867 
4868 /***************************************************/
4869 // 7815
4870 
4871 enum Closure {
4872     Matrix
4873 }
4874 
4875 struct BasicMatrix {
4876     mixin Operand!( Closure.Matrix );
4877 }
4878 
4879 template Operand( Closure closure_ ) {
4880     alias closure_ closure;
4881 }
4882 
4883 struct Expression( string op_, Lhs, Rhs = void ) {
4884     enum lhsClosure = closureOf!Lhs;
4885 }
4886 
4887 template closureOf( T ) {
4888     enum closureOf = T.closure;
4889 }
4890 
4891 alias Expression!("+", BasicMatrix) Foo7815;
4892 
4893 /***************************************************/
4894 
4895 struct Test244 {
4896     static immutable c = Test244();
4897     static if( true ){}
4898 }
4899 
4900 /***************************************************/
4901 
4902 int noswap245(ubyte *data)
4903 {
4904     return
4905 	(data[0]<<  0) |
4906 	(data[1]<<  8) |
4907 	(data[2]<< 16) |
4908 	(data[3]<< 24);
4909 }
4910 
4911 int bswap245(ubyte *data)
4912 {
4913     return
4914 	(data[0]<< 24) |
4915 	(data[1]<< 16) |
4916 	(data[2]<< 8 ) |
4917 	(data[3]<< 0 );
4918 }
4919 
4920 void test245()
4921 {
4922     int x1 = 0x01234567;
4923     x1 = noswap245(cast(ubyte *)&x1);
4924     assert(x1 == 0x01234567);
4925     x1 = bswap245(cast(ubyte *)&x1);
4926     assert(x1 == 0x67452301);
4927 }
4928 
4929 /***************************************************/
4930 
4931 mixin template mix7974()
4932 {
4933     uint _x;
4934 }
4935 
4936 struct Foo7974
4937 {
4938     static immutable Foo7974 fa = Foo7974(0);
4939 
4940     this(uint x)
4941     {
4942         _x = x;
4943     }
4944 
4945     mixin mix7974!();
4946 }
4947 
4948 /***************************************************/
4949 // 4155
4950 
4951 
4952 float getnanf() { return float.nan; }
4953 double getnand() { return double.nan; }
4954 real getnanr() { return real.nan; }
4955 
4956 void test4155()
4957 {
4958     assert(getnanf() != 0);
4959     assert(getnand() != 0);
4960     assert(getnanr() != 0);
4961 }
4962 
4963 /***************************************************/
4964 // 7911
4965 
4966 struct Klass7911
4967 {
4968     double value;
4969 
4970     //static const Klass zero; // Does not trigger bug!
4971     static const Klass7911 zero = {0}; // Bug trigger #1
4972 
4973     static if (true) // Bug trigger #2
4974         static if (true)
4975             Klass7911 foo() { return Klass7911(); }
4976 }
4977 
4978 void test7911()
4979 {
4980     auto a = Klass7911().foo();
4981 }
4982 
4983 /***************************************************/
4984 // 8429
4985 
4986 static if(true)
4987     version = Foo8429;
4988 static if(true)
4989     version(Foo8429) {}
4990 
4991 /***************************************************/
4992 // 8069
4993 
4994 interface I8069
4995 {
4996     void f();
4997 }
4998 struct A8069
4999 {
5000     final class B8069 : I8069
5001     {
5002         A8069 a;
5003         void f() {}
5004     }
5005 }
5006 
5007 /***************************************************/
5008 // 8095
5009 
5010 void bug8095(int p0, int *p1, int z, int edx, int *p4, int p5)
5011 {
5012     int x = z / 3;
5013     if (z) {
5014         int c = p5 + *p1 + p0; // *p1 segfaults -- it does *z !!
5015         if ( z / 5 )
5016             c = 1;
5017         *p4 = c;
5018         x = c;
5019     }
5020     void never_used() {
5021         ++x;
5022         int * unused = p1; // kills p4 somehow
5023     }
5024 }
5025 
5026 void test8095() {
5027     int x, y;
5028     bug8095(0, &x, 1, 0, &y, 0);
5029 }
5030 
5031 /***************************************************/
5032 // 8091
5033 
5034 int solve1(int n) {
5035     int a;
5036     return ((a = n ? (n>=1u) : 1) != 0) ? a : 0;
5037 //    return ((a = !n ? 1 : (n>=1u)) != 0) ? a : 0;
5038 }
5039 
5040 int solve2(int n) {
5041     int a;
5042 //    return ((a = n ? (n>=1u) : 1) != 0) ? a : 0;
5043     return ((a = !n ? 1 : (n>=1u)) != 0) ? a : 0;
5044 }
5045 
5046 void test8091() {
5047     assert(solve1(1) ==  1);
5048     assert(solve2(1) ==  1);
5049 }
5050 
5051 /***************************************************/
5052 
5053 struct IPoint {
5054     int x, y;
5055 }
5056 
5057 void bug6189_2(uint half, IPoint pos, float[4] *pts, uint unused) {
5058     pos.y += half;
5059     float xo = pos.x;
5060     float yo = pos.y;
5061 
5062     (*pts)[0] = xo;
5063     (*pts)[1] = yo;
5064     (*pts)[2] = xo;
5065 }
5066 
5067 void test6189_2()
5068 {
5069     auto pos = IPoint(2, 2);
5070     float[4] pts;
5071     pts[0] = pts[1] = pts[2] = pts[3] = 0;
5072     bug6189_2(0, pos, &pts, 0);
5073 
5074     assert(pts[0] == 2);
5075 }
5076 
5077 /***************************************************/
5078 // 8199
5079 
5080 version (D_InlineAsm_X86_64)
5081 {
5082     version = Check;
5083     enum Align = 0x8;
5084 }
5085 else version (D_InlineAsm_X86)
5086 {
5087     version = Check;
5088     version (OSX)
5089         enum Align = 0xC;
5090 }
5091 
5092 void onFailure()
5093 {
5094     assert(0, "alignment failure");
5095 }
5096 
5097 void checkAlign()
5098 {
5099     version (Check)
5100     {
5101         static if (is(typeof(Align)))
5102         asm
5103         {
5104             naked;
5105             mov EAX, ESP;
5106             and EAX, 0xF;
5107             cmp EAX, Align;
5108             je Lpass;
5109             call onFailure;
5110         Lpass:
5111             ret;
5112         }
5113     }
5114     else
5115         return;
5116 }
5117 
5118 void foo8199()
5119 {
5120 }
5121 
5122 void test8199()
5123 {
5124     try
5125         foo8199();
5126     finally
5127         checkAlign();
5128 }
5129 
5130 /***************************************************/
5131 
5132 void test246()
5133 {
5134     struct Struct
5135     {
5136         void method() {}
5137     }
5138     auto val = Struct();
5139 }
5140 
5141 /***************************************************/
5142 
5143 double sqrt8454(double d) { return d/2; }
5144 void foo8454(cdouble m) {}
5145 void test8454() {
5146     foo8454(0 - sqrt8454(1.0) * 1i);
5147 }
5148 
5149 /***************************************************/
5150 // 8423
5151 
5152 struct S8423
5153 {
5154     int opCmp(S8423 rhs)
5155     {
5156         return 1;
5157     }
5158 }
5159 
5160 void enforce8423(bool value, string a, string b)
5161 {
5162     if (!value) assert(false);
5163 }
5164 
5165 void test8423()
5166 {
5167     auto a = S8423();
5168     auto b = S8423();
5169     enforce8423(a > b, null, null);
5170 }
5171 
5172 /***************************************************/
5173 class Foo8496
5174 {
5175 public:
5176     void foo(uint value)
5177     {
5178         ubyte size = value < (0x7fU << 0 ) ? 1 :
5179                      value < (0x7fU << 14) ? 2 :
5180                                              3;
5181         import std.stdio;
5182         writeln(size);
5183 	assert(size == 2);
5184     }
5185 }
5186 
5187 void test8496()
5188 {
5189     Foo8496 f = new Foo8496();
5190     f.foo(1000000);
5191 }
5192 
5193 /***************************************************/
5194 
5195 long foo8840() { return 4; }
5196 
5197 int bar8840(long g) { assert(g == 4); return printf("%llx\n", g); }
5198 
5199 void test8840()
5200 {
5201     long f1 = foo8840();
5202     long f2 = foo8840();
5203 
5204     long f = (f1 < f2 ? f1 : f2);
5205     int len = (f == 0 ? 0 : bar8840(f));
5206 }
5207 
5208 /***************************************************/
5209 
5210 struct S8889
5211 {
5212     real f;
5213     int i;
5214 }
5215 
5216 void test8889()
5217 {
5218 }
5219 
5220 /***************************************************/
5221 
5222 struct S8870
5223 {
5224     float x = 0;
5225     float y = 0;
5226     float z = 0;
5227     float w = 0;
5228 }
5229 
5230 void test8870()
5231 {
5232     S8870 r1 = S8870(1,2,3,4);
5233     S8870 r2 = S8870(5,6,7,8);
5234 
5235     foo8870(r1, r2, false, 1);
5236     bar8870(r1, r2, false, 1);
5237 }
5238 
5239 //extern (C)
5240 void foo8870(S8870 t1, S8870 t2, bool someBool, float finalFloat)
5241 {
5242     printf("t1: %g %g %g %g\n", t1.x, t1.y, t1.z, t1.w);
5243     printf("t2: %g %g %g %g\n", t2.x, t2.y, t2.z, t2.w);
5244     printf("someBool: %d\n", someBool);
5245     printf("finalFloat: %g\n", finalFloat);
5246 
5247     assert(t1.x == 1 && t1.y == 2 && t1.z == 3 && t1.w == 4);
5248     assert(t2.x == 5 && t2.y == 6 && t2.z == 7 && t2.w == 8);
5249     assert(someBool == false);
5250     assert(finalFloat == 1);
5251 }
5252 
5253 extern (C)
5254 void bar8870(S8870 t1, S8870 t2, bool someBool, float finalFloat)
5255 {
5256     printf("t1: %g %g %g %g\n", t1.x, t1.y, t1.z, t1.w);
5257     printf("t2: %g %g %g %g\n", t2.x, t2.y, t2.z, t2.w);
5258     printf("someBool: %d\n", someBool);
5259     printf("finalFloat: %g\n", finalFloat);
5260 
5261     assert(t1.x == 1 && t1.y == 2 && t1.z == 3 && t1.w == 4);
5262     assert(t2.x == 5 && t2.y == 6 && t2.z == 7 && t2.w == 8);
5263     assert(someBool == false);
5264     assert(finalFloat == 1);
5265 }
5266 
5267 /***************************************************/
5268 
5269 int foo9781(int[1] x)
5270 {
5271     return x[0] * x[0];
5272 }
5273 
5274 void test9781()
5275 {
5276     foo9781([7]);
5277 }
5278 
5279 /***************************************************/
5280 
5281 struct S247 { size_t length; size_t ptr; }
5282 
5283 S247 foo247()
5284 {
5285     S247 f;
5286     f.length = 7;
5287     f.ptr = 8;
5288     return f;
5289 }
5290 
5291 void test247()
5292 {
5293     S247 f;
5294     f = foo247();
5295     assert(f.length == 7);
5296     assert(f.ptr == 8);
5297 }
5298 
5299 /***************************************************/
5300 // 8340
5301 
5302 void test8340(){
5303     byte[] ba = [1,2,3,4,5];
5304     short[] sa = [1,2,3,4,5];
5305     int[] ia = [1,2,3,4,5];
5306     long[] la = [1,2,3,4,5];
5307 
5308     ba[2] *= -1;
5309     sa[2] *= -1;
5310     ia[2] *= -1;
5311     la[2] *= -1;
5312 
5313     assert(ba == [1,2,-3,4,5]);
5314     assert(sa == [1,2,-3,4,5]);
5315     assert(ia == [1,2,-3,4,5]);
5316     assert(la == [1,2,-3,4,5]);
5317 }
5318 
5319 /***************************************************/
5320 // 8376
5321 
5322 void test8376() {
5323     int i = 0;
5324     int[2] a;
5325     a[1]=1;
5326     while(!a[0]){
5327         if(a[i]) continue;
5328         a[i] = 1;
5329     }
5330 }
5331 
5332 /***************************************************/
5333 
5334 // Don't call, compile only
5335 void test8987(){
5336     int last = 0;
5337     int count = 0;
5338     int d;
5339 
5340     for (int x = 0; count < 100; x++){
5341         d = 3;
5342 
5343         while (x / d)
5344 	    d += 2;
5345 
5346         if (x & d) {
5347             last = x;
5348             count++;
5349         }
5350     }
5351 
5352     printf("Last: %d\n", last);
5353 }
5354 
5355 /***************************************************/
5356 // 8796
5357 
5358 int* wrong8796(int* p)
5359 {
5360     *p++ = 1;
5361     return p;
5362 }
5363 
5364 void test8796()
5365 {
5366     int[3] arr;
5367     int* q = arr.ptr;
5368     q = wrong8796(q);
5369     assert(q != arr.ptr);
5370 }
5371 
5372 /***************************************************/
5373 // 9171
5374 
5375 ulong bitcomb9171(ulong v)
5376 {
5377     if(v)
5378     {
5379         ulong result;
5380         if(v & 1)
5381         {
5382             auto r = bitcomb9171(v >> 1);
5383 	    printf("r=%016llx\n", r);
5384 
5385             auto z = ((r & (r-1) ^ r));
5386 	    check9171("str", z>>1);
5387 //	    printf("z=%016llx\n", z>>1);
5388             return r;
5389         }
5390         else
5391         {
5392             auto fb = v & (v-1) ^ v;
5393             result = (fb >> 1) | (v ^ fb);
5394         }
5395         return result;
5396     }
5397     return 0;
5398 }
5399 
5400 void check9171(const char *s, ulong v)
5401 {
5402     assert(v == 0x80000000);
5403 }
5404 
5405 void test9171()
5406 {
5407     bitcomb9171(0b1110000000000000010000000000000000000000000000000001);
5408 }
5409 
5410 /***************************************************/
5411 // 9248
5412 
5413 void test9248()
5414 {
5415     void*[] a = [cast(void*)1];
5416     void*[] b = [cast(void*)2];
5417     auto c = a ~ b;
5418     assert(c == [cast(void*)1, cast(void*)2]);
5419 }
5420 
5421 /***************************************************/
5422 // 14682
5423 
5424 void test14682a()
5425 {
5426     // operands
5427     int[]       a1;
5428     int[][]     a2;
5429     int[][][]   a3;
5430     int[][][][] a4;
5431 
5432     // results
5433     int[]       r1w =    [];    assert(r1w.length == 0);
5434     int[][]     r2w =    [];    assert(r2w.length == 0);
5435     int[][][]   r3w =    [];    assert(r3w.length == 0);
5436     int[][][][] r4w =    [];    assert(r4w.length == 0);
5437     // ----
5438     int[][]     r2x =   [[]];   assert(r2x.length == 1 && r2x[0].length == 0);
5439     int[][][]   r3x =   [[]];   assert(r3x.length == 1 && r3x[0].length == 0);
5440     int[][][][] r4x =   [[]];   assert(r4x.length == 1 && r4x[0].length == 0);
5441     // ----
5442     int[][][]   r3y =  [[[]]];  assert(r3y.length == 1 && r3y[0].length == 1 && r3y[0][0].length == 0);
5443     int[][][][] r4y =  [[[]]];  assert(r4y.length == 1 && r4y[0].length == 1 && r4y[0][0].length == 0);
5444     // ----
5445     int[][][][] r4z = [[[[]]]]; assert(r4z.length == 1 && r4z[0].length == 1 && r4z[0][0].length == 1 && r4z[0][0][0].length == 0);
5446 
5447     // ArrayLiteralExp conforms to the type of LHS.
5448     { auto x = a1 ~    []   ;   static assert(is(typeof(x) == typeof(a1))); assert(x == r1w); } // no ambiguity
5449     { auto x = a2 ~    []   ;   static assert(is(typeof(x) == typeof(a2))); assert(x == r2w); } // fix <- ambiguity
5450     { auto x = a3 ~    []   ;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3w); } // fix <- ambiguity
5451     { auto x = a4 ~    []   ;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4w); } // fix <- ambiguity
5452     // ----
5453   //{ auto x = a1 ~   [[]]  ; } // (see test14682b)
5454     { auto x = a2 ~   [[]]  ;   static assert(is(typeof(x) == typeof(a2))); assert(x == r2x); } // no ambiguity
5455     { auto x = a3 ~   [[]]  ;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3x); } // fix <- ambiguity
5456     { auto x = a4 ~   [[]]  ;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4x); } // fix <- ambiguity
5457     // ----
5458     static assert(!__traits(compiles, { auto x = a1 ~   [[[]]] ; }));
5459   //{ auto x = a2 ~  [[[]]] ; } // (see test14682b)
5460     { auto x = a3 ~  [[[]]] ;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3y); } // no ambiguity
5461     { auto x = a4 ~  [[[]]] ;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4y); } // fix <- ambiguity
5462     // ----
5463     static assert(!__traits(compiles, { auto x = a1 ~  [[[[]]]]; }));
5464     static assert(!__traits(compiles, { auto x = a2 ~  [[[[]]]]; }));
5465   //{ auto x = a3 ~ [[[[]]]]; } // (see test14682b)
5466     { auto x = a4 ~ [[[[]]]];   static assert(is(typeof(x) == typeof(a4))); assert(x == r4z); } // no ambiguity
5467 
5468     // ArrayLiteralExp conforms to the type of RHS.
5469     { auto x =    []    ~ a1;   static assert(is(typeof(x) == typeof(a1))); assert(x == r1w); } // no ambiguity
5470     { auto x =    []    ~ a2;   static assert(is(typeof(x) == typeof(a2))); assert(x == r2w); } // fix <- ambiguity
5471     { auto x =    []    ~ a3;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3w); } // fix <- ambiguity
5472     { auto x =    []    ~ a4;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4w); } // fix <- ambiguity
5473     // ----
5474   //{ auto x =   [[]]   ~ a1; } // (see test14682b)
5475     { auto x =   [[]]   ~ a2;   static assert(is(typeof(x) == typeof(a2))); assert(x == r2x); } // no ambiguity
5476     { auto x =   [[]]   ~ a3;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3x); } // fix <- ambiguity
5477     { auto x =   [[]]   ~ a4;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4x); } // fix <- ambiguity
5478     // ----
5479     static assert(!__traits(compiles, { auto x =  [[[]]]  ~ a1; }));
5480   //{ auto x =  [[[]]]  ~ a2; } // (see test14682b)
5481     { auto x =  [[[]]]  ~ a3;   static assert(is(typeof(x) == typeof(a3))); assert(x == r3y); } // no ambiguity
5482     { auto x =  [[[]]]  ~ a4;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4y); } // fix <- ambiguity
5483     // ----
5484     static assert(!__traits(compiles, { auto x = [[[[]]]] ~ a1; }));
5485     static assert(!__traits(compiles, { auto x = [[[[]]]] ~ a2; }));
5486   //{ auto x = [[[[]]]] ~ a3; } // (see test14682b)
5487     { auto x = [[[[]]]] ~ a4;   static assert(is(typeof(x) == typeof(a4))); assert(x == r4z); } // no ambiguity
5488 }
5489 
5490 void test14682b()
5491 {
5492     // operands
5493     int[]       a1;
5494     int[][]     a2;
5495     int[][][]   a3;
5496     int[][][][] a4;
5497 
5498     // results
5499     int[][]     r2a = [[],   []  ]; assert(r2a.length == 2 && r2a[0].length == 0 && r2a[1].length == 0);
5500   //int[][][]   r3a = [[],  [[]] ]; // should work, but doesn't
5501   //int[][][][] r4a = [[], [[[]]]]; // should work, but doesn't
5502     int[][][]   r3a;  { r3a.length = 2; r3a[0] = []; r3a[1] =  [[]] ; }
5503                                     assert(r3a.length == 2 && r3a[0].length == 0 && r3a[1].length == 1 && r3a[1][0].length == 0);
5504     int[][][][] r4a;  { r4a.length = 2; r4a[0] = []; r4a[1] = [[[]]]; }
5505                                     assert(r4a.length == 2 && r4a[0].length == 0 && r4a[1].length == 1 && r4a[1][0].length == 1 && r4a[1][0][0].length == 0);
5506     // ----
5507     int[][]     r2b = [  []  , []]; assert(r2b.length == 2 && r2b[1].length == 0 && r2b[0].length == 0);
5508   //int[][][]   r3b = [ [[]] , []]; // should work, but doesn't
5509   //int[][][][] r4b = [[[[]]], []]; // should work, but doesn't
5510     int[][][]   r3b;  { r3b.length = 2; r3b[0] =  [[]] ; r3b[1] = []; }
5511                                     assert(r3b.length == 2 && r3b[1].length == 0 && r3b[0].length == 1 && r3b[0][0].length == 0);
5512     int[][][][] r4b;  { r4b.length = 2; r4b[0] = [[[]]]; r4b[1] = []; }
5513                                     assert(r4b.length == 2 && r4b[1].length == 0 && r4b[0].length == 1 && r4b[0][0].length == 1 && r4b[0][0][0].length == 0);
5514 
5515     // ArrayLiteralExp conforms to the typeof(LHS)->arrayOf().
5516     { auto x = a1 ~   [[]]  ;   static assert(is(typeof(x) == typeof(a1)[])); assert(x == r2a); } // fix
5517     { auto x = a2 ~  [[[]]] ;   static assert(is(typeof(x) == typeof(a2)[])); assert(x == r3a); } // fix
5518     { auto x = a3 ~ [[[[]]]];   static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4a); } // fix
5519 
5520     // ArrayLiteralExp conforms to the typeof(RHS)->arrayOf().
5521     { auto x =   [[]]   ~ a1;   static assert(is(typeof(x) == typeof(a1)[])); assert(x == r2b); } // fix
5522     { auto x =  [[[]]]  ~ a2;   static assert(is(typeof(x) == typeof(a2)[])); assert(x == r3b); } // fix
5523     { auto x = [[[[]]]] ~ a3;   static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4b); } // fix
5524 }
5525 
5526 /***************************************************/
5527 // 9739
5528 
5529 class Foo9739
5530 {
5531     int val = 1;
5532     this(int arg = 2) { val = arg; }
5533 }
5534 
5535 class Bar9739 : Foo9739 { }
5536 
5537 void test9739()
5538 {
5539     Bar9739 bar = new Bar9739;
5540     assert(bar.val == 2);
5541 }
5542 
5543 /***************************************************/
5544 // 6057
5545 void test6057()
5546 {
5547     enum Foo { A=1, B=2 }
5548     Foo[] bar = [cast(Foo)1];
5549 }
5550 
5551 /***************************************************/
5552 
5553 ulong d2ulong(double u)
5554 {
5555     return cast(ulong)u;
5556 }
5557 
5558 void testdbl_to_ulong()
5559 {
5560     auto u = d2ulong(12345.6);
5561     //writeln(u);
5562     assert(u == 12345);
5563 
5564     real adjust = 1.0L/real.epsilon;
5565     u = d2ulong(adjust);
5566     //writefln("%s %s", adjust, u);
5567     static if(real.mant_dig == 64)
5568         assert(u == 9223372036854775808UL);
5569     else static if(real.mant_dig == 53)
5570         assert(u == 4503599627370496UL);
5571     else
5572         static assert(false, "Test not implemented for this architecture");
5573 
5574     auto v = d2ulong(adjust * 1.1);
5575     //writefln("%s %s %s", adjust, v, u + u/10);
5576 
5577     // The following can vary in the last bits with different optimization settings,
5578     // i.e. the conversion from real to double may not happen.
5579     //assert(v == 10145709240540254208UL);
5580 }
5581 
5582 /***************************************************/
5583 
5584 
5585 
5586 uint d2uint(double u)
5587 {
5588     return cast(uint)u;
5589 }
5590 
5591 void testdbl_to_uint()
5592 {
5593     auto u = d2uint(12345.6);
5594     //writeln(u);
5595     assert(u == 12345);
5596 }
5597 
5598 /***************************************************/
5599 
5600 ulong r2ulong(real u)
5601 {
5602     return cast(ulong)u;
5603 }
5604 
5605 void testreal_to_ulong()
5606 {
5607     auto u = r2ulong(12345.6L);
5608     //writeln(u);
5609     assert(u == 12345);
5610 
5611     real adjust = 1.0L/real.epsilon;
5612     u = r2ulong(adjust);
5613     //writefln("%s %s", adjust, u);
5614     static if(real.mant_dig == 64)
5615         assert(u == 9223372036854775808UL);
5616     else static if(real.mant_dig == 53)
5617         assert(u == 4503599627370496UL);
5618     else
5619         static assert(false, "Test not implemented for this architecture");
5620 
5621     auto v = r2ulong(adjust * 1.1);
5622     writefln("%s %s %s", adjust, v, u + u/10);
5623 
5624     //assert(v == 10145709240540253389UL);
5625 }
5626 
5627 /***************************************************/
5628 
5629 long testbt1(long a, long b, int c)
5630 {
5631     return a + ((b >> c) & 1);
5632 //    return a + ((b & (1L << c)) != 0);
5633 }
5634 
5635 
5636 long testbt2(long a, long b, int c)
5637 {
5638 //    return a + ((b >> c) & 1);
5639     return a + ((b & (1L << c)) != 0);
5640 }
5641 
5642 int testbt3(int a, int b, int c)
5643 {
5644     return a + ((b >> c) & 1);
5645 //    return a + ((b & (1 << c)) != 0);
5646 }
5647 
5648 int testbt4(int a, int b, int c)
5649 {
5650 //    return a + ((b >> c) & 1);
5651     return a + ((b & (1 << c)) != 0);
5652 }
5653 
5654 
5655 void test248()
5656 {
5657     auto a1 = testbt1(3, 4, 2);
5658     assert(a1 == 4);
5659     a1 = testbt2(3, 4, 2);
5660     assert(a1 == 4);
5661     a1 = testbt3(3, 4, 2);
5662     assert(a1 == 4);
5663     a1 = testbt4(3, 4, 2);
5664     assert(a1 == 4);
5665 
5666     a1 = testbt1(3, 8, 2);
5667     assert(a1 == 3);
5668     a1 = testbt2(3, 8, 2);
5669     assert(a1 == 3);
5670     a1 = testbt3(3, 8, 2);
5671     assert(a1 == 3);
5672     a1 = testbt4(3, 8, 2);
5673     assert(a1 == 3);
5674 }
5675 
5676 /***************************************************/
5677 
5678 int foo249(int a, int b)
5679 {
5680     return a + ((b & 0x80) != 0);
5681 }
5682 
5683 long bar249(long a, int b)
5684 {
5685     return a + ((b & 0x80) != 0);
5686 }
5687 
5688 void test249()
5689 {
5690   {
5691     auto i = foo249(3, 6);
5692     assert(i == 3);
5693     i = foo249(3, 0x88);
5694     assert(i == 4);
5695   }
5696   {
5697     auto i = bar249(3, 6);
5698     assert(i == 3);
5699     i = bar249(3, 0x88);
5700     assert(i == 4);
5701   }
5702 }
5703 
5704 /***************************************************/
5705 
5706 // These should all compile to a BT instruction when -O, for -m32 and -m64
5707 
5708 int bt32(uint *p, uint b) { return ((p[b >> 5] & (1 << (b & 0x1F)))) != 0; }
5709 
5710 int bt64a(ulong *p, uint b) { return ((p[b >> 6] & (1L << (b & 63)))) != 0; }
5711 
5712 int bt64b(ulong *p, size_t b) { return ((p[b >> 6] & (1L << (b & 63)))) != 0; }
5713 
5714 void test250()
5715 {
5716     static uint[2]  a1 = [0x1001_1100, 0x0220_0012];
5717 
5718     if ( bt32(a1.ptr,30)) assert(0);
5719     if (!bt32(a1.ptr,8))  assert(0);
5720     if ( bt32(a1.ptr,30+32)) assert(0);
5721     if (!bt32(a1.ptr,1+32))  assert(0);
5722 
5723     static ulong[2] a2 = [0x1001_1100_12345678, 0x0220_0012_12345678];
5724 
5725     if ( bt64a(a2.ptr,30+32)) assert(0);
5726     if (!bt64a(a2.ptr,8+32))  assert(0);
5727     if ( bt64a(a2.ptr,30+32+64)) assert(0);
5728     if (!bt64a(a2.ptr,1+32+64))  assert(0);
5729 
5730     if ( bt64b(a2.ptr,30+32)) assert(0);
5731     if (!bt64b(a2.ptr,8+32))  assert(0);
5732     if ( bt64b(a2.ptr,30+32+64)) assert(0);
5733     if (!bt64b(a2.ptr,1+32+64))  assert(0);
5734 }
5735 
5736 /***************************************************/
5737 
5738 struct S251 { int a,b,c,d; }
5739 
5740 S251 foo251(S251 s)
5741 {
5742     S251 a = s;
5743     S251 b = a;	// copy propagation
5744     S251 c = b;
5745     S251 d = c;
5746     S251 e = d;	// dead assignment
5747     return d;
5748 }
5749 
5750 void test251()
5751 {
5752     S251 a;
5753     a.a = 1;
5754     a.b = 2;
5755     a.c = 3;
5756     a.d = 4;
5757     a = foo251(a);
5758     assert(a.a == 1);
5759     assert(a.b == 2);
5760     assert(a.c == 3);
5761     assert(a.d == 4);
5762 }
5763 
5764 /***************************************************/
5765 // 9387
5766 
5767 void bug9387a(double x) { }
5768 
5769 void ice9387()
5770 {
5771     double x = 0.3;
5772     double r = x*0.1;
5773     double q = x*0.1 + r;
5774     double p = x*0.1 + r*0.2;
5775     if ( q )
5776         p = -p;
5777     bug9387a(p);
5778 }
5779 
5780 /***************************************************/
5781 
5782 void bug6962(string value)
5783 {
5784     string v = value;
5785     try
5786     {
5787         v = v[0LU..0LU];
5788         return;
5789     }
5790     finally
5791     {
5792         assert(!v.length);
5793     }
5794 }
5795 
5796 void test6962()
5797 {
5798     bug6962("42");
5799 }
5800 
5801 /***************************************************/
5802 
5803 int[1] foo4414() {
5804     return [7];
5805 }
5806 
5807 ubyte[4] bytes4414()
5808 {
5809     ubyte[4] x;
5810     x[0] = 7;
5811     x[1] = 8;
5812     x[2] = 9;
5813     x[3] = 10;
5814     return x;
5815 }
5816 
5817 void test4414() {
5818   {
5819     int x = foo4414()[0];
5820     assert(x == 7);
5821   }
5822   {
5823     auto x = bytes4414()[0..4];
5824     if (x[0] != 7 || x[1] != 8 || x[2] != 9 || x[3] != 10)
5825 	assert(0);
5826   }
5827 }
5828 
5829 /***************************************************/
5830 
5831 void test9844() {
5832     int a = -1;
5833     long b = -1;
5834     assert(a == -1);
5835     assert(b == -1L);
5836 }
5837 
5838 /***************************************************/
5839 // 10628
5840 
5841 abstract class B10628
5842 {
5843     static if (! __traits(isVirtualMethod, foo))
5844     {
5845     }
5846 
5847     private bool _bar;
5848     public void foo();
5849 }
5850 
5851 class D10628 : B10628
5852 {
5853     public override void foo() {}
5854 }
5855 
5856 void test10628()
5857 {
5858     assert(typeid(D10628).vtbl.length - typeid(Object).vtbl.length == 1);
5859 }
5860 
5861 /***************************************************/
5862 // 11265
5863 
5864 struct S11265
5865 {
5866     class InnerClass
5867     {
5868         S11265 s;
5869 
5870         bool empty()
5871         {
5872             return true;
5873         }
5874     }
5875 }
5876 
5877 void test11265()
5878 {
5879     S11265.InnerClass trav = new S11265.InnerClass();
5880     trav.empty();
5881 }
5882 
5883 /***************************************************/
5884 
5885 struct TimeOfDay
5886 {
5887     void roll(int value) 
5888     {
5889         value %= 60;
5890         auto newVal = _seconds + value;
5891 
5892         if(newVal < 0)
5893             newVal += 60;
5894         else if(newVal >= 60)
5895             newVal -= 60;
5896 
5897         _seconds = cast(ubyte)newVal;
5898     }
5899 
5900     ubyte _seconds;
5901 }
5902 
5903 
5904 void test10633()
5905 {
5906     TimeOfDay tod = TimeOfDay(0);
5907     tod.roll(-1);
5908     assert(tod._seconds == 59);
5909 }
5910 
5911 /***************************************************/
5912 
5913 import std.stdio;
5914 
5915 void _assertEq (ubyte lhs, short rhs, string msg, string file, size_t line)
5916 {
5917     immutable result = lhs == rhs;
5918 
5919     if(!result)
5920     {
5921         string op = "==";
5922         if(msg.length > 0)
5923             writefln(`_assertEq failed: [%s] is not [%s].`, lhs, rhs);
5924         else
5925             writefln(`_assertEq failed: [%s] is not [%s]: %s`, lhs, rhs, msg);
5926     }
5927 
5928     assert(result);
5929 }
5930 
5931 struct Date
5932 {
5933     short year;
5934     ubyte month;
5935     ubyte day;
5936 }
5937 
5938 struct MonthDay
5939 {
5940     ubyte month;
5941     short day;
5942 }
5943 
5944 void test10642()
5945 {
5946     static void test(Date date, int day, MonthDay expected, size_t line = __LINE__)
5947     {
5948         _assertEq(date.day, expected.day, "", __FILE__, line);
5949     }
5950 
5951     test(Date(1999, 1, 1), 1, MonthDay(1,1));
5952 }
5953 
5954 /***************************************************/
5955 // 11581
5956 
5957 alias TT11581(T...) = T;
5958 
5959 void test11581()
5960 {
5961     static class A {}
5962 
5963     static class C { alias Types = TT11581!(4, int); }
5964     static C makeC() { return null; }
5965 
5966     alias T = TT11581!(A);
5967 
5968     // edim == IntergerExp(0)
5969     auto a1 = new T[0];
5970     static assert(is(typeof(a1) == A));
5971 
5972     enum d2 = 0;
5973 
5974     // edim == TypeIdentifier('d2') --> IdentifierExp
5975     auto a2 = new T[d2];
5976     static assert(is(typeof(a2) == A));
5977 
5978     alias U = int;
5979     int d3 = 3;
5980 
5981     // edim == TypeIdentifier('d3') --> IdentifierExp
5982     auto a3 = new U[d3];
5983     static assert(is(typeof(a3) == U[]));
5984     assert(a3.length == d3);
5985 
5986     // edim == IndexExp(DotIdExp(CallExp(makeC, []), 'Types'), 0)
5987     auto a4 = new U[makeC().Types[0]];
5988     static assert(is(typeof(a4) == U[]));
5989     assert(a4.length == C.Types[0]);
5990 }
5991 
5992 /***************************************************/
5993 // 7436
5994 
5995 void test7436()
5996 {
5997     ubyte a = 10;
5998     float f = 6;
5999     ubyte b = a += f;
6000     assert(b == 16);
6001 }
6002 
6003 /***************************************************/
6004 // 12138
6005 
6006 struct S12138
6007 {
6008     int num;
6009     this(int n) { num = n; }
6010     ~this() { num = 0; }
6011 }
6012 
6013 void test12138()
6014 {
6015 label:
6016     auto s = S12138(10);
6017     assert(s.num == 10);
6018 }
6019 
6020 /***************************************************/
6021 // 14430
6022 
6023 void setCookie(long x = 1L << 32L, string y = null){
6024     assert(y.ptr is null);
6025 }
6026 
6027 void test14430(){
6028     setCookie();
6029 }
6030 
6031 /***************************************************/
6032 // 14510
6033 
6034 alias Vector14510 = ulong[3];
6035 
6036 void fun14510(Vector14510 vec, bool recursive = false)
6037 {
6038     assert(vec[2] == 0);
6039     if (recursive)
6040         return;
6041     fun14510(vec, true);
6042 }
6043 
6044 void test14510()
6045 {
6046     Vector14510 vec;
6047     fun14510(vec);
6048 }
6049 
6050 /***************************************************/
6051 // https://issues.dlang.org/show_bug.cgi?id=16027
6052 
6053 void test16027()
6054 {
6055     double value = 1.0;
6056     value *= -1.0;
6057     assert(value == -1.0);    // fails, value is +1.0
6058 
6059     value = 1.0;
6060     value = value * -1.0;
6061     assert(value == -1.0);
6062 }
6063 
6064 /***************************************************/
6065 
6066 int main()
6067 {
6068     test1();
6069     test2();
6070     test3();
6071     test4();
6072     test5();
6073     test6();
6074     test7();
6075     test8();
6076     test9();
6077     test10();
6078     test11();
6079     test12();
6080     test13();
6081     test14();
6082     test15();
6083     test16();
6084     test17();
6085     test18();
6086     test19();
6087     test20();
6088     test21();
6089     test22();
6090     test23();
6091     test24();
6092     test25();
6093     test27();
6094     test28();
6095     test29();
6096     test31();
6097     test32();
6098     test33();
6099     test34();
6100     test35();
6101     test36();
6102     test37();
6103     test38();
6104     test39();
6105     test40();
6106     test41();
6107     test42();
6108     test43();
6109     test44();
6110     test45();
6111     test46();
6112     test47();
6113     test48();
6114     test49();
6115     test50();
6116     test51();
6117     test52();
6118     test53();
6119     test54();
6120     test55();
6121     test56();
6122     test57();
6123     test58();
6124     test59();
6125     test60();
6126     test61();
6127     test62();
6128     test63();
6129     test64();
6130     test65();
6131     test66();
6132     test67();
6133     test68();
6134     test69();
6135     test70();
6136     test71();
6137     test72();
6138     test73();
6139     test74();
6140     test75();
6141     test76();
6142     test77();
6143     test78();
6144     test79();
6145     test80();
6146     test81();
6147     test82();
6148     test83();
6149     test84();
6150     test85();
6151     test86();
6152     test87();
6153     test88();
6154     test89();
6155     test90();
6156     test91();
6157     test92();
6158     test93();
6159     test94();
6160     test95();
6161     test96();
6162     test97();
6163     test98();
6164     test99();
6165     test100();
6166     test101();
6167     test103();
6168     test104();
6169     test105();
6170     test107();
6171     test108();
6172     test109();
6173     test110();
6174     test111();
6175     test112();
6176     test113();
6177     test114();
6178     test115();
6179     test116();
6180     test117();
6181     test118();
6182     test119();
6183     test120();
6184     test121();
6185     //test122();
6186     test123();
6187     test124();
6188     test125();
6189     test126();
6190     test127();
6191     test128();
6192     test129();
6193     test130();
6194     test131();
6195     test132();
6196     test133();
6197 
6198 //    test135();
6199     test136();
6200     test137();
6201 
6202     test139();
6203     test140();
6204 
6205     test142();
6206     test143();
6207     test144();
6208     test145();
6209     test146();
6210     test147();
6211     test148();
6212     test149();
6213 
6214     test151();
6215     test152();
6216     test153();
6217     test154();
6218 
6219     test156();
6220     test157();
6221 
6222     test160();
6223 
6224     test163();
6225 
6226 
6227     test169();
6228 
6229     test171();
6230 
6231     test173();
6232     test174();
6233 
6234     test176();
6235     test177();
6236 
6237     test179();
6238 
6239     test181();
6240     test182();
6241 
6242     test188();
6243     test189();
6244     test190();
6245     test191();
6246 
6247     test193();
6248     test194();
6249 
6250     test198();
6251 
6252     test200();
6253     test201();
6254     test202();
6255     test203();
6256 
6257 //    test208();
6258 
6259     test210();
6260 
6261     test212();
6262     test213();
6263     test214();
6264     test215();
6265     test216();
6266     test217();
6267     test218();
6268     test219();
6269     test220();
6270 
6271     test222();
6272     test223();
6273     test224();
6274     test225();
6275     test226();
6276     test227();
6277     test228();
6278     test229();
6279     test230();
6280     test230();
6281     bug5717();
6282     test231();
6283     test232();
6284     test233();
6285     bug6184();
6286     test236();
6287     test237();
6288     test238();
6289     test239();
6290     test6229();
6291     test6270();
6292     test6506();
6293     test240();
6294     test6563();
6295     test241();
6296     test6665();
6297     test5364();
6298     test6189();
6299     test6997();
6300     test7026();
6301     test6354();
6302     test7072();
6303     test7212();
6304     test242();
6305     test7290();
6306     test7367();
6307     test7375();
6308     test6504();
6309     test7422();
6310     test7424();
6311     test7502();
6312     test4820();
6313     test4820_2();
6314     test243();
6315     test7742();
6316     test245();
6317     test7807();
6318     test4155();
6319     test7911();
6320     test8095();
6321     test8091();
6322     test6189_2();
6323     test8199();
6324     test246();
6325     test8454();
6326     test8423();
6327     test8496();
6328     test8840();
6329     test8889();
6330     test8870();
6331     test9781();
6332     test247();
6333     test8340();
6334     test8376();
6335     test8796();
6336     test9171();
6337     test9248();
6338     test14682a();
6339     test14682b();
6340     test9739();
6341     testdbl_to_ulong();
6342     testdbl_to_uint();
6343     testreal_to_ulong();
6344     test248();
6345     test249();
6346     test250();
6347     test6057();
6348     test251();
6349     test6962();
6350     test4414();
6351     test9844();
6352     test10628();
6353     test11265();
6354     test10633();
6355     test10642();
6356     test11581();
6357     test7436();
6358     test12138();
6359     test14430();
6360     test14510();
6361     test16027();
6362 
6363     writefln("Success");
6364     return 0;
6365 }
6366