7 import core.stdc.stdio;
11 /***************************************************/
24 int i = foo.myCast!(int)(1.0);
27 /***************************************************/
31 static T foo(T)(T t) { return 7 + t; }
43 i = Bar.a.foo!(int)(2);
49 /***************************************************/
53 auto i = mixin("__LINE__");
58 /***************************************************/
77 /***************************************************/
79 char a5 = (cast(char[])['a']) [$-1];
86 /***************************************************/
87 // Bug 1200. One case moved to deprecate1.d
106 synchronized debug {}
117 /***************************************************/
131 foreach( char[] c; t ){
132 new class( c ) C7, I7 {
133 public this( char[] c ){
142 /***************************************************/
144 const ulong[] A8 = ([1LU])[0..$];
151 /***************************************************/
155 writeln(long.max.stringof);
156 writeln(ulong.max.stringof);
157 assert(long.max.stringof == "9223372036854775807L");
158 assert(ulong.max.stringof == "18446744073709551615LU");
161 /***************************************************/
163 const ulong[] A10 = [1UL];
164 const ulong[] B10 = A10 ~ [1UL];
170 /***************************************************/
173 private final void foo() {}
176 class Derived11 : Base11 {
184 /***************************************************/
189 assert((bar ~ 1).length == bar.length + 1);
192 assert((baz ~ cast(int[])[1]).length == baz.length + 1);
195 assert((foo ~ cast(char[])"foo").length == foo.length + 1);
196 assert((cast(char[])"foo" ~ foo).length == foo.length + 1);
198 printf("%d\n", (foo ~ cast(char[])"foo")[0].length);
200 assert((foo ~ [cast(char[])"foo"]).length == foo.length + 1);
203 assert(([qux] ~ cast(char[])"foo").length == [qux].length + 1);
205 assert(([cast(dchar[])"asdf"] ~ cast(dchar[])"foo").length == [cast(dchar[])"asdf"].length + 1);
208 auto quuux = quux.dup;
210 assert (quuux.length == quux.length + 1);
213 /***************************************************/
215 int prop() { return 3; }
223 /***************************************************/
225 void recurse(ref int i)
235 /***************************************************/
237 void bar15(void delegate(int) dg)
246 private void callback(int i)
265 /***************************************************/
267 void bar16(int i, ...) { }
274 bar16(1, cast(void function())&foo16);
277 /***************************************************/
279 void foo17(char[4] buf, dchar c) { }
280 void foo17(string s) { }
281 void foo17(wstring s) { }
290 /***************************************************/
296 static void opCall(string msg) { assert(0); }
298 static void opCall() { }
306 /***************************************************/
312 static void opCall(string msg) { assert(0); }
314 static void opCall() { }
322 /***************************************************/
324 extern (System) void test20()
328 /***************************************************/
336 return *cast(int*)&func21;
344 /***************************************************/
346 void bar22(alias T)()
359 Test22 t = new Test22();
364 /***************************************************/
390 /***************************************************/
400 auto s24 = Foo24.gen();
404 assert(s24 == "abc");
407 /***************************************************/
411 int[10] arrayA = [0,1,2,3,4,5,6,7,8,9];
412 foreach(int i; arrayA)
418 /************************************/
420 const char[][7] DAY_NAME = [
421 DAY.SUN: "sunday", "monday", "tuesday", "wednesday",
422 "thursday", "friday", "saturday"
425 enum DAY { SUN, MON, TUE, WED, THU, FRI, SAT }
429 assert(DAY_NAME[DAY.SUN] == "sunday");
430 assert(DAY_NAME[DAY.MON] == "monday");
431 assert(DAY_NAME[DAY.TUE] == "tuesday");
432 assert(DAY_NAME[DAY.WED] == "wednesday");
433 assert(DAY_NAME[DAY.THU] == "thursday");
434 assert(DAY_NAME[DAY.FRI] == "friday");
435 assert(DAY_NAME[DAY.SAT] == "saturday");
438 /***************************************************/
444 /***************************************************/
448 C29 copy() { return this; }
463 /***************************************************/
465 template Tuple31(T...) { alias T Tuple31; }
466 alias Tuple31!(int,int) TType31;
468 void bar31(TType31) {
475 /***************************************************/
477 template Foo32(T : S!(T), alias S)
488 Foo32!(Struct32!(int)) f;
491 /***************************************************/
501 /***************************************************/
503 void foo34(in string s)
512 /***************************************************/
524 auto t = typeid(S35);
525 writefln("s = %s", s);
526 writefln("s = %s", t);
527 auto tis = cast(TypeInfo_Struct)t;
528 writefln("s = %s", tis);
529 writefln("s = %s", tis.xtoString);
530 assert(tis.xtoString != null);
533 /***************************************************/
542 /***************************************************/
544 template isStaticArray(T : U[], U)
546 const bool isStaticArray = is(typeof(U) == typeof(T.init));
549 template isStaticArray(T, U = void)
551 const bool isStaticArray = false;
554 template isStaticArray(T : T[N], size_t N)
556 const bool isStaticArray = true;
559 static assert (isStaticArray!(int[51]));
560 static assert (isStaticArray!(int[][2]));
561 static assert (isStaticArray!(char[][int][11]));
562 static assert (!isStaticArray!(int[]));
563 static assert (!isStaticArray!(int[char]));
564 static assert (!isStaticArray!(int[1][]));
566 static assert(isStaticArray!(void[0]));
572 /***************************************************/
576 const bool Foo38 = false;
579 template Foo38(T : U[N], U, size_t N)
581 const bool Foo38 = true;
586 static assert (Foo38!(int[51]));
589 /***************************************************/
595 /***************************************************/
599 static x = [[1.0, 2.0], [3.0, 4.0]]; // works
600 assert(x[0][0] == 1.0);
601 assert(x[0][1] == 2.0);
602 assert(x[1][0] == 3.0);
603 assert(x[1][1] == 4.0);
605 auto y = [[1.0, 2.0], [3.0, 4.0]]; // fails
606 assert(y[0][0] == 1.0);
607 assert(y[0][1] == 2.0);
608 assert(y[1][0] == 3.0);
609 assert(y[1][1] == 4.0);
612 /***************************************************/
624 printf("&x = %p\n", &x41);
625 printf("&s = %p\n", &s41);
626 assert((cast(int)&s41 & 0xF) == 0);
629 /***************************************************/
631 int test42(string[] args = null)
634 version(dummy) int i;
640 /***************************************************/
642 void foo43(float length, byte b)
644 // b /= cast(cfloat) length;
651 /***************************************************/
656 // f *= 2.0fi; // illegal but compiles
661 /***************************************************/
673 version (Win32) // this test fails in -release because asserts will be removed
685 /***************************************************/
688 void va_copy46(out void* dest, void* src)
697 /***************************************************/
701 enum { _P_WAIT, _P_NOWAIT, _P_OVERLAY }
703 alias _P_WAIT P_WAIT;
704 alias _P_NOWAIT P_NOWAIT;
707 /***************************************************/
711 const(char)[] blah = (x == 1 ? "hello".dup : "world");
719 /***************************************************/
725 assert((25.5).stringof ~ (3.0625).stringof == "2.55e+13.0625e+0");
726 assert(25.5.stringof ~ 3.0625.stringof == "2.55e+13.0625e+0");
730 assert((25.5).stringof ~ (3.01).stringof == "25.53.01");
731 assert(25.5.stringof ~ 3.01.stringof == "25.53.01");
735 /***************************************************/
742 void update(ubyte input, int i)
745 (((size + i) & 1) == 0) ?
755 /***************************************************/
759 assert(is(typeof(return) == int*));
768 /***************************************************/
770 template Foo52(ulong U)
775 template Foo52(uint U)
780 template Foo52(ubyte U)
793 /***************************************************/
800 /***************************************************/
802 void func54(string delegate() dg)
809 string[] k=["adf","AsdfadSF","dfdsfassdf"];
812 printf("%.*s\n", d.length, d.ptr);
813 string foo() {assert(d!="");return d;}
815 func54(delegate string() {assert(d!="");return d;});
819 /***************************************************/
824 alias int CVHeaderType ;
825 enum anon:CVHeaderType{ CV_NONE, CV_DOS, CV_NT, CV_DBG }
832 /***************************************************/
834 template T56() { int i; }
848 assert(S56.data.i == 4);
851 /***************************************************/
853 void writecrossing(bool goal)
855 writeln(goal?"escape":"return");
861 writecrossing(false);
864 /***************************************************/
867 void g58(char[] s) {}
880 if (s[0..0] == "" && s[0..0])
892 /***************************************************/
896 int[] array = new int[5];
898 foreach (it; array.ptr .. array.ptr + array.length) {
901 assert(check == array.length);
904 /***************************************************/
917 auto foo = new Foo60!();
920 /***************************************************/
927 struct ZipEntryInfo61 {}
933 /***************************************************/
937 int foo() { return 0; }
938 int bar() { return 0; }
940 auto t1 = typeid(typeof(foo));
941 auto t2 = typeid(typeof(bar));
946 /***************************************************/
959 int x = S63.a.sizeof;
961 assert(S63.foo() == 4);
964 /***************************************************/
974 assert(a.length == 1);
975 assert(a[0].length == 0);
978 /***************************************************/
982 string[][] result = [];
991 assert(s.length == 1);
992 assert(s[0].length == 0);
995 /***************************************************/
999 string[] strings = ["a","bc"];
1000 string [][] result = [];
1001 foreach (s; strings)
1011 assert(s.length == 2);
1012 assert(s[0].length == 1);
1013 assert(s[0][0].length == 1);
1014 assert(s[1].length == 1);
1015 assert(s[1][0].length == 2);
1018 /***************************************************/
1020 template Tuple67(A...)
1032 alias Tuple67!(Bar67!()) tuple;
1034 alias tuple[0] bara;
1035 alias tuple[i] barb;
1037 static assert(bara.s == "a bar");
1038 static assert(barb.s == "a bar");
1041 /***************************************************/
1043 template Tuple68(A...)
1055 alias Tuple68!("one", "two") tuple;
1056 static assert(tuple[foo68()] == "two");
1059 /***************************************************/
1063 class Da69 : Base69 {}
1064 class Db69 : Base69 {}
1068 auto b = i ? new Da69 : new Db69;
1069 assert(is(typeof(b) == Base69));
1072 /***************************************************/
1084 /***************************************************/
1086 template Foo71(string s)
1094 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1095 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1096 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1097 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1098 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1099 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1100 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1101 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1102 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1103 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1104 "helloabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
1105 "When dealing with complex template tuples, it's very easy to overflow the
1106 maximum symbol length allowed by OPTLINK. This is, simply put, a damn shame,
1107 because it prevents otherwise completely legal code from compiling and linking
1108 with DMDWin, whereas it works perfectly fine when using DMDNix or GDC.
1109 I know that this is neither a simple nor a small issue to fix: either the
1110 ancient, nearly-immutable OPTLINK would have to be modified, or DMDWin would
1111 have to be changed to output a more reasonable format, in which case a new
1112 linker would probably have to be written. Until then, this issue should stand
1113 as a reminder that DMDWin is inherently limited.
1114 Oplink isn't the issue. The OMF file format has a hard limit. This results in
1115 the only solutions being: convert DMD to use some other .obj format or have DMD
1116 do something else for name mangling.
1117 In talking to Walter, the issue is that it's easy to get symbols that have more
1118 info in them than can be fit into the limit. (the limit has already stretched
1119 by gziping the symbols.)
1120 The simple solution I have proposed is to just MD5 (or what not) the symbols.
1121 The only issue (besides a vanishingly small chance of a hash collision) is that
1122 this looses information so you can't look at a symbol and directly determine
1123 what it was. My answer to that is, who cares? The only place where hashing
1124 provides less info than compressing is in a debugger and it can grab the full
1125 symbol from a table in the static data segment.
1126 I suppose as a stopgap measure that'd work fine, and might even be controlled
1127 by a compiler switch, so that in the general case debugger info wouldn't be
1128 affected. And what's more -- the only time these issues come up is with
1129 templates, which a lot of debuggers have serious problems with anyway, so..
1130 I would set it up as a method of last resort. It wouldn't be used unless the
1131 symbol can't be used any other way.
1136 /***************************************************/
1138 class B72 { this(bool b, string c){} }
1144 alias typeof(super(false,"hello")) foo;
1145 super(false,"hello");
1153 /***************************************************/
1157 mixin ("const int x = 3;");
1162 pragma(msg, "success");
1166 alias Foo73!() foo73;
1172 /***************************************************/
1176 void simple_func_t(T)(T s, foo74 i)
1178 assert(s == "hello");
1184 simple_func_t("hello", 3);
1187 /***************************************************/
1189 void foo75(T)(T[] x ...)
1191 assert(x.length == 3);
1195 assert(is(T == int));
1203 /***************************************************/
1205 void delegate(U) Curry(A, U...)(void delegate(A,U) dg,A arg)
1209 typeof(dg) callback;
1211 void OpCall(U args) { callback(arg,args); }
1213 auto temp = new ArgRecord;
1216 return &temp.OpCall;
1219 void delegate(A) Seq(A...)(void delegate(A)[] dgs...)
1221 return Curry(delegate void(void delegate(A)[] dgs1,A args)
1236 void delegate(int) tmp;
1237 auto bob = new Foo76;
1238 auto dan = new Foo76;
1240 tmp = Seq!(int)(&bob.fred); // this works
1241 tmp = Seq!(int)(&bob.fred, &dan.fred); // this works
1242 tmp = Seq (&bob.fred); // this doesn't
1243 tmp = Seq (&bob.fred, &dan.fred); // neither does this
1246 /***************************************************/
1268 /***************************************************/
1274 T x; // Compiles, but is implicitly static
1275 void func(T t) // Ok, non-static member template function
1276 { assert(t == 2); assert(this.bar == 42); }
1284 Foo.TBar!(int).x = 2;
1285 //Foo.TBar!(int).func(2); // error, since funcx is not static
1290 f.TBar!(int).func(2); // works
1292 f.TBar!(int).x = 10;
1293 g.TBar!(int).x = 20;
1294 assert(f.TBar!(int).x == 20); // prints 20
1297 /***************************************************/
1307 writeln(c.__vptr[0]);
1308 writeln(cast(void*)c.classinfo);
1309 assert(c.__vptr[0] == cast(void*)c.classinfo);
1310 writeln(c.__monitor);
1311 assert(c.__monitor == null);
1314 writeln(c.__monitor);
1315 assert(c.__monitor !is null);
1319 /***************************************************/
1329 assert(Test80.test!()==1);
1330 assert((new Test80).test!()==1);
1333 /***************************************************/
1337 static const test2=1;
1339 static const int test=1;
1346 static assert(typeof(a).test2==1);//ok
1348 static assert(t.test!()==1);//ok
1349 static assert(typeof(a).test!()==1);//syntax error
1352 /***************************************************/
1357 void foo82(A82 x) { }
1364 /***************************************************/
1368 deprecated void foo(int param)
1372 void foo(string param)
1379 Bar83 b = new Bar83;
1384 /***************************************************/
1389 printf("%u\n", &arr[9] - &arr[0]);
1390 auto i = &arr[9] - &arr[0];
1394 /***************************************************/
1406 static myid myidinst;
1409 myidinst = new myid("abc");
1416 assert(cast(myid)(Lex.myidinst) !is null);
1419 /***************************************************/
1428 Time created, /// time created
1429 accessed, /// last time accessed
1430 modified; /// last time modified
1433 Stamps getTimeStamps()
1435 foreach(i; 0..10) { }
1438 time.modified = Time(20);
1439 time.accessed = Time(20);
1440 time.created = Time(20);
1446 foreach(i; 0..10) { }
1447 return timeStamps(4).accessed;
1450 Stamps timeStamps (int name)
1452 return getTimeStamps();
1458 assert(accessed().ticks == 20);
1461 /***************************************************/
1463 const bool foo87 = is(typeof(function void() { }));
1464 const bar87 = is(typeof(function void() { }));
1468 assert(foo87 == true);
1469 assert(bar87 == true);
1472 /***************************************************/
1474 int function() wrap88(void function()) { return null; }
1483 /***************************************************/
1487 static const float[2] z = 3;
1492 static const float[2] z = 3;
1495 void bar89(float f) { assert(f == 3); }
1506 /***************************************************/
1508 void trigger(char[] txt)
1524 /***************************************************/
1528 enum ABC { a, b, c }
1529 assert(ABC.stringof == "ABC");
1532 /***************************************************/
1548 /***************************************************/
1553 static assert(is(typeof(1 || foo()) == void));
1554 static assert(is(typeof(1 && foo()) == void));
1557 /***************************************************/
1563 struct f94(alias func=foo94!(int))
1572 /***************************************************/
1576 import core.stdc.stdio;
1581 X95.core.stdc.stdio.printf("hello\n");
1584 /***************************************************/
1586 template foo96(alias bar)
1588 pragma(msg, bar.stringof ~ " " ~ typeof(bar).stringof);
1589 static assert((bar.stringof ~ " " ~ typeof(bar).stringof) == "myInt int" ||
1590 (bar.stringof ~ " " ~ typeof(bar).stringof) == "myBool bool");
1603 /***************************************************/
1607 const short[] ct = cast(short[]) [cast(byte)1, 1];
1609 assert(ct.length == 2 && ct[0] == 1 && ct[1] == 1);
1611 short[] rt = cast(short[]) [cast(byte)1, cast(byte)1].dup;
1613 assert(rt.length == 1 && rt[0] == 257);
1616 /***************************************************/
1625 printf("%c\n", foo[i]);
1627 printf("%c\n", foo[i]);
1628 assert(foo[i] == 'b');
1634 auto f = new Foo98();
1638 /***************************************************/
1640 template implicitlyConverts99(S, T)
1642 enum bool implicitlyConverts99 = T.sizeof >= S.sizeof
1643 && is(typeof({S s; T t = s;}()));
1646 static assert(!implicitlyConverts99!(long, short));
1652 /***************************************************/
1656 static void check(ulong value)
1659 ulong d = cast(ulong)r;
1660 printf("ulong: %llu => real: %Lg => ulong: %llu\n", value, r, d);
1664 // check biggest power of 2 representable in ulong: 2^63
1667 // check biggest representable uneven number
1668 static if (real.mant_dig >= 64) // > 64: limited by ulong precision
1669 check(ulong.max); // 2^64-1
1671 check((1L << real.mant_dig) - 1);
1674 /***************************************************/
1676 auto e101(int x) { return 5; }
1680 assert(is(typeof(e101(3)) == int));
1683 /***************************************************/
1689 int arg = va_arg!int(_argptr);
1690 printf("external: %d\n", arg);
1700 int arg = va_arg!int(_argptr);
1701 printf("internal: %d\n", arg);
1714 (new C103).method ();
1717 /***************************************************/
1726 static assert(!is(typeof(C104.Bar.foo)));
1732 /***************************************************/
1736 const char [] XXX = Type.mangleof;
1743 auto s = Templ!(int).XXX;
1748 /***************************************************/
1749 // rejects-valid 2.012.
1752 alias foo107 bar107;
1755 bar107 a = new bar107();
1756 bar107 b = new bar107();
1764 /***************************************************/
1777 foreach (char c; foo.byLine)
1782 /***************************************************/
1786 double x[] = new double[1];
1790 /***************************************************/
1797 static C g_c2_ = { };
1800 /***************************************************/
1802 template Foo111(T...) {
1808 auto y = (Foo111!(int) x){ return 0; };
1811 /***************************************************/
1813 bool isNull(string str) {
1817 const bool foo112 = isNull("hello!");
1824 /***************************************************/
1828 for (int j=1; j<2; j++) {
1829 int x = (j<0) ? -j : j;
1831 for (int i=0; i<x; i++) ++q;
1836 /***************************************************/
1840 static int opCall(int value)
1851 void bar(int value, int i)
1853 int args[2] = [ VariantN(value), VariantN(i) ];
1861 /***************************************************/
1863 class B115 : A115!(B115) { }
1870 /***************************************************/
1873 this(U...)(U values) { }
1881 /***************************************************/
1898 /***************************************************/
1912 /***************************************************/
1916 static class B119 : C119.D { }
1928 /***************************************************/
1931 class B120 : C120.D { }
1944 /***************************************************/
1948 static assert(null is null);
1951 /***************************************************/
1953 T[] find123(alias pred, T)(T[] input) {
1954 while (input.length > 0) {
1955 if (pred(input[0])) break;
1956 input = input[1 .. $];
1963 int[] a = [ 1, 2, 3, 4, -5, 3, -4 ];
1964 find123!(function bool(int i) { return i < 0; })(a);
1968 /***************************************************/
1970 static assert(!is(typeof((){(){}
1974 /***************************************************/
1978 /***************************************************/
1985 foreach (foo_t i, dchar d; aa)
1991 /***************************************************/
2008 /***************************************************/
2026 /***************************************************/
2028 struct S127(T, int topology = 1)
2033 void cons127(int t)(S127!(int, t) tail)
2044 /***************************************************/
2046 struct S128(T, int topology = 1)
2051 void cons128(int t)(S128!(int, t) tail)
2062 /***************************************************/
2064 struct R129(R : E[], E)
2067 static R129 opCall(E[] range)
2070 result.forward = range;
2075 R129!(E[]) retro129(E)(E[] r)
2077 return R129!(E[])(r);
2080 int begin129(F)(R129!(F) range)
2087 int[] a = [ 1, 2, 3 ];
2088 auto r = retro129(a);
2089 auto i = begin129(r);
2092 /***************************************************/
2095 struct R12725(R : E[], E)
2099 int begin12725(F)(R12725!(F) range)
2106 R12725!(int[], int) r;
2107 auto i = begin12725(r);
2110 /***************************************************/
2113 struct Matrix12728(T, uint m, uint n = m, ubyte f = 0)
2115 void foo(uint r)(auto ref in Matrix12728!(T, n, r) b)
2122 alias Matrix4 = Matrix12728!(float, 4);
2128 /***************************************************/
2135 __gshared S130 e130;
2137 const(S130) example130() { return e130; }
2143 /***************************************************/
2145 void foo131(real z) {}
2150 foo131( 1 + (F*3*2.1) );
2153 /***************************************************/
2161 uint i = cast(uint) 11468.78f;
2164 uint j = cast(uint) getFloat();
2168 /***************************************************/
2170 template T133(string s) {
2171 const string T133 = s;
2174 string f133(string s) {
2181 //writeln(foo.stringof);
2182 assert ("foo" == f133(foo.stringof));
2183 assert ("foo" == T133!(foo.stringof));
2186 /***************************************************/
2188 public struct foo134
2190 public this(real aleft)
2197 final void fun(foo134 arg = foo134(0.)) { }
2200 /***************************************************/
2210 dchar[3] d = "abc"d;
2215 /***************************************************/
2219 struct S { int i[3]; }
2221 const int i = s.i[2];
2225 /***************************************************/
2232 size_t[char[16]] pKindsIdx;
2235 { auto idx=p.name in pKindsIdx;
2242 size_t[char[16]] aa;
2243 auto r=n in aa; // works
2246 /***************************************************/
2250 return *cast(long*)(&y);
2253 /***************************************************/
2257 auto famousNamedConstants =
2258 [ "pi" : 3.14, "e" : 2.71, "moving sofa" : 2.22 ];
2260 assert(famousNamedConstants["e"]==2.71);
2263 /***************************************************/
2265 int* get140() { return (new int[4]).ptr; }
2274 /***************************************************/
2279 in { assert (!next); } body
2281 void* p = cast(void*)this;
2285 /***************************************************/
2287 void a142(int b = 1+2)(){};
2295 /***************************************************/
2306 override void fill() { }
2311 auto b = new B143();
2315 /***************************************************/
2319 static Pair opCall(uint a, uint b) { return Pair.init; }
2324 Pair pop() { return Pair.init; }
2330 Pair item = stack.pop;
2333 /***************************************************/
2336 int ashes = cast(int)0;
2338 void funky (Ashes s = Ashes()) { }
2344 void func145(S145 s = S145()) { }
2352 /***************************************************/
2354 string foo146(T...)(T args)
2358 foreach(arg; args) {
2362 assert(ret=="b"); // passes
2368 string s = foo146("b");
2369 assert(s == "b"); // fails
2372 /***************************************************/
2379 assert(s == "foox");
2383 assert(ws == "foox");
2386 /***************************************************/
2390 string a = "\U00091234";
2400 /***************************************************/
2407 assert( (b[0]) == 0x3FFFFFFFFFFFFFFFL);
2410 /***************************************************/
2415 return cast(void*) (x & 1) == null;
2418 /***************************************************/
2433 void bug3521(int *a)
2437 if ( *a || (*a != (c = 200)) )
2441 /***************************************************/
2443 string foo152(T...)() {
2448 foo152!(int, char)();
2451 /***************************************************/
2461 int foo153(ulong a1, ulong extra, ulong extra2, ulong extra3)
2463 if (!((a1 & 1) | (get_value() | array1[cast(uint)(a1^1)])))
2466 if (0 >= array2[cast(uint)(a1^1)])
2477 /***************************************************/
2492 return SomeEnum.EnumMember;
2498 auto b = new B154();
2499 assert(cast(int)b.someEnum == 10);
2502 /***************************************************/
2514 /***************************************************/
2516 void f156(Value156.Id t)
2518 assert(cast(int)t == 1);
2522 public static enum Id {
2530 Value156.Id t = Value156.Id.B;
2534 /***************************************************/
2543 enum Policy157 {Default, Cached, Direct}
2549 /***************************************************/
2553 enum NX { BLA, BLA1 }
2557 enum NY { FOO, BAR }
2561 /***************************************************/
2571 /***************************************************/
2578 assert( (b[0]) == 0x3FFFFFFFFFFFFFFFL);
2580 assert(i >>>2 == 0x3FFFFFFF);
2583 /***************************************************/
2611 /***************************************************/
2621 C162 foo() { return null; }
2622 C162 foo() const { return null; }
2625 abstract class C162 : A162
2627 C162 foo() { return null; }
2628 C162 foo() const { return null; }
2631 /***************************************************/
2633 void func163( A... )( string name, string v )
2639 func163!( int, long, float )( "val", "10" );
2640 func163!()( "tmp", "77" );
2641 alias func163!() TMP; TMP( "tmp", "77" );
2644 /***************************************************/
2648 B164 foo() { return null; }
2649 B164 foo() const { return null; }
2652 abstract class B164 : A164
2654 override final B164 foo() { return null; }
2655 override final B164 foo() const { return null; }
2658 /***************************************************/
2662 B165 foo() { return null; }
2663 const(B165) foo() const { return null; }
2666 abstract class B165 : A165
2668 override final B165 foo() { return null; }
2669 override final const(B165) foo() const { return null; }
2672 /***************************************************/
2681 /***************************************************/
2684 static assert(false);
2688 const bool y168 = is(typeof( { x168!(T)(); } ));
2691 static assert(!y168!(int));
2693 /***************************************************/
2697 int AssociativeArray;
2699 foreach (x; foo) { }
2702 /***************************************************/
2716 /***************************************************/
2719 abstract class Address {
2720 abstract int nameLen();
2723 class Class171 : Address {
2726 struct FwdStruct { }
2728 override int nameLen() { return 0; }
2733 Class171 xxx = new Class171;
2734 assert(typeid(Class171).vtbl.length - typeid(Object).vtbl.length == 1);
2737 /***************************************************/
2741 enum bool BAR = is (typeof({}()));
2742 static assert (BAR == is (typeof({}())));
2745 /***************************************************/
2747 const char[][ 89 ] ENUM_NAME = [ 1:"N0" ];
2758 /***************************************************/
2775 auto b = new B174();
2779 /***************************************************/
2781 void badvariadic(...) {}
2783 static assert(!is(typeof(mixin(badvariadic()))));
2785 /***************************************************/
2792 Foo176 getFoo(Foo176 irrelevant)
2794 Foo176 p = Foo176(400);
2803 assert(getFoo( Foo176(0) ).x == 400);
2806 /***************************************************/
2810 long[1] c = [0]; // must be long
2818 if (c[0]) assert(c[0]);
2823 /***************************************************/
2828 template T(int val) {
2829 enum S178 T = { val };
2833 const x178 = S178.T!(0);
2835 /***************************************************/
2837 double[100_000] arr = 0.0;
2839 /***************************************************/
2841 alias ireal BUG3919;
2842 alias typeof(BUG3919.init*BUG3919.init) ICE3919;
2843 alias typeof(BUG3919.init/BUG3919.init) ICE3920;
2845 /***************************************************/
2851 void show(char[] args...) {
2852 assert(args[0]=='A');
2853 assert(args[1]=='L');
2854 assert(args[2]=='D');
2855 assert(args[3]=='O');
2858 void A179( S179 ss ) {
2859 show( ss.a, ss.b, ss.c, ss.d );
2872 /***************************************************/
2874 struct XY { union { int x, y; } }
2877 void a(XY x) { aa = x; }
2882 void a(XY x) { aHolder.a(x); }
2887 void setB() { ab.b = XY(); }
2894 /***************************************************/
2896 void fooa181(int x, int y, int[0] a, int z, int t)
2898 if (!(x == 2 && y == 4 && z == 6 && t == 8))
2902 void foob181(int x, int y, int[0] a)
2904 if (!(x == 2 && y == 4))
2908 void fooc181(int[0] a, int x, int y)
2910 if (!(x == 2 && y == 4))
2914 void food181(int[0] a)
2921 fooa181(2, 4, arr, 6, 8);
2927 /***************************************************/
2930 template isQObjectType(T)
2932 enum isQObjectType = is(T.__isQObjectType);
2935 template QTypeInfo(T)
2937 static if (!isQObjectType!T)
2939 enum size = T.sizeof;
2945 alias QTypeInfo!T TI;
2954 void exec(QList!(QAction) actions) {}
2956 interface IQGraphicsItem
2961 class QGraphicsObject : IQGraphicsItem
2965 class QGraphicsWidget : QGraphicsObject
2971 void associatedGraphicsWidgets(QList!(QGraphicsWidget) a)
2973 QList!(QGraphicsWidget) x;
2981 /***************************************************/
2983 enum { a183 = b183() }
2985 int b183() { return 0; }
2987 /***************************************************/
2991 union { Foo184 foo; }
2994 struct Foo184 { size_t offset = 0;}
2996 /***************************************************/
3013 /***************************************************/
3015 const PM_QS_INPUT = QS_INPUT;
3018 /***************************************************/
3023 /***************************************************/
3025 int foo188(int[3] s)
3027 return s[0] + s[1] + s[2];
3038 /***************************************************/
3040 template X189(alias fn) {
3041 alias typeof(fn) X189;
3044 void a189()(T1189 x) {
3045 alias X189!(T1189.foo) P; //line 7
3052 printf("T1.foo()\n");
3056 class T2189 : T1189 {
3058 printf("T2.blah()\n");
3059 assert(false); //line 19
3064 a189!()(new T2189());
3067 /***************************************************/
3073 if (true) scope(exit) s ~= "a";
3074 if (false) { } else scope(exit) s ~= "b";
3075 if (true) scope(exit) scope(exit) s ~= "c";
3076 foreach(x; 1..2) scope(exit) s ~= "d";
3077 if (true) L1: scope(exit) s ~= "e";
3078 do scope(exit) s ~= "f"; while (false);
3079 int i; while (++i == 1) scope(exit) s ~= "g";
3080 try { } finally scope(exit) s ~= "h";
3081 assert(s == "abcdefgh");
3084 /***************************************************/
3088 S191 opCall(int i) {
3089 printf("%d %d\n", last, i);
3090 assert(i == 1 && last == 0 || i == 2 && last == 1 || i == 3 && last == 1);
3103 /***************************************************/
3109 //pragma(msg, foo.mangleof);
3110 static assert(foo192.mangleof == "E6test426foo192");
3112 /***************************************************/
3124 pragma(msg, i.stringof);
3125 pragma(msg, s.stringof);
3127 static assert(i.stringof == "i");
3128 static assert(s.stringof == "s");
3131 /***************************************************/
3135 uint[][] b = [[ 1, 2, ]];
3138 /***************************************************/
3147 const T195 x195 = 0;
3149 /***************************************************/
3162 static assert(A196.sizeof == B196.sizeof);
3164 /***************************************************/
3166 template Compileable(int z) { bool OK;}
3169 int bar() { return 7; }
3175 static assert(!is(typeof(Compileable!(foo.bar()))));
3176 static assert(!is(typeof(Compileable!((foo = Bug3569.init).bar()))));
3184 /***************************************************/
3186 void test198() // Bugzilla 4506
3189 for (int k = 0; k < 2; k++) {
3190 assert((k == 0 && c == 1) || (k == 1 && c == -1));
3195 /***************************************************/
3198 void g199(void delegate(void*, void*) d) { }
3201 void f(void*, void*) {}
3208 /***************************************************/
3217 void foo4443(Struct4443 *dest, Struct4443[] arr)
3219 int junk = arr[$-1].x;
3220 if (dest || arr[$-1].x) {
3232 /***************************************************/
3241 Bug2931 p = Bug2931(67); // Applies to struct static initializers too
3251 assert(v.scale == 4);
3258 Bug2931 w = Bug2931(68);
3260 for (int i = 0; i < 4; i++)
3262 for (int j = 0; j < 3; j++)
3264 assert(w.val[j][i] == 68);
3265 assert(v.p.val[j][i] == 67);
3268 assert(v.scale == 4);
3272 static assert(bug2931()==2);
3275 assert(bug2931()==2);
3276 assert(bug2931_2()==2);
3280 /***************************************************/
3281 // This was the original varargs example in std.vararg
3285 void foo202(int x, ...) {
3286 printf("%d arguments\n", _arguments.length);
3287 for (int i = 0; i < _arguments.length; i++) {
3288 int j = va_arg!(int)(_argptr);
3289 printf("\t%d\n", j);
3294 void fooRef202(ref int x, ...) {
3295 printf("%d arguments\n", _arguments.length);
3296 for (int i = 0; i < _arguments.length; i++) {
3297 int j = va_arg!(int)(_argptr);
3298 printf("\t%d\n", j);
3305 foo202(1, 2, 3, 4, 5);
3310 fooRef202(x, 2, 3, 4, 5);
3313 /***************************************************/
3333 auto b = a.new B203;
3336 writeln(a.tupleof); // prints: A
3337 writeln(b.tupleof); // prints: B main.A
3338 writeln(c.tupleof); // prints: C 0000
3339 assert(a.tupleof.length == 1 && a.tupleof[0] == 'A');
3340 assert(b.tupleof.length == 1 && b.tupleof[0] == 'B');
3341 assert(c.tupleof.length == 1 && c.tupleof[0] == 'C');
3344 /***************************************************/
3347 struct A204 { B204 b; }
3350 /***************************************************/
3353 class Collection205(T) { }
3356 alias Collection205!int ICollection;
3358 /***************************************************/
3360 enum TaskStatus:int { Building=-1, }
3362 TaskStatus test206(char[] s){
3363 char[] t="TaskStatus".dup;
3364 if (s.length>t.length && s[0..t.length]==t){
3366 if (s[t.length]=='-') res= -res; // <= OPnegass
3367 return cast(TaskStatus)cast(int)res;
3372 /***************************************************/
3374 struct UN { double dd; long ll; }
3375 bool cmp( UN * pU ) { return pU.dd >= pU.ll ? true : false; }
3377 struct UN2 { real dd; long ll; }
3378 bool cmp2( UN2 * pU ) { return pU.dd >= pU.ll ? true : false; }
3380 struct UN3 { double dd; int ll; }
3381 bool cmp3( UN3 * pU ) { return pU.dd >= pU.ll ? true : false; }
3385 static UN u = { 10.50, 10 };
3387 printf( "%d\n", cmp( &u ) );
3390 static UN2 u2 = { 10.50, 10 };
3394 static UN3 u3 = { 10.50, 10 };
3398 static UN3 u3_1 = { 9.50, 10 };
3403 /***************************************************/
3405 template fail4302() {
3408 template bug4302() {
3409 alias fail4302!() bad;
3411 static if (is(bug4302!())) {}
3413 /***************************************************/
3415 template tough4302()
3425 static if (is(bar!())) {}
3428 alias tough4302!() tougher;
3430 /***************************************************/
3432 template Bug6602A(T) {
3433 Bug6602B!(T).Result result;
3436 template Bug6602B(U) {
3437 static assert(is(U == int));
3441 enum bug6602Compiles = __traits(compiles, Bug6602A!short);
3443 /***************************************************/
3446 const bar209 = foo209;
3447 const int * foo209 = null;
3449 /***************************************************/
3455 a = cast(ulong)(a * 2.0L);
3458 /***************************************************/
3460 static assert(!is(typeof(Object.tupleof[2000]=0)));
3462 /***************************************************/
3466 void bug4430(T)(int x) {}
3467 void bug4430(T)(Ghost x) {}
3471 bug4430!(char)( 777 );
3474 /***************************************************/
3477 struct A213 { B213 b; }
3478 enum B213 { Z213 = 2 }
3486 /***************************************************/
3488 void g214(int j) { }
3495 void f() { g214(i); }
3500 /***************************************************/
3502 template Q(s...) { alias s q; }
3507 enum assocarrayliteral = Q!( [1:2] ).q.stringof;
3508 enum complex80 = Q!( 1+1.0i ).q.stringof;
3509 //enum dottype = Q!( C.Object.toString ).q.stringof;
3510 enum halt = (assert(0), 0).stringof; // ICE w/ -release
3511 //enum remove = Q!( [1:2].remove(1) ).q.stringof;
3512 enum templat = Q!( Q ).q.stringof;
3515 /***************************************************/
3518 template T216(_...) { alias _ T216; }
3519 size_t mid216(size_t n) { return n/2; }
3521 alias T216!(int, int)[0 .. mid216($)] A216;
3522 alias T216!(1, 2, 3)[0 .. mid216($)] B216;
3526 T216!(int, int, int) values;
3527 auto slice = values[0 .. mid216($)]; // C
3530 /***************************************************/
3532 int bug4529a() { return 0; }
3533 int function() bug4529b;
3534 auto ivorBomb1 = typeid(typeof(bug4529a));
3535 auto ivorBomb2 = typeid(typeof(bug4529b));
3537 /***************************************************/
3539 void bug5218c(char [3] s) {}
3540 void bug5218w(wchar [3] s) {}
3541 void bug5218d(dchar [3] s) {}
3550 /***************************************************/
3561 dchar[3] d = "abc"d;
3566 /***************************************************/
3575 mixin T219!(int); // using a named mixin here fixes it
3577 pragma(msg, T219!(int).C.mangleof);
3578 pragma(msg, C.mangleof); // incorrectly outputs the same as above
3580 assert(T219!(int).C.classinfo !is C.classinfo); // fails
3581 assert(T219!(int).C.mangleof != C.mangleof); // fails
3585 /***************************************************/
3591 class C { this() { } }
3599 writeln(T220!(int).C.classinfo.initializer.length);
3600 writeln(C.classinfo.initializer.length);
3601 writeln(D220.classinfo.initializer.length);
3603 auto c = new C; // segfault in _d_newclass
3606 /***************************************************/
3613 static assert(is(typeof(S5110.value) == int));
3615 /***************************************************/
3620 string toString() { return ""; }
3628 /***************************************************/
3630 immutable class Bug5504
3638 shared class Bug5504b
3648 immutable Bug5504 c;
3656 /***************************************************/
3658 void bug5105() // compilation test -- don't need to run
3660 auto c = new shared(C5105);
3664 synchronized shared class C5105
3669 /***************************************************/
3683 final override I221 sync()
3684 in { assert( valid ); }
3693 override I221 sync()
3694 in { assert( valid ); }
3706 /***************************************************/
3708 template Bug3276(bool B) {
3710 alias Bug3276!(false) Bug3276;
3712 alias double Bug3276;
3715 template Bug3276_b(alias W) {
3716 alias W!(true) Bug3276_b;
3719 alias Bug3276_b!(Bug3276) Bug3276_c;
3721 /***************************************************/
3729 for (int i = 0; i < 2; i++) {
3731 foo222(i * 5 - 6); // comment this out and it makes 2 loops
3733 printf("%d\n", count); // compile with -O and it prints 1
3737 /***************************************************/
3739 void foo223(long x,long a,long b,long c,long d,long e,long f)
3741 assert(x == 0x123456789ABCDEF0);
3746 foo223(0x123456789ABCDEF0,2,3,4,5,6,7);
3749 /***************************************************/
3752 template BigTuple(U...) {
3757 BigTuple!(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3758 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3759 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3760 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3761 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
3762 1,1,1,1,1,1) Tuple4379;
3766 foreach(x; Tuple4379) { }
3769 /***************************************************/
3772 public final class A3681 {
3776 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3777 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3778 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3779 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3780 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3781 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3782 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3783 i = j * 15; j = i * 59; i = j * 15; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3784 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3785 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3786 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3787 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3788 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3789 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3790 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3791 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3792 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3793 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3794 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3795 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3796 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3797 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3798 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3799 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3800 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3801 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3802 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3803 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3804 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3805 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3806 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3807 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3808 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15;
3809 j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; j = i * 59; i = j * 15; j = i * 59;
3810 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3811 i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59; i = j * 15; j = i * 59;
3815 /***************************************************/
3822 assert(s.length==3);
3825 assert(s.length==4);
3828 assert(s.length==3);
3830 assert(s.length==4);
3834 assert(z.length==2);
3837 assert(z.length==2);
3841 static assert(bug4389());
3853 static assert(ice4389());
3855 // ICE(expression.c)
3865 static assert(mixin(ice4390()) == ``);
3866 static assert(mixin(ice4390()) == ``);
3868 /***************************************************/
3872 void eat(avocado x225 = .x225);
3879 /***************************************************/
3882 void doStuff(byte start, byte end, uint increment = 1U) {
3883 auto output = new byte[3];
3886 for(byte i = start; i < end; i += increment) {
3887 output[count++] = i;
3895 /***************************************************/
3900 int[] as = [111, 666];
3902 assert(as.length == 3);
3903 assert(as[2] == 111);
3906 /***************************************************/
3914 const A_SIZE = (A4017.sizeof);
3918 /***************************************************/
3921 void thrw(Data *s) {
3922 throw new Exception("xxx");
3937 uint jaz(ubyte[] data) {
3938 return cast(uint)data.length;
3942 void set(Data *data, string[] soup) {
3946 uint[] f = [jaz(data.w ? data.w.con[data.n ..data.m] : null), data.m - data.n];
3951 /**************************************/
3960 /***************************************************/
3963 void doSynchronized() {
3964 printf("In doSynchronized() 1: %p\n", cast(void*) global229);
3966 printf("In doSynchronized() 2: %p\n", cast(void*) global229);
3970 __gshared Object global229;
3973 auto local = new Object;
3976 printf("In main() 1: %p\t%p\n",
3977 cast(void*) global229, cast(void*) local);
3979 printf("In main() 1: %p\t%p\n",
3980 cast(void*) global229, cast(void*) local);
3982 assert(cast(void*) global229 == cast(void*) local);
3985 /***************************************************/
3987 static immutable real negtab[14] =
3988 [ 1e-4096L,1e-2048L,1e-1024L,1e-512L,1e-256L,1e-128L,1e-64L,1e-32L,
3989 1e-16L,1e-8L,1e-4L,1e-2L,1e-1L,1.0L ];
3990 static immutable real postab[13] =
3991 [ 1e+4096L,1e+2048L,1e+1024L,1e+512L,1e+256L,1e+128L,1e+64L,1e+32L,
3992 1e+16L,1e+8L,1e+4L,1e+2L,1e+1L ];
3994 float parse(ref string p)
4006 printf("ldval = %Lg\n", ldval);
4039 string s = "123e+2";
4041 //printf("f = %g\n", f);
4042 assert( f == 123e+2f );
4045 /***************************************************/
4049 class Template4033(T) {
4050 static assert(is(T : Bug4033));
4053 alias Template4033!(Z4033) Bla;
4055 class Z4033 : Bug4033 { }
4057 /***************************************************/
4064 Bug4322 f = Bug4322();
4065 Bug4322 g = Bug4322.init;
4068 /***************************************************/
4070 bool bug5672(long v)
4072 return (v & 1) == 1;
4073 return (v & 1) == 1;
4076 /***************************************************/
4082 for (int i=0; i<s.length; i++)
4087 /***************************************************/
4092 void b(int z, short c) {}
4093 void c(int z, short d) {}
4097 auto z = new X231();
4098 TypeInfo a = typeid(typeof(&z.a));
4099 TypeInfo b = typeid(typeof(&z.b));
4100 TypeInfo c = typeid(typeof(&z.c));
4102 assert(a !is b, "1");
4103 assert(a != b, "2");
4104 assert(b == c, "3");
4107 /***************************************************/
4110 const A232 = [1,2,3];
4111 const B232 = A232[1..A232.length];
4112 const C232 = A232[1..$];
4116 assert(A232[0] == 1);
4117 assert(A232[1] == 2);
4118 assert(A232[2] == 3);
4119 assert(B232[0] == 2);
4120 assert(B232[1] == 3);
4121 assert(C232[0] == 2);
4122 assert(C232[1] == 3);
4125 /***************************************************/
4134 /***************************************************/
4139 void foo234(bool cond){}
4146 static assert(!__traits(compiles, assert(a))); // type A does not have a boolean value
4147 static assert(!__traits(compiles, assert(i || a))); // type A does not have a boolean value
4148 static assert(!__traits(compiles, assert(0 || a))); // OK
4150 // if(a) {} // type A does not have a boolean value
4151 // if(i || a) {} // type A does not have a boolean value
4152 // if(0 || a) {} // type A does not have a boolean value
4154 static assert(!__traits(compiles, foo234(a))); // cannot implicitly convert type A to bool
4155 static assert(!__traits(compiles, foo234(i || a))); // OK
4156 static assert(!__traits(compiles, foo234(0 || a))); // OK
4160 /***************************************************/
4162 int space() { return 4001; }
4166 const int bowie = space();
4167 static assert(space() == 4001); // OK
4168 static assert(bowie == 4001); // doesn't compile
4171 /***************************************************/
4172 // https://issues.dlang.org/show_bug.cgi?id=3809
4187 BUG3809 b = { bug3809() };
4190 /***************************************************/
4195 bool cmp(ref int[3] a, ref int[3] b)
4207 assert(!cmp(a.ary, b.ary));
4209 assert(cmp(a.ary, b.ary));
4211 // change high bit of ary address
4212 *(cast(size_t*)&b) ^= (1UL << (size_t.sizeof * 4));
4213 assert(!cmp(a.ary, b.ary));
4216 /***************************************************/
4238 /***************************************************/
4245 return sumFloats(0.0f, 0.0f);
4248 static float sumFloats(float a, float b)
4256 auto painter = new XMMPainter;
4257 assert(XMMPainter.sumFloats(20, painter.call()) == 20.0f);
4258 auto dg = () { return XMMPainter.sumFloats(0.0f, 0.0f); };
4259 assert(XMMPainter.sumFloats(20, dg()) == 20.0f);
4262 /***************************************************/
4264 void testrolror(int shift)
4268 r = (a >> shift) | (a << (int.sizeof * 8 - shift));
4269 assert(r == 0x8000_0003);
4270 r = (r << shift) | (r >> (int.sizeof * 8 - shift));
4280 /***************************************************/
4285 foreach (s, i; [ "a":1, "b":2 ])
4292 /***************************************************/
4294 void foo238(long a, long b)
4296 while (1) // prevent inlining
4312 long y = a % b; // evaluate at compile time
4319 /***************************************************/
4322 struct S239 { int x; }
4332 /***************************************************/
4334 void enforce6506b(bool condition, void delegate() m) {
4337 void toImpl6506b(int value) {
4339 enforce6506b(value >= 0, &f);
4342 toImpl6506b(-112345);
4345 /***************************************************/
4353 double a = foo240();
4354 double b = foo240();
4355 double x = a*a + a*a + a*a + a*a + a*a + a*a + a*a +
4360 /***************************************************/
4363 int foo6563(float a, float b, float c, float d, float e, float f, float g, float h)
4366 return 0; // return something to prevent folding
4371 auto res = foo6563(1, 1, 1, 1, 1, 1, 1, 1);
4374 /***************************************************/
4376 ubyte foo241(ubyte[] data)
4399 assert(foo241(data[]) == 0x40);
4401 assert(foo241(data[]) == 0x40);
4404 /***************************************************/
4410 double foo(size_t i, size_t j)
4412 return dat[i][j] = 0;
4421 /***************************************************/
4423 double entropy(double[] probs) {
4425 foreach (p; probs) {
4432 /***************************************************/
4434 long b5364(long bmax){
4437 if(bmax >= 0) bmax = -1;
4443 assert(b5364(0) == -1L);
4447 /***************************************************/
4453 void constructBezier(FPoint p0, FPoint p1, FPoint p2, ref FPoint[3] quad) {
4455 quad[1] = FPoint(p1.x, p1.y);
4460 auto p0 = FPoint(0, 0);
4461 auto p1 = FPoint(1, 1);
4462 auto p2 = FPoint(2, 2);
4464 // avoid inline of call
4466 auto f = &constructBezier;
4467 f(p0, p1, p2, quad);
4469 assert(quad == [p0, p1, p2]);
4472 /***************************************************/
4475 long fun6997(long a,long b,long c)
4477 return a < b ? a < c ? a : b < c ? b : c : b;
4480 long baz6997(long a, long b)
4482 bool s = (a<0) != (b<0);
4496 long a = baz6997(bar, 0),
4497 b = baz6997(bar, 0),
4498 c = baz6997(bar, 0);
4499 return S6997(fun6997(a,b,c), fun6997(a,b,c));
4507 auto x = S6997().foo();
4510 /***************************************************/
4512 ubyte foo7026(uint n) {
4513 ubyte[5] buf = void;
4517 if ((n & ~0x7F) == 0) {
4518 buf[wsize++] = cast(ubyte)n;
4521 buf[wsize++] = cast(ubyte)((n & 0x7F) | 0x80);
4526 printf("%hhu\n", wsize);
4531 if (foo7026(3) != 3)
4536 /***************************************************/
4542 scope(failure) int i = 0;
4544 ushort left = 0xffU;
4545 left <<= (ushort.sizeof - 1) * 8;
4547 assert((((left & 0xff00U) >> 8) | ((left & 0x00ffU) << 8)) == 0xffu);
4551 /***************************************************/
4559 auto s = S7072( null );
4562 /***************************************************/
4576 /***************************************************/
4578 void foo7212(scope int delegate(int a) dg)
4582 void foo7212(bool a)
4588 foo7212((int a) => a);
4591 /***************************************************/
4595 foreach(v; long.max / 8 .. long.max / 8 + 1)
4597 immutable long t1 = v;
4600 assert(t2 > long.max / 4);
4604 /***************************************************/
4607 void foo7290a(alias dg)()
4612 void foo7290b(scope int delegate(int a) dg)
4617 void foo7290c(int delegate(int a) dg)
4625 scope dg = (int a) => a + add;
4627 assert(GC.addrOf(dg.ptr) == null);
4634 /***************************************************/
4643 /***************************************************/
4647 class B7375(int i) : A7375 {}
4648 class C7375(int i) : B7375!i {}
4650 template DerivedAlias(int i)
4652 alias B7375!i DerivedAlias;
4655 alias DerivedAlias!22 X7375;
4659 A7375 foo = new C7375!11();
4660 assert(cast(B7375!22)foo is null);
4663 /***************************************************/
4667 for (int i=0; i<3; ++i)
4670 char[] x2 = "xxx" ~ ['c'];
4672 assert(x2[1] == 'x');
4678 /***************************************************/
4682 @property inout(int) g()() inout { return 7424; }
4695 void test3() immutable
4704 inout(T) g(T)(T x) inout
4725 immutable(S7424a) s2;
4737 /***************************************************/
4740 static bool info()() {
4746 if (Logger.info()) {
4750 /***************************************************/
4764 /***************************************************/
4766 void nextis(void delegate() dg = {}) {}
4772 /***************************************************/
4776 void nextis(void delegate() dg = {}) {}
4780 /***************************************************/
4782 template T3509(bool b) { static assert (b); }
4784 template Mix3509() { void f() {} }
4787 alias T3509!(is(typeof(M.f))) U;
4791 /***************************************************/
4793 struct S3510(int x) {}
4795 template Mix3510() { Sa s; }
4802 /***************************************************/
4804 struct Array243(T) if (is(T == bool))
4808 Array243!bool _outer;
4815 return Range(this, 0, 3);
4825 /***************************************************/
4829 static immutable f = Foo7742(1, 2);
4835 static immutable f = Bar7742(1, 2);
4840 assert(Foo7742.f.x == 1);
4841 assert(Foo7742.f.y == 2);
4843 assert(Bar7742.f.x == 1);
4844 assert(Bar7742.f.y == 2);
4847 /***************************************************/
4850 interface Interface7807
4852 Interface7807 getNext();
4853 const(Interface7807) getNext() const;
4856 class Implementation7807 : Interface7807
4858 Implementation7807 getNext()
4863 const(Implementation7807) getNext() const
4871 auto mc = new Implementation7807();
4872 assert(mc.getNext() is mc);
4873 Interface7807 mi = mc;
4874 assert(mi.getNext() is mi);
4876 auto cc = new const(Implementation7807)();
4877 assert(cc.getNext() is null);
4878 const(Interface7807) ci = cc;
4879 assert(ci.getNext() is null);
4882 /***************************************************/
4889 struct BasicMatrix {
4890 mixin Operand!( Closure.Matrix );
4893 template Operand( Closure closure_ ) {
4894 alias closure_ closure;
4897 struct Expression( string op_, Lhs, Rhs = void ) {
4898 enum lhsClosure = closureOf!Lhs;
4901 template closureOf( T ) {
4902 enum closureOf = T.closure;
4905 alias Expression!("+", BasicMatrix) Foo7815;
4907 /***************************************************/
4910 static immutable c = Test244();
4914 /***************************************************/
4916 int noswap245(ubyte *data)
4918 version (LittleEndian)
4933 int bswap245(ubyte *data)
4935 version (LittleEndian)
4951 int x1 = 0x01234567;
4952 x1 = noswap245(cast(ubyte *)&x1);
4953 assert(x1 == 0x01234567);
4954 x1 = bswap245(cast(ubyte *)&x1);
4955 assert(x1 == 0x67452301);
4958 /***************************************************/
4960 mixin template mix7974()
4967 static immutable Foo7974 fa = Foo7974(0);
4977 /***************************************************/
4981 float getnanf() { return float.nan; }
4982 double getnand() { return double.nan; }
4983 real getnanr() { return real.nan; }
4987 assert(getnanf() != 0);
4988 assert(getnand() != 0);
4989 assert(getnanr() != 0);
4992 /***************************************************/
4999 //static const Klass zero; // Does not trigger bug!
5000 static const Klass7911 zero = {0}; // Bug trigger #1
5002 static if (true) // Bug trigger #2
5004 Klass7911 foo() { return Klass7911(); }
5009 auto a = Klass7911().foo();
5012 /***************************************************/
5020 /***************************************************/
5029 final class B8069 : I8069
5036 /***************************************************/
5039 void bug8095(int p0, int *p1, int z, int edx, int *p4, int p5)
5043 int c = p5 + *p1 + p0; // *p1 segfaults -- it does *z !!
5051 int * unused = p1; // kills p4 somehow
5057 bug8095(0, &x, 1, 0, &y, 0);
5060 /***************************************************/
5065 return ((a = n ? (n>=1u) : 1) != 0) ? a : 0;
5066 // return ((a = !n ? 1 : (n>=1u)) != 0) ? a : 0;
5071 // return ((a = n ? (n>=1u) : 1) != 0) ? a : 0;
5072 return ((a = !n ? 1 : (n>=1u)) != 0) ? a : 0;
5076 assert(solve1(1) == 1);
5077 assert(solve2(1) == 1);
5080 /***************************************************/
5086 void bug6189_2(uint half, IPoint pos, float[4] *pts, uint unused) {
5098 auto pos = IPoint(2, 2);
5100 pts[0] = pts[1] = pts[2] = pts[3] = 0;
5101 bug6189_2(0, pos, &pts, 0);
5103 assert(pts[0] == 2);
5106 /***************************************************/
5109 version (D_InlineAsm_X86_64)
5114 else version (D_InlineAsm_X86)
5123 assert(0, "alignment failure");
5130 static if (is(typeof(Align)))
5159 /***************************************************/
5167 auto val = Struct();
5170 /***************************************************/
5172 double sqrt8454(double d) { return d/2; }
5173 void foo8454(cdouble m) {}
5175 foo8454(0 - sqrt8454(1.0) * 1i);
5178 /***************************************************/
5183 int opCmp(S8423 rhs)
5189 void enforce8423(bool value, string a, string b)
5191 if (!value) assert(false);
5198 enforce8423(a > b, null, null);
5201 /***************************************************/
5205 void foo(uint value)
5207 ubyte size = value < (0x7fU << 0 ) ? 1 :
5208 value < (0x7fU << 14) ? 2 :
5218 Foo8496 f = new Foo8496();
5222 /***************************************************/
5224 long foo8840() { return 4; }
5226 int bar8840(long g) { assert(g == 4); return printf("%llx\n", g); }
5230 long f1 = foo8840();
5231 long f2 = foo8840();
5233 long f = (f1 < f2 ? f1 : f2);
5234 int len = (f == 0 ? 0 : bar8840(f));
5237 /***************************************************/
5249 /***************************************************/
5261 S8870 r1 = S8870(1,2,3,4);
5262 S8870 r2 = S8870(5,6,7,8);
5264 foo8870(r1, r2, false, 1);
5265 bar8870(r1, r2, false, 1);
5269 void foo8870(S8870 t1, S8870 t2, bool someBool, float finalFloat)
5271 printf("t1: %g %g %g %g\n", t1.x, t1.y, t1.z, t1.w);
5272 printf("t2: %g %g %g %g\n", t2.x, t2.y, t2.z, t2.w);
5273 printf("someBool: %d\n", someBool);
5274 printf("finalFloat: %g\n", finalFloat);
5276 assert(t1.x == 1 && t1.y == 2 && t1.z == 3 && t1.w == 4);
5277 assert(t2.x == 5 && t2.y == 6 && t2.z == 7 && t2.w == 8);
5278 assert(someBool == false);
5279 assert(finalFloat == 1);
5283 void bar8870(S8870 t1, S8870 t2, bool someBool, float finalFloat)
5285 printf("t1: %g %g %g %g\n", t1.x, t1.y, t1.z, t1.w);
5286 printf("t2: %g %g %g %g\n", t2.x, t2.y, t2.z, t2.w);
5287 printf("someBool: %d\n", someBool);
5288 printf("finalFloat: %g\n", finalFloat);
5290 assert(t1.x == 1 && t1.y == 2 && t1.z == 3 && t1.w == 4);
5291 assert(t2.x == 5 && t2.y == 6 && t2.z == 7 && t2.w == 8);
5292 assert(someBool == false);
5293 assert(finalFloat == 1);
5296 /***************************************************/
5298 int foo9781(int[1] x)
5308 /***************************************************/
5310 struct S247 { size_t length; size_t ptr; }
5324 assert(f.length == 7);
5328 /***************************************************/
5332 byte[] ba = [1,2,3,4,5];
5333 short[] sa = [1,2,3,4,5];
5334 int[] ia = [1,2,3,4,5];
5335 long[] la = [1,2,3,4,5];
5342 assert(ba == [1,2,-3,4,5]);
5343 assert(sa == [1,2,-3,4,5]);
5344 assert(ia == [1,2,-3,4,5]);
5345 assert(la == [1,2,-3,4,5]);
5348 /***************************************************/
5361 /***************************************************/
5363 // Don't call, compile only
5369 for (int x = 0; count < 100; x++){
5381 printf("Last: %d\n", last);
5384 /***************************************************/
5387 int* wrong8796(int* p)
5398 assert(q != arr.ptr);
5401 /***************************************************/
5404 ulong bitcomb9171(ulong v)
5411 auto r = bitcomb9171(v >> 1);
5412 printf("r=%016llx\n", r);
5414 auto z = ((r & (r-1) ^ r));
5415 check9171("str", z>>1);
5416 // printf("z=%016llx\n", z>>1);
5421 auto fb = v & (v-1) ^ v;
5422 result = (fb >> 1) | (v ^ fb);
5429 void check9171(const char *s, ulong v)
5431 assert(v == 0x80000000);
5436 bitcomb9171(0b1110000000000000010000000000000000000000000000000001);
5439 /***************************************************/
5444 void*[] a = [cast(void*)1];
5445 void*[] b = [cast(void*)2];
5447 assert(c == [cast(void*)1, cast(void*)2]);
5450 /***************************************************/
5462 int[] r1w = []; assert(r1w.length == 0);
5463 int[][] r2w = []; assert(r2w.length == 0);
5464 int[][][] r3w = []; assert(r3w.length == 0);
5465 int[][][][] r4w = []; assert(r4w.length == 0);
5467 int[][] r2x = [[]]; assert(r2x.length == 1 && r2x[0].length == 0);
5468 int[][][] r3x = [[]]; assert(r3x.length == 1 && r3x[0].length == 0);
5469 int[][][][] r4x = [[]]; assert(r4x.length == 1 && r4x[0].length == 0);
5471 int[][][] r3y = [[[]]]; assert(r3y.length == 1 && r3y[0].length == 1 && r3y[0][0].length == 0);
5472 int[][][][] r4y = [[[]]]; assert(r4y.length == 1 && r4y[0].length == 1 && r4y[0][0].length == 0);
5474 int[][][][] r4z = [[[[]]]]; assert(r4z.length == 1 && r4z[0].length == 1 && r4z[0][0].length == 1 && r4z[0][0][0].length == 0);
5476 // ArrayLiteralExp conforms to the type of LHS.
5477 { auto x = a1 ~ [] ; static assert(is(typeof(x) == typeof(a1))); assert(x == r1w); } // no ambiguity
5478 { auto x = a2 ~ [] ; static assert(is(typeof(x) == typeof(a2))); assert(x == r2w); } // fix <- ambiguity
5479 { auto x = a3 ~ [] ; static assert(is(typeof(x) == typeof(a3))); assert(x == r3w); } // fix <- ambiguity
5480 { auto x = a4 ~ [] ; static assert(is(typeof(x) == typeof(a4))); assert(x == r4w); } // fix <- ambiguity
5482 //{ auto x = a1 ~ [[]] ; } // (see test14682b)
5483 { auto x = a2 ~ [[]] ; static assert(is(typeof(x) == typeof(a2))); assert(x == r2x); } // no ambiguity
5484 { auto x = a3 ~ [[]] ; static assert(is(typeof(x) == typeof(a3))); assert(x == r3x); } // fix <- ambiguity
5485 { auto x = a4 ~ [[]] ; static assert(is(typeof(x) == typeof(a4))); assert(x == r4x); } // fix <- ambiguity
5487 static assert(!__traits(compiles, { auto x = a1 ~ [[[]]] ; }));
5488 //{ auto x = a2 ~ [[[]]] ; } // (see test14682b)
5489 { auto x = a3 ~ [[[]]] ; static assert(is(typeof(x) == typeof(a3))); assert(x == r3y); } // no ambiguity
5490 { auto x = a4 ~ [[[]]] ; static assert(is(typeof(x) == typeof(a4))); assert(x == r4y); } // fix <- ambiguity
5492 static assert(!__traits(compiles, { auto x = a1 ~ [[[[]]]]; }));
5493 static assert(!__traits(compiles, { auto x = a2 ~ [[[[]]]]; }));
5494 //{ auto x = a3 ~ [[[[]]]]; } // (see test14682b)
5495 { auto x = a4 ~ [[[[]]]]; static assert(is(typeof(x) == typeof(a4))); assert(x == r4z); } // no ambiguity
5497 // ArrayLiteralExp conforms to the type of RHS.
5498 { auto x = [] ~ a1; static assert(is(typeof(x) == typeof(a1))); assert(x == r1w); } // no ambiguity
5499 { auto x = [] ~ a2; static assert(is(typeof(x) == typeof(a2))); assert(x == r2w); } // fix <- ambiguity
5500 { auto x = [] ~ a3; static assert(is(typeof(x) == typeof(a3))); assert(x == r3w); } // fix <- ambiguity
5501 { auto x = [] ~ a4; static assert(is(typeof(x) == typeof(a4))); assert(x == r4w); } // fix <- ambiguity
5503 //{ auto x = [[]] ~ a1; } // (see test14682b)
5504 { auto x = [[]] ~ a2; static assert(is(typeof(x) == typeof(a2))); assert(x == r2x); } // no ambiguity
5505 { auto x = [[]] ~ a3; static assert(is(typeof(x) == typeof(a3))); assert(x == r3x); } // fix <- ambiguity
5506 { auto x = [[]] ~ a4; static assert(is(typeof(x) == typeof(a4))); assert(x == r4x); } // fix <- ambiguity
5508 static assert(!__traits(compiles, { auto x = [[[]]] ~ a1; }));
5509 //{ auto x = [[[]]] ~ a2; } // (see test14682b)
5510 { auto x = [[[]]] ~ a3; static assert(is(typeof(x) == typeof(a3))); assert(x == r3y); } // no ambiguity
5511 { auto x = [[[]]] ~ a4; static assert(is(typeof(x) == typeof(a4))); assert(x == r4y); } // fix <- ambiguity
5513 static assert(!__traits(compiles, { auto x = [[[[]]]] ~ a1; }));
5514 static assert(!__traits(compiles, { auto x = [[[[]]]] ~ a2; }));
5515 //{ auto x = [[[[]]]] ~ a3; } // (see test14682b)
5516 { auto x = [[[[]]]] ~ a4; static assert(is(typeof(x) == typeof(a4))); assert(x == r4z); } // no ambiguity
5528 int[][] r2a = [[], [] ]; assert(r2a.length == 2 && r2a[0].length == 0 && r2a[1].length == 0);
5529 //int[][][] r3a = [[], [[]] ]; // should work, but doesn't
5530 //int[][][][] r4a = [[], [[[]]]]; // should work, but doesn't
5531 int[][][] r3a; { r3a.length = 2; r3a[0] = []; r3a[1] = [[]] ; }
5532 assert(r3a.length == 2 && r3a[0].length == 0 && r3a[1].length == 1 && r3a[1][0].length == 0);
5533 int[][][][] r4a; { r4a.length = 2; r4a[0] = []; r4a[1] = [[[]]]; }
5534 assert(r4a.length == 2 && r4a[0].length == 0 && r4a[1].length == 1 && r4a[1][0].length == 1 && r4a[1][0][0].length == 0);
5536 int[][] r2b = [ [] , []]; assert(r2b.length == 2 && r2b[1].length == 0 && r2b[0].length == 0);
5537 //int[][][] r3b = [ [[]] , []]; // should work, but doesn't
5538 //int[][][][] r4b = [[[[]]], []]; // should work, but doesn't
5539 int[][][] r3b; { r3b.length = 2; r3b[0] = [[]] ; r3b[1] = []; }
5540 assert(r3b.length == 2 && r3b[1].length == 0 && r3b[0].length == 1 && r3b[0][0].length == 0);
5541 int[][][][] r4b; { r4b.length = 2; r4b[0] = [[[]]]; r4b[1] = []; }
5542 assert(r4b.length == 2 && r4b[1].length == 0 && r4b[0].length == 1 && r4b[0][0].length == 1 && r4b[0][0][0].length == 0);
5544 // ArrayLiteralExp conforms to the typeof(LHS)->arrayOf().
5545 { auto x = a1 ~ [[]] ; static assert(is(typeof(x) == typeof(a1)[])); assert(x == r2a); } // fix
5546 { auto x = a2 ~ [[[]]] ; static assert(is(typeof(x) == typeof(a2)[])); assert(x == r3a); } // fix
5547 { auto x = a3 ~ [[[[]]]]; static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4a); } // fix
5549 // ArrayLiteralExp conforms to the typeof(RHS)->arrayOf().
5550 { auto x = [[]] ~ a1; static assert(is(typeof(x) == typeof(a1)[])); assert(x == r2b); } // fix
5551 { auto x = [[[]]] ~ a2; static assert(is(typeof(x) == typeof(a2)[])); assert(x == r3b); } // fix
5552 { auto x = [[[[]]]] ~ a3; static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4b); } // fix
5555 /***************************************************/
5561 this(int arg = 2) { val = arg; }
5564 class Bar9739 : Foo9739 { }
5568 Bar9739 bar = new Bar9739;
5569 assert(bar.val == 2);
5572 /***************************************************/
5576 enum Foo { A=1, B=2 }
5577 Foo[] bar = [cast(Foo)1];
5580 /***************************************************/
5582 ulong d2ulong(double u)
5584 return cast(ulong)u;
5587 void testdbl_to_ulong()
5589 auto u = d2ulong(12345.6);
5593 static if (real.mant_dig <= 64)
5595 real adjust = 1.0L/real.epsilon;
5596 u = d2ulong(adjust);
5597 //writefln("%s %s", adjust, u);
5598 static if(real.mant_dig == 64)
5599 assert(u == 9223372036854775808UL);
5600 else static if(real.mant_dig == 53)
5601 assert(u == 4503599627370496UL);
5603 static assert(false, "Test not implemented for this architecture");
5605 auto v = d2ulong(adjust * 1.1);
5606 //writefln("%s %s %s", adjust, v, u + u/10);
5608 // The following can vary in the last bits with different optimization settings,
5609 // i.e. the conversion from real to double may not happen.
5610 //assert(v == 10145709240540254208UL);
5614 /***************************************************/
5618 uint d2uint(double u)
5623 void testdbl_to_uint()
5625 auto u = d2uint(12345.6);
5630 /***************************************************/
5632 ulong r2ulong(real u)
5634 return cast(ulong)u;
5637 void testreal_to_ulong()
5639 auto u = r2ulong(12345.6L);
5643 real adjust = 1.0L/real.epsilon;
5644 u = r2ulong(adjust);
5645 //writefln("%s %s", adjust, u);
5646 static if(real.mant_dig == 113)
5647 assert(u == 18446744073709551615UL);
5648 else static if(real.mant_dig == 106)
5649 assert(u == 18446744073709551615UL);
5650 else static if(real.mant_dig == 64)
5651 assert(u == 9223372036854775808UL);
5652 else static if(real.mant_dig == 53)
5653 assert(u == 4503599627370496UL);
5655 static assert(false, "Test not implemented for this architecture");
5657 auto v = r2ulong(adjust * 1.1);
5658 writefln("%s %s %s", adjust, v, u + u/10);
5660 //assert(v == 10145709240540253389UL);
5663 /***************************************************/
5665 long testbt1(long a, long b, int c)
5667 return a + ((b >> c) & 1);
5668 // return a + ((b & (1L << c)) != 0);
5672 long testbt2(long a, long b, int c)
5674 // return a + ((b >> c) & 1);
5675 return a + ((b & (1L << c)) != 0);
5678 int testbt3(int a, int b, int c)
5680 return a + ((b >> c) & 1);
5681 // return a + ((b & (1 << c)) != 0);
5684 int testbt4(int a, int b, int c)
5686 // return a + ((b >> c) & 1);
5687 return a + ((b & (1 << c)) != 0);
5693 auto a1 = testbt1(3, 4, 2);
5695 a1 = testbt2(3, 4, 2);
5697 a1 = testbt3(3, 4, 2);
5699 a1 = testbt4(3, 4, 2);
5702 a1 = testbt1(3, 8, 2);
5704 a1 = testbt2(3, 8, 2);
5706 a1 = testbt3(3, 8, 2);
5708 a1 = testbt4(3, 8, 2);
5712 /***************************************************/
5714 int foo249(int a, int b)
5716 return a + ((b & 0x80) != 0);
5719 long bar249(long a, int b)
5721 return a + ((b & 0x80) != 0);
5727 auto i = foo249(3, 6);
5729 i = foo249(3, 0x88);
5733 auto i = bar249(3, 6);
5735 i = bar249(3, 0x88);
5740 /***************************************************/
5742 // These should all compile to a BT instruction when -O, for -m32 and -m64
5744 int bt32(uint *p, uint b) { return ((p[b >> 5] & (1 << (b & 0x1F)))) != 0; }
5746 int bt64a(ulong *p, uint b) { return ((p[b >> 6] & (1L << (b & 63)))) != 0; }
5748 int bt64b(ulong *p, size_t b) { return ((p[b >> 6] & (1L << (b & 63)))) != 0; }
5752 static uint[2] a1 = [0x1001_1100, 0x0220_0012];
5754 if ( bt32(a1.ptr,30)) assert(0);
5755 if (!bt32(a1.ptr,8)) assert(0);
5756 if ( bt32(a1.ptr,30+32)) assert(0);
5757 if (!bt32(a1.ptr,1+32)) assert(0);
5759 static ulong[2] a2 = [0x1001_1100_12345678, 0x0220_0012_12345678];
5761 if ( bt64a(a2.ptr,30+32)) assert(0);
5762 if (!bt64a(a2.ptr,8+32)) assert(0);
5763 if ( bt64a(a2.ptr,30+32+64)) assert(0);
5764 if (!bt64a(a2.ptr,1+32+64)) assert(0);
5766 if ( bt64b(a2.ptr,30+32)) assert(0);
5767 if (!bt64b(a2.ptr,8+32)) assert(0);
5768 if ( bt64b(a2.ptr,30+32+64)) assert(0);
5769 if (!bt64b(a2.ptr,1+32+64)) assert(0);
5772 /***************************************************/
5774 struct S251 { int a,b,c,d; }
5779 S251 b = a; // copy propagation
5782 S251 e = d; // dead assignment
5800 /***************************************************/
5803 void bug9387a(double x) { }
5809 double q = x*0.1 + r;
5810 double p = x*0.1 + r*0.2;
5816 /***************************************************/
5818 void bug6962(string value)
5837 /***************************************************/
5843 ubyte[4] bytes4414()
5855 int x = foo4414()[0];
5859 auto x = bytes4414()[0..4];
5860 if (x[0] != 7 || x[1] != 8 || x[2] != 9 || x[3] != 10)
5865 /***************************************************/
5874 /***************************************************/
5877 abstract class B10628
5879 static if (! __traits(isVirtualMethod, foo))
5887 class D10628 : B10628
5889 public override void foo() {}
5894 assert(typeid(D10628).vtbl.length - typeid(Object).vtbl.length == 1);
5897 /***************************************************/
5915 S11265.InnerClass trav = new S11265.InnerClass();
5919 /***************************************************/
5923 void roll(int value)
5926 auto newVal = _seconds + value;
5930 else if(newVal >= 60)
5933 _seconds = cast(ubyte)newVal;
5942 TimeOfDay tod = TimeOfDay(0);
5944 assert(tod._seconds == 59);
5947 /***************************************************/
5951 void _assertEq (ubyte lhs, short rhs, string msg, string file, size_t line)
5953 immutable result = lhs == rhs;
5959 writefln(`_assertEq failed: [%s] is not [%s].`, lhs, rhs);
5961 writefln(`_assertEq failed: [%s] is not [%s]: %s`, lhs, rhs, msg);
5982 static void test(Date date, int day, MonthDay expected, size_t line = __LINE__)
5984 _assertEq(date.day, expected.day, "", __FILE__, line);
5987 test(Date(1999, 1, 1), 1, MonthDay(1,1));
5990 /***************************************************/
5993 alias TT11581(T...) = T;
5999 static class C { alias Types = TT11581!(4, int); }
6000 static C makeC() { return null; }
6002 alias T = TT11581!(A);
6004 // edim == IntergerExp(0)
6006 static assert(is(typeof(a1) == A));
6010 // edim == TypeIdentifier('d2') --> IdentifierExp
6011 auto a2 = new T[d2];
6012 static assert(is(typeof(a2) == A));
6017 // edim == TypeIdentifier('d3') --> IdentifierExp
6018 auto a3 = new U[d3];
6019 static assert(is(typeof(a3) == U[]));
6020 assert(a3.length == d3);
6022 // edim == IndexExp(DotIdExp(CallExp(makeC, []), 'Types'), 0)
6023 auto a4 = new U[makeC().Types[0]];
6024 static assert(is(typeof(a4) == U[]));
6025 assert(a4.length == C.Types[0]);
6028 /***************************************************/
6039 /***************************************************/
6045 this(int n) { num = n; }
6046 ~this() { num = 0; }
6052 auto s = S12138(10);
6053 assert(s.num == 10);
6056 /***************************************************/
6059 void setCookie(long x = 1L << 32L, string y = null){
6060 assert(y.ptr is null);
6067 /***************************************************/
6070 alias Vector14510 = ulong[3];
6072 void fun14510(Vector14510 vec, bool recursive = false)
6074 assert(vec[2] == 0);
6077 fun14510(vec, true);
6086 /***************************************************/
6087 // https://issues.dlang.org/show_bug.cgi?id=16027
6093 assert(value == -1.0); // fails, value is +1.0
6096 value = value * -1.0;
6097 assert(value == -1.0);
6100 /***************************************************/
6101 // https://issues.dlang.org/show_bug.cgi?id=16530
6103 double entropy2(double[] probs)
6111 import std.math : log2;
6112 result -= p * log2(p);
6120 if (entropy2([1.0, 0, 0]) != 0.0)
6124 /***************************************************/
6128 __gshared int x = 7;
6129 __gshared long y = 217;
6136 /***************************************************/
6415 testreal_to_ulong();
6437 writefln("Success");