d: Merge upstream dmd, druntime 4ca4140e58, phobos 454dff14d.
[official-gcc.git] / gcc / testsuite / gdc.test / runnable / xtest46.d
blobe57f52f6578364f9a3b19fdea5b8e5a17289d3b7
1 // REQUIRED_ARGS: -preview=rvaluerefparam
2 //
3 /* TEST_OUTPUT:
4 ---
5 runnable/xtest46.d(165): Deprecation: alias this for classes/interfaces is deprecated
6 Boo!double
7 Boo!int
8 true
9 int
10 !! immutable(int)[]
11 runnable/xtest46.d(2932): Deprecation: alias this for classes/interfaces is deprecated
12 runnable/xtest46.d(2964): Deprecation: alias this for classes/interfaces is deprecated
13 int(int i, long j = 7L)
14 long
15 C10390(C10390(C10390(<recursion>)))
16 tuple(height)
17 tuple(get, get)
18 tuple(clear)
19 tuple(draw, draw)
20 const(int)
21 string[]
22 double[]
23 double[]
25 runnable/xtest46.d(4670): Deprecation: alias this for classes/interfaces is deprecated
26 tuple("m")
27 true
28 TFunction1: extern (C) void function()
29 ---
32 //import std.stdio;
33 import core.stdc.stdio;
35 /******************************************/
37 struct S
39 int opUnary(string op)() if (op == "*") { return 7; }
42 void test1()
44 S s;
46 printf("%d\n", *s);
47 assert(*s == 7);
50 /******************************************/
52 void test2()
54 double[1][2] bar;
55 bar[0][0] = 1.0;
56 bar[1][0] = 2.0;
57 foo2(bar);
60 void foo2(T...)(T args)
62 foreach (arg; args[0 .. $])
64 //writeln(arg);
65 bar2!(typeof(arg))(&arg);
70 void bar2(D)(const(void)* arg)
72 D obj = *cast(D*) arg;
76 /***************************************************/
78 void test4()
80 immutable int maxi = 8;
81 int[][maxi] neighbors = [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4],
82 [ 2, 3, 5], [ 4, 5, 6 ] ];
83 int[maxi] grid;
85 // neighbors[0].length = 0;
87 void place(int k, uint mask)
88 { if(k<maxi) {
89 for(uint m = 1, d = 1; d <= maxi; d++, m<<=1)
90 if(!(mask & m)) {
91 bool ok = true;
92 int dif;
93 foreach(nb; neighbors[k])
94 if((dif=grid[nb]-d)==1 || dif==-1) {
95 ok = false; break;
97 if(ok) {
98 grid[k] = d;
99 place(k+1, mask | m);
102 } else {
103 printf(" %d\n%d %d %d\n%d %d %d\n %d\n\n",
104 grid[0], grid[1], grid[2], grid[3], grid[4], grid[5], grid[6], grid[7]);
107 place(0, 0);
111 /***************************************************/
113 struct S5
115 enum S5 some_constant = {2};
117 int member;
120 void test5()
124 /***************************************************/
126 struct S6
128 int a, b, c;
131 struct T6
133 S6 s;
134 int b = 7;
136 alias s this;
139 void test6()
141 T6 t;
142 t.a = 4;
143 t.b = 5;
144 t.c = 6;
145 assert(t.a == 4);
146 assert(t.b == 5);
147 assert(t.c == 6);
148 assert(t.s.b == 0);
149 assert(t.sizeof == 4*4);
150 assert(t.init.sizeof == 4*4);
153 /***************************************************/
155 struct S7
157 int a, b, c;
160 class C7
162 S7 s;
163 int b = 7;
165 alias s this;
168 void test7()
170 C7 t = new C7();
171 t.a = 4;
172 t.b = 5;
173 t.c = 6;
174 assert(t.a == 4);
175 assert(t.b == 5);
176 assert(t.c == 6);
177 assert(t.s.b == 0);
178 assert(t.sizeof == (void*).sizeof);
179 assert(t.init is null);
182 /***************************************************/
184 void foo8(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)
186 assert(n1 < n2);
187 printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr);
190 void test8()
192 foo8();
195 /***************************************************/
197 void foo9(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)()
199 assert(n1 < n2);
200 printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr);
203 void test9()
205 foo9();
208 /***************************************************/
210 int foo10(char c) pure nothrow
212 return 1;
215 void test10()
217 int function(char c) fp;
218 int function(char c) pure nothrow fq;
220 fp = &foo10;
221 fq = &foo10;
224 /***************************************************/
226 class Base11 {}
227 class Derived11 : Base11 {}
228 class MoreDerived11 : Derived11 {}
230 int fun11(Base11) { return 1; }
231 int fun11(Derived11) { return 2; }
233 void test11()
235 MoreDerived11 m;
237 auto i = fun11(m);
238 assert(i == 2);
241 /***************************************************/
243 interface ABC {};
244 interface AB: ABC {};
245 interface BC: ABC {};
246 interface AC: ABC {};
247 interface A: AB, AC {};
248 interface B: AB, BC {};
249 interface C: AC, BC {};
251 int f12(AB ab) { return 1; }
252 int f12(ABC abc) { return 2; }
254 void test12()
256 A a;
257 auto i = f12(a);
258 assert(i == 1);
261 /***************************************************/
263 template Foo13(alias x)
265 enum bar = x + 1;
268 static assert(Foo13!(2+1).bar == 4);
270 template Bar13(alias x)
272 enum bar = x;
275 static assert(Bar13!("abc").bar == "abc");
277 void test13()
281 /***************************************************/
283 template Foo14(alias a)
285 alias Bar14!(a) Foo14;
288 int Bar14(alias a)()
290 return a.sizeof;
293 void test14()
295 auto i = Foo14!("hello")();
296 printf("i = %d\n", i);
297 assert(i == "hello".sizeof);
298 i = Foo14!(1)();
299 printf("i = %d\n", i);
300 assert(i == 4);
303 /***************************************************/
305 auto foo15()(int x)
307 return 3 + x;
310 void test15()
313 auto bar()(int x)
315 return 5 + x;
318 printf("%d\n", foo15(4));
319 printf("%d\n", bar(4));
322 /***************************************************/
324 int foo16(int x) { return 1; }
325 int foo16(ref int x) { return 2; }
327 void test16()
329 int y;
330 auto i = foo16(y);
331 printf("i == %d\n", i);
332 assert(i == 2);
333 i = foo16(3);
334 assert(i == 1);
337 /***************************************************/
339 class A17 { }
340 class B17 : A17 { }
341 class C17 : B17 { }
343 int foo17(A17, ref int x) { return 1; }
344 int foo17(B17, ref int x) { return 2; }
346 void test17()
348 C17 c;
349 int y;
350 auto i = foo17(c, y);
351 printf("i == %d\n", i);
352 assert(i == 2);
355 /***************************************************/
357 class C18
359 void foo(int x) { foo("abc"); }
360 void foo(string s) { } // this is hidden, but that's ok 'cuz no overlap
361 void bar()
363 foo("abc");
367 class D18 : C18
369 override void foo(int x) { }
372 void test18()
374 D18 d = new D18();
375 d.bar();
378 /***************************************************/
380 int foo19(alias int a)() { return a; }
382 void test19()
384 int y = 7;
385 auto i = foo19!(y)();
386 printf("i == %d\n", i);
387 assert(i == 7);
389 i = foo19!(4)();
390 printf("i == %d\n", i);
391 assert(i == 4);
394 /***************************************************/
396 template Foo20(int x) if (x & 1)
398 const int Foo20 = 6;
401 template Foo20(int x) if ((x & 1) == 0)
403 const int Foo20 = 7;
406 void test20()
408 int i = Foo20!(3);
409 printf("%d\n", i);
410 assert(i == 6);
411 i = Foo20!(4);
412 printf("%d\n", i);
413 assert(i == 7);
416 /***************************************************/
418 template isArray21(T : U[], U)
420 static const isArray21 = 1;
423 template isArray21(T)
425 static const isArray21 = 0;
428 int foo21(T)(T x) if (isArray21!(T))
430 return 1;
433 int foo21(T)(T x) if (!isArray21!(T))
435 return 2;
438 void test21()
440 auto i = foo21(5);
441 assert(i == 2);
442 int[] a;
443 i = foo21(a);
444 assert(i == 1);
447 /***************************************************/
449 void test22()
451 immutable uint x, y;
452 foreach (i; x .. y) {}
455 /***************************************************/
457 const bool foo23 = is(typeof(function void() { }));
458 const bar23 = is(typeof(function void() { }));
460 void test23()
462 assert(foo23 == true);
463 assert(bar23 == true);
466 /***************************************************/
468 ref int foo24(int i)
470 static int x;
471 x = i;
472 return x;
475 void test24()
477 int x = foo24(3);
478 assert(x == 3);
481 /***************************************************/
483 ref int foo25(int i)
485 static int x;
486 x = i;
487 return x;
490 int bar25(ref int x)
492 return x + 1;
495 void test25()
497 int x = bar25(foo25(3));
498 assert(x == 4);
501 /***************************************************/
503 static int x26;
505 ref int foo26(int i)
507 x26 = i;
508 return x26;
511 void test26()
513 int* p = &foo26(3);
514 assert(*p == 3);
517 /***************************************************/
519 static int x27 = 3;
521 ref int foo27(int i)
523 return x27;
526 void test27()
528 foo27(3) = 4;
529 assert(x27 == 4);
532 /***************************************************/
534 ref int foo28(return ref int x) { return x; }
536 void test28()
538 int a;
539 foo28(a);
542 /***************************************************/
544 void wyda(int[] a) { printf("aaa\n"); }
545 void wyda(int[int] a) { printf("bbb\n"); }
547 struct S29
549 int[] a;
551 void wyda()
553 a.wyda;
554 a.wyda();
558 void test29()
560 int[] a;
561 a.wyda;
562 int[5] b;
563 b.wyda;
564 int[int] c;
565 c.wyda;
567 S29 s;
568 s.wyda();
571 /***************************************************/
573 void foo30(D)(D arg) if (isIntegral!D)
577 struct S30(T) { }
578 struct U30(int T) { }
580 alias int myint30;
582 void test30()
585 S30!myint30 u;
586 S30!int s;
587 S30!(int) t = s;
589 // U30!3 v = s;
592 /***************************************************/
594 class A31
596 void foo(int* p) { }
599 class B31 : A31
601 override void foo(scope int* p) { }
604 void test31()
608 /***************************************************/
610 void bar32() { }
612 nothrow void foo32(int* p)
614 //try { bar32(); } catch (Object o) { }
615 try { bar32(); } catch (Throwable o) { }
616 try { bar32(); } catch (Exception o) { }
619 void test32()
620 { int i;
622 foo32(&i);
625 /***************************************************/
627 struct Integer
629 this(int i)
631 this.i = i;
634 this(long ii)
636 i = 3;
639 const int i;
642 void test33()
646 /***************************************************/
648 void test34()
650 alias uint Uint;
651 foreach(Uint u;1..10) {}
652 for(Uint u=1;u<10;u++) {}
655 /***************************************************/
657 ref int foo35(bool condition, return ref int lhs, return ref int rhs)
659 if ( condition ) return lhs;
660 return rhs;
663 ref int bar35()(bool condition, return ref int lhs, return ref int rhs)
665 if ( condition ) return lhs;
666 return rhs;
669 void test35()
671 int a = 10, b = 11;
673 foo35(a<b, a, b) = 42;
674 printf("a = %d and b = %d\n", a, b); // a = 42 and b = 11
675 assert(a == 42 && b == 11);
677 bar35(a<b, a, b) = 52;
678 printf("a = %d and b = %d\n", a, b);
679 assert(a == 42 && b == 52);
682 /***************************************************/
684 int foo36(T...)(T ts)
685 if (T.length > 1)
687 return T.length;
690 int foo36(T...)(T ts)
691 if (T.length <= 1)
693 return T.length * 7;
696 void test36()
698 auto i = foo36!(int,int)(1, 2);
699 assert(i == 2);
700 i = foo36(1, 2, 3);
701 assert(i == 3);
702 i = foo36(1);
703 assert(i == 7);
704 i = foo36();
705 assert(i == 0);
709 /***************************************************/
711 void test6685()
713 struct S { int x; }
714 with({ return S(); }())
716 x++;
720 /***************************************************/
722 struct A37(alias T)
726 void foo37(X)(X x) if (is(X Y == A37!(U), alias U))
730 void bar37() {}
732 void test37()
734 A37!(bar37) a2;
735 foo37(a2);
736 foo37!(A37!bar37)(a2);
739 /***************************************************/
741 struct A38
743 this(this)
745 printf("B's copy\n");
747 bool empty() {return false;}
748 void popFront() {}
749 int front() { return 1; }
750 // ref A38 opSlice() { return this; }
753 void test38()
755 A38 a;
756 int i;
757 foreach (e; a) { if (++i == 100) break; }
760 /***************************************************/
762 alias int function() Fun39;
763 alias ref int function() Gun39;
764 static assert(!is(Fun39 == Gun39));
766 void test39()
770 /***************************************************/
772 int x40;
774 struct Proxy
776 ref int at(int i)() { return x40; }
779 void test40()
781 Proxy p;
782 auto x = p.at!(1);
785 /***************************************************/
787 template Foo41(TList...)
789 alias TList Foo41;
792 alias Foo41!(immutable(ubyte)[], ubyte[]) X41;
794 void test41()
799 /***************************************************/
801 bool endsWith(A1, A2)(A1 longer, A2 shorter)
803 static if (is(typeof(longer[0 .. 0] == shorter)))
806 else
809 return false;
812 void test42()
814 char[] a;
815 byte[] b;
816 endsWith(a, b);
819 /***************************************************/
821 void f43(S...)(S s) if (S.length > 3)
825 void test43()
827 f43(1, 2, 3, 4);
831 /***************************************************/
833 struct S44(int x = 1){}
835 void fun()(S44!(1) b) { }
837 void test44()
839 S44!() s;
840 fun(s);
843 /***************************************************/
844 // https://issues.dlang.org/show_bug.cgi?id=2006
846 void test2006()
848 string [][] aas = [];
849 assert(aas.length == 0);
850 aas ~= cast (string []) [];
851 assert(aas.length == 1);
852 aas = aas ~ cast (string []) [];
853 assert(aas.length == 2);
856 /***************************************************/
857 // https://issues.dlang.org/show_bug.cgi?id=8442
859 void test8442()
861 enum int[] fooEnum = [];
862 immutable fooImmutable = fooEnum;
865 /***************************************************/
867 class A45
869 int x;
870 int f()
872 printf("A\n");
873 return 1;
877 class B45 : A45
879 override const int f()
881 printf("B\n");
882 return 2;
886 void test45()
888 A45 y = new B45;
889 int i = y.f;
890 assert(i == 2);
893 /***************************************************/
895 void text10682()
897 ulong x = 1;
898 ulong y = 2 ^^ x;
901 /***************************************************/
903 struct Test46
905 int foo;
908 void test46()
910 enum Test46 test = {};
911 enum q = test.foo;
914 /***************************************************/
916 pure int double_sqr(int x) {
917 int y = x;
918 void do_sqr() { y *= y; }
919 do_sqr();
920 return y;
923 void test47()
925 assert(double_sqr(10) == 100);
928 /***************************************************/
930 void sort(alias less)(string[] r)
932 bool pred()
934 return less("a", "a");
936 .sort!(less)(r);
939 void foo48()
941 int[string] freqs;
942 string[] words;
944 sort!((a, b) { return freqs[a] > freqs[b]; })(words);
945 sort!((string a, string b) { return freqs[a] > freqs[b]; })(words);
946 //sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words);
947 //sort!(function (a, b) { return freqs[a] > freqs[b]; })(words);
948 //sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words);
949 sort!(delegate bool(string a, string b) { return freqs[a] > freqs[b]; })(words);
953 void test48()
957 /***************************************************/
958 // https://issues.dlang.org/show_bug.cgi?id=6408
960 static assert(!is(typeof(string[0..1].init)));
961 static assert(is(typeof(string[].init) == string[]));
962 static assert(is(typeof(string[][].init) == string[][]));
963 static assert(is(typeof(string[][][].init) == string[][][]));
965 static assert(is(typeof(string[1].init) == string[1]));
966 static assert(is(typeof(string[1][1].init) == string[1][1]));
967 static assert(is(typeof(string[1][1][1].init) == string[1][1][1]));
969 static assert(is(typeof(string[string].init) == string[string]));
970 static assert(is(typeof(string[string][string].init) == string[string][string]));
971 static assert(is(typeof(string[string][string][string].init) == string[string][string][string]));
973 template TT6408(T...) { alias T TT6408; }
974 static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int)));
975 static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int)));
976 static assert(is(typeof(TT6408!(int, int)[$-1].init) == int));
978 /***************************************************/
979 // https://issues.dlang.org/show_bug.cgi?id=9409
981 template TT9409(T...) { alias T TT9409; }
983 template idxTypes9409(Prefix...)
985 TT9409!((Prefix[$-1])) idxTypes9409;
988 alias idxTypes9409!(int) Types9409;
990 /***************************************************/
992 struct S49
994 static void* p;
996 this( string name )
998 printf( "(ctor) &%.*s.x = %p\n", cast(int)name.length, name.ptr, &x );
999 p = cast(void*)&x;
1002 invariant() {}
1004 int x;
1007 void test49()
1009 auto s = new S49("s2");
1011 printf( "&s2.x = %p\n", &s.x );
1012 assert(cast(void*)&s.x == S49.p);
1015 /***************************************************/
1017 auto max50(Ts...)(Ts args)
1018 if (Ts.length >= 2
1019 && is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init)))
1021 static if (Ts.length == 2)
1022 return args[1] > args[0] ? args[1] : args[0];
1023 else
1024 return max50(max50(args[0], args[1]), args[2 .. $]);
1027 void test50()
1029 assert(max50(4, 5) == 5);
1030 assert(max50(2.2, 4.5) == 4.5);
1031 assert(max50("Little", "Big") == "Little");
1033 assert(max50(4, 5.5) == 5.5);
1034 assert(max50(5.5, 4) == 5.5);
1037 /***************************************************/
1039 void test51()
1041 static immutable int[2] array = [ 42 ];
1042 enum e = array[1];
1043 static immutable int[1] array2 = [ 0: 42 ];
1044 enum e2 = array2[0];
1045 assert(e == 0);
1046 assert(e2 == 42);
1049 /***************************************************/
1051 enum ubyte[4] a52 = [5,6,7,8];
1053 void test52()
1055 int x=3;
1056 assert(a52[x]==8);
1059 /***************************************************/
1061 void test53()
1063 size_t func2(immutable(void)[] t)
1065 return 0;
1069 /***************************************************/
1071 void foo54(void delegate(void[]) dg) { }
1073 void test54()
1075 void func(void[] t) pure { }
1076 foo54(&func);
1078 // void func2(const(void)[] t) { }
1079 // foo54(&func2);
1082 /***************************************************/
1084 class Foo55
1086 synchronized void noop1() { }
1087 void noop2() shared { }
1090 void test55()
1092 auto foo = new shared(Foo55);
1093 foo.noop1();
1094 foo.noop2();
1097 /***************************************************/
1099 enum float one56 = 1 * 1;
1100 template X56(float E) { int X56 = 2; }
1101 alias X56!(one56 * one56) Y56;
1103 void test56()
1105 assert(Y56 == 2);
1108 /***************************************************/
1110 void test57()
1112 alias shared(int) T;
1113 assert (is(T == shared));
1116 /***************************************************/
1118 struct A58
1120 int a,b;
1123 void test58()
1125 A58[2] rg=[{1,2},{5,6}];
1126 assert(rg[0].a == 1);
1127 assert(rg[0].b == 2);
1128 assert(rg[1].a == 5);
1129 assert(rg[1].b == 6);
1132 /***************************************************/
1134 class A59 {
1135 const foo(int i) { return i; }
1138 /***************************************************/
1140 void test60()
1142 enum real ONE = 1.0;
1143 real x;
1144 for (x=0.0; x<10.0; x+=ONE)
1145 printf("%Lg\n", x);
1146 printf("%Lg\n", x);
1147 assert(x == 10);
1150 /***************************************************/
1152 pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){
1154 immutable(T)[] fooState;
1156 immutable(T)[] bar(immutable(T)[] x){
1157 fooState = "hello ";
1158 return x ~ y;
1161 return fooState ~ bar(x);
1166 void test61()
1168 auto s = fooPT("p", "c");
1169 printf("%.*s\n", cast(int)s.length, s.ptr);
1172 /***************************************************/
1174 void test9577()
1176 static int function(int)[] foo = [x => x];
1177 foo[0](0);
1180 /***************************************************/
1182 int[3] foo62(int[3] a)
1184 a[1]++;
1185 return a;
1188 void test62()
1190 int[3] b;
1191 b[0] = 1;
1192 b[1] = 2;
1193 b[2] = 3;
1194 auto c = foo62(b);
1195 assert(b[0] == 1);
1196 assert(b[1] == 2);
1197 assert(b[2] == 3);
1199 assert(c[0] == 1);
1200 assert(c[1] == 3);
1201 assert(c[2] == 3);
1204 /***************************************************/
1206 void test3927()
1208 int[] array;
1209 assert(array.length++ == 0);
1210 assert(array.length == 1);
1211 assert(array.length-- == 1);
1212 assert(array.length == 0);
1215 /***************************************************/
1217 void test63()
1219 int[3] b;
1220 b[0] = 1;
1221 b[1] = 2;
1222 b[2] = 3;
1223 auto c = b;
1224 b[1]++;
1225 assert(b[0] == 1);
1226 assert(b[1] == 3);
1227 assert(b[2] == 3);
1229 assert(c[0] == 1);
1230 assert(c[1] == 2);
1231 assert(c[2] == 3);
1234 /***************************************************/
1236 void test64()
1238 int[3] b;
1239 b[0] = 1;
1240 b[1] = 2;
1241 b[2] = 3;
1242 int[3] c;
1243 c = b;
1244 b[1]++;
1245 assert(b[0] == 1);
1246 assert(b[1] == 3);
1247 assert(b[2] == 3);
1249 assert(c[0] == 1);
1250 assert(c[1] == 2);
1251 assert(c[2] == 3);
1254 /***************************************************/
1256 int[2] foo65(int[2] a)
1258 a[1]++;
1259 return a;
1262 void test65()
1264 int[2] b;
1265 b[0] = 1;
1266 b[1] = 2;
1267 int[2] c = foo65(b);
1268 assert(b[0] == 1);
1269 assert(b[1] == 2);
1271 assert(c[0] == 1);
1272 assert(c[1] == 3);
1275 /***************************************************/
1277 int[1] foo66(int[1] a)
1279 a[0]++;
1280 return a;
1283 void test66()
1285 int[1] b;
1286 b[0] = 1;
1287 int[1] c = foo66(b);
1288 assert(b[0] == 1);
1289 assert(c[0] == 2);
1292 /***************************************************/
1294 int[2] foo67(out int[2] a)
1296 a[0] = 5;
1297 a[1] = 6;
1298 return a;
1301 void test67()
1303 int[2] b;
1304 b[0] = 1;
1305 b[1] = 2;
1306 int[2] c = foo67(b);
1307 assert(b[0] == 5);
1308 assert(b[1] == 6);
1310 assert(c[0] == 5);
1311 assert(c[1] == 6);
1314 /***************************************************/
1316 void test68()
1318 digestToString(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b");
1321 void digestToString(const ubyte[16] digest)
1323 assert(digest[0] == 0xc3);
1324 assert(digest[15] == 0x3b);
1327 /***************************************************/
1329 void test69()
1331 digestToString69(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b");
1334 void digestToString69(ref const ubyte[16] digest)
1336 assert(digest[0] == 0xc3);
1337 assert(digest[15] == 0x3b);
1340 /***************************************************/
1342 void test70()
1344 digestToString70("1234567890123456");
1347 void digestToString70(ref const char[16] digest)
1349 assert(digest[0] == '1');
1350 assert(digest[15] == '6');
1353 /***************************************************/
1355 void foo71(out shared int o) {}
1357 /***************************************************/
1359 struct foo72
1361 int bar() shared { return 1; }
1364 void test72()
1366 shared foo72 f;
1367 auto x = f.bar;
1370 /***************************************************/
1372 class Foo73
1374 static if (is(typeof(this) T : shared T))
1375 static assert(0);
1376 static if (is(typeof(this) U == shared U))
1377 static assert(0);
1378 static if (is(typeof(this) U == const U))
1379 static assert(0);
1380 static if (is(typeof(this) U == immutable U))
1381 static assert(0);
1382 static if (is(typeof(this) U == const shared U))
1383 static assert(0);
1385 static assert(!is(int == const));
1386 static assert(!is(int == immutable));
1387 static assert(!is(int == shared));
1389 static assert(is(int == int));
1390 static assert(is(const(int) == const));
1391 static assert(is(immutable(int) == immutable));
1392 static assert(is(shared(int) == shared));
1393 static assert(is(const(shared(int)) == shared));
1394 static assert(is(const(shared(int)) == const));
1396 static assert(!is(const(shared(int)) == immutable));
1397 static assert(!is(const(int) == immutable));
1398 static assert(!is(const(int) == shared));
1399 static assert(!is(shared(int) == const));
1400 static assert(!is(shared(int) == immutable));
1401 static assert(!is(immutable(int) == const));
1402 static assert(!is(immutable(int) == shared));
1405 template Bar(T : T)
1407 alias T Bar;
1410 template Barc(T : const(T))
1412 alias T Barc;
1415 template Bari(T : immutable(T))
1417 alias T Bari;
1420 template Bars(T : shared(T))
1422 alias T Bars;
1425 template Barsc(T : shared(const(T)))
1427 alias T Barsc;
1431 void test73()
1433 auto f = new Foo73;
1435 alias int T;
1437 // 5*5 == 25 combinations, plus 2 for swapping const and shared
1439 static assert(is(Bar!(T) == T));
1440 static assert(is(Bar!(const(T)) == const(T)));
1441 static assert(is(Bar!(immutable(T)) == immutable(T)));
1442 static assert(is(Bar!(shared(T)) == shared(T)));
1443 static assert(is(Bar!(shared(const(T))) == shared(const(T))));
1445 static assert(is(Barc!(const(T)) == T));
1446 static assert(is(Bari!(immutable(T)) == T));
1447 static assert(is(Bars!(shared(T)) == T));
1448 static assert(is(Barsc!(shared(const(T))) == T));
1450 static assert(is(Barc!(T) == T));
1451 static assert(is(Barc!(immutable(T)) == T));
1452 static assert(is(Barc!(const(shared(T))) == shared(T)));
1453 static assert(is(Barsc!(immutable(T)) == T));
1455 static assert(is(Bars!(const(shared(T))) == const(T)));
1456 static assert(is(Barsc!(shared(T)) == T));
1458 Bars!(shared(const(T))) b;
1459 pragma(msg, typeof(b));
1461 static assert(is(Bars!(shared(const(T))) == const(T)));
1462 static assert(is(Barc!(shared(const(T))) == shared(T)));
1464 static assert(!is(Bari!(T)));
1465 static assert(!is(Bari!(const(T))));
1466 static assert(!is(Bari!(shared(T))));
1467 static assert(!is(Bari!(const(shared(T)))));
1469 static assert(is(Barc!(shared(T))));
1471 static assert(!is(Bars!(T)));
1472 static assert(!is(Bars!(const(T))));
1473 static assert(!is(Bars!(immutable(T))));
1474 static assert(!is(Barsc!(T)));
1475 static assert(!is(Barsc!(const(T))));
1478 /***************************************************/
1480 pure nothrow {
1481 alias void function(int) A74;
1484 alias void function(int) pure nothrow B74;
1485 alias pure nothrow void function(int) C74;
1487 void test74()
1489 A74 a = null;
1490 B74 b = null;
1491 C74 c = null;
1492 a = b;
1493 a = c;
1496 /***************************************************/
1498 void test9212()
1500 int[int] aa;
1501 foreach (const key, const val; aa) {}
1502 foreach (size_t key, size_t val; aa) {}
1505 /***************************************************/
1507 class A75
1509 pure static void raise(string s)
1511 throw new Exception(s);
1515 void test75()
1516 { int x = 0;
1519 A75.raise("a");
1520 } catch (Exception e)
1522 x = 1;
1524 assert(x == 1);
1527 /***************************************************/
1529 void test76()
1531 int x, y;
1532 bool which;
1533 (which ? x : y) += 5;
1534 assert(y == 5);
1537 /***************************************************/
1539 void test77()
1541 auto a = ["hello", "world"];
1542 pragma(msg, typeof(a));
1543 auto b = a;
1544 assert(a is b);
1545 assert(a == b);
1546 b = a.dup;
1547 assert(a == b);
1548 assert(a !is b);
1551 /***************************************************/
1553 void test78()
1555 auto array = [0, 2, 4, 6, 8, 10];
1556 array = array[0 .. $ - 2]; // Right-shrink by two elements
1557 assert(array == [0, 2, 4, 6]);
1558 array = array[1 .. $]; // Left-shrink by one element
1559 assert(array == [2, 4, 6]);
1560 array = array[1 .. $ - 1]; // Shrink from both sides
1561 assert(array == [4]);
1564 /***************************************************/
1566 void test79()
1568 auto a = [87, 40, 10];
1569 a ~= 42;
1570 assert(a == [87, 40, 10, 42]);
1571 a ~= [5, 17];
1572 assert(a == [87, 40, 10, 42, 5, 17]);
1575 /***************************************************/
1577 void test6317()
1579 int b = 12345;
1580 struct nested { int a; int fun() { return b; } }
1581 static assert(!__traits(compiles, { nested x = { 3, null }; }));
1582 nested g = { 7 };
1583 auto h = nested(7);
1584 assert(g.fun() == 12345);
1585 assert(h.fun() == 12345);
1588 /***************************************************/
1590 void test80()
1592 auto array = new int[10];
1593 array.length += 1000;
1594 assert(array.length == 1010);
1595 array.length /= 10;
1596 assert(array.length == 101);
1597 array.length -= 1;
1598 assert(array.length == 100);
1599 array.length |= 1;
1600 assert(array.length == 101);
1601 array.length ^= 3;
1602 assert(array.length == 102);
1603 array.length &= 2;
1604 assert(array.length == 2);
1605 array.length *= 2;
1606 assert(array.length == 4);
1607 array.length <<= 1;
1608 assert(array.length == 8);
1609 array.length >>= 1;
1610 assert(array.length == 4);
1611 array.length >>>= 1;
1612 assert(array.length == 2);
1613 array.length %= 2;
1614 assert(array.length == 0);
1616 int[]* foo()
1618 static int x;
1619 x++;
1620 assert(x == 1);
1621 auto p = &array;
1622 return p;
1625 (*foo()).length += 2;
1626 assert(array.length == 2);
1629 /***************************************************/
1631 void test81()
1633 int[3] a = [1, 2, 3];
1634 int[3] b = a;
1635 a[1] = 42;
1636 assert(b[1] == 2); // b is an independent copy of a
1637 int[3] fun(int[3] x, int[3] y) {
1638 // x and y are copies of the arguments
1639 x[0] = y[0] = 100;
1640 return x;
1642 auto c = fun(a, b); // c has type int[3]
1643 assert(c == [100, 42, 3]);
1644 assert(b == [1, 2, 3]); // b is unaffected by fun
1647 /***************************************************/
1649 void test82()
1651 auto a1 = [ "Jane":10.0, "Jack":20, "Bob":15 ];
1652 auto a2 = a1; // a1 and a2 refer to the same data
1653 a1["Bob"] = 100; // Changing a1
1654 assert(a2["Bob"] == 100); //is same as changing a2
1655 a2["Sam"] = 3.5; //and vice
1656 assert(a2["Sam"] == 3.5); // versa
1659 /***************************************************/
1661 void test7942()
1663 string a = "a";
1664 wstring b = "b";
1665 dstring c = "c";
1667 a ~= "a"c;
1668 static assert(!is(typeof(a ~= "b"w)));
1669 static assert(!is(typeof(a ~= "c"d)));
1670 static assert(!is(typeof(b ~= "a"c)));
1671 b ~= "b"w;
1672 static assert(!is(typeof(b ~= "c"d)));
1673 static assert(!is(typeof(c ~= "a"c)));
1674 static assert(!is(typeof(c ~= "b"w)));
1675 c ~= "c"d;
1677 assert(a == "aa");
1678 assert(b == "bb");
1679 assert(c == "cc");
1682 /***************************************************/
1684 void bump(ref int x) { ++x; }
1686 void test83()
1688 int x = 1;
1689 bump(x);
1690 assert(x == 2);
1693 /***************************************************/
1695 interface Test4174
1697 void func(T)() {}
1700 /***************************************************/
1702 auto foo84 = [1, 2.4];
1704 void test84()
1706 pragma(msg, typeof([1, 2.4]));
1707 static assert(is(typeof([1, 2.4]) == double[]));
1709 pragma(msg, typeof(foo84));
1710 static assert(is(typeof(foo84) == double[]));
1713 /***************************************************/
1715 void test85()
1717 dstring c = "V\u00E4rld";
1718 c = c ~ '!';
1719 assert(c == "V\u00E4rld!");
1720 c = '@' ~ c;
1721 assert(c == "@V\u00E4rld!");
1723 wstring w = "V\u00E4rld";
1724 w = w ~ '!';
1725 assert(w == "V\u00E4rld!");
1726 w = '@' ~ w;
1727 assert(w == "@V\u00E4rld!");
1729 string s = "V\u00E4rld";
1730 s = s ~ '!';
1731 assert(s == "V\u00E4rld!");
1732 s = '@' ~ s;
1733 assert(s == "@V\u00E4rld!");
1736 /***************************************************/
1738 void test86()
1740 int[][] a = [ [1], [2,3], [4] ];
1741 int[][] w = [ [1, 2], [3], [4, 5], [] ];
1742 int[][] x = [ [], [1, 2], [3], [4, 5], [] ];
1745 /***************************************************/
1747 // https://issues.dlang.org/show_bug.cgi?id=3379
1749 T1[] find(T1, T2)(T1[] longer, T2[] shorter)
1750 if (is(typeof(longer[0 .. 1] == shorter) : bool))
1752 while (longer.length >= shorter.length) {
1753 if (longer[0 .. shorter.length] == shorter) break;
1754 longer = longer[1 .. $];
1756 return longer;
1759 auto max(T...)(T a)
1760 if (T.length == 2
1761 && is(typeof(a[1] > a[0] ? a[1] : a[0]))
1762 || T.length > 2
1763 && is(typeof(max(max(a[0], a[1]), a[2 .. $])))) {
1764 static if (T.length == 2) {
1765 return a[1] > a[0] ? a[1] : a[0];
1766 } else {
1767 return max(max(a[0], a[1]), a[2 .. $]);
1771 // Cases which would ICE or segfault
1772 struct Bulldog(T){
1773 static void cat(Frog)(Frog f) if (true)
1777 void mouse(){
1778 Bulldog!(int).cat(0);
1781 void test87()
1783 double[] d1 = [ 6.0, 1.5, 2.4, 3 ];
1784 double[] d2 = [ 1.5, 2.4 ];
1785 assert(find(d1, d2) == d1[1 .. $]);
1786 assert(find(d1, d2) == d1[1 .. $]); // Check for memory corruption
1787 assert(max(4, 5) == 5);
1788 assert(max(3, 4, 5) == 5);
1791 /***************************************************/
1793 template test4284(alias v) { enum test4284 = v.length == 0; }
1794 static assert(test4284!(cast(string)null));
1795 static assert(test4284!(cast(string[])null));
1797 /***************************************************/
1799 struct S88
1801 void opDispatch(string s, T)(T i)
1803 printf("S.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i);
1807 class C88
1809 void opDispatch(string s)(int i)
1811 printf("C.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i);
1815 struct D88
1817 template opDispatch(string s)
1819 enum int opDispatch = 8;
1823 void test88()
1825 S88 s;
1826 s.opDispatch!("hello")(7);
1827 s.foo(7);
1829 auto c = new C88();
1830 c.foo(8);
1832 D88 d;
1833 printf("d.foo = %d\n", d.foo);
1834 assert(d.foo == 8);
1837 /***************************************************/
1839 void test89() {
1840 static struct X {
1841 int x;
1842 int bar() { return x; }
1844 X s;
1845 printf("%zd\n", s.sizeof);
1846 assert(s.sizeof == 4);
1849 /***************************************************/
1851 struct S90
1853 void opDispatch( string name, T... )( T values )
1855 assert(values[0] == 3.14);
1859 void test90( )
1860 { S90 s;
1861 s.opDispatch!("foo")( 3.14 );
1862 s.foo( 3.14 );
1865 /***************************************************/
1867 struct A7439(int r, int c)
1869 alias r R;
1870 alias c C;
1871 alias float[R * C] Data;
1872 Data _data;
1873 alias _data this;
1875 this(Data ar){ _data = ar; }
1877 pure ref float opIndex(size_t rr, size_t cc){ return _data[cc + rr * C]; }
1880 void test7439()
1882 A7439!(2, 2) a = A7439!(2, 2)([8, 3, 2, 9]);
1883 a[0,0] -= a[0,0] * 2.0;
1886 /***************************************************/
1888 void foo91(uint line = __LINE__) { printf("%d\n", line); }
1890 void test91()
1892 foo91();
1893 printf("%d\n", __LINE__);
1896 /***************************************************/
1898 bool fun13468(Object e, typeof(null) needle)
1900 return (e == needle);
1903 void test13468()
1905 assert(fun13468(null, null));
1908 /***************************************************/
1910 auto ref foo92(ref int x) { return x; }
1911 int bar92(ref int x) { return x; }
1913 void test92()
1915 int x = 3;
1916 int i = bar92(foo92(x));
1917 assert(i == 3);
1920 /***************************************************/
1922 struct Foo93
1924 public int foo() const
1926 return 2;
1930 void test93()
1932 const Foo93 bar = Foo93();
1933 enum bla = bar.foo();
1934 assert(bla == 2);
1937 /***************************************************/
1940 extern(C++) class C1687
1942 void func() {}
1945 void test1687()
1947 auto c = new C1687();
1948 assert(c.__vptr[0] == (&c.func).funcptr);
1951 /***************************************************/
1953 struct Foo94
1955 int x, y;
1956 real z;
1959 pure nothrow Foo94 makeFoo(const int x, const int y)
1961 return Foo94(x, y, 3.0);
1964 void test94()
1966 auto f = makeFoo(1, 2);
1967 assert(f.x==1);
1968 assert(f.y==2);
1969 assert(f.z==3);
1972 /***************************************************/
1974 struct T95
1976 @disable this(this)
1981 struct S95
1983 T95 t;
1986 @disable void foo95() { }
1988 struct T95A
1990 @disable this(this);
1993 struct S95A
1995 T95A t;
1998 @disable void foo95A() { }
2000 void test95()
2002 S95 s;
2003 S95 t;
2004 static assert(!__traits(compiles, t = s));
2005 static assert(!__traits(compiles, foo95()));
2007 S95A u;
2008 S95A v;
2009 static assert(!__traits(compiles, v = u));
2010 static assert(!__traits(compiles, foo95A()));
2013 /***************************************************/
2015 struct S96(alias init)
2017 int[] content = init;
2020 void test96()
2022 S96!([12, 3]) s1;
2023 S96!([1, 23]) s2;
2024 //writeln(s1.content);
2025 //writeln(s2.content);
2026 assert(!is(typeof(s1) == typeof(s2)));
2029 /***************************************************/
2031 struct A97
2033 const bool opEquals(ref const A97) { return true; }
2034 ref A97 opUnary(string op)() if (op == "++")
2036 return this;
2040 void test97()
2042 A97 a, b;
2043 foreach (e; a .. b) {
2047 /***************************************************/
2049 void test98()
2051 auto a = new int[2];
2052 // the name "length" should not pop up in an index expression
2053 static assert(!is(typeof(a[length - 1])));
2056 /***************************************************/
2058 string s99;
2060 void bar99(string i)
2064 void function(string) foo99(string i)
2066 return &bar99;
2069 void test99()
2071 foo99 (s99 ~= "a") (s99 ~= "b");
2072 assert(s99 == "ab");
2075 /***************************************************/
2076 // https://issues.dlang.org/show_bug.cgi?id=5081
2078 void test5081()
2080 static pure immutable(int[]) x1()
2082 int[] a = new int[](10);
2083 return a;
2085 static pure immutable(int[]) x2(int len)
2087 int[] a = new int[](len);
2088 return a;
2090 static pure immutable(int[]) x3(immutable(int[]) org)
2092 int[] a = new int[](org.length);
2093 return a;
2096 immutable a1 = x1();
2097 immutable a2 = x2(10);
2098 immutable a3 = x3([1,2]);
2100 static pure int[] y1()
2102 return new int[](10);
2105 immutable b1 = y1();
2108 /***************************************************/
2110 void test100()
2112 string s;
2114 /* Testing order of evaluation */
2115 void delegate(string, string) fun(string) {
2116 s ~= "b";
2117 return delegate void(string x, string y) { s ~= "e"; };
2119 fun(s ~= "a")(s ~= "c", s ~= "d");
2120 assert(s == "abcde", s);
2123 /***************************************************/
2125 void test101()
2127 int[] d1 = [ 6, 1, 2 ];
2128 byte[] d2 = [ 6, 1, 2 ];
2129 assert(d1 == d2);
2130 d2 ~= [ 6, 1, 2 ];
2131 assert(d1 != d2);
2134 /***************************************************/
2137 void test5403()
2139 struct S
2141 static int front;
2142 enum back = "yes!";
2143 bool empty;
2144 void popAny() { empty = true; }
2145 alias popAny popFront;
2146 alias popAny popBack;
2148 S.front = 7;
2149 foreach(int i; S()) assert(i == 7);
2150 S.front = 2;
2151 foreach(i; S()) assert(i == 2);
2152 foreach_reverse(i; S()) assert(i == "yes!");
2155 /***************************************************/
2157 static assert([1,2,3] == [1.0,2,3]);
2159 /***************************************************/
2161 int transmogrify(uint) { return 1; }
2162 int transmogrify(long) { return 2; }
2164 void test103()
2166 assert(transmogrify(42) == 1);
2169 /***************************************************/
2171 int foo104(int x)
2173 int* p = &(x += 1);
2174 return *p;
2177 int bar104(int *x)
2179 int* p = &(*x += 1);
2180 return *p;
2183 void test104()
2185 auto i = foo104(1);
2186 assert(i == 2);
2187 i = bar104(&i);
2188 assert(i == 3);
2191 /***************************************************/
2193 ref int bump105(return ref int x) { return ++x; }
2195 void test105()
2197 int x = 1;
2198 bump105(bump105(x)); // two increments
2199 assert(x == 3);
2202 /***************************************************/
2204 pure int genFactorials(int n) {
2205 static pure int factorial(int n) {
2206 if (n==2) return 1;
2207 return factorial(2);
2209 return factorial(n);
2212 /***************************************************/
2214 void test107()
2216 int[6] a;
2217 //writeln(a);
2218 //writeln(a.init);
2219 assert(a.init == [0,0,0,0,0,0]);
2222 /***************************************************/
2224 class A109 {}
2226 void test109()
2228 immutable(A109) b;
2229 A109 c;
2230 auto z = true ? b : c;
2231 //writeln(typeof(z).stringof);
2232 static assert(is(typeof(z) == const(A109)));
2235 /***************************************************/
2237 template Boo(T) {}
2238 struct Foo110(T, alias V = Boo!T)
2240 pragma(msg, V.stringof);
2241 static const s = V.stringof;
2243 alias Foo110!double B110;
2244 alias Foo110!int A110;
2246 static assert(B110.s == "Boo!double");
2247 static assert(A110.s == "Boo!int");
2249 /***************************************************/
2251 int test11247()
2253 static assert(is(byte[typeof(int.init).sizeof] == byte[4]));
2254 static assert(is(byte[typeof(return).sizeof] == byte[4]));
2255 return 0;
2258 /***************************************************/
2260 // https://issues.dlang.org/show_bug.cgi?id=3716
2261 void test111()
2263 auto k1 = true ? [1,2] : []; // OK
2264 auto k2 = true ? [[1,2]] : [[]];
2265 auto k3 = true ? [] : [[1,2]];
2266 auto k4 = true ? [[[]]] : [[[1,2]]];
2267 auto k5 = true ? [[[1,2]]] : [[[]]];
2268 auto k6 = true ? [] : [[[]]];
2269 static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail
2272 /***************************************************/
2273 // https://issues.dlang.org/show_bug.cgi?id=658
2275 void test658()
2277 struct S { int i; }
2278 class C { int i; }
2280 S s;
2281 S* sp = &s;
2282 with (sp) i = 42;
2283 assert(s.i == 42);
2284 with (&s) i = 43;
2285 assert(s.i == 43);
2287 C c = new C;
2288 C* cp = &c;
2289 with (cp) i = 42;
2290 assert(c.i == 42);
2291 with (&c) i = 43;
2292 assert(c.i == 43);
2295 /***************************************************/
2297 void test3069()
2299 ubyte id = 0;
2300 void[] v = [id] ~ [id];
2303 /***************************************************/
2304 // https://issues.dlang.org/show_bug.cgi?id=4303
2306 template foo112() if (__traits(compiles,undefined))
2308 enum foo112 = false;
2311 template foo112() if (true)
2313 enum foo112 = true;
2316 pragma(msg,__traits(compiles,foo112!()));
2317 static assert(__traits(compiles,foo112!()));
2319 const bool bar112 = foo112!();
2322 /***************************************************/
2324 struct File113
2326 this(int name) { }
2328 ~this() { }
2330 void opAssign(File113 rhs) { }
2332 struct ByLine
2334 File113 file;
2336 this(int) { }
2340 ByLine byLine()
2342 return ByLine(1);
2346 auto filter113(File113.ByLine rs)
2348 struct Filter
2350 this(File113.ByLine r) { }
2353 return Filter(rs);
2356 void test113()
2358 auto f = File113(1);
2359 auto rx = f.byLine();
2360 auto file = filter113(rx);
2363 /***************************************************/
2365 template foo114(fun...)
2367 auto foo114(int[] args)
2369 return 1;
2373 pragma(msg, typeof(foo114!"a + b"([1,2,3])));
2375 /***************************************************/
2376 // https://issues.dlang.org/show_bug.cgi?id=3935
2378 struct Foo115 {
2379 void opBinary(string op)(Foo other) {
2380 pragma(msg, "op: " ~ op);
2381 assert(0);
2385 void test115()
2387 Foo115 f;
2388 f = f;
2391 /***************************************************/
2392 // https://issues.dlang.org/show_bug.cgi?id=2477
2394 void foo116(T,)(T t) { T x; }
2396 void test116()
2398 int[] data = [1,2,3,]; // OK
2400 data = [ 1,2,3, ]; // fails
2401 auto i = data[1,];
2402 foo116!(int)(3);
2403 foo116!(int,)(3);
2404 foo116!(int,)(3,);
2407 /***************************************************/
2409 void test1891()
2411 struct C {
2412 char[8] x = "helloabc";
2415 int main()
2417 C* a = new C;
2418 C*[] b;
2419 b ~= new C;
2421 auto g = a ~ b;
2422 assert(g[0] && g[1] && g[0].x == g[1].x);
2424 return 0;
2428 /***************************************************/
2429 // https://issues.dlang.org/show_bug.cgi?id=4291
2431 void test117() pure
2433 mixin declareVariable;
2434 var = 42;
2435 mixin declareFunction;
2436 readVar();
2438 template declareVariable() { int var; }
2439 template declareFunction()
2441 int readVar() { return var; }
2444 /***************************************************/
2445 // https://issues.dlang.org/show_bug.cgi?id=4177
2447 pure real log118(real x) {
2448 if (__ctfe)
2449 return 0.0;
2450 else
2451 return 1.0;
2454 enum x118 = log118(4.0);
2456 void test118() {}
2458 /***************************************************/
2460 void bug4465()
2462 const a = 2 ^^ 2;
2463 int b = a;
2466 /***************************************************/
2468 pure void foo(int *p)
2470 *p = 3;
2473 pure void test120()
2475 int i;
2476 foo(&i);
2477 assert(i == 3);
2480 /***************************************************/
2481 // https://issues.dlang.org/show_bug.cgi?id=4866
2483 immutable int[3] statik = [ 1, 2, 3 ];
2484 enum immutable(int)[] dynamic = statik;
2486 static assert(is(typeof(dynamic) == immutable(int)[]));
2487 static if (! is(typeof(dynamic) == immutable(int)[]))
2489 static assert(0); // (7)
2491 pragma(msg, "!! ", typeof(dynamic));
2493 /***************************************************/
2494 // https://issues.dlang.org/show_bug.cgi?id=2943
2496 struct Foo2943
2498 int a;
2499 int b;
2500 alias b this;
2503 void test122()
2505 Foo2943 foo, foo2;
2506 foo.a = 1;
2507 foo.b = 2;
2508 foo2.a = 3;
2509 foo2.b = 4;
2511 foo2 = foo;
2512 assert(foo2.a == foo.a);
2515 /***************************************************/
2516 // https://issues.dlang.org/show_bug.cgi?id=4641
2518 struct S123 {
2519 int i;
2520 alias i this;
2523 void test123() {
2524 S123[int] ss;
2525 ss[0] = S123.init; // This line causes Range Violation.
2528 /***************************************************/
2529 // https://issues.dlang.org/show_bug.cgi?id=2451
2531 struct Foo124 {
2532 int z = 3;
2533 void opAssign(Foo124 x) { z= 2;}
2536 struct Bar124 {
2537 int z = 3;
2538 this(this){ z = 17; }
2541 void test124() {
2542 Foo124[string] stuff;
2543 stuff["foo"] = Foo124.init;
2544 assert(stuff["foo"].z == 3);
2545 stuff["foo"] = Foo124.init;
2546 assert(stuff["foo"].z == 2);
2548 Bar124[string] stuff2;
2549 Bar124 q;
2550 stuff2["dog"] = q;
2551 assert(stuff2["dog"].z == 17);
2554 /***************************************************/
2556 void doNothing() {}
2558 void bug5071(short d, ref short c) {
2559 assert(c==0x76);
2561 void closure() {
2562 auto c2 = c;
2563 auto d2 = d;
2564 doNothing();
2566 auto useless = &closure;
2569 void test125()
2571 short c = 0x76;
2572 bug5071(7, c);
2575 /***************************************************/
2577 struct Foo126
2579 static Foo126 opCall(in Foo126 _f) pure
2581 return _f;
2585 /***************************************************/
2587 void test796()
2589 struct S { invariant() { throw new Exception(""); } }
2590 S* s;
2591 try {
2592 assert(s);
2593 } catch (Error) {
2597 /***************************************************/
2599 void test7077()
2601 if(0) mixin("auto x = 2;");
2602 auto x = 1;
2605 /***************************************************/
2607 struct Tuple127(S...)
2609 S expand;
2610 alias expand this;
2613 alias Tuple127!(int, int) Foo127;
2615 void test127()
2617 Foo127[] m_array;
2618 Foo127 f;
2619 m_array ~= f;
2622 /***************************************************/
2624 struct Bug4434 {}
2625 alias const Bug4434* IceConst4434;
2626 alias shared Bug4434* IceShared4434;
2627 alias shared Bug4434[] IceSharedArray4434;
2628 alias immutable Bug4434* IceImmutable4434;
2629 alias shared const Bug4434* IceSharedConst4434;
2631 alias int MyInt4434;
2632 alias const MyInt4434[3] IceConstInt4434;
2634 alias immutable string[] Bug4830;
2636 /***************************************************/
2637 // https://issues.dlang.org/show_bug.cgi?id=4254
2639 void bub(const inout int other) {}
2641 void test128()
2643 bub(1);
2647 /***************************************************/
2649 pure nothrow @safe auto bug4915a() { return 0; }
2650 pure nothrow @safe int bug4915b() { return bug4915a(); }
2652 void bug4915c()
2654 pure nothrow @safe int d() { return 0; }
2655 int e() pure nothrow @safe { return d(); }
2658 /***************************************************/
2659 // https://issues.dlang.org/show_bug.cgi?id=5164
2661 static if (is(int Q == int, Z...)) { }
2663 /***************************************************/
2664 // https://issues.dlang.org/show_bug.cgi?id=5195
2666 alias typeof(foo5195) food5195;
2667 const int * foo5195 = null;
2668 alias typeof(foo5195) good5195;
2669 static assert( is (food5195 == good5195));
2671 /***************************************************/
2673 version (Windows)
2676 else
2678 int[0] var5332;
2679 void test5332() { auto x = var5332; }
2682 /***************************************************/
2683 // https://issues.dlang.org/show_bug.cgi?id=5191
2685 struct Foo129
2687 void add(T)(T value) nothrow
2689 this.value += value;
2692 this(int value)
2694 this.value = value;
2697 int value;
2700 void test129()
2702 auto foo = Foo129(5);
2703 assert(foo.value == 5);
2705 foo.add(2);
2706 printf("%d\n", foo.value);
2707 assert(foo.value == 7);
2709 foo.add(3);
2710 printf("%d\n", foo.value);
2711 assert(foo.value == 10);
2713 foo.add(3);
2714 printf("%d\n", foo.value);
2715 assert(foo.value == 13);
2717 void delegate (int) nothrow dg = &foo.add!(int);
2718 dg(7);
2719 assert(foo.value == 20);
2722 /***************************************************/
2723 // https://issues.dlang.org/show_bug.cgi?id=6169
2725 auto ctfefunc6169() { return "{}"; }
2726 enum ctfefptr6169 = &ctfefunc6169;
2727 int ctfefunc6169a() { return 1; }
2728 template x6169(string c) { alias int x6169; }
2729 template TT6169(T...) { alias T TT6169; }
2730 @property ctfeprop6169() { return "g"; }
2732 void test6169() pure @safe
2734 enum a = ctfefunc6169();
2735 static b = ctfefunc6169();
2736 x6169!(ctfefunc6169()) tt;
2737 mixin(ctfefunc6169());
2738 static if(ctfefunc6169()) {}
2739 pragma(msg, ctfefunc6169());
2740 enum xx
2742 k = 0,
2743 j = ctfefunc6169a()
2745 auto g = mixin('"' ~ ctfefunc6169() ~ '"');
2746 //auto h = import("testx.d" ~ false ? ctfefunc() : "");
2747 alias TT6169!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i;
2748 alias TT6169!(int, int)[ctfefunc6169a()] j;
2749 int[ctfefunc6169a()+1] k;
2750 alias int[ctfefunc6169a()] l;
2751 switch(1)
2753 //case ctfefunc6169a(): // Can't do this because of case variables
2754 case ctfefunc6169a()+1:
2756 case ctfefunc6169a()+2:
2757 default:
2758 break;
2760 static assert(ctfefunc6169a());
2761 void fun(int i : ctfefunc6169a() = ctfefunc6169a(), alias j)() if (ctfefunc6169a()) {}
2762 fun!(ctfefunc6169a(), ctfefunc6169())();
2763 enum z = ctfefptr6169();
2765 auto p = mixin(ctfeprop6169);
2768 /***************************************************/
2769 // https://issues.dlang.org/show_bug.cgi?id=10506
2771 void impureFunc10506() {}
2772 string join10506(RoR)(RoR ror)
2774 impureFunc10506();
2775 return ror[0] ~ ror[1];
2778 void test10506() pure
2780 void foobar() {}
2782 mixin(["foo", "bar"].join10506()~";");
2785 /***************************************************/
2787 const shared class C5107
2789 int x;
2792 static assert(is(typeof(C5107.x) == const)); // okay
2793 static assert(is(typeof(C5107.x) == shared)); // fails!
2795 /***************************************************/
2797 immutable struct S3598
2799 static void funkcja() { }
2802 /***************************************************/
2803 // https://issues.dlang.org/show_bug.cgi?id=4211
2805 @safe struct X130
2807 void func() { }
2810 @safe class Y130
2812 void func() { }
2815 @safe void test130()
2817 X130 x;
2818 x.func();
2819 auto y = new Y130;
2820 y.func();
2823 /***************************************************/
2825 template Return(alias fun)
2827 static if (is(typeof(fun) R == return)) alias R Return;
2830 interface I4217
2832 int square(int n);
2833 real square(real n);
2835 alias Return!( __traits(getOverloads, I4217, "square")[0] ) R4217;
2836 alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217;
2838 static assert(! is(R4217 == S4217));
2840 /***************************************************/
2841 // https://issues.dlang.org/show_bug.cgi?id=5094
2843 void test131()
2845 S131 s;
2846 int[] conv = s;
2849 struct S131
2851 @property int[] get() { return [1,2,3]; }
2852 alias get this;
2855 /***************************************************/
2857 struct S7545
2859 uint id;
2860 alias id this;
2863 void test7545()
2865 auto id = 0 ? S7545() : -1;
2868 /***************************************************/
2869 // https://issues.dlang.org/show_bug.cgi?id=5020
2871 void test132()
2873 S132 s;
2874 if (!s) {}
2877 struct S132
2879 bool cond;
2880 alias cond this;
2883 /***************************************************/
2884 // https://issues.dlang.org/show_bug.cgi?id=5343
2886 struct Tuple5343(Specs...)
2888 Specs[0] field;
2891 struct S5343(E)
2893 immutable E x;
2895 enum A5343{a,b,c}
2896 alias Tuple5343!(A5343) TA5343;
2897 alias S5343!(A5343) SA5343;
2899 /***************************************************/
2900 // https://issues.dlang.org/show_bug.cgi?id=5365
2902 interface IFactory
2904 void foo();
2907 class A133
2909 protected static class Factory : IFactory
2911 void foo()
2916 this()
2918 _factory = createFactory();
2921 protected IFactory createFactory()
2923 return new Factory;
2926 private IFactory _factory;
2927 @property final IFactory factory()
2929 return _factory;
2932 alias factory this;
2935 void test133()
2938 IFactory f = new A133;
2939 f.foo(); // segfault
2942 /***************************************************/
2943 // https://issues.dlang.org/show_bug.cgi?id=5365
2945 class B134
2949 class A134
2952 B134 _b;
2954 this()
2956 _b = new B134;
2959 B134 b()
2961 return _b;
2964 alias b this;
2967 void test134()
2970 auto a = new A134;
2971 B134 b = a; // b is null
2972 assert(a._b is b); // fails
2975 /***************************************************/
2976 // https://issues.dlang.org/show_bug.cgi?id=5025
2978 struct S135 {
2979 void delegate() d;
2982 void test135()
2984 shared S135[] s;
2985 if (0)
2986 s[0] = S135();
2989 /***************************************************/
2990 // https://issues.dlang.org/show_bug.cgi?id=5545
2992 bool enforce136(bool value, lazy const(char)[] msg = null) {
2993 if(!value) {
2994 return false;
2997 return value;
3000 struct Perm {
3001 byte[3] perm;
3002 ubyte i;
3004 this(byte[] input) {
3005 foreach(elem; input) {
3006 enforce136(i < 3);
3007 perm[i++] = elem;
3008 printf("%d\n", i); // Never gets incremented. Stays at 0.
3013 void test136() {
3014 byte[] stuff = [0, 1, 2];
3015 auto perm2 = Perm(stuff);
3016 //writeln(perm2.perm); // Prints [2, 0, 0]
3017 assert(perm2.perm[] == [0, 1, 2]);
3020 /***************************************************/
3021 // https://issues.dlang.org/show_bug.cgi?id=4097
3023 void foo4097() { }
3024 alias typeof(&foo4097) T4097;
3025 static assert(is(T4097 X : X*) && is(X == function));
3027 static assert(!is(X));
3029 /***************************************************/
3030 // https://issues.dlang.org/show_bug.cgi?id=5798
3032 void assign9(ref int lhs) pure {
3033 lhs = 9;
3036 void assign8(ref int rhs) pure {
3037 rhs = 8;
3040 int test137(){
3041 int a=1,b=2;
3042 assign8(b),assign9(a);
3043 assert(a == 9);
3044 assert(b == 8); // <-- fail
3046 assign9(b),assign8(a);
3047 assert(a == 8);
3048 assert(b == 9); // <-- fail
3050 return 0;
3053 /***************************************************/
3055 // https://issues.dlang.org/show_bug.cgi?id=9366
3056 static assert(!is(typeof((void[]).init ~ cast(void)0)));
3057 static assert(!is(typeof(cast(void)0 ~ (void[]).init)));
3059 /***************************************************/
3061 struct Size138
3063 union
3065 struct
3067 int width;
3068 int height;
3071 long size;
3075 enum Size138 foo138 = {2 ,5};
3077 Size138 bar138 = foo138;
3079 void test138()
3081 assert(bar138.width == 2);
3082 assert(bar138.height == 5);
3085 /***************************************************/
3087 void test3822()
3089 import core.stdc.stdlib;
3090 int i = 0;
3091 void* ptr;
3092 while(i++ != 2)
3094 auto p = alloca(2);
3095 assert(p != ptr);
3096 ptr = p;
3100 /***************************************************/
3102 // https://issues.dlang.org/show_bug.cgi?id=5939
3103 // https://issues.dlang.org/show_bug.cgi?id=5940
3105 template map(fun...)
3107 auto map(double[] r)
3109 struct Result
3111 this(double[] input)
3116 return Result(r);
3121 void test139()
3123 double[] x;
3124 alias typeof(map!"a"(x)) T;
3125 T a = void;
3126 auto b = map!"a"(x);
3127 auto c = [map!"a"(x)];
3128 T[3] d = void;
3132 /***************************************************/
3133 // https://issues.dlang.org/show_bug.cgi?id=5966
3135 string[] foo5966(string[] a)
3137 a[0] = a[0][0..$];
3138 return a;
3141 enum var5966 = foo5966([""]);
3143 /***************************************************/
3144 // https://issues.dlang.org/show_bug.cgi?id=5975
3146 int foo5975(wstring replace)
3148 wstring value = "";
3149 value ~= replace;
3150 return 1;
3153 enum X5975 = foo5975("X"w);
3155 /***************************************************/
3156 // https://issues.dlang.org/show_bug.cgi?id=5965
3158 template mapx(fun...) if (fun.length >= 1)
3160 int mapx(Range)(Range r)
3162 return 1;
3166 void test140()
3168 int foo(int i) { return i; }
3170 int[] arr;
3171 auto x = mapx!( (int a){return foo(a);} )(arr);
3174 /***************************************************/
3176 void bug5976()
3178 int[] barr;
3179 int * k;
3180 foreach (ref b; barr)
3182 scope(failure)
3183 k = &b;
3184 k = &b;
3188 /***************************************************/
3189 // https://issues.dlang.org/show_bug.cgi?id=5771
3191 struct S141
3193 this(A)(auto ref A a){}
3196 void test141()
3198 S141 s = S141(10);
3201 /***************************************************/
3203 class test5498_A {}
3204 class test5498_B : test5498_A {}
3205 class test5498_C : test5498_A {}
3207 static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[]));
3209 /***************************************************/
3210 // https://issues.dlang.org/show_bug.cgi?id=3688
3212 struct S142
3214 int v;
3215 this(int n) pure { v = n; }
3216 const bool opCast(T:bool)() { return true; }
3219 void test142()
3221 if (int a = 1)
3222 assert(a == 1);
3223 else assert(0);
3225 if (const int a = 2)
3226 assert(a == 2);
3227 else assert(0);
3229 if (immutable int a = 3)
3230 assert(a == 3);
3231 else assert(0);
3233 if (auto s = S142(10))
3234 assert(s.v == 10);
3235 else assert(0);
3237 if (auto s = const(S142)(20))
3238 assert(s.v == 20);
3239 else assert(0);
3241 if (auto s = immutable(S142)(30))
3242 assert(s.v == 30);
3243 else assert(0);
3246 /***************************************************/
3247 // https://issues.dlang.org/show_bug.cgi?id=6072
3249 static assert({
3250 if (int x = 5) {}
3251 return true;
3252 }());
3254 /***************************************************/
3255 // https://issues.dlang.org/show_bug.cgi?id=5959
3257 int n;
3259 void test143()
3261 ref int f(){ return n; } // NG
3262 f() = 1;
3263 assert(n == 1);
3265 nothrow ref int f1(){ return n; } // OK
3266 f1() = 2;
3267 assert(n == 2);
3269 auto ref int f2(){ return n; } // OK
3270 f2() = 3;
3271 assert(n == 3);
3274 /***************************************************/
3275 // https://issues.dlang.org/show_bug.cgi?id=6119
3277 void startsWith(alias pred) () if (is(typeof(pred('c', 'd')) : bool))
3281 void startsWith(alias pred) () if (is(typeof(pred('c', "abc")) : bool))
3285 void test144()
3287 startsWith!((a, b) { return a == b; })();
3290 /***************************************************/
3292 void test145()
3294 import core.stdc.stdio;
3295 printf("hello world 145\n");
3298 void test146()
3300 test1();
3301 static import core.stdc.stdio;
3302 core.stdc.stdio.printf("hello world 146\n");
3305 /***************************************************/
3306 // https://issues.dlang.org/show_bug.cgi?id=5856
3308 struct X147
3310 void f() { printf("X.f mutable\n"); }
3311 void f() const { printf("X.f const\n"); }
3313 void g()() { printf("X.g mutable\n"); }
3314 void g()() const { printf("X.g const\n"); }
3316 void opOpAssign(string op)(int n) { printf("X+= mutable\n"); }
3317 void opOpAssign(string op)(int n) const { printf("X+= const\n"); }
3320 void test147()
3322 X147 xm;
3323 xm.f(); // prints "X.f mutable"
3324 xm.g(); // prints "X.g mutable"
3325 xm += 10; // should print "X+= mutable" (1)
3327 const(X147) xc;
3328 xc.f(); // prints "X.f const"
3329 xc.g(); // prints "X.g const"
3330 xc += 10; // should print "X+= const" (2)
3334 /***************************************************/
3336 void test3559()
3338 static class A
3340 int foo(int a) { return 0; }
3341 int foo(float a) { return 1; }
3343 int bar(float a) { return 1; }
3344 int bar(int a) { return 0; }
3347 static class B : A
3349 override int foo(float a) { return 2; }
3350 alias A.foo foo;
3352 alias A.bar bar;
3353 override int bar(float a) { return 2; }
3357 auto x = new A;
3358 auto f1 = cast(int delegate(int))&x.foo;
3359 auto f2 = cast(int delegate(float))&x.foo;
3360 int delegate(int) f3 = &x.foo;
3361 int delegate(float) f4 = &x.foo;
3363 assert(f1(0) == 0);
3364 assert(f2(0) == 1);
3365 assert(f3(0) == 0);
3366 assert(f4(0) == 1);
3370 auto x = new B;
3371 auto f1 = cast(int delegate(int))&x.foo;
3372 auto f2 = cast(int delegate(float))&x.foo;
3373 int delegate(int) f3 = &x.foo;
3374 int delegate(float) f4 = &x.foo;
3376 assert(f1(0) == 0);
3377 assert(f2(0) == 2);
3378 assert(f3(0) == 0);
3379 assert(f4(0) == 2);
3383 auto x = new A;
3384 auto f1 = cast(int delegate(int))&x.bar;
3385 auto f2 = cast(int delegate(float))&x.bar;
3386 int delegate(int) f3 = &x.bar;
3387 int delegate(float) f4 = &x.bar;
3389 assert(f1(0) == 0);
3390 assert(f2(0) == 1);
3391 assert(f3(0) == 0);
3392 assert(f4(0) == 1);
3396 auto x = new B;
3397 auto f1 = cast(int delegate(int))&x.bar;
3398 auto f2 = cast(int delegate(float))&x.bar;
3399 int delegate(int) f3 = &x.bar;
3400 int delegate(float) f4 = &x.bar;
3402 assert(f1(0) == 0);
3403 assert(f2(0) == 2);
3404 assert(f3(0) == 0);
3405 assert(f4(0) == 2);
3409 /***************************************************/
3411 extern(C++)
3412 class C13182
3416 void test13182()
3418 scope C13182 c = new C13182();
3421 /***************************************************/
3422 // https://issues.dlang.org/show_bug.cgi?id=5897
3424 struct A148{ int n; }
3425 struct B148{
3426 int n, m;
3427 this(A148 a){ n = a.n, m = a.n*2; }
3430 struct C148{
3431 int n, m;
3432 static C148 opCall(A148 a)
3434 C148 b;
3435 b.n = a.n, b.m = a.n*2;
3436 return b;
3440 void test148()
3442 auto a = A148(10);
3443 auto b = cast(B148)a;
3444 assert(b.n == 10 && b.m == 20);
3445 auto c = cast(C148)a;
3446 assert(c.n == 10 && c.m == 20);
3449 /***************************************************/
3450 // https://issues.dlang.org/show_bug.cgi?id=4969
3452 class MyException : Exception
3454 this()
3456 super("An exception!");
3460 void throwAway()
3462 throw new MyException;
3465 void cantthrow() nothrow
3468 throwAway();
3469 catch(MyException me)
3470 assert(0);
3471 catch(Exception e)
3472 assert(0);
3475 /***************************************************/
3476 // https://issues.dlang.org/show_bug.cgi?id=2356
3478 void test2356()
3480 int[3] x = [1,2,3];
3481 printf("x[] = [%d %d %d]\n", x[0], x[1], x[2]);
3482 assert(x[0] == 1 && x[1] == 2 && x[2] == 3);
3484 struct S
3486 static int pblit;
3487 int n;
3488 this(this) { ++pblit; printf("postblit: %d\n", n); }
3490 S s2 = S(2);
3491 S[3] s = [S(1), s2, S(3)];
3492 assert(s[0].n == 1 && s[1].n == 2 && s[2].n == 3);
3493 printf("s[].n = [%d %d %d]\n", s[0].n, s[1].n, s[2].n);
3494 assert(S.pblit == 1);
3496 ubyte[1024] v;
3497 v = typeof(v).init;
3498 printf("v[] = [%d %d %d, ..., %d]\n", v[0], v[1], v[2], v[$-1]);
3499 foreach (ref a; v) assert(a == 0);
3501 int n = 5;
3502 int[3] y = [n, n, n];
3503 printf("y[] = [%d %d %d]\n", y[0], y[1], y[2]);
3504 assert(y[0] == 5 && y[1] == 5 && y[2] == 5);
3506 S[3] z = [s2, s2, s2];
3507 assert(z[0].n == 2 && z[1].n == 2 && z[2].n == 2);
3508 printf("z[].n = [%d %d %d]\n", z[0].n, z[1].n, z[2].n);
3509 assert(S.pblit == 1 + 3);
3511 int[0] nsa0 = [];
3512 void[0] vsa0 = [];
3514 void foo(T)(T){}
3515 foo(vsa0);
3517 ref int[0] bar() { static int[1] sa; return *cast(int[0]*)&sa; }
3518 bar() = [];
3521 /***************************************************/
3522 // https://issues.dlang.org/show_bug.cgi?id=13652
3524 void test13652()
3526 // reduced case
3527 uint[9][5] arr =
3528 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3529 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3530 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3531 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3532 [9, 7, 0, 0, 0, 0, 0, 8, 3]];
3533 assert(arr[0][0] == 0 && arr[0][1] == 0 && arr[0][2] == 0 &&
3534 arr[0][3] == 0 && arr[0][4] == 1 && arr[0][5] == 5 &&
3535 arr[0][6] == 8 && arr[0][7] == 0 && arr[0][8] == 7);
3536 assert(arr[1][0] == 0 && arr[1][1] == 3 && arr[1][2] == 8 &&
3537 arr[1][3] == 0 && arr[1][4] == 2 && arr[1][5] == 0 &&
3538 arr[1][6] == 0 && arr[1][7] == 6 && arr[1][8] == 0);
3539 assert(arr[2][0] == 0 && arr[2][1] == 0 && arr[2][2] == 7 &&
3540 arr[2][3] == 0 && arr[2][4] == 6 && arr[2][5] == 8 &&
3541 arr[2][6] == 9 && arr[2][7] == 4 && arr[2][8] == 0);
3542 assert(arr[3][0] == 0 && arr[3][1] == 0 && arr[3][2] == 0 &&
3543 arr[3][3] == 0 && arr[3][4] == 0 && arr[3][5] == 1 &&
3544 arr[3][6] == 2 && arr[3][7] == 9 && arr[3][8] == 0);
3545 assert(arr[4][0] == 9 && arr[4][1] == 7 && arr[4][2] == 0 &&
3546 arr[4][3] == 0 && arr[4][4] == 0 && arr[4][5] == 0 &&
3547 arr[4][6] == 0 && arr[4][7] == 8 && arr[4][8] == 3);
3549 // original case
3550 uint[9][9] tbl =
3551 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3552 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3553 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3554 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3555 [9, 7, 0, 0, 0, 0, 0, 8, 3],
3556 [0, 2, 1, 6, 0, 0, 0, 0, 0],
3557 [0, 6, 9, 5, 4, 0, 3, 0, 0],
3558 [0, 4, 0, 0, 8, 0, 6, 5, 0],
3559 [2, 0, 5, 9, 3, 0, 0, 0, 0]];
3560 assert(tbl[0][0] == 0 && tbl[0][1] == 0 && tbl[0][2] == 0 &&
3561 tbl[0][3] == 0 && tbl[0][4] == 1 && tbl[0][5] == 5 &&
3562 tbl[0][6] == 8 && tbl[0][7] == 0 && tbl[0][8] == 7);
3563 assert(tbl[1][0] == 0 && tbl[1][1] == 3 && tbl[1][2] == 8 &&
3564 tbl[1][3] == 0 && tbl[1][4] == 2 && tbl[1][5] == 0 &&
3565 tbl[1][6] == 0 && tbl[1][7] == 6 && tbl[1][8] == 0);
3566 assert(tbl[2][0] == 0 && tbl[2][1] == 0 && tbl[2][2] == 7 &&
3567 tbl[2][3] == 0 && tbl[2][4] == 6 && tbl[2][5] == 8 &&
3568 tbl[2][6] == 9 && tbl[2][7] == 4 && tbl[2][8] == 0);
3569 assert(tbl[3][0] == 0 && tbl[3][1] == 0 && tbl[3][2] == 0 &&
3570 tbl[3][3] == 0 && tbl[3][4] == 0 && tbl[3][5] == 1 &&
3571 tbl[3][6] == 2 && tbl[3][7] == 9 && tbl[3][8] == 0);
3572 assert(tbl[4][0] == 9 && tbl[4][1] == 7 && tbl[4][2] == 0 &&
3573 tbl[4][3] == 0 && tbl[4][4] == 0 && tbl[4][5] == 0 &&
3574 tbl[4][6] == 0 && tbl[4][7] == 8 && tbl[4][8] == 3);
3575 assert(tbl[5][0] == 0 && tbl[5][1] == 2 && tbl[5][2] == 1 &&
3576 tbl[5][3] == 6 && tbl[5][4] == 0 && tbl[5][5] == 0 &&
3577 tbl[5][6] == 0 && tbl[5][7] == 0 && tbl[5][8] == 0);
3578 assert(tbl[6][0] == 0 && tbl[6][1] == 6 && tbl[6][2] == 9 &&
3579 tbl[6][3] == 5 && tbl[6][4] == 4 && tbl[6][5] == 0 &&
3580 tbl[6][6] == 3 && tbl[6][7] == 0 && tbl[6][8] == 0);
3581 assert(tbl[7][0] == 0 && tbl[7][1] == 4 && tbl[7][2] == 0 &&
3582 tbl[7][3] == 0 && tbl[7][4] == 8 && tbl[7][5] == 0 &&
3583 tbl[7][6] == 6 && tbl[7][7] == 5 && tbl[7][8] == 0);
3584 assert(tbl[8][0] == 2 && tbl[8][1] == 0 && tbl[8][2] == 5 &&
3585 tbl[8][3] == 9 && tbl[8][4] == 3 && tbl[8][5] == 0 &&
3586 tbl[8][6] == 0 && tbl[8][6] == 0 && tbl[8][8] == 0);
3589 /***************************************************/
3590 // https://issues.dlang.org/show_bug.cgi?id=11238
3592 void test11238()
3594 int[2] m;
3595 m[0] = 4,m[1] = 6;
3596 //printf("%d,%d\n", m[0], m[1]);
3597 assert(m[0] == 4 && m[1] == 6);
3599 m = [m[1], m[0]]; // swap
3600 assert(m[0] == 6 && m[1] == 4);
3601 //printf("%d,%d\n", m[0], m[1]);
3603 m = [m[1], m[0]]; // swap
3604 //printf("%d,%d\n", m[0], m[1]);
3605 assert(m[0] == 4 && m[1] == 6);
3608 /***************************************************/
3610 void test11805()
3612 int i;
3614 i = 47;
3615 i = 1 && i;
3616 assert(i == 1);
3617 i = 0 || i;
3618 assert(i == 1);
3621 /***************************************************/
3623 class A2540
3625 int a;
3626 int foo() { return 0; }
3627 alias int X;
3630 class B2540 : A2540
3632 int b;
3633 override typeof(super).X foo() { return 1; }
3635 alias typeof(this) athis;
3636 alias typeof(this).b thisb;
3637 alias typeof(super).a supera;
3638 alias typeof(super).foo superfoo;
3639 alias typeof(this).foo thisfoo;
3642 struct X2540
3644 alias typeof(this) athis;
3647 void test2540()
3649 auto x = X2540.athis.init;
3650 static assert(is(typeof(x) == X2540));
3652 B2540 b = new B2540();
3654 assert(&b.a == &b.supera);
3655 assert(&b.b == &b.thisb);
3656 assert(b.thisfoo() == 1);
3659 /***************************************************/
3661 class B14348
3663 int foo() { return 0; }
3666 class C14348 : B14348
3668 override int foo() { return 1; }
3670 alias superfoo = typeof(super).foo;
3671 alias thisfoo = typeof(this).foo;
3674 B14348 test14348()
3676 alias foo = typeof(return).foo; // currently doesn't work.
3677 assert(&B14348.foo is &C14348.superfoo);
3678 assert(&C14348.foo is &C14348.thisfoo);
3679 return null;
3682 /***************************************************/
3683 // https://issues.dlang.org/show_bug.cgi?id=7295
3685 struct S7295
3687 int member;
3688 @property ref int refCountedPayload() return { return member; }
3689 alias refCountedPayload this;
3692 void foo7295(S)(immutable S t, int qq) pure { }
3693 void foo7295(S)(S s) pure { }
3695 void bar7295() pure
3697 S7295 b;
3698 foo7295(b);
3701 /***************************************************/
3702 // https://issues.dlang.org/show_bug.cgi?id=5659
3704 void test149()
3706 char a;
3707 immutable(char) b;
3709 static assert(is(typeof(true ? a : b) == const(char)));
3710 static assert(is(typeof([a, b][0]) == const(char)));
3714 /***************************************************/
3715 // https://issues.dlang.org/show_bug.cgi?id=1373
3717 void func1373a(){}
3719 static assert(typeof(func1373a).stringof == "void()");
3720 static assert(typeof(func1373a).mangleof == "FZv");
3721 static assert(!__traits(compiles, typeof(func1373a).alignof));
3722 static assert(!__traits(compiles, typeof(func1373a).init));
3723 static assert(!__traits(compiles, typeof(func1373a).offsetof));
3725 void func1373b(int n){}
3727 static assert(typeof(func1373b).stringof == "void(int n)");
3728 static assert(typeof(func1373b).mangleof == "FiZv");
3729 static assert(!__traits(compiles, typeof(func1373b).alignof));
3730 static assert(!__traits(compiles, typeof(func1373b).init));
3731 static assert(!__traits(compiles, typeof(func1373b).offsetof));
3733 /***************************************************/
3735 void bar150(T)(T n) { }
3737 @safe void test150()
3739 bar150(1);
3742 /***************************************************/
3744 void test5785()
3746 static struct x { static int y; }
3747 assert(x.y !is 1);
3748 assert(x.y !in [1:0]);
3751 /***************************************************/
3753 void bar151(T)(T n) { }
3755 nothrow void test151()
3757 bar151(1);
3760 /***************************************************/
3762 @property int coo() { return 1; }
3763 @property auto doo(int i) { return i; }
3765 @property int eoo() { return 1; }
3766 @property auto ref hoo(int i) { return i; }
3768 // https://issues.dlang.org/show_bug.cgi?id=3359
3770 int goo(int i) pure { return i; }
3771 auto ioo(int i) pure { return i; }
3772 auto ref boo(int i) pure nothrow { return i; }
3774 class A152 {
3775 auto hoo(int i) pure { return i; }
3776 const boo(int i) nothrow { return i; }
3777 auto coo(int i) const { return i; }
3778 auto doo(int i) immutable { return i; }
3779 auto eoo(int i) shared { return i; }
3782 // https://issues.dlang.org/show_bug.cgi?id=4706
3784 struct Foo152(T) {
3785 @property auto ref front() {
3786 return T.init;
3789 @property void front(T num) {}
3792 void test152() {
3793 Foo152!int foo;
3794 auto a = foo.front;
3795 foo.front = 2;
3798 /***************************************************/
3799 // https://issues.dlang.org/show_bug.cgi?id=6733
3801 void bug6733(int a, int b) pure nothrow { }
3802 void test6733() {
3803 int z = 1;
3804 bug6733(z++, z++);
3805 assert(z==3);
3808 /***************************************************/
3809 // https://issues.dlang.org/show_bug.cgi?id=3799
3811 void test153()
3813 void bar()
3817 static assert(!__traits(isStaticFunction, bar));
3820 /***************************************************/
3821 // https://issues.dlang.org/show_bug.cgi?id=3632
3823 void test154()
3825 float f;
3826 assert(f is float.init);
3827 double d;
3828 assert(d is double.init);
3829 real r;
3830 assert(r is real.init);
3832 assert(float.nan is float.nan);
3833 assert(double.nan is double.nan);
3834 assert(real.nan is real.nan);
3837 /***************************************************/
3839 __gshared int global3632 = 1;
3841 void test3632()
3843 int test(T)()
3845 static struct W
3847 T f;
3848 this(T g) { if (__ctfe || global3632) f = g; }
3850 auto nan = W(T.nan);
3851 auto nan2 = W(T.nan);
3852 auto init = W(T.init);
3853 auto init2 = W(T.init);
3854 auto zero = W(cast(T)0);
3855 auto zero2 = W(cast(T)0);
3856 auto nzero2 = W(-cast(T)0);
3858 // Struct equality
3859 assert(!(nan == nan2));
3860 assert(!(nan == init2));
3861 assert(!(init == init2));
3862 assert( (zero == zero2));
3863 assert( (zero == nzero2));
3865 // Float equality
3866 assert(!(nan.f == nan2.f));
3867 assert(!(nan.f == init2.f));
3868 assert(!(init.f == init2.f));
3869 assert( (zero.f == zero2.f));
3870 assert( (zero.f == nzero2.f));
3872 // Struct identity
3873 assert( (nan is nan2));
3874 assert( (nan is init2));
3875 assert( (init is init2));
3876 assert( (zero is zero2));
3877 assert(!(zero is nzero2));
3879 // Float identity
3880 assert( (nan.f is nan2.f));
3881 assert( (nan.f is init2.f));
3882 assert( (init.f is init2.f));
3883 assert( (zero.f is zero2.f));
3884 assert(!(zero.f is nzero2.f));
3886 // Struct !identity
3887 assert(!(nan !is nan2));
3888 assert( (nan is init2));
3889 assert(!(init !is init2));
3890 assert(!(zero !is zero2));
3891 assert( (zero !is nzero2));
3893 // float !identity
3894 assert(!(nan.f !is nan2.f));
3895 assert( (nan.f is init2.f));
3896 assert(!(init.f !is init2.f));
3897 assert(!(zero.f !is zero2.f));
3898 assert( (zero.f !is nzero2.f));
3900 // .init identity
3901 assert(W.init is W.init);
3903 return 1;
3906 auto rtF = test!float();
3907 enum ctF = test!float();
3908 auto rtD = test!double();
3909 enum ctD = test!double();
3910 auto rtR = test!real();
3911 enum ctR = test!real();
3913 assert(float.nan !is -float.nan);
3914 assert(double.nan !is -double.nan);
3915 assert(real.nan !is -real.nan);
3918 /***************************************************/
3920 void test6545()
3922 static int[] func()
3924 auto a = [1, 2, 3];
3925 auto b = [2, 3, 4];
3926 auto c = [3, 4, 5];
3928 a[] = b[] + c[];
3930 return a;
3933 auto a = func();
3934 enum b = func();
3935 assert(a == b);
3938 /***************************************************/
3939 // https://issues.dlang.org/show_bug.cgi?id=3147
3942 void test155()
3944 byte b = 1;
3945 short s;
3946 int i;
3947 long l;
3949 s = b + b;
3950 b = s % b;
3951 s = s >> b;
3952 b = 1;
3953 b = i % b;
3954 b = b >> i;
3957 /***************************************************/
3958 // https://issues.dlang.org/show_bug.cgi?id=2486
3960 void test2486()
3962 void foo(ref int[] arr) {}
3964 int[] arr = [1,2,3];
3965 foo(arr); //OK
3966 static assert(__traits(compiles, foo(arr[1..2])));
3968 struct S
3970 int[] a;
3971 auto ref opSlice(){ return a[]; } // line 4
3973 S s;
3974 s[];
3975 // opSlice should return rvalue
3976 static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe));
3977 static assert(__traits(compiles, foo(s[])));
3980 /***************************************************/
3982 extern(C++) class C15080
3984 uint x = 1;
3985 uint y = 2;
3988 __gshared c15080 = new C15080();
3990 void test15080()
3992 assert(c15080.x == 1);
3993 assert(c15080.y == 2);
3996 /***************************************************/
3997 // https://issues.dlang.org/show_bug.cgi?id=2521
3999 immutable int val = 23;
4000 const int val2 = 23;
4002 ref immutable(int) func2521_() {
4003 return val;
4005 ref immutable(int) func2521_2() {
4006 return *&val;
4008 ref immutable(int) func2521_3() {
4009 return func2521_;
4011 ref const(int) func2521_4() {
4012 return val2;
4014 ref const(int) func2521_5() {
4015 return val;
4017 auto ref func2521_6() {
4018 return val;
4020 ref func2521_7() {
4021 return val;
4024 /***************************************************/
4026 void test5554()
4028 class MA { }
4029 class MB : MA { }
4030 class MC : MB { }
4032 class A { abstract MA foo(); }
4033 interface I { MB foo(); }
4034 class B : A
4036 override MC foo() { return null; }
4038 class C : B, I
4040 override MC foo() { return null; }
4044 /***************************************************/
4045 // https://issues.dlang.org/show_bug.cgi?id=5962
4047 struct S156
4049 auto g()(){ return 1; }
4050 const auto g()(){ return 2; }
4053 void test156()
4055 auto ms = S156();
4056 assert(ms.g() == 1);
4057 auto cs = const(S156)();
4058 assert(cs.g() == 2);
4061 /***************************************************/
4063 void test10724()
4065 const(char)* s = "abc"[0..$-1];
4066 assert(s[2] == '\0');
4069 /***************************************************/
4071 void test6708(const ref int y)
4073 immutable int x;
4074 test6708(x);
4077 /***************************************************/
4078 // https://issues.dlang.org/show_bug.cgi?id=4258
4080 struct Vec4258 {
4081 Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") {
4082 return this;
4084 Vec4258 opBinary(string Op:"+")(Vec4258 other) {
4085 Vec4258 result;
4086 return result += other;
4089 void test4258() {
4090 Vec4258 v;
4091 v += Vec4258() + Vec4258(); // line 12
4094 // regression fix test
4096 struct Foo4258 {
4097 // binary ++/--
4098 int opPostInc()() if (false) { return 0; }
4100 // binary 1st
4101 int opAdd(R)(R rhs) if (false) { return 0; }
4102 int opAdd_r(R)(R rhs) if (false) { return 0; }
4104 // compare
4105 int opCmp(R)(R rhs) if (false) { return 0; }
4107 // binary-op assign
4108 int opAddAssign(R)(R rhs) if (false) { return 0; }
4110 struct Bar4258 {
4111 // binary commutive 1
4112 int opAdd_r(R)(R rhs) if (false) { return 0; }
4114 // binary-op assign
4115 int opOpAssign(string op, R)(R rhs) if (false) { return 0; }
4117 struct Baz4258 {
4118 // binary commutive 2
4119 int opAdd(R)(R rhs) if (false) { return 0; }
4121 static assert(!is(typeof(Foo4258.init++)));
4122 static assert(!is(typeof(Foo4258.init + 1)));
4123 static assert(!is(typeof(1 + Foo4258.init)));
4124 static assert(!is(typeof(Foo4258.init < Foo4258.init)));
4125 static assert(!is(typeof(Foo4258.init += 1)));
4126 static assert(!is(typeof(Bar4258.init + 1)));
4127 static assert(!is(typeof(Bar4258.init += 1)));
4128 static assert(!is(typeof(1 + Baz4258.init)));
4130 /***************************************************/
4131 // https://issues.dlang.org/show_bug.cgi?id=4539
4133 void test4539()
4135 static assert(!__traits(compiles, "hello" = "red"));
4137 void foo1(ref string s){}
4138 void foo2(ref const char[10] s){}
4139 void foo3(ref char[5] s){}
4141 void foo4(ref const char[5] s)
4143 assert(s[0] == 'h');
4144 assert(s[4] == 'o');
4146 void foo5(ref const ubyte[5] s)
4148 assert(s[0] == 0xc3);
4149 assert(s[4] == 0x61);
4152 static assert(__traits(compiles, foo1("hello")));
4153 static assert(!__traits(compiles, foo2("hello")));
4154 static assert(!__traits(compiles, foo3("hello")));
4156 // same as test68, 69, 70
4157 foo4("hello");
4158 foo5(cast(ubyte[5])"\xc3\xfc\xd3\xd7\x61");
4160 //import std.conv;
4161 //static assert(!__traits(compiles, parse!int("10") == 10));
4164 /***************************************************/
4165 // https://issues.dlang.org/show_bug.cgi?id=1471
4167 void test1471()
4169 int n;
4170 string bar = "BOOM"[n..$-1];
4171 assert(bar == "BOO");
4174 /***************************************************/
4176 deprecated @disable int bug6389;
4177 static assert(!is(typeof(bug6389 = bug6389)));
4179 /***************************************************/
4181 void test4963()
4183 struct Value {
4184 byte a;
4186 Value single()
4188 return Value();
4191 Value[] list;
4192 auto x = single() ~ list;
4195 /***************************************************/
4197 pure int test4031()
4199 static const int x = 8;
4200 return x;
4203 /***************************************************/
4204 // https://issues.dlang.org/show_bug.cgi?id=5437
4206 template EnumMembers5437(E)
4208 template TypeTuple(T...){ alias T TypeTuple; }
4210 alias TypeTuple!("A", "B") EnumMembers5437;
4212 template IntValue5437()
4214 int IntValue5437 = 10;
4217 void test5437()
4219 enum Foo { A, B }
4220 alias EnumMembers5437!Foo members; // OK
4221 enum n1 = members.length; // OK
4222 enum n2 = (EnumMembers5437!Foo).length; // NG, type -> symbol
4224 enum s1 = IntValue5437!().sizeof; // OK
4225 enum s2 = (IntValue5437!()).sizeof; // NG, type -> expression
4228 /***************************************************/
4229 // https://issues.dlang.org/show_bug.cgi?id=1962
4232 void test1962()
4234 class C { abstract void x(); }
4235 assert(C.classinfo.create() is null);
4238 /***************************************************/
4239 // https://issues.dlang.org/show_bug.cgi?id=6228
4241 void test6228()
4243 int val;
4244 const(int)* ptr = &val;
4245 const(int) temp;
4246 auto x = (*ptr) ^^ temp;
4249 /***************************************************/
4251 int test7544()
4253 try { throw new Exception(""); }
4254 catch (Exception e) static assert(1);
4255 return 1;
4258 static assert(test7544());
4260 /***************************************************/
4262 struct S6230 {
4263 int p;
4264 int q() const pure {
4265 return p;
4267 void r() pure {
4268 p = 231;
4271 class C6230 {
4272 int p;
4273 int q() const pure {
4274 return p;
4276 void r() pure {
4277 p = 552;
4280 int q6230(ref const S6230 s) pure { // <-- Currently OK
4281 return s.p;
4283 int q6230(ref const C6230 c) pure { // <-- Currently OK
4284 return c.p;
4286 void r6230(ref S6230 s) pure {
4287 s.p = 244;
4289 void r6230(ref C6230 c) pure {
4290 c.p = 156;
4292 bool test6230pure() pure {
4293 auto s = S6230(4);
4294 assert(s.p == 4);
4295 assert(q6230(s) == 4);
4296 assert(s.q == 4);
4298 auto c = new C6230;
4299 c.p = 6;
4300 assert(q6230(c) == 6);
4301 assert(c.q == 6);
4303 r6230(s);
4304 assert(s.p == 244);
4305 s.r();
4306 assert(s.p == 231);
4308 r6230(c);
4309 assert(c.p == 156);
4310 c.r();
4311 assert(c.p == 552);
4313 return true;
4315 void test6230() {
4316 assert(test6230pure());
4319 /***************************************************/
4321 void test6264()
4323 struct S { auto opSlice() { return this; } }
4324 int[] a;
4325 S s;
4326 static assert(!is(typeof(a[] = s[])));
4327 int*[] b;
4328 static assert(is(typeof(b[] = [new immutable(int)])));
4329 char[] c = new char[](5);
4330 c[] = "hello";
4333 /***************************************************/
4334 // https://issues.dlang.org/show_bug.cgi?id=5046
4336 void test5046()
4338 auto va = S5046!("", int)();
4339 auto vb = makeS5046!("", int)();
4342 struct S5046(alias p, T)
4344 T s;
4345 T fun() { return s; } // (10)
4348 S5046!(p, T) makeS5046(alias p, T)()
4350 return typeof(return)();
4353 /***************************************************/
4354 // https://issues.dlang.org/show_bug.cgi?id=6335
4356 struct S6335
4358 const int value;
4359 this()(int n){ value = n; }
4361 void test6335()
4363 S6335 s = S6335(10);
4366 /***************************************************/
4368 struct S6295(int N) {
4369 int[N] x;
4370 const nothrow pure @safe f() { return x.length; }
4373 void test6295() {
4374 auto bar(T: S6295!(N), int N)(T x) {
4375 return x.f();
4377 S6295!4 x;
4378 assert(bar(x) == 4);
4381 /***************************************************/
4383 template TT4536(T...) { alias T TT4536; }
4385 void test4536()
4387 auto x = TT4536!(int, long, [1, 2]).init;
4388 assert(x[0] is int.init);
4389 assert(x[1] is long.init);
4390 assert(x[2] is [1, 2].init);
4393 /***************************************************/
4395 struct S6284 {
4396 int a;
4398 class C6284 {
4399 int a;
4401 pure int bug6284a() {
4402 S6284 s = {4};
4403 auto b = s.a; // ok
4404 with (s) {
4405 b += a; // should be ok.
4407 return b;
4409 pure int bug6284b() {
4410 auto s = new S6284;
4411 s.a = 4;
4412 auto b = s.a;
4413 with (*s) {
4414 b += a;
4416 return b;
4418 pure int bug6284c() {
4419 auto s = new C6284;
4420 s.a = 4;
4421 auto b = s.a;
4422 with (s) {
4423 b += a;
4425 return b;
4427 void test6284() {
4428 assert(bug6284a() == 8);
4429 assert(bug6284b() == 8);
4430 assert(bug6284c() == 8);
4433 /***************************************************/
4435 class C6293 {
4436 C6293 token;
4438 void f6293(in C6293[] a) pure {
4439 auto x0 = a[0].token;
4440 assert(x0 is a[0].token.token.token);
4441 assert(x0 is (&x0).token);
4442 auto p1 = &x0 + 1;
4443 assert(x0 is (p1 - 1).token);
4444 int c = 0;
4445 assert(x0 is a[c].token);
4447 void test6293() {
4448 auto x = new C6293;
4449 x.token = x;
4450 f6293([x]);
4453 /***************************************************/
4454 // https://issues.dlang.org/show_bug.cgi?id=3733
4456 class C3733
4458 int foo() { return 1; }
4459 int foo() shared { return 2; }
4461 int bar() { return foo(); }
4463 void test3733()
4465 auto c = new C3733();
4466 assert(c.bar() == 1);
4469 /***************************************************/
4470 // https://issues.dlang.org/show_bug.cgi?id=4392
4472 class C4392
4474 int foo() const { return 1; }
4475 int foo() { return 2; }
4477 int bar() const { return foo(); }
4479 void test4392()
4481 auto c = new C4392();
4482 assert(c.bar() == 1);
4485 /***************************************************/
4486 // https://issues.dlang.org/show_bug.cgi?id=6220
4488 void test6220() {
4489 struct Foobar { real x; real y; real z;}
4490 switch("x") {
4491 foreach(i,member; __traits(allMembers, Foobar)) {
4492 case member : break;
4494 default : break;
4498 /***************************************************/
4499 // https://issues.dlang.org/show_bug.cgi?id=5799
4501 void test5799()
4503 int a;
4504 int *u = &(a ? a : (a ? a : a));
4505 assert(u == &a);
4508 /***************************************************/
4509 // https://issues.dlang.org/show_bug.cgi?id=6529
4511 enum Foo6529 : char { A='a' }
4512 ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; }
4514 /***************************************************/
4516 void test783()
4518 const arr = [ 1,2,3 ];
4519 const i = 2;
4520 auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]"
4523 /***************************************************/
4525 template X157(alias x)
4527 alias x X157;
4530 template Parent(alias foo)
4532 alias X157!(__traits(parent, foo)) Parent;
4535 template ParameterTypeTuple(alias foo)
4537 static if (is(typeof(foo) P == function))
4538 alias P ParameterTypeTuple;
4539 else
4540 static assert(0, "argument has no parameters");
4543 template Mfp(alias foo)
4545 auto Mfp = function(Parent!foo self, ParameterTypeTuple!foo i) { return self.foo(i); };
4548 class C157 {
4549 int a = 3;
4550 int foo(int i, int y) { return i + a + y; }
4553 void test157()
4555 auto c = new C157();
4556 auto mfp = Mfp!(C157.foo);
4557 auto i = mfp(c, 1, 7);
4558 assert(i == 11);
4561 /***************************************************/
4562 // https://issues.dlang.org/show_bug.cgi?id=6473
4564 struct Eins6473
4566 ~this() {}
4569 struct Zwei6473
4571 void build(Eins6473 devices = Eins6473())
4576 void build(Eins6473 devices = Eins6473())
4579 void test6473()
4581 void build(Eins6473 devices = Eins6473())
4585 /***************************************************/
4587 uint rol11417(uint n)(in uint x)
4589 return x << n | x >> 32 - n;
4592 uint ror11417(uint n)(in uint x)
4594 return x >> n | x << 32 - n;
4597 void test11417()
4599 assert(rol11417!1(0x8000_0000) == 0x1);
4600 assert(ror11417!1(0x1) == 0x8000_0000);
4603 /***************************************************/
4605 void test6578()
4607 static struct Foo
4609 this(int x) pure {}
4611 auto f1 = new const(Foo)(1);
4612 auto f2 = new immutable(Foo)(1);
4613 auto f3 = new shared(Foo)(1);
4614 auto f4 = const(Foo)(1);
4615 auto f5 = immutable(Foo)(1);
4616 auto f6 = shared(Foo)(1);
4617 static assert(is(typeof(f1) == const(Foo)*));
4618 static assert(is(typeof(f2) == immutable(Foo)*));
4619 static assert(is(typeof(f3) == shared(Foo)*));
4620 static assert(is(typeof(f4) == const(Foo)));
4621 static assert(is(typeof(f5) == immutable(Foo)));
4622 static assert(is(typeof(f6) == shared(Foo)));
4624 static struct Bar
4626 this(int x) const pure {}
4628 auto g1 = new const(Bar)(1);
4629 auto g2 = new immutable(Bar)(1);
4630 auto g3 = new shared(Bar)(1);
4631 auto g4 = const(Bar)(1);
4632 auto g5 = immutable(Bar)(1);
4633 auto g6 = shared(Bar)(1);
4634 static assert(is(typeof(g1) == const(Bar)*));
4635 static assert(is(typeof(g2) == immutable(Bar)*));
4636 static assert(is(typeof(g3) == shared(Bar)*));
4637 static assert(is(typeof(g4) == const(Bar)));
4638 static assert(is(typeof(g5) == immutable(Bar)));
4639 static assert(is(typeof(g6) == shared(Bar)));
4641 static struct Baz
4643 this()(int x) const pure {}
4645 auto h1 = new const(Baz)(1);
4646 auto h2 = new immutable(Baz)(1);
4647 auto h3 = new shared(const(Baz))(1);
4648 auto h4 = const(Baz)(1);
4649 auto h5 = immutable(Baz)(1);
4650 auto h6 = shared(const(Baz))(1);
4651 static assert(is(typeof(h1) == const(Baz)*));
4652 static assert(is(typeof(h2) == immutable(Baz)*));
4653 static assert(is(typeof(h3) == shared(const(Baz))*));
4654 static assert(is(typeof(h4) == const(Baz)));
4655 static assert(is(typeof(h5) == immutable(Baz)));
4656 static assert(is(typeof(h6) == shared(const(Baz))));
4659 /***************************************************/
4660 // https://issues.dlang.org/show_bug.cgi?id=6630
4662 void test6630()
4664 static class B {}
4666 static class A
4668 this() { b = new B(); }
4669 B b;
4670 alias b this;
4673 void fun(A a)
4675 a = null;
4676 assert(a is null);
4679 auto a = new A;
4680 assert(a.b !is null);
4681 fun(a);
4682 assert(a !is null);
4683 assert(a.b !is null);
4686 /***************************************************/
4688 int i199 = 1;
4690 void test199()
4692 label:
4694 int i199 = 2;
4696 assert(i199 == 1);
4699 /***************************************************/
4700 // https://issues.dlang.org/show_bug.cgi?id=6690
4702 T useLazy6690(T)(lazy T val)
4704 return val;
4705 // val is converted to delegate call, but it is typed as int delegate() - not @safe!
4707 void test6690() @safe
4709 useLazy6690(0);
4710 // Error: safe function 'test6690' cannot call system function 'useLazy6690'
4713 /***************************************************/
4715 template Hoge6691()
4717 immutable static int[int] dict;
4718 immutable static int value;
4720 shared static this()
4722 dict = [1:1, 2:2];
4723 value = 10;
4726 alias Hoge6691!() H6691;
4728 /***************************************************/
4730 void test10626()
4732 double[2] v, x;
4733 struct Y { double u; }
4734 double z;
4735 Y y;
4736 double[2] r = v[] * x[0];
4737 //double[2] s = v[] * z++;
4738 //double[2] t = v[] * z--;
4739 double[2] a = v[] * ++z;
4740 double[2] b = v[] * --z;
4741 double[2] c = v[] * y.u;
4742 x[] = 3;
4743 double[2] d = v[] * x[0];
4744 double[2] e = v[] * (v[] ~ z)[0];
4748 /***************************************************/
4749 // https://issues.dlang.org/show_bug.cgi?id=2953
4751 template Tuple2953(T...)
4753 alias T Tuple2953;
4755 template Range2953(int b)
4757 alias Tuple2953!(1) Range2953;
4759 void foo2953()()
4761 Tuple2953!(int, int) args;
4762 foreach( x ; Range2953!(args.length) ){ }
4764 void test2953()
4766 foo2953!()();
4769 /***************************************************/
4770 // https://issues.dlang.org/show_bug.cgi?id=2997
4772 abstract class B2997 { void foo(); }
4773 interface I2997 { void bar(); }
4774 abstract class C2997 : B2997, I2997 {}
4775 //pragma(msg, __traits(allMembers, C).stringof);
4777 void test2997()
4779 enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
4781 static assert([__traits(allMembers, C2997)] == ["foo"] ~ ObjectMembers ~ ["bar"]);
4784 /***************************************************/
4785 // https://issues.dlang.org/show_bug.cgi?id=6596
4787 extern (C) int function() pfunc6596;
4788 extern (C) int cfunc6596(){ return 0; }
4789 static assert(typeof(pfunc6596).stringof == "extern (C) int function()");
4790 static assert(typeof(cfunc6596).stringof == "extern (C) int()");
4793 /***************************************************/
4794 // https://issues.dlang.org/show_bug.cgi?id=4423
4796 struct S4423
4798 this(string phrase, int num)
4800 this.phrase = phrase;
4801 this.num = num;
4804 int opCmp(const ref S4423 rhs)
4806 if (phrase < rhs.phrase)
4807 return -1;
4808 else if (phrase > rhs.phrase)
4809 return 1;
4811 if (num < rhs.num)
4812 return -1;
4813 else if (num > rhs.num)
4814 return 1;
4816 return 0;
4819 string phrase;
4820 int num;
4823 enum E4423 : S4423
4825 a = S4423("hello", 1),
4826 b = S4423("goodbye", 45),
4827 c = S4423("world", 22),
4830 void test4423()
4832 E4423 e;
4833 assert(e.phrase == "hello");
4835 e = E4423.b;
4836 assert(e.phrase == "goodbye");
4839 /***************************************************/
4840 // https://issues.dlang.org/show_bug.cgi?id=4647
4842 interface Timer
4844 final int run() { printf("Timer.run()\n"); fun(); return 1; };
4845 int fun();
4848 interface Application
4850 final int run() { printf("Application.run()\n"); fun(); return 2; };
4851 int fun();
4854 class TimedApp : Timer, Application
4856 int funCalls;
4857 override int fun()
4859 printf("TimedApp.fun()\n");
4860 funCalls++;
4861 return 2;
4865 class SubTimedApp : TimedApp
4867 int subFunCalls;
4869 override int fun()
4871 printf("SubTimedApp.fun()\n");
4872 subFunCalls++;
4873 return 1;
4877 void test4647()
4879 //Test access to TimedApps base interfaces
4880 auto app = new TimedApp();
4881 assert((cast(Application)app).run() == 2);
4882 assert((cast(Timer)app).run() == 1);
4883 assert(app.Timer.run() == 1); // error, no Timer property
4884 assert(app.Application.run() == 2); // error, no Application property
4885 assert(app.run() == 1); // This would call Timer.run() if the two calls
4886 // above were commented out
4887 assert(app.funCalls == 5);
4889 assert(app.TimedApp.fun() == 2);
4890 assert(app.funCalls == 6);
4892 //Test direct access to SubTimedApp interfaces
4893 auto app2 = new SubTimedApp();
4894 assert((cast(Application)app2).run() == 2);
4895 assert((cast(Timer)app2).run() == 1);
4896 assert(app2.Application.run() == 2);
4897 assert(app2.Timer.run() == 1);
4898 assert(app2.funCalls == 0);
4899 assert(app2.subFunCalls == 4);
4901 assert(app2.fun() == 1);
4902 assert(app2.SubTimedApp.fun() == 1);
4903 assert(app2.funCalls == 0);
4904 assert(app2.subFunCalls == 6);
4906 //Test access to SubTimedApp interfaces via TimedApp
4907 auto app3 = new SubTimedApp();
4908 (cast(Timer)cast(TimedApp)app3).run();
4909 app3.TimedApp.Timer.run();
4910 assert((cast(Application)cast(TimedApp)app3).run() == 2);
4911 assert((cast(Timer)cast(TimedApp)app3).run() == 1);
4912 assert(app3.TimedApp.Application.run() == 2);
4913 assert(app3.TimedApp.Timer.run() == 1);
4914 assert(app3.funCalls == 0);
4915 assert(app3.subFunCalls == 6);
4918 /***************************************************/
4920 template T1064(E...) { alias E T1064; }
4922 int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ];
4924 void test1064()
4926 assert(var1064 == [1,2,3,4,5,6]);
4929 /***************************************************/
4930 // https://issues.dlang.org/show_bug.cgi?id=5696
4932 template Seq5696(T...){ alias T Seq5696; }
4933 template Pred5696(T) { alias T Pred5696; } // TOKtemplate
4934 template Scope5696(int n){ template X(T) { alias T X; } } // TOKimport
4935 T foo5696(T)(T x) { return x; }
4936 void test5696()
4938 foreach (pred; Seq5696!(Pred5696, Pred5696))
4940 static assert(is(pred!int == int));
4943 foreach (scop; Seq5696!(Scope5696!0, Scope5696!1))
4945 static assert(is(scop.X!int == int));
4948 alias Seq5696!(foo5696, foo5696) funcs;
4949 assert(funcs[0](0) == 0);
4950 assert(funcs[1](1) == 1);
4951 foreach (i, fn; funcs)
4953 assert(fn(i) == i);
4957 /***************************************************/
4958 // https://issues.dlang.org/show_bug.cgi?id=5933
4960 int dummyfunc5933();
4961 alias typeof(dummyfunc5933) FuncType5933;
4963 struct S5933a { auto x() { return 0; } }
4964 static assert(is(typeof(&S5933a.init.x) == int delegate() pure nothrow @nogc @safe));
4966 struct S5933b { auto x() { return 0; } }
4967 //static assert(is(typeof(S5933b.init.x) == FuncType5933));
4969 struct S5933c { auto x() { return 0; } }
4970 static assert(is(typeof(&S5933c.x) == int function()));
4972 struct S5933d { auto x() { return 0; } }
4973 static assert(is(typeof(S5933d.x) == FuncType5933));
4976 class C5933a { auto x() { return 0; } }
4977 static assert(is(typeof(&(new C5933b()).x) == int delegate() pure nothrow @nogc @safe));
4979 class C5933b { auto x() { return 0; } }
4980 //static assert(is(typeof((new C5933b()).x) == FuncType5933));
4982 class C5933c { auto x() { return 0; } }
4983 static assert(is(typeof(&C5933c.x) == int function()));
4985 class C5933d { auto x() { return 0; } }
4986 static assert(is(typeof(C5933d.x) == FuncType5933));
4988 /***************************************************/
4989 // https://issues.dlang.org/show_bug.cgi?id=6084
4991 template TypeTuple6084(T...){ alias T TypeTuple6084; }
4992 void test6084()
4994 int foo(int x)() { return x; }
4995 foreach(i; TypeTuple6084!(0))
4996 foo!(i);
4999 /***************************************************/
5000 // https://issues.dlang.org/show_bug.cgi?id=6763
5002 template TypeTuple6763(TList...)
5004 alias TList TypeTuple6763;
5007 alias TypeTuple6763!(int) T6763;
5009 void f6763( T6763) { } ///
5010 void c6763(const T6763) { } ///T now is (const int)
5011 void r6763(ref T6763) { } ///T now is(ref const int)
5012 void i6763(in T6763) { } ///Uncomment to get an Assertion failure in 'mtype.c'
5013 void o6763(out T6763) { } ///ditto
5015 void test6763()
5017 int n;
5019 f6763(0); //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int)
5020 c6763(0);
5021 r6763(n); static assert(__traits(compiles, r6763(0)));
5022 i6763(0);
5023 o6763(n); static assert(!__traits(compiles, o6763(0)));
5025 // https://issues.dlang.org/show_bug.cgi?id=6755
5026 static assert(typeof(f6763).stringof == "void(int _param_0)");
5027 static assert(typeof(c6763).stringof == "void(const(int) _param_0)");
5028 static assert(typeof(r6763).stringof == "void(ref int _param_0)");
5029 static assert(typeof(i6763).stringof == "void(in int _param_0)");
5030 static assert(typeof(o6763).stringof == "void(out int _param_0)");
5033 /***************************************************/
5034 // https://issues.dlang.org/show_bug.cgi?id=6695
5036 struct X6695
5038 void mfunc()
5040 static assert(is(typeof(this) == X6695));
5042 void cfunc() const
5044 static assert(is(typeof(this) == const(X6695)));
5046 void ifunc() immutable
5048 static assert(is(typeof(this) == immutable(X6695)));
5050 void sfunc() shared
5052 static assert(is(typeof(this) == shared(X6695)));
5054 void scfunc() shared const
5056 static assert(is(typeof(this) == shared(const(X6695))));
5058 void wfunc() inout
5060 static assert(is(typeof(this) == inout(X6695)));
5062 void swfunc() shared inout
5064 static assert(is(typeof(this) == shared(inout(X6695))));
5067 static assert(is(typeof(this) == X6695));
5070 /***************************************************/
5071 // https://issues.dlang.org/show_bug.cgi?id=6087
5073 template True6087(T)
5075 immutable True6087 = true;
5077 struct Foo6087
5079 static assert( True6087!(typeof(this)) );
5082 struct Bar6087
5084 static assert( is(typeof(this) == Bar6087) );
5087 /***************************************************/
5088 // https://issues.dlang.org/show_bug.cgi?id=6848
5090 class Foo6848 {}
5092 class Bar6848 : Foo6848
5094 void func() immutable
5096 static assert(is(typeof(this) == immutable(Bar6848))); // immutable(Bar6848)
5097 auto t = this;
5098 static assert(is(typeof(t) == immutable(Bar6848))); // immutable(Bar6848)
5100 static assert(is(typeof(super) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848)
5101 auto s = super;
5102 static assert(is(typeof(s) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848)
5106 /***************************************************/
5108 version(none)
5110 cent issue785;
5111 ucent issue785;
5114 static assert(is(cent) && is(ucent) || !is(cent) && !is(ucent));
5115 static if (is(cent))
5116 static assert(__traits(compiles, { cent x; }));
5117 else
5118 static assert(!__traits(compiles, { cent x; }));
5120 /***************************************************/
5121 // https://issues.dlang.org/show_bug.cgi?id=6847
5123 template True6847(T)
5125 immutable True6847 = true;
5127 class Foo6847
5130 class Bar6847 : Foo6847
5132 static assert( True6847!(typeof(super)) );
5133 static assert( is(typeof(super) == Foo6847) );
5136 /***************************************************/
5137 // https://issues.dlang.org/show_bug.cgi?id=6488
5139 struct TickDuration
5141 template to(T) if (__traits(isIntegral,T))
5143 const T to()
5145 return 1;
5149 template to(T) if (__traits(isFloating,T))
5151 const T to()
5153 return 0;
5157 const long seconds()
5159 return to!(long)();
5164 void test6488()
5166 TickDuration d;
5167 d.seconds();
5170 /***************************************************/
5171 // https://issues.dlang.org/show_bug.cgi?id=6565
5173 void foo6565(out int[2][2] m) {}
5175 void test6565()
5177 int[2][2] mat = [[1, 2], [3, 4]];
5178 foo6565(mat);
5179 assert(mat == [[0, 0], [0, 0]]);
5182 /***************************************************/
5183 // https://issues.dlang.org/show_bug.cgi?id=6836
5185 template map6836(fun...) if (fun.length >= 1)
5187 auto map6836(Range)(Range r)
5191 void test6836()
5193 [1].map6836!"a"();
5196 /***************************************************/
5198 string func12864() { return ['a', 'b', 'c']; }
5200 void test12864(string s)
5202 switch (s)
5204 case func12864():
5205 break;
5207 default:
5208 break;
5212 /***************************************************/
5214 void test5448()
5216 int[int][] aaa = [[1: 2]];
5217 int[string][] a2 = [["cc":0], ["DD":10]];
5220 /***************************************************/
5221 // https://issues.dlang.org/show_bug.cgi?id=6837
5223 struct Ref6837a(T)
5225 T storage;
5226 alias storage this;
5229 struct Ref6837b(T)
5231 T storage;
5232 @property ref T get(){ return storage; }
5233 alias get this;
5236 int front6837(int[] arr){ return arr[0]; }
5238 void popFront6837(ref int[] arr){ arr = arr[1..$]; }
5240 void test6837()
5242 assert([1,2,3].front6837 == 1);
5244 auto r1 = Ref6837a!(int[])([1,2,3]);
5245 assert(r1.front6837() == 1); // ng
5246 assert(r1.front6837 == 1); // ok
5247 r1.popFront6837(); // ng
5248 r1.storage.popFront6837(); // ok
5250 auto r2 = Ref6837b!(int[])([1,2,3]);
5251 assert(r2.front6837() == 1); // ng
5252 assert(r2.front6837 == 1); // ok
5253 r2.popFront6837(); // ng
5254 r2.get.popFront6837(); // ng
5255 r2.get().popFront6837(); // ok
5258 /***************************************************/
5259 // https://issues.dlang.org/show_bug.cgi?id=6927
5261 @property int[] foo6927()
5263 return [1, 2];
5265 int[] bar6927(int[] a)
5267 return a;
5269 void test6927()
5271 bar6927(foo6927); // OK
5272 foo6927.bar6927(); // line 9, Error
5275 /***************************************************/
5277 struct Foo6813(T)
5279 Foo6813 Bar()
5281 return Foo6813(_indices.abc());
5284 T _indices;
5287 struct SortedRange(alias pred)
5289 SortedRange abc()
5291 return SortedRange();
5295 void test6813() {
5296 auto ind = SortedRange!({ })();
5297 auto a = Foo6813!(typeof(ind))();
5300 /***************************************************/
5302 struct Interval6753{ int a,b; }
5303 @safe struct S6753
5305 int[] arr;
5306 @trusted @property auto byInterval() const
5308 return cast(const(Interval6753)[])arr;
5312 /***************************************************/
5313 // https://issues.dlang.org/show_bug.cgi?id=6859
5315 class Parent6859
5317 public:
5318 bool isHage() const @property;
5320 public:
5321 abstract void fuga()
5324 assert(isHage);
5326 do { }
5329 class Child6859 : Parent6859
5331 override bool isHage() const @property
5333 return true;
5335 override void fuga()
5337 //nop
5341 void test6859()
5343 auto t = new Child6859;
5344 t.fuga();
5345 printf("done.\n");
5348 /***************************************************/
5349 // https://issues.dlang.org/show_bug.cgi?id=6910
5351 template Test6910(alias i, B)
5353 void fn()
5355 foreach(t; B.Types)
5357 switch(i)
5359 case 0://IndexOf!(t, B.Types):
5361 pragma(msg, __traits(allMembers, t));
5362 pragma(msg, __traits(hasMember, t, "m"));
5363 static assert(__traits(hasMember, t, "m")); // test
5364 break;
5366 default: {}
5371 void test6910()
5373 static struct Bag(S...)
5375 alias S Types;
5377 static struct A
5379 int m;
5382 int i;
5383 alias Test6910!(i, Bag!(A)).fn func;
5386 /***************************************************/
5388 void fun12503()
5390 string b = "abc";
5395 b = null;
5396 return;
5398 catch(Throwable)
5402 finally
5404 assert("abc" !is b);
5408 void test12503()
5410 fun12503();
5413 /***************************************************/
5414 // https://issues.dlang.org/show_bug.cgi?id=6902
5416 void test6902()
5418 static assert(is(typeof({
5419 return int.init; // int, long, real, etc.
5420 })));
5422 int f() pure nothrow { assert(0); }
5423 alias int T() pure nothrow @safe @nogc;
5424 static if(is(typeof(&f) DT == delegate))
5426 static assert(is(DT* == T*)); // ok
5428 // Error: static assert (is(pure nothrow int() == pure nothrow int())) is false
5429 static assert(is(DT == T));
5433 /***************************************************/
5434 // https://issues.dlang.org/show_bug.cgi?id=6330
5436 struct S6330
5438 void opAssign(S6330 s) @disable
5440 assert(0); // This fails.
5444 void test6330()
5446 S6330 s;
5447 S6330 s2;
5448 static assert(!is(typeof({ s2 = s; })));
5451 /***************************************************/
5453 struct S8269
5455 bool dtor = false;
5456 ~this()
5458 dtor = true;
5462 void test8269()
5464 with(S8269())
5466 assert(!dtor);
5470 /***************************************************/
5471 // https://issues.dlang.org/show_bug.cgi?id=5311
5473 class C5311
5475 private static int globalData;
5477 void breaksPure() pure const
5479 static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR
5480 static assert(!__traits(compiles, { C5311.globalData++; }));// SHOULD BE ERROR
5481 static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5483 static assert(!__traits(compiles, { int a = this.globalData; }));
5486 static void breaksPure5311a(C5311 x) pure
5488 static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR
5490 static assert(!__traits(compiles, { int a = x.globalData; }));
5493 struct S5311
5495 private static int globalData;
5497 void breaksPure() pure const
5499 static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR
5500 static assert(!__traits(compiles, { S5311.globalData++; }));// SHOULD BE ERROR
5501 static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5503 static assert(!__traits(compiles, { int a = this.globalData; }));
5506 static void breaksPure5311b(S5311 x) pure
5508 static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR
5510 static assert(!__traits(compiles, { int a = x.globalData; }));
5513 /***************************************************/
5514 // https://issues.dlang.org/show_bug.cgi?id=6868
5516 @property bool empty6868(T)(in T[] a) @safe pure nothrow
5518 return !a.length;
5521 void test6868()
5523 alias int[] Range;
5524 static if (is(char[1 + Range.empty6868])) // Line 9
5525 enum bool isInfinite = true;
5527 char[0] s; // need
5530 /***************************************************/
5531 // https://issues.dlang.org/show_bug.cgi?id=2856
5533 struct foo2856 { static void opIndex(int i) { printf("foo\n"); } }
5534 struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } }
5536 void test2856()
5538 foo2856[1];
5539 bar2856!(float)[1]; // Error (# = __LINE__)
5540 alias bar2856!(float) B;
5541 B[1]; // Okay
5544 /***************************************************/
5546 void test13947()
5548 struct S {}
5549 static assert(S.sizeof == 1);
5551 S a;
5552 S b;
5553 *cast(ubyte*)&a = 1;
5554 *cast(ubyte*)&b = 2;
5555 assert(a == b);
5556 assert(a is b);
5557 assert(!(a != b));
5558 assert(!(a !is b));
5559 static assert(S() == S());
5560 static assert(S() is S());
5561 static assert(!(S() != S()));
5562 static assert(!(S() !is S()));
5565 /***************************************************/
5566 // https://issues.dlang.org/show_bug.cgi?id=3091
5568 void test3091(inout int = 0)
5570 struct Foo {}
5572 auto pm = new Foo; static assert(is( typeof( pm) == Foo * ));
5573 auto pc = new const Foo; static assert(is( typeof( pc) == const(Foo) * ));
5574 auto pw = new inout Foo; static assert(is( typeof( pw) == inout(Foo) * ));
5575 auto psm = new shared Foo; static assert(is( typeof(psm) == shared(Foo) * ));
5576 auto psc = new shared const Foo; static assert(is( typeof(psc) == shared(const(Foo))* ));
5577 auto psw = new shared inout Foo; static assert(is( typeof(psw) == shared(inout(Foo))* ));
5578 auto pi = new immutable Foo; static assert(is( typeof( pi) == immutable(Foo) * ));
5580 auto m = Foo(); static assert(is( typeof( m) == Foo ));
5581 auto c = const Foo(); static assert(is( typeof( c) == const(Foo) ));
5582 auto w = inout Foo(); static assert(is( typeof( w) == inout(Foo) ));
5583 auto sm = shared Foo(); static assert(is( typeof(sm) == shared(Foo) ));
5584 auto sc = shared const Foo(); static assert(is( typeof(sc) == shared(const(Foo)) ));
5585 auto sw = shared inout Foo(); static assert(is( typeof(sw) == shared(inout(Foo)) ));
5586 auto i = immutable Foo(); static assert(is( typeof( i) == immutable(Foo) ));
5589 /***************************************************/
5590 // https://issues.dlang.org/show_bug.cgi?id=6837
5592 template Id6837(T)
5594 alias T Id6837;
5596 static assert(is(Id6837!(shared const int) == shared const int));
5597 static assert(is(Id6837!(shared inout int) == shared inout int));
5599 /***************************************************/
5600 // https://issues.dlang.org/show_bug.cgi?id=6056 fixup
5602 template ParameterTypeTuple6056(func)
5604 static if (is(func Fptr : Fptr*) && is(Fptr P == function))
5605 alias P ParameterTypeTuple6056;
5606 else
5607 static assert(0, "argument has no parameters");
5610 extern(C) alias void function() fpw_t;
5612 alias void function(fpw_t fp) cb_t;
5614 void bar6056(ParameterTypeTuple6056!(cb_t) args) {
5615 pragma (msg, "TFunction1: " ~ typeof(args[0]).stringof);
5618 extern(C) void foo6056() { }
5620 void test6056()
5622 bar6056(&foo6056);
5625 /***************************************************/
5626 // https://issues.dlang.org/show_bug.cgi?id=6356
5628 int f6356()(int a)
5630 return a*a;
5633 alias f6356!() g6356; // comment this out to eliminate the errors
5635 pure nothrow @safe int i6356()
5637 return f6356(1);
5640 void test6356()
5642 assert(i6356() == 1);
5645 /***************************************************/
5646 // https://issues.dlang.org/show_bug.cgi?id=7108
5648 static assert(!__traits(hasMember, int, "x"));
5649 static assert( __traits(hasMember, int, "init"));
5651 /***************************************************/
5652 // https://issues.dlang.org/show_bug.cgi?id=7073
5654 void test7073()
5656 string f(int[] arr...)
5658 return "";
5662 /***************************************************/
5663 // https://issues.dlang.org/show_bug.cgi?id=7104
5665 void test7104()
5667 typeof(new class {}) c;
5668 c = new typeof(c);
5671 /***************************************************/
5672 // https://issues.dlang.org/show_bug.cgi?id=7150
5674 struct A7150
5676 static int cnt;
5678 this(T)(T thing, int i)
5680 this(thing, i > 0); // Error: constructor call must be in a constructor
5681 ++cnt;
5683 this(T)(T thing, bool b)
5685 ++cnt;
5689 void test7150()
5691 auto a = A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating
5692 assert(A7150.cnt == 2);
5695 /***************************************************/
5696 // https://issues.dlang.org/show_bug.cgi?id=7159
5698 alias void delegate() Void7159;
5700 class HomeController7159 {
5701 Void7159 foo() {
5702 return cast(Void7159)&HomeController7159.displayDefault;
5704 auto displayDefault() {
5705 return 1;
5709 /***************************************************/
5710 // https://issues.dlang.org/show_bug.cgi?id=7160
5712 class HomeController {
5713 static if (false) {
5714 mixin(q{ int a; });
5716 void foo() {
5717 foreach (m; __traits(derivedMembers, HomeController)) {
5722 void test7160()
5725 /***************************************************/
5726 // https://issues.dlang.org/show_bug.cgi?id=7168
5728 void test7168()
5730 static class X
5732 void foo(){}
5734 static class Y : X
5736 void bar(){}
5739 enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
5741 static assert([__traits(allMembers, X)] == ["foo"]~ObjectMembers); // pass
5742 static assert([__traits(allMembers, Y)] == ["bar", "foo"]~ObjectMembers); // fail
5743 static assert([__traits(allMembers, Y)] != ["bar", "foo"]); // fail
5746 /***************************************************/
5747 // https://issues.dlang.org/show_bug.cgi?id=7170
5749 T to7170(T)(string x) { return 1; }
5750 void test7170()
5752 // auto i = to7170!int("1"); // OK
5753 auto j = "1".to7170!int(); // NG, Internal error: e2ir.c 683
5756 /***************************************************/
5757 // https://issues.dlang.org/show_bug.cgi?id=7196
5759 auto foo7196(int x){return x;}
5760 auto foo7196(double x){return x;}
5762 void test7196()
5764 auto x = (&foo7196)(1); // ok
5765 auto y = (&foo7196)(1.0); // fail
5768 /***************************************************/
5769 // https://issues.dlang.org/show_bug.cgi?id=7285
5771 int[2] spam7285()
5773 int[2] ab;
5774 if (true)
5775 return (true) ? ab : [0, 0]; // Error
5776 else
5777 return (true) ? [0, 0] : ab; // OK
5780 void test7285()
5782 auto sa = spam7285();
5785 /***************************************************/
5786 // https://issues.dlang.org/show_bug.cgi?id=14737
5788 void test14737()
5790 // compile-time
5791 enum string[2] a1 = ["d", "e"];
5792 enum b1x = ["a", "b", "c"] ~ a1; // Tarray vs Tsarray
5793 enum b1y = a1 ~ ["a", "b", "c"]; // Tsarray vs Tarray
5794 static assert(is(typeof(b1x) == string[]));
5795 static assert(is(typeof(b1y) == string[]));
5796 static assert(b1x == ["a", "b", "c", "d", "e"]);
5797 static assert(b1y == ["d", "e", "a", "b", "c"]);
5799 // runtime
5800 string[2] a2 = ["d", "e"];
5801 auto b2x = ["a", "b", "c"] ~ a2; // Tarray vs Tsarray
5802 auto b2y = a2 ~ ["a", "b", "c"]; // Tsarray vs Tarray
5803 static assert(is(typeof(b2x) == string[]));
5804 static assert(is(typeof(b2y) == string[]));
5805 assert(b2x == ["a", "b", "c", "d", "e"]);
5806 assert(b2y == ["d", "e", "a", "b", "c"]);
5809 /***************************************************/
5810 // https://issues.dlang.org/show_bug.cgi?id=7321
5812 void test7321()
5814 static assert(is(typeof((){})==void function()pure nothrow @nogc @safe)); // ok
5815 static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe)); // fail
5818 /***************************************************/
5820 class A158
5822 pure void foo1() { }
5823 const void foo2() { }
5824 nothrow void foo3() { }
5825 @safe void foo4() { }
5828 class B158 : A158
5830 override void foo1() { }
5831 override void foo2() const { }
5832 override void foo3() { }
5833 override void foo4() { }
5836 /***************************************************/
5837 // https://issues.dlang.org/show_bug.cgi?id=9231
5839 class B9231 { void foo() inout pure {} }
5840 class D9231 : B9231 { override void foo() inout {} }
5842 /***************************************************/
5843 // https://issues.dlang.org/show_bug.cgi?id=3282
5845 class Base3282
5847 string f()
5849 return "Base.f()";
5852 class Derived3282 : Base3282
5854 override string f()
5856 return "Derived.f()";
5858 /*override*/ string f() const
5860 return "Derived.f() const";
5864 void test3282()
5866 auto x = new Base3282;
5867 assert(x.f() == "Base.f()");
5868 auto y = new Derived3282;
5869 assert(y.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const.
5870 auto z = new const(Derived3282);
5871 assert(z.f() == "Derived.f() const");
5874 /***************************************************/
5875 // https://issues.dlang.org/show_bug.cgi?id=7534
5877 class C7534
5879 int foo(){ return 1; }
5881 class D7534 : C7534
5883 override int foo(){ return 2; }
5884 /*override*/ int foo() const { return 3; }
5885 // Error: D.foo multiple overrides of same function
5887 void test7534()
5889 C7534 mc = new C7534();
5890 assert(mc.foo() == 1);
5892 D7534 md = new D7534();
5893 assert(md.foo() == 2);
5894 mc = md;
5895 assert(mc.foo() == 2);
5897 const(D7534) cd = new const(D7534)();
5898 assert(cd.foo() == 3);
5899 md = cast()cd;
5900 assert(md.foo() == 2);
5903 /***************************************************/
5904 // https://issues.dlang.org/show_bug.cgi?id=7534
5905 // return type covariance
5907 class X7534 {}
5908 class Y7534 : X7534
5910 int value; this(int n){ value = n; }
5913 class V7534
5915 X7534 foo(){ return new X7534(); }
5917 class W7534 : V7534
5919 override Y7534 foo(){ return new Y7534(1); }
5920 /*override*/ Y7534 foo() const { return new Y7534(2); }
5923 void test7534cov()
5925 auto mv = new V7534();
5926 assert(typeid(mv.foo()) == typeid(X7534));
5928 auto mw = new W7534();
5929 assert(typeid(mw.foo()) == typeid(Y7534));
5930 assert(mw.foo().value == 1);
5931 mv = mw;
5932 assert(typeid(mv.foo()) == typeid(Y7534));
5933 assert((cast(Y7534)mv.foo()).value == 1);
5935 auto cw = new const(W7534)();
5936 assert(typeid(cw.foo()) == typeid(Y7534));
5937 assert(cw.foo().value == 2);
5940 /***************************************************/
5941 // https://issues.dlang.org/show_bug.cgi?id=7562
5943 static struct MyInt
5945 private int value;
5946 mixin ProxyOf!value;
5948 mixin template ProxyOf(alias a)
5950 template X1(){}
5951 template X2(){}
5952 template X3(){}
5953 template X4(){}
5954 template X5(){}
5955 template X6(){}
5956 template X7(){}
5957 template X8(){}
5958 template X9(){}
5959 template X10(){}
5961 void test1(this X)(){}
5962 void test2(this Y)(){}
5965 /***************************************************/
5967 import core.stdc.stdlib;
5969 void test13427(void* buffer = alloca(100))
5973 /***************************************************/
5974 // https://issues.dlang.org/show_bug.cgi?id=7583
5976 template Tup7583(E...) { alias E Tup7583; }
5978 struct S7583
5980 Tup7583!(float, char) field;
5981 alias field this;
5982 this(int x) { }
5985 int bug7583() {
5986 S7583[] arr;
5987 arr ~= S7583(0);
5988 return 1;
5991 static assert (bug7583());
5993 /***************************************************/
5994 // https://issues.dlang.org/show_bug.cgi?id=7618
5996 void test7618(const int x = 1)
5998 int func(ref int x) { return 1; }
5999 static assert(!__traits(compiles, func(x)));
6000 // Error: function test.foo.func (ref int _param_0) is not callable using argument types (const(int))
6002 int delegate(ref int) dg = (ref int x) => 1;
6003 static assert(!__traits(compiles, dg(x)));
6004 // --> no error, bad!
6006 int function(ref int) fp = (ref int x) => 1;
6007 static assert(!__traits(compiles, fp(x)));
6008 // --> no error, bad!
6011 /***************************************************/
6012 // https://issues.dlang.org/show_bug.cgi?id=7621
6014 void test7621()
6016 enum uint N = 4u;
6017 char[] A = "hello".dup;
6018 uint[immutable char[4u]] dict;
6019 dict[*cast(immutable char[4]*)(A[0 .. N].ptr)] = 0; // OK
6020 dict[*cast(immutable char[N]*)(A[0 .. N].ptr)] = 0; // line 6, error
6023 /***************************************************/
6024 // https://issues.dlang.org/show_bug.cgi?id=7682
6026 template ConstOf7682(T)
6028 alias const(T) ConstOf7682;
6030 bool pointsTo7682(S)(ref const S source) @trusted pure nothrow
6032 return true;
6034 void test7682()
6036 shared(ConstOf7682!(int[])) x; // line A
6038 struct S3 { int[10] a; }
6039 shared(S3) sh3;
6040 shared(int[]) sh3sub = sh3.a[];
6041 assert(pointsTo7682(sh3sub)); // line B
6044 /***************************************************/
6045 // https://issues.dlang.org/show_bug.cgi?id=7735
6047 void a7735(void[][] data...)
6049 //writeln(data);
6050 assert(data.length == 1);
6051 b7735(data);
6054 void b7735(void[][] data...)
6056 //writeln(data);
6057 assert(data.length == 1);
6058 c7735(data);
6061 void c7735(void[][] data...)
6063 //writeln(data);
6064 assert(data.length == 1);
6067 void test7735()
6069 a7735([]);
6070 a7735([]);
6073 /***************************************************/
6075 struct A7823 {
6076 long a;
6077 enum A7823 b = {0};
6080 void test7823(A7823 a = A7823.b) { }
6082 /***************************************************/
6083 // https://issues.dlang.org/show_bug.cgi?id=7871
6085 struct Tuple7871
6087 string field;
6088 alias field this;
6091 //auto findSplitBefore(R1)(R1 haystack)
6092 auto findSplitBefore7871(string haystack)
6094 return Tuple7871(haystack);
6097 void test7871()
6099 string line = `<bookmark href="https://stuff">`;
6100 auto a = findSplitBefore7871(line[0 .. $])[0];
6103 /***************************************************/
6104 // https://issues.dlang.org/show_bug.cgi?id=7906
6106 void test7906()
6108 static assert(!__traits(compiles, { enum s = [string.min]; }));
6111 /***************************************************/
6112 // https://issues.dlang.org/show_bug.cgi?id=7907
6114 template Id7907(E)
6116 alias E Id7907;
6118 template Id7907(alias E)
6120 alias E Id7907;
6123 void test7907()
6125 static assert(!__traits(compiles, { alias Id7907!([string.min]) X; }));
6128 /***************************************************/
6129 // https://issues.dlang.org/show_bug.cgi?id=1175
6131 class A1175
6133 class I1 { }
6136 class B1175 : A1175
6138 class I2 : I1 { }
6140 I1 getI() { return new I2; }
6143 /***************************************************/
6144 // https://issues.dlang.org/show_bug.cgi?id=8004
6146 void test8004()
6148 auto n = (int n = 10){ return n; }();
6149 assert(n == 10);
6152 /***************************************************/
6153 // https://issues.dlang.org/show_bug.cgi?id=8064
6155 void test8064()
6157 uint[5] arry;
6158 ref uint acc(size_t i) {
6159 return arry[i];
6161 auto arryacc = &acc;
6162 arryacc(3) = 5; // same error
6165 /***************************************************/
6166 // https://issues.dlang.org/show_bug.cgi?id=8220
6168 void foo8220(int){}
6169 static assert(!__traits(compiles, foo8220(typeof(0)))); // fail
6171 /***************************************************/
6173 void func8105(in ref int x) { }
6175 void test8105()
6179 /***************************************************/
6181 template ParameterTypeTuple159(alias foo)
6183 static if (is(typeof(foo) P == __parameters))
6184 alias P ParameterTypeTuple159;
6185 else
6186 static assert(0, "argument has no parameters");
6189 int func159(int i, long j = 7) { return 3; }
6191 alias ParameterTypeTuple159!func159 PT;
6193 int bar159(PT) { return 4; }
6195 pragma(msg, typeof(bar159));
6196 pragma(msg, PT[1]);
6198 PT[1] boo159(PT[1..2] a) { return a[0]; }
6200 void test159()
6202 assert(bar159(1) == 4);
6203 assert(boo159() == 7);
6206 /***************************************************/
6207 // https://issues.dlang.org/show_bug.cgi?id=8283
6209 struct Foo8283 {
6210 this(long) { }
6213 struct FooContainer {
6214 Foo8283 value;
6217 auto get8283() {
6218 union Buf { FooContainer result; }
6219 Buf buf = {};
6220 return buf.result;
6223 void test8283() {
6224 auto a = get8283();
6228 /***************************************************/
6229 // https://issues.dlang.org/show_bug.cgi?id=8395
6231 struct S8395
6233 int v;
6234 this(T : long)(T x) { v = x * 2; }
6236 void test8395()
6238 S8395 ms = 6;
6239 assert(ms.v == 12);
6240 const S8395 cs = 7;
6241 assert(cs.v == 14);
6244 /***************************************************/
6245 // https://issues.dlang.org/show_bug.cgi?id=5749
6247 void test5749()
6249 static struct A
6251 A foo(int x, int i)
6253 //printf("this = %p, %d: i=%d\n", &this, x, i);
6254 assert(i == x);
6255 return this;
6257 A bar(int x, ref int i)
6259 //printf("this = %p, %d: i=%d\n", &this, x, i);
6260 assert(i == x);
6261 return this;
6265 static int inc1(ref int i) { return ++i; }
6266 static ref int inc2(ref int i) { return ++i; }
6268 int i;
6269 A a;
6270 //printf("&a = %p\n", &a);
6272 i = 0; a.foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6273 i = 0; a.bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6274 i = 0; a.foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6275 i = 0; a.bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6276 //printf("\n");
6278 A getVal() { static A a; return a; }
6279 i = 0; getVal().foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6280 i = 0; getVal().bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6281 i = 0; getVal().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6282 i = 0; getVal().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6283 //printf("\n");
6285 ref A getRef() { static A a; return a; }
6286 i = 0; getRef().foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6287 i = 0; getRef().bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6288 i = 0; getRef().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6289 i = 0; getRef().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6292 /***************************************************/
6293 // https://issues.dlang.org/show_bug.cgi?id=8396
6295 void test8396()
6297 static int g;
6299 static extern(C) int bar(int a, int b)
6301 //printf("a = %d, b = %d\n", a, b);
6302 assert(b - a == 1);
6303 return ++g;
6305 static auto getFunc(int n)
6307 assert(++g == n);
6308 return &bar;
6311 static struct Tuple { int _a, _b; }
6312 static Tuple foo(int n)
6314 assert(++g == n);
6315 return Tuple(1, 2);
6318 g = 0;
6319 assert(bar(foo(1).tupleof) == 2);
6321 g = 0;
6322 assert(getFunc(1)(foo(2).tupleof) == 3);
6325 /***************************************************/
6327 enum E160 : ubyte { jan = 1 }
6329 struct D160
6331 short _year = 1;
6332 E160 _month = E160.jan;
6333 ubyte _day = 1;
6335 this(int year, int month, int day) pure
6337 _year = cast(short)year;
6338 _month = cast(E160)month;
6339 _day = cast(ubyte)day;
6343 struct T160
6345 ubyte _hour;
6346 ubyte _minute;
6347 ubyte _second;
6349 this(int hour, int minute, int second = 0) pure
6351 _hour = cast(ubyte)hour;
6352 _minute = cast(ubyte)minute;
6353 _second = cast(ubyte)second;
6357 struct DT160
6359 D160 _date;
6360 T160 _tod;
6362 this(int year, int month, int day,
6363 int hour = 0, int minute = 0, int second = 0) pure
6365 _date = D160(year, month, day);
6366 _tod = T160(hour, minute, second);
6370 void foo160(DT160 dateTime)
6372 printf("test7 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6373 assert(dateTime._date._year == 1999);
6374 assert(dateTime._date._day == 6);
6377 void test160()
6379 auto dateTime = DT160(1999, 7, 6, 12, 30, 33);
6380 printf("test5 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6381 assert(dateTime._date._year == 1999);
6382 assert(dateTime._date._day == 6);
6383 foo160(DT160(1999, 7, 6, 12, 30, 33));
6386 /***************************************************/
6387 // https://issues.dlang.org/show_bug.cgi?id=8437
6389 class Cgi8437
6391 struct PostParserState {
6392 UploadedFile piece;
6395 static struct UploadedFile {
6396 string contentFilename;
6400 /***************************************************/
6401 // https://issues.dlang.org/show_bug.cgi?id=8665
6403 auto foo8665a(bool val)
6405 if (val)
6406 return 42;
6407 else
6408 return 1.5;
6410 auto foo8665b(bool val)
6412 if (!val)
6413 return 1.5;
6414 else
6415 return 42;
6418 void test8665()
6420 static assert(is(typeof(foo8665a(true)) == double));
6421 static assert(is(typeof(foo8665b(false)) == double));
6422 assert(foo8665a(true) == 42); // assertion failure
6423 assert(foo8665b(true) == 42); // assertion failure
6424 assert(foo8665a(false) == 1.5);
6425 assert(foo8665b(false) == 1.5);
6427 static assert(foo8665a(true) == 42);
6428 static assert(foo8665b(true) == 42);
6429 static assert(foo8665a(false) == 1.5);
6430 static assert(foo8665b(false) == 1.5);
6433 /***************************************************/
6435 int foo8108(int, int);
6437 int foo8108(int a, int b)
6439 return a + b;
6442 void test8108()
6444 foo8108(1,2);
6447 /***************************************************/
6448 // https://issues.dlang.org/show_bug.cgi?id=8360
6450 struct Foo8360
6452 int value = 0;
6453 int check = 1337;
6455 this(int value)
6457 assert(0);
6458 this.value = value;
6461 ~this()
6463 assert(0);
6464 assert(check == 1337);
6467 string str()
6469 assert(0);
6470 return "Foo";
6474 Foo8360 makeFoo8360()
6476 assert(0);
6477 return Foo8360(2);
6480 void test8360()
6482 size_t length = 0;
6484 // The message part 'makeFoo().str()' should not be evaluated at all.
6485 assert(length < 5, makeFoo8360().str());
6488 /***************************************************/
6489 // https://issues.dlang.org/show_bug.cgi?id=8361
6491 struct Foo8361
6493 string bar = "hello";
6494 ~this() {}
6497 void test8361()
6499 assert(true, Foo8361().bar);
6502 /***************************************************/
6503 // https://issues.dlang.org/show_bug.cgi?id=6141
6504 // https://issues.dlang.org/show_bug.cgi?id=8526
6506 void test6141()
6508 static void takeADelegate(void delegate()) {}
6509 auto items = new int[1];
6510 items[0] = 17;
6511 foreach (ref item; items)
6513 // both asserts fail
6514 assert(item == 17);
6515 assert(&item == items.ptr);
6517 takeADelegate({ auto x = &item; });
6520 foreach(ref val; [3])
6522 auto dg = { int j = val; };
6523 assert(&val != null); // Assertion failure
6524 assert(val == 3);
6527 static void f(lazy int) {}
6528 int i = 0;
6529 auto dg = { int j = i; };
6530 foreach(ref val; [3])
6532 f(val);
6533 assert(&val != null); // Assertion failure
6534 assert(val == 3);
6538 void test8526()
6540 static void call(void delegate() dg) { dg(); }
6542 foreach (i, j; [0])
6544 call({
6545 assert(i == 0); // fails, i is corrupted
6549 foreach (n; 0..1)
6551 call({
6552 assert(n == 0); // fails, n is corrupted
6557 /***************************************************/
6559 template ParameterTuple(alias func)
6561 static if(is(typeof(func) P == __parameters))
6562 alias P ParameterTuple;
6563 else
6564 static assert(0);
6567 int foo161(ref float y);
6569 void test161()
6571 alias PT = ParameterTuple!foo161;
6572 auto x = __traits(identifier, PT);
6573 assert(x == "y");
6576 /***************************************************/
6577 // https://issues.dlang.org/show_bug.cgi?id=7175
6579 void test7175()
6581 struct S { ubyte[0] arr; }
6582 S s;
6583 assert(s.arr.ptr !is null);
6584 assert(cast(void*)s.arr.ptr is cast(void*)&s);
6587 /***************************************************/
6588 // https://issues.dlang.org/show_bug.cgi?id=8819
6590 void test8819()
6592 void[1] sa1 = (void[1]).init;
6593 assert((cast(ubyte*)sa1.ptr)[0] == 0);
6595 void[4] sa4 = [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4];
6596 assert((cast(ubyte*)sa4.ptr)[0] == 1);
6597 assert((cast(ubyte*)sa4.ptr)[1] == 2);
6598 assert((cast(ubyte*)sa4.ptr)[2] == 3);
6599 assert((cast(ubyte*)sa4.ptr)[3] == 4);
6601 auto sa22 = (void[2][2]).init;
6602 static assert(sa22.sizeof == ubyte.sizeof * 2 * 2);
6603 ubyte[4]* psa22 = cast(ubyte[4]*)sa22.ptr;
6604 assert((*psa22)[0] == 0);
6605 assert((*psa22)[1] == 0);
6606 assert((*psa22)[2] == 0);
6607 assert((*psa22)[3] == 0);
6610 /***************************************************/
6611 // https://issues.dlang.org/show_bug.cgi?id=8897
6613 class C8897
6615 static mixin M8897!(int);
6616 static class causesAnError {}
6619 template M8897 ( E ) { }
6621 /***************************************************/
6622 // https://issues.dlang.org/show_bug.cgi?id=8917
6624 void test8917()
6626 int[3] a;
6627 int[3] a2;
6628 int[3] b = a[] + a2[];
6631 /***************************************************/
6632 // https://issues.dlang.org/show_bug.cgi?id=8945
6634 struct S8945 // or `class`, or `union`
6636 struct S0(T) { int i; }
6637 struct S1(T) { this(int){} }
6640 void test8945()
6642 auto cs0a = const S8945.S0!int(); // ok
6643 auto cs0b = const S8945.S0!int(1); // ok
6644 auto cs1 = const S8945.S1!int(1); // ok
6646 auto s0a = S8945.S0!int(); // Error: struct S0 does not overload ()
6647 auto s0b = S8945.S0!int(1); // Error: struct S0 does not overload ()
6648 auto s1 = S8945.S1!int(1); // Error: struct S1 does not overload ()
6651 /***************************************************/
6653 struct S162
6655 static int generateMethodStubs( Class )()
6657 int text;
6659 foreach( m; __traits( allMembers, Class ) )
6661 static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) == function ) )
6663 pragma(msg, __traits( getOverloads, Class, m ));
6667 return text;
6670 enum int ttt = generateMethodStubs!( S162 )();
6672 float height();
6673 int get( int );
6674 int get( long );
6675 void clear();
6677 void draw( int );
6678 void draw( long );
6681 /***************************************************/
6683 void test163() {
6684 static class C { int x; int y; }
6686 immutable C c = new C();
6687 shared C c2 = new C();
6688 shared const C c3 = new C();
6690 class D { int x; int y; }
6691 immutable D d;
6692 assert(!__traits(compiles, d = new D()));
6694 static struct S { int x; int y; }
6696 immutable S* s = new S();
6697 shared S* s2 = new S();
6698 shared const S* s3 = new S();
6700 shared S* s4;
6701 assert(__traits(compiles, s4 = new immutable(S)()));
6703 struct T { int x; int y; }
6704 immutable T* t;
6705 assert(!__traits(compiles, t = new T()));
6707 immutable int* pi = new int();
6708 immutable void* pv = new int();
6710 immutable int[] ai = new int[1];
6711 immutable void[] av = new int[2];
6714 /***************************************************/
6715 struct S9000
6716 { ubyte i = ubyte.max; }
6718 enum E9000 = S9000.init;
6720 /***************************************************/
6722 mixin template DefineCoreType(string type)
6724 struct Faulty
6726 static int x;
6728 static void instance()
6730 x = 3;
6733 X164!() xxx;
6737 mixin DefineCoreType!("");
6740 mixin template A164()
6742 static this()
6747 struct X164()
6749 mixin A164!();
6753 /***************************************************/
6754 // https://issues.dlang.org/show_bug.cgi?id=9428
6756 void test9428()
6758 int[2][] items = [[1, 2]];
6759 int[2] x = [3, 4];
6761 auto r1 = items ~ [x];
6762 assert(r1.length == 2);
6763 assert(r1[0][0] == 1);
6764 assert(r1[0][1] == 2);
6765 assert(r1[1][0] == 3);
6766 assert(r1[1][1] == 4);
6768 auto r2 = items ~ x;
6769 assert(r2.length == 2);
6770 assert(r2[0][0] == 1);
6771 assert(r2[0][1] == 2);
6772 assert(r2[1][0] == 3);
6773 assert(r2[1][1] == 4);
6775 auto r3 = [x] ~ items;
6776 assert(r3.length == 2);
6777 assert(r3[0][0] == 3);
6778 assert(r3[0][1] == 4);
6779 assert(r3[1][0] == 1);
6780 assert(r3[1][1] == 2);
6782 auto r4 = x ~ items;
6783 assert(r4.length == 2);
6784 assert(r4[0][0] == 3);
6785 assert(r4[0][1] == 4);
6786 assert(r4[1][0] == 1);
6787 assert(r4[1][1] == 2);
6790 /***************************************************/
6791 // https://issues.dlang.org/show_bug.cgi?id=9477
6793 template Tuple9477(T...) { alias T Tuple9477; }
6794 template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; }
6796 void test9477()
6798 static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; }
6799 static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; }
6801 // Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9748
6802 int order;
6803 // Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9756
6804 auto checkOrder(bool dyn, uint expected)()
6806 assert(order==expected);
6807 order++;
6808 // Use temporary ("v") to work around https://issues.dlang.org/show_bug.cgi?id=9402
6809 auto v = cast(Select9477!(dyn, string, char[1]))"a";
6810 return v;
6813 foreach (b1; Tuple9477!(false, true))
6814 foreach (b2; Tuple9477!(false, true))
6816 version (D_PIC) {} else version (D_PIE) {} else // Work around https://issues.dlang.org/show_bug.cgi?id=9754
6818 assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" ));
6819 assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" ));
6821 assert(!isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6822 assert( isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6825 assert( isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6826 assert(!isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6828 assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6829 assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6831 assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6832 assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6834 // Note: order of evaluation was not followed before this patch
6835 // (thus, the test below will fail without the patch).
6836 // Although the specification mentions that as implementation-defined behavior,
6837 // I understand that this isn't by design, but rather an inconvenient aspect of DMD
6838 // that has been moved to the specification.
6839 order = 0;
6840 bool result = checkOrder!(b1, 0)() == checkOrder!(b2, 1)();
6841 assert(result);
6842 assert(order == 2);
6845 // need largest natural alignment to avoid unaligned access on
6846 // some architectures, double in this case.
6847 align(8) ubyte[64] a1, a2;
6848 foreach (T; Tuple9477!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double))
6850 auto s1 = cast(T[])(a1[]);
6851 auto s2 = cast(T[])(a2[]);
6852 assert(s1 == s2);
6853 a2[$-1]++;
6854 assert(s1 != s2);
6855 assert(s1[0..$-1]==s2[0..$-1]);
6856 a2[$-1]--;
6860 /***************************************************/
6861 // https://issues.dlang.org/show_bug.cgi?id=9504
6863 struct Bar9504
6865 template Abc(T)
6867 T y;
6870 enum size_t num = 123;
6872 class Def {}
6875 template GetSym9504(alias sym) { static assert(__traits(isSame, sym, Bar9504.Abc)); }
6876 template GetExp9504(size_t n) { static assert(n == Bar9504.num); }
6877 template GetTyp9504(T) { static assert(is(T == Bar9504.Def)); }
6879 alias GetSym9504!(typeof(Bar9504.init).Abc) X9504; // NG
6880 alias GetExp9504!(typeof(Bar9504.init).num) Y9504; // NG
6881 alias GetTyp9504!(typeof(Bar9504.init).Def) Z9504;
6883 Bar9504 test9504()
6885 alias GetSym9504!(typeof(return).Abc) V9504; // NG
6886 alias GetExp9504!(typeof(return).num) W9504; // NG
6887 alias GetTyp9504!(typeof(return).Def) X9504;
6888 return Bar9504();
6891 /***************************************************/
6892 // https://issues.dlang.org/show_bug.cgi?id=9538
6894 void test9538()
6896 void*[1] x;
6897 auto ti = typeid(x.ptr);
6900 /***************************************************/
6901 // https://issues.dlang.org/show_bug.cgi?id=9539
6903 void test9539()
6905 void f(int** ptr)
6907 assert(**ptr == 10);
6909 int* p = new int;
6910 *p = 10;
6911 int*[1] x = [p];
6912 f(&x[0]);
6914 int*[] arr = [null];
6915 static assert(!__traits(compiles, p = arr)); // bad!
6918 /***************************************************/
6919 // https://issues.dlang.org/show_bug.cgi?id=9700
6921 mixin template Proxy9700(alias a)
6923 auto ref opOpAssign(string op, V)(V v) { return a += v; } // NG
6924 //auto ref opOpAssign(string op, V)(V v) { a += v; } // OK
6926 struct MyInt9700
6928 int value;
6929 invariant() { assert(value >= 0); }
6930 mixin Proxy9700!value;
6932 void test9700()
6934 MyInt9700 a = { 2 };
6935 a *= 3; // object.Error: Access Violation
6938 /***************************************************/
6939 // https://issues.dlang.org/show_bug.cgi?id=9834
6941 struct Event9834
6943 void delegate() dg;
6944 void set(void delegate() h) pure { dg = h; } // AV occurs
6945 void call() { dg(); }
6947 void test9834()
6949 Event9834 ev;
6950 auto a = new class
6952 Object o;
6953 this()
6955 o = new Object;
6956 ev.set((){ o.toString(); });
6959 ev.call();
6962 /***************************************************/
6963 // https://issues.dlang.org/show_bug.cgi?id=9859
6965 void test9859(inout int[] arr)
6967 auto dg1 = { foreach (i, e; arr) { } };
6968 dg1();
6970 void foo() { auto v = arr; auto w = arr[0]; }
6971 void bar(inout int i) { auto v = arr[i]; }
6973 auto dg2 =
6975 auto dg =
6977 void foo(T)()
6979 auto dg =
6981 auto dg =
6983 auto v = arr;
6987 foo!int;
6991 void qux(T)()
6993 auto v = arr;
6994 auto dg1 = { auto v = arr; };
6995 auto dg2 =
6997 auto dg =
6999 auto v = arr;
7003 qux!int;
7006 /***************************************************/
7007 // https://issues.dlang.org/show_bug.cgi?id=9912
7009 template TypeTuple9912(Stuff...)
7011 alias Stuff TypeTuple9912;
7014 struct S9912
7016 int i;
7017 alias TypeTuple9912!i t;
7019 void testA() {
7020 auto x = t;
7023 void testB() {
7024 auto x = t;
7028 /***************************************************/
7029 // https://issues.dlang.org/show_bug.cgi?id=9883
7031 struct S9883
7033 @property size_t p9883(T)() { return 0; }
7036 @property size_t p9883(T)() { return 0; }
7038 void test9883()
7040 S9883 s;
7041 auto n1 = p9883!int; // OK
7042 auto n2 = s.p9883!int; // OK
7043 auto a1 = new int[p9883!int]; // Error: need size of rightmost array, not type p!(int)
7044 auto a2 = new int[s.p9883!int]; // Error: no property 'p!(int)' for type 'S'
7048 /***************************************************/
7049 // https://issues.dlang.org/show_bug.cgi?id=10091
7051 struct S10091
7053 enum e = "a";
7056 void test10091()
7058 auto arr = cast(ubyte[1]) S10091.e;
7061 /***************************************************/
7063 void test12824()
7065 label:
7066 static if (0)
7071 /***************************************************/
7072 // https://issues.dlang.org/show_bug.cgi?id=9130
7074 class S9130 { void bar() { } }
7076 import core.stdc.stdio : printf;
7078 struct Function
7080 int[] ai = [1,2,3];
7083 @property void meta(alias m)()
7085 static Function md;
7086 printf("length = %zd\n", md.ai.length);
7087 printf("ptr = %p\n", md.ai.ptr);
7088 md.ai[0] = 0;
7091 void test9130()
7093 meta!(__traits(getOverloads, S9130, "bar")[0]);
7094 meta!(S9130.bar);
7097 /***************************************************/
7098 // https://issues.dlang.org/show_bug.cgi?id=10390
7100 class C10390 { this() { this.c = this; } C10390 c; }
7101 const c10390 = new C10390();
7102 pragma(msg, c10390);
7104 /***************************************************/
7105 // https://issues.dlang.org/show_bug.cgi?id=10542
7107 class B10542
7109 this() nothrow pure @safe { }
7112 class D10542 : B10542
7116 void test10542() nothrow pure @safe
7118 new D10542;
7121 /***************************************************/
7122 // https://issues.dlang.org/show_bug.cgi?id=10539
7124 void test10539()
7126 int[2][2] a;
7127 int* p1 = a.ptr.ptr; // OK <- error
7128 int* p2 = (*a.ptr).ptr; // OK
7129 assert(p1 is p2);
7132 /***************************************************/
7134 struct TimeOfDay
7136 ubyte h, m, s;
7139 __gshared byte glob;
7141 struct DateTime
7143 this(ubyte _d, ubyte _m, ubyte _y, TimeOfDay _tod = TimeOfDay.init)
7145 d = _d;
7146 m = _m;
7147 y = _y;
7148 tod = _tod;
7150 TimeOfDay tod;
7151 ubyte d, m, y;
7155 void test10634()
7157 glob = 123;
7158 DateTime date1 = DateTime(0, 0, 0);
7159 DateTime date2;
7160 assert(date1 == date2);
7163 /***************************************************/
7165 immutable(char)[4] bar7254(int i)
7167 if (i)
7169 immutable(char)[4] r; return r;
7171 else
7172 return "1234";
7175 void test7254()
7177 assert(bar7254(0) == "1234");
7180 /***************************************************/
7182 struct S11075() { int x = undefined_expr; }
7184 class C11075() { int x = undefined_expr; }
7186 interface I11075() { enum int x = undefined_expr; }
7188 void test11075()
7190 static assert(!is(typeof(S11075!().x)));
7191 static assert(!is(typeof(S11075!().x)));
7193 static assert(!is(typeof(C11075!().x)));
7194 static assert(!is(typeof(C11075!().x)));
7196 static assert(!is(typeof(I11075!().x)));
7197 static assert(!is(typeof(I11075!().x)));
7200 /***************************************************/
7201 // https://issues.dlang.org/show_bug.cgi?id=11181
7203 void test11181()
7205 auto a = ["a", "b"];
7207 static assert(!is(typeof([a, "x"])));
7208 static assert(!is(typeof(true ? a : "x")));
7210 static assert(!is(typeof(true ? a[0 .. $] : "x")));
7211 static assert(!is(typeof([a[0 .. $], "x"])));
7214 /***************************************************/
7215 // https://issues.dlang.org/show_bug.cgi?id=11317
7217 void test11317()
7219 auto ref uint fun()
7221 return 0;
7224 void test(ref uint x) {}
7225 static assert(__traits(compiles, test(fun())));
7227 assert(fun() == 0);
7230 /***************************************************/
7231 // https://issues.dlang.org/show_bug.cgi?id=11888
7233 void test11888()
7235 static long val;
7237 static ubyte* foo(size_t* len)
7239 *len = val.sizeof;
7240 return cast(ubyte*)&val;
7243 size_t size;
7244 ubyte[] t = foo(&size)[0..size];
7245 assert(t.ptr is cast(void*)&val);
7246 assert(t.length == 8);
7248 // regression test
7249 int[3] sa1 = [1,2,3];
7250 int[1] sa2 = sa1[1..2]; // convert slice to Tsarray
7251 assert(sa2.length == 1);
7252 assert(sa2[0] == 2);
7255 /***************************************************/
7256 // https://issues.dlang.org/show_bug.cgi?id=12036
7258 template T12036(alias a)
7260 string value;
7263 struct S12036
7265 auto fun() { }
7266 mixin T12036!fun;
7269 void test12036()
7271 S12036 s;
7272 assert(s.value == "");
7275 /***************************************************/
7276 // https://issues.dlang.org/show_bug.cgi?id=12153
7278 void test12153()
7280 int[1] i, j;
7281 bool b = true;
7282 (b ? i : j)[] = [4];
7283 assert(i == [4]);
7285 // regression test
7286 int[1][1] k, l;
7287 (b ? k : l)[0..1][0..1] = [4];
7288 assert(k == [[4]]);
7291 /***************************************************/
7292 // https://issues.dlang.org/show_bug.cgi?id=12498
7294 string a12498()
7296 string b;
7297 while (b) { }
7298 for (; b; ) { }
7299 return "";
7302 void test12498()
7304 enum t = a12498();
7305 string x = t;
7308 /***************************************************/
7309 // https://issues.dlang.org/show_bug.cgi?id=12900
7311 struct A12900
7313 char[1] b;
7316 void test12900()
7318 A12900 c;
7319 if (*c.b.ptr)
7320 return;
7323 /***************************************************/
7324 // https://issues.dlang.org/show_bug.cgi?id=12929
7326 struct Foo12929
7328 union { }
7329 int var;
7332 struct Bar12929
7334 struct { }
7335 int var;
7338 /***************************************************/
7339 // https://issues.dlang.org/show_bug.cgi?id=12937
7341 void test12937()
7343 void[1] sa2 = cast(void[])[cast(ubyte)1]; // ICE!
7344 assert((cast(ubyte[])sa2[])[0] == 1);
7347 /***************************************************/
7348 // https://issues.dlang.org/show_bug.cgi?id=13154
7350 void test13154()
7352 int[3] ints = [2 , 1 , 0 , 1 ][0..3];
7353 float[3] floats0 = [2f , 1f , 0f , 1f ][0..3];
7354 float[3] floats1 = [2.0 , 1.0 , 0.0 , 1.0 ][0..3]; // fails!
7355 float[3] floats2 = [2.0f, 1.0f, 0.0f, 1.0f][0..3];
7356 assert(ints == [2, 1, 0]);
7357 assert(floats0 == [2, 1, 0]);
7358 assert(floats1 == [2, 1, 0]); // fail!
7359 assert(floats1 != [0, 0, 0]); // fail!
7360 assert(floats2 == [2, 1, 0]);
7363 /***************************************************/
7364 // https://issues.dlang.org/show_bug.cgi?id=13437
7366 ubyte[4] foo13437() { return [1,2,3,4]; }
7368 void test13437()
7370 auto n = cast(ubyte[4])foo13437()[]; // OK <- ICE: e2ir.c 4616
7371 static assert(is(typeof(n) == ubyte[4]));
7372 assert(n == [1,2,3,4]);
7375 /***************************************************/
7376 // https://issues.dlang.org/show_bug.cgi?id=13472
7378 class A13472
7380 int a;
7383 void test13472()
7385 A13472[] test;
7386 test.length = 4;
7387 auto b = test[0..2] ~ null ~ test[2..$];
7388 assert(b.length == 5);
7391 /***************************************************/
7392 // https://issues.dlang.org/show_bug.cgi?id=13476
7394 template ParameterTypeTuple13476(func...)
7396 static if (is(typeof(*func[0]) P == function))
7397 alias ParameterTypeTuple13476 = P;
7398 else
7399 static assert(0, "argument has no parameters");
7402 int flag13476;
7404 __gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476;
7406 extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args)
7408 ++flag13476;
7409 extern(C) void function(int) nothrow impl = (i) { };
7410 return (func = impl)(args);
7413 __gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP;
7414 __gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt;
7416 extern(C) auto Stub13476Alt(alias func)(int args) nothrow
7418 ++flag13476;
7419 extern(C) void function(int) nothrow impl = (i) {};
7420 return (*func = impl)(args);
7423 void test13476()
7425 assert(flag13476 == 0);
7427 someFunc13476(42);
7428 assert(flag13476 == 1);
7429 someFunc13476(43);
7430 assert(flag13476 == 1);
7432 someFunc13476Alt(42);
7433 assert(flag13476 == 2);
7434 someFunc13476Alt(43);
7435 assert(flag13476 == 2);
7438 /***************************************************/
7439 // https://issues.dlang.org/show_bug.cgi?id=14038
7441 static immutable ubyte[string] wordsAA14038;
7442 shared static this()
7444 wordsAA14038["zero"] = 0;
7447 /***************************************************/
7448 // https://issues.dlang.org/show_bug.cgi?id=14192
7450 void test14192()
7452 shared int[int] map;
7453 map[1] = 1;
7456 /***************************************************/
7457 // https://issues.dlang.org/show_bug.cgi?id=13720
7459 struct FracSec13720
7461 this(int hnsecs) {}
7464 struct SysTime13720
7466 this(TimeOfDay13720 dateTime, FracSec13720 fracSec)
7471 struct TimeOfDay13720
7473 ~this() { }
7476 void assertThrown13720(T)(lazy T) {}
7478 void test13720()
7480 assertThrown13720(SysTime13720(TimeOfDay13720.init, FracSec13720(-1)));
7483 /***************************************************/
7484 // https://issues.dlang.org/show_bug.cgi?id=13952
7486 struct Reg13952
7488 ubyte type;
7489 ubyte regNo;
7490 ushort size;
7493 struct Imm13952
7495 ulong imm;
7498 struct Opnd13952
7500 union
7502 Reg13952 reg; // size == 4
7503 Imm13952 imm; // size == 8
7505 ubyte tag;
7507 this(Reg13952 r) { reg = r; }
7510 Opnd13952 opnd13952(Reg13952 reg)
7512 return Opnd13952(reg);
7515 void test13952()
7517 Reg13952 reg;
7518 auto op = opnd13952(reg);
7519 auto buf = (cast(ubyte*)&op)[0 .. op.sizeof];
7520 //debug
7522 // import std.stdio;
7523 // writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]);
7524 // writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]);
7526 foreach (e; buf) assert(e == 0);
7529 /***************************************************/
7530 // https://issues.dlang.org/show_bug.cgi?id=14165
7532 class Foo14165
7534 @disable this();
7535 this(int i) {}
7538 /***************************************************/
7539 // https://issues.dlang.org/show_bug.cgi?id=13985
7541 interface I13985
7543 void m1();
7544 void m2();
7545 void m3();
7547 final void mf()
7549 m3();
7553 class C13985 : I13985
7555 void m1() {}
7556 void m2() {}
7557 void m3() {}
7560 class D13985 : C13985
7562 void ml()
7564 super.mf();
7568 void test13985()
7570 auto d = new D13985();
7571 d.ml();
7574 /***************************************************/
7575 // https://issues.dlang.org/show_bug.cgi?id=14211
7577 extern(C++) // all derived classes won't have invariants
7578 class B14211
7580 void func()
7585 final class C14211 : B14211
7589 void test14211()
7591 auto c = new C14211();
7592 *cast(void**)c = null;
7593 c.func(); // called without vtbl access
7596 /***************************************************/
7597 // https://issues.dlang.org/show_bug.cgi?id=14552
7599 template map14552(fun...)
7601 template AppliedReturnType(alias f)
7603 alias typeof(f(0)) AppliedReturnType;
7606 auto map14552(int[] r)
7608 assert(!is(AppliedReturnType!fun));
7609 return MapResult14552!fun();
7613 struct MapResult14552(alias fun)
7615 @property front()
7617 fun(0);
7621 class Outer14552
7623 auto test()
7625 [1].map14552!(j => new Inner);
7627 class Inner {}
7630 /***************************************************/
7631 // https://issues.dlang.org/show_bug.cgi?id=14853
7633 struct Queue14853(T)
7635 struct Node
7637 T mfPayload = T.init;
7638 union
7640 typeof(this)* mfPrev;
7641 shared(typeof(this)*) mfShPrev;
7643 union
7645 typeof(this)* mfNext;
7646 shared(typeof(this)*) mfShNext;
7650 Node root;
7652 void pfPut(T v, Node* r = null)
7654 shared n = new Node(v); // problem!
7658 void test14853()
7660 auto b1 = new Queue14853!uint;
7663 /********************************************************/
7664 // https://issues.dlang.org/show_bug.cgi?id=15045
7666 void test15045()
7668 void testName(T, bool r, string name)()
7670 T t;
7672 static assert(r == is(typeof(mixin("T."~name))));
7673 static assert(r == is(typeof(mixin("t."~name))));
7674 static assert(r == __traits(compiles, mixin("T."~name)));
7675 static assert(r == __traits(compiles, mixin("t."~name)));
7676 static assert(r == mixin("__traits(compiles, T."~name~")"));
7677 static assert(r == mixin("__traits(compiles, t."~name~")"));
7679 static assert(r == __traits(hasMember, T, name) );
7680 static assert(r == __traits(hasMember, t, name) );
7681 static assert(r == __traits(compiles, __traits(getMember, T, name) ));
7682 static assert(r == __traits(compiles, __traits(getMember, t, name) ));
7683 static assert(r == __traits(compiles, __traits(getOverloads, T, name) ));
7684 static assert(r == __traits(compiles, __traits(getOverloads, t, name) ));
7686 void test(T, bool r)()
7688 testName!(T, r, "__ctor")();
7689 testName!(T, r, "__dtor")();
7690 testName!(T, r, "__xdtor")();
7691 testName!(T, r, "__postblit")();
7692 testName!(T, r, "__xpostblit")();
7695 static struct X
7697 this(int) {}
7698 this(this) {}
7699 ~this() {}
7702 static struct S1
7704 auto opDispatch(string name, A...)(A args) { }
7706 static struct S2
7708 X get() { return X(); };
7709 alias get this;
7711 static struct S3
7713 X opDot() { return X(); };
7716 test!(X, true)();
7717 test!(S1, false)();
7718 test!(S2, false)();
7719 test!(S3, false)();
7722 /***************************************************/
7723 // https://issues.dlang.org/show_bug.cgi?id=15116
7725 alias TypeTuple15116(T...) = T;
7727 template Mix15116()
7729 TypeTuple15116!(int, int) tup;
7732 struct S15116
7734 mixin Mix15116 mix;
7737 void test15116()
7739 S15116 s;
7740 auto x1 = s.tup; // OK
7741 auto x2 = s.mix.tup; // OK <- NG
7744 /***************************************************/
7745 // https://issues.dlang.org/show_bug.cgi?id=15117
7747 template Mix15117()
7749 int y = { typeof(this)* s; return s ? s.mix.y : 0; }();
7752 struct S15117
7754 int x = { typeof(this)* s; return s ? s.x : 0; }(); // OK
7756 mixin Mix15117 mix; // OK <- NG
7759 /***************************************************/
7760 // https://issues.dlang.org/show_bug.cgi?id=15126
7762 struct Json15126
7764 ubyte[16] m_data;
7765 int opDispatch(string prop)() const { return 0; }
7766 int opDispatch(string prop)() { return 0; }
7769 template isCustomSerializable15126(T)
7771 enum isCustomSerializable15126 = T.init.toRepresentation();
7774 alias bug15126 = isCustomSerializable15126!Json15126;
7776 /***************************************************/
7777 // https://issues.dlang.org/show_bug.cgi?id=15141
7779 class A15141
7781 abstract void method();
7784 class B15141 : A15141 { }
7786 void test15141()
7788 auto a = Object.factory(__MODULE__ ~ ".A15141");
7789 assert(a is null);
7790 auto b = Object.factory(__MODULE__ ~ ".B15141");
7791 assert(b is null); // OK <- oops
7794 /***************************************************/
7795 // https://issues.dlang.org/show_bug.cgi?id=15366
7797 enum E15366 : bool { A, B };
7799 struct S15366
7801 void func1(E15366 e) {}
7803 void func2(E15366 a, E15366 b)
7805 func1(cast(E15366)(a && b));
7806 func1(cast(E15366)(a || b));
7808 auto x1 = cast(E15366)(a && b);
7809 auto x2 = cast(E15366)(a || b);
7813 /***************************************************/
7814 // https://issues.dlang.org/show_bug.cgi?id=15369
7816 struct MsgTable15369
7818 const(char)[] ident;
7819 const(char)* name;
7822 MsgTable15369[] msgTable15369 =
7824 { "empty", "" },
7827 void test15369()
7829 auto id = msgTable15369[0].ident;
7830 auto p = msgTable15369[0].name;
7832 // a string literal "" should be zero-terminated
7833 assert(*p == '\0');
7836 void test15638()
7838 class A {}
7839 class B : A {}
7840 class C : A {}
7842 B b;
7843 C c;
7844 const(B) cb;
7845 const(C) cc;
7846 immutable(B) ib;
7847 immutable(C) ic;
7849 // Common type for const derived classes
7850 auto constCommon = true ? cb : cc;
7851 static assert(is(typeof(constCommon) == const(A)));
7853 // Common type for immutable derived classes
7854 auto immutableCommon = true ? ib : ic;
7855 static assert(is(typeof(immutableCommon) == immutable(A)));
7857 // Common type for mixed const/immutable derived classes
7858 auto mixed1 = true ? cb : ic;
7859 static assert(is(typeof(mixed1) == const(A)));
7860 auto mixed2 = true ? ib : cc;
7861 static assert(is(typeof(mixed2) == const(A)));
7863 // Common type for mixed mutable/immutable derived classes
7864 auto mixed3 = true ? b : ic;
7865 static assert(is(typeof(mixed3) == const(A)));
7866 auto mixed4 = true ? ib : c;
7867 static assert(is(typeof(mixed4) == const(A)));
7869 // Array literal type deduction
7870 auto arr1 = [ new immutable(B), new C ];
7871 auto arr2 = [ new B, new const(C) ];
7872 auto arr3 = [ new immutable(B), new immutable(C) ];
7873 static assert(is(typeof(arr1) == const(A)[]));
7874 static assert(is(typeof(arr2) == const(A)[]));
7875 static assert(is(typeof(arr3) == immutable(A)[]));
7878 /***************************************************/
7879 // https://issues.dlang.org/show_bug.cgi?id=15961
7881 struct SliceOverIndexed15961(T)
7883 enum assignableIndex = T.init;
7886 struct Grapheme15961
7888 SliceOverIndexed15961!Grapheme15961 opSlice()
7890 assert(0);
7893 struct
7895 ubyte* ptr_;
7899 /***************************************************/
7900 // https://issues.dlang.org/show_bug.cgi?id=16022
7902 bool test16022()
7904 enum Type { Colon, Comma }
7905 Type type;
7906 return type == Type.Comma;
7909 bool test16022_structs()
7911 struct A
7913 int i;
7914 string s;
7917 enum Type { Colon = A(0, "zero"), Comma = A(1, "one") }
7918 Type type;
7919 return type == Type.Comma;
7922 /***************************************************/
7923 // https://issues.dlang.org/show_bug.cgi?id=16233
7925 enum valueConvertible(T1, T2) = blah;
7927 struct Checked(T, Hook)
7929 bool opEquals(U)(Checked!(U, Hook) rhs)
7931 alias R = typeof(payload + rhs.payload);
7932 static if (valueConvertible!(T, R))
7935 return false;
7939 void test16233()
7941 Checked!(Checked!(int, void), void) x1;
7944 /***************************************************/
7945 // https://issues.dlang.org/show_bug.cgi?id=16466
7947 void test16466()
7949 static struct S
7951 real r;
7953 real r;
7954 printf("S.alignof: %zx, r.alignof: %zx\n", S.alignof, r.alignof);
7955 assert(S.alignof == r.alignof);
7958 /***************************************************/
7960 // https://issues.dlang.org/show_bug.cgi?id=16408
7962 char[1] SDL_GetKeyName_buffer;
7964 const(char)[] SDL_GetKeyName(char k)
7966 pragma(inline, false);
7967 SDL_GetKeyName_buffer[0] = k;
7968 return SDL_GetKeyName_buffer[];
7971 void formattedWrite(const(char)[] strW, const(char)[] strA, const(char)[] strC)
7973 pragma(inline, false);
7975 assert(strW == "W");
7976 assert(strA == "A");
7977 assert(strC == "C");
7980 void test16408()
7982 pragma(inline, false);
7983 formattedWrite(
7984 SDL_GetKeyName('W').idup,
7985 SDL_GetKeyName('A').idup,
7986 SDL_GetKeyName('C').idup
7990 /***************************************************/
7991 // https://issues.dlang.org/show_bug.cgi?id=17349
7993 void test17349()
7995 static struct S
7997 // Specify attribute inferred for dg1/dg2
7998 int bar(void delegate(ref int*) pure nothrow @nogc @safe) { return 1; }
7999 int bar(void delegate(ref const int*) pure nothrow @nogc @safe) const { return 2; }
8002 void dg1(ref int*) { }
8003 void dg2(ref const int*) { }
8004 S s;
8005 int i;
8006 i = s.bar(&dg1);
8007 assert(i == 1);
8008 i = s.bar(&dg2);
8009 assert(i == 2);
8012 /***************************************************/
8013 // https://issues.dlang.org/show_bug.cgi?id=17915
8015 void test17915()
8017 static class MyClass
8019 S17915!MyClass m_member;
8023 struct S17915(T)
8025 T owner;
8028 void test18232()
8030 static struct Canary
8032 int x = 0x900D_900D;
8034 union U
8036 Canary method()
8038 Canary c;
8039 return c;
8042 U u;
8043 assert(u.method() == Canary.init);
8046 /***************************************************/
8048 int main()
8050 test1();
8051 test2();
8052 test4();
8053 test5();
8054 test6();
8055 test7();
8056 test8();
8057 test9();
8058 test10();
8059 test11();
8060 test12();
8061 test13();
8062 test14();
8063 test15();
8064 test16();
8065 test17();
8066 test18();
8067 test19();
8068 test20();
8069 test21();
8070 test22();
8071 test23();
8072 test24();
8073 test25();
8074 test26();
8075 test27();
8076 test28();
8077 test29();
8078 test30();
8079 test31();
8080 test32();
8081 test33();
8082 test34();
8083 test35();
8084 test36();
8085 test37();
8086 test38();
8087 test39();
8088 test40();
8089 test41();
8090 test42();
8091 test43();
8092 test44();
8093 test45();
8094 test46();
8095 test47();
8096 test48();
8097 test49();
8098 test796();
8099 test50();
8100 test51();
8101 test52();
8102 test53();
8103 test54();
8104 test55();
8105 test56();
8106 test57();
8107 test58();
8109 test60();
8110 test61();
8111 test62();
8112 test63();
8113 test64();
8114 test65();
8115 test66();
8116 test67();
8117 test68();
8118 test69();
8119 test70();
8121 test5785();
8122 test72();
8123 test73();
8124 test74();
8125 test75();
8126 test76();
8127 test77();
8128 test78();
8129 test79();
8130 test80();
8131 test81();
8132 test82();
8133 test83();
8134 test3559();
8135 test84();
8136 test85();
8137 test2006();
8138 test8442();
8139 test86();
8140 test87();
8141 test2486();
8142 test5554();
8143 test88();
8144 test7545();
8145 test89();
8146 test90();
8147 test91();
8148 test92();
8149 test4536();
8150 test93();
8151 test94();
8152 test95();
8153 test5403();
8154 test96();
8155 test97();
8156 test98();
8157 test99();
8158 test100();
8159 test101();
8161 test103();
8162 test104();
8163 test105();
8164 test3927();
8165 test107();
8167 test109();
8169 test111();
8171 test113();
8173 test115();
8174 test116();
8175 test117();
8176 test3822();
8177 test6545();
8178 test118();
8179 test5081();
8181 test120();
8182 test10724();
8183 test122();
8184 test123();
8185 test124();
8186 test125();
8187 test6763();
8189 test127();
8190 test128();
8191 test1891();
8192 test129();
8193 test130();
8194 test1064();
8195 test131();
8196 test132();
8197 test133();
8198 test134();
8199 test135();
8200 test136();
8201 test137();
8202 test138();
8203 test1962();
8204 test139();
8205 test140();
8206 test141();
8207 test6317();
8208 test142();
8209 test143();
8210 test144();
8211 test145();
8212 test146();
8213 test147();
8214 test6685();
8215 test148();
8216 test149();
8217 test2356();
8218 test13652();
8219 test11238();
8220 test2540();
8221 test14348();
8222 test150();
8223 test151();
8224 test152();
8225 test153();
8226 test154();
8227 test155();
8228 test156();
8229 test658();
8230 test3632();
8231 test4258();
8232 test4539();
8233 test4963();
8234 test4031();
8235 test5437();
8236 test6230();
8237 test6264();
8238 test6284();
8239 test6295();
8240 test6293();
8241 test5046();
8242 test1471();
8243 test6335();
8244 test1687();
8245 test6228();
8246 test3733();
8247 test4392();
8248 test7942();
8249 test6220();
8250 test5799();
8251 test157();
8252 test6473();
8253 test6630();
8254 test6690();
8255 test2953();
8256 test2997();
8257 test4423();
8258 test4647();
8259 test5696();
8260 test6084();
8261 test6488();
8262 test6565();
8263 test6836();
8264 test6837();
8265 test6927();
8266 test6733();
8267 test6813();
8268 test6859();
8270 test6910();
8271 test6902();
8272 test6330();
8273 test6868();
8274 test2856();
8275 test3091();
8276 test6056();
8277 test6356();
8278 test7073();
8279 test7104();
8280 test7150();
8281 test7160();
8282 test7168();
8283 test7170();
8284 test7196();
8285 test7285();
8286 test14737();
8287 test7321();
8288 test3282();
8289 test7534();
8290 test7534cov();
8291 test7618();
8292 test7621();
8293 test11417();
8294 test7682();
8295 test7735();
8296 test7823();
8297 test7871();
8298 test7906();
8299 test7907();
8300 test12503();
8301 test8004();
8302 test8064();
8303 test8105();
8304 test159();
8305 test12824();
8306 test8283();
8307 test13182();
8308 test8269();
8309 test8395();
8310 test13427();
8311 test5749();
8312 test8396();
8313 test160();
8314 test8665();
8315 test8108();
8316 test8360();
8317 test9577();
8318 test6141();
8319 test199();
8320 test8526();
8321 test161();
8322 test7175();
8323 test8819();
8324 test8917();
8325 test8945();
8326 test11805();
8327 test14192();
8328 test163();
8329 test9428();
8330 test9477();
8331 test9538();
8332 test9700();
8333 test9834();
8334 test13947();
8335 test9883();
8336 test10091();
8337 test9130();
8338 test10542();
8339 test10539();
8340 test10634();
8341 test15080();
8342 test7254();
8343 test13468();
8344 test11075();
8345 test11181();
8346 test11317();
8347 test11888();
8348 test12036();
8349 test12153();
8350 test12937();
8351 test13154();
8352 test13437();
8353 test13472();
8354 test13476();
8355 test13720();
8356 test13952();
8357 test13985();
8358 test14211();
8359 test15141();
8360 test15369();
8361 test15638();
8362 test16233();
8363 test16466();
8364 test16408();
8365 test17349();
8366 test17915();
8367 test18232();
8369 printf("Success\n");
8370 return 0;