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