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