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