6 import core.stdc.stdlib;
9 import core.stdc.stdlib;
12 /*******************************************/
16 int opSliceAssign(int v, size_t i, size_t j)
24 int opSliceAssign(int v)
35 assert((s[9 .. 10] = 5) == 3);
36 assert((s[] = 6) == 11);
39 /*******************************************/
45 synchronized { int i2 = 2; }
49 /*******************************************/
55 for(ulong i = 0; i < border; i++)
60 ulong result = cast(ulong)r;
69 /*******************************************/
76 /*******************************************/
80 int[] qwert = new int[6];
82 yuiop = qwert[2..5] = 3;
83 assert(yuiop.length == 3);
84 assert(yuiop[0] == 3);
85 assert(yuiop[1] == 3);
86 assert(yuiop[2] == 3);
89 /*******************************************/
124 Foo6.farray()[Foo6.flwr() .. $ - Foo6.fupr()] = 3;
126 assert(yuiop.length == 3);
127 assert(yuiop[0] == 3);
128 assert(yuiop[1] == 3);
129 assert(yuiop[2] == 3);
132 /*******************************************/
136 real a = 3.40483; // this is treated as 3.40483L
145 /*******************************************/
152 for (size_t i = 0; i < 5; i++)
153 for (size_t j = 0; j < 5; j++)
155 if (i == 1 && (j >= 1 && j < 3))
156 assert(m[i][j] == 2);
158 assert(m[i][j] == 1);
162 /*******************************************/
186 ClassOf!(int) c = new ClassOf!(int)();
201 /*******************************************/
205 static if( int.mangleof.length > 1 && int.mangleof[1] == 'x' )
206 printf("'x' as second char\n");
209 /*******************************************/
211 class Foo11 : Bar11 { }
221 f = new Foo11T!(int);
228 Foo11 fooIt = new Foo11();
230 writefln("fooIt should be valid");
232 writefln("it worked");
235 /*******************************************/
253 printf("%d\n", A12.sizeof);
254 assert(A12.sizeof == 12);
257 /*******************************************/
259 template declare13(X) { X declare13; }
261 typeof(declare13!(int[0]).ptr[0]) x13;
262 typeof(declare13!(typeof(""))[0..$]) y13;
268 /*******************************************/
274 writefln("Called Mother.test!");
275 return new Child(42);
279 class Child : Mother, Father {
282 this(int d) { data = d; }
284 override Child test() {
285 writefln("Called Child.test!");
286 return new Child(69);
292 Child aChild = new Child(105);
293 Mother childsMum = aChild;
294 Child childsChild = aChild.test();
295 Child mumsChild = cast(Child) childsMum.test();
296 writefln("Success2");
300 /*******************************************/
317 B b = new B(); // This is okay
323 B b = new B(); // No 'this' for nested class B
335 /*******************************************/
353 assert(x16 == -2.0L + 0.0Li);
356 /*******************************************/
365 /*const*/ float f = 1.2f;
377 "flds %1; fstps %0;" : "=m" (g) : "m" (f) : ;
379 else version(X86_64) asm
381 "flds %1; fstps %0;" : "=m" (g) : "m" (f) : ;
383 else version(ARM) asm
385 "vldr d0, %1; vstr d0, %0;" : "=m" (g) : "m" (f), : "d0";
387 else static assert(false, "ASM code not implemented for this architecture");
393 fld f; // doesn't work with PIC
401 /*******************************************/
403 class Foo18 : Bar18 {}
405 class Bar18 : FooT18!(int) {}
411 /*******************************************/
431 /*******************************************/
435 void bar (void * src)
437 void baz (void function (void *, size_t) xyz)
439 size_t foo (void [] dst)
441 size_t len = dst.length;
442 dst [0 .. len] = src [0 .. len];
454 /*******************************************/
458 int opApply (int delegate(ref int) dg)
469 int foo (int delegate() dg)
486 /*******************************************/
504 printf("Bar22.sizeof = %zd, double.sizeof = %zd\n", Bar22.sizeof, double.sizeof);
505 assert(Bar22.sizeof == double.sizeof);
510 /*******************************************/
523 with(a) fnp = &Ag.func;
540 with(a) fnp = &Ah.func;
550 /*******************************************/
556 uint[] arr3 = arr1[ cast(int)(idx) .. (cast(int) idx) + 3 ]; // OK
557 uint[] arr4 = arr1[ cast(int) idx .. cast(int) idx + 3 ]; // OK
558 uint[] arr5 = arr1[ cast(int)(idx) .. cast(int)(idx) + 3 ]; // C style cast illegal, use cast(idx)+3
559 uint[] arr6 = arr1[ cast(int)(idx) .. cast(int)(idx + 3) ]; // OK
562 /*******************************************/
566 char[6] cstr = "123456"c;
567 auto str1 = cast(wchar[3])(cstr);
569 writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1));
570 assert(cast(char[])str1 == "123456"c);
572 auto str2 = cast(wchar[3])("789abc"c);
573 writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2));
574 assert(cast(char[])str2 == "789abc"c);
576 auto str3 = cast(wchar[3])("defghi");
577 writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3));
578 assert(cast(char[])str3 == "d\000e\000f\000"c);
581 /*******************************************/
585 assert(foo26(5) == 25);
596 /*******************************************/
612 B b = new B(); // This is okay
616 B b = new B(); // No 'this' for nested class B
631 /*******************************************/
640 auto s = std.string.format("%s", "abc123"[intRes() % $] );
644 static const char[] foo = "abc123";
645 s = std.string.format("%s", foo[intRes() % $] );
649 static string bar = "abc123";
650 s = std.string.format("%s", bar[intRes() % $] );
653 const char[] abc = "abc123";
654 s = std.string.format("%s", abc[intRes() % $] );
657 string def = "abc123";
658 s = std.string.format("%s", def[intRes() % $] );
662 /*******************************************/
665 A29 f() { return null; }
669 override B29 f() { return null; }
684 /*******************************************/
686 class Foo30 : Bar30 {}
690 class Bar30 : FooT30!(int) {}
697 /*******************************************/
701 struct X31 { static void opCall() { y31 = 3; } }
710 /*******************************************/
718 void* p = core.stdc.stdlib.malloc(sz);
719 printf("new(sz = %d) = %p\n", sz, p);
726 printf("delete(p = %p)\n", p);
728 if (p) core.stdc.stdlib.free(p);
738 /*******************************************/
742 // this() { printf("this()\n"); }
743 // ~this() { printf("~this()\n"); }
748 new (size_t sz, int i)
750 void* p = core.stdc.stdlib.malloc(sz);
751 printf("new(sz = %d) = %p\n", sz, p);
758 printf("delete(p = %p)\n", p);
760 if (p) core.stdc.stdlib.free(p);
767 scope Foo33 f = new(3) Foo33;
773 assert(Foo33.del == 1);
776 /*******************************************/
778 struct o_O { int a; }
792 int o1 = Foo34.ok.offsetof;
794 int o2 = Foo34.foo.offsetof;
796 int o3 = Foo34.bar.offsetof;
798 int o4 = Foo34.baz.offsetof;
799 assert((o4 % (void*).sizeof) == 0);
803 /*******************************************/
807 float[4] array = 1.0;
813 Foo37 f = new Foo37();
815 writefln("Foo.array[0] = %s", f.array[0] );
816 writefln("Foo.array[1] = %s", f.array[1] );
817 writefln("Foo.array[2] = %s", f.array[2] );
818 writefln("Foo.array[3] = %s", f.array[3] );
819 writefln("Foo.count = %s", f.count );
821 assert(f.array[0] == 1.0);
822 assert(f.array[1] == 1.0);
823 assert(f.array[2] == 1.0);
824 assert(f.array[3] == 1.0);
825 assert(f.count == 10);
828 /*******************************************/
833 static void checkParameters()
844 /*******************************************/
846 void delegate() foo39()
857 writefln("delegate!");
865 void delegate() dg = foo39();
870 /*******************************************/
874 assert( typeid(int) == typeid(int) );
875 assert( (typeid(int) != typeid(int)) == false );
879 bool b1 = (typeid(typeof(x)) != typeid(int));
881 TypeInfo t1 = typeid(typeof(x));
882 TypeInfo t2 = typeid(int);
884 bool b2 = (t1 != t2);
889 /*******************************************/
893 short shift = cast(short)(s.length * 3);
896 for (size_t i = 0; i < s.length; i++){
897 answer = s[i] << shift;
905 if(foo41("\u0001") != 8){
910 /*******************************************/
916 static S42 foo(int x){
943 /*******************************************/
949 static S43 foo(int x){
976 /*******************************************/
982 static S44 foo(int x){
1009 /*******************************************/
1013 char[] buffer = "abcdefghijklmnopqrstuvwxyz".dup;
1014 foreach(ref char c; buffer)
1016 if('a' <= c && c <= 'z')
1018 c -= cast(char)'a' - 'A'; // segfault here
1021 for(int i = 0; i < buffer.length; i++)
1023 if('a' <= buffer[i] && buffer[i] <= 'z')
1025 buffer[i] -= cast(char)'a' - 'A'; // segfault here
1031 /*******************************************/
1037 template t2(int n2) { }
1041 alias st46.t1!().t2 a46;
1047 /*******************************************/
1052 void opSliceAssign(int x)
1054 printf("x = %d\n", x);
1057 A47 d() { return this; }
1064 printf("y = %d\n", a.y);
1066 printf("y = %d\n", a.y);
1069 printf("y = %d\n", a.y);
1073 /*******************************************/
1075 static uint[] sarray48 = void;
1079 static uint[] array = void;
1081 assert(sarray48 == null);
1082 assert(array == null);
1085 /*******************************************/
1098 printf("test50()\n");
1100 for(int i = 0; i < 10; i++)
1107 /*******************************************/
1111 printf("test52()\n");
1113 s = ['a', 'b', 'c'];
1117 x = [17, 18u, 29, 33];
1118 assert(x.length == 4);
1123 assert(x == [17, 18, 29, 33]);
1126 /*******************************************/
1130 printf("test54()\n");
1134 assert(data.length == 1);
1135 foreach (ref foo; data)
1137 assert(foo.length == 500);
1138 foreach (ref u; foo)
1139 { //printf("u = %u\n", u);
1144 foreach (ref foo; data)
1146 assert(foo.length == 500);
1155 /*******************************************/
1159 private string myfoo;
1160 private string mybar;
1162 // Get/set properties that will be overridden.
1163 void foo(string s) { myfoo = s; }
1164 string foo() { return myfoo; }
1166 // Get/set properties that will not be overridden.
1167 void bar(string s) { mybar = s; }
1168 string bar() { return mybar; }
1171 class Derived56: Base56
1173 alias Base56.foo foo; // Bring in Base56's foo getter.
1174 override void foo(string s) { super.foo = s; } // Override foo setter.
1179 Derived56 d = new Derived56;
1185 assert(foo == "hi");
1186 assert(d.foo == "hi");
1187 assert(bar == "hi");
1191 /*******************************************/
1195 void addToReg57(const(void)[] a, int b, bool v)
1199 auto key = a~(cast(void*)&b)[0..4];
1200 reg57[cast(immutable(void)[])key] = v;
1206 addToReg57("test", 1024, true);
1209 /*******************************************/
1211 int bar58( string msg ){
1215 int foo58( lazy string dg ){
1216 return bar58( dg() );
1221 printf("test58()\n");
1229 /*******************************************/
1241 writefln("s = %s", s);
1244 p = std.string.format("s = %s", s);
1245 assert(p == "s = foo");
1248 /*******************************************/
1253 a = [ [-1,2], [3,4] ];
1254 assert(a[0][0] == -1);
1255 assert(a[0][1] == 2);
1256 assert(a[1][0] == 3);
1257 assert(a[1][1] == 4);
1260 b = [ [-1,2], [3,4] ];
1261 assert(b[0][0] == -1);
1262 assert(b[0][1] == 2);
1263 assert(b[1][0] == 3);
1264 assert(b[1][1] == 4);
1267 /*******************************************/
1271 int[][] f = [[1,2],[3,4]];
1272 assert(f[0][0] == 1);
1273 assert(f[0][1] == 2);
1274 assert(f[1][0] == 3);
1275 assert(f[1][1] == 4);
1279 /*******************************************/
1289 return model ? model.list() : List62.init;
1294 private Model model;
1301 /*******************************************/
1312 // runtime crash, the length == 1
1313 printf("%d\n", arr.length);
1314 assert (arr.length == 2);
1315 assert(arr[0] == 1);
1316 assert(arr[1] == 2);
1319 assert(arr.length == 2);
1320 assert(arr[0] == 2);
1321 assert(arr[1] == 1);
1324 assert(arr.length == 3);
1325 assert(arr[0] == 2);
1326 assert(arr[1] == 3);
1327 assert(arr[2] == 1);
1329 foo63([1] ~ 2, 2 ~ [1], [1,2] ~ [3,4,5]);
1332 /*******************************************/
1336 printf("test64()\n");
1337 int[] x = [1,2,3,4];
1340 foreach_reverse(v; x)
1349 foreach_reverse(i, v; x)
1351 writefln("[%s] = %s", i, v);
1357 printf("-test64()\n");
1360 /*******************************************/
1364 // Bugzilla Issue 407.
1365 int i = *cast(int*)cast(char[4])['0', '0', '0', '0']; // compiler seg-fault
1366 printf("i = %x\n", i);
1369 /*******************************************/
1375 byte[] data = new byte[ia[0]];
1376 byte[] data2 = new byte[ cast(int)(ia[0])];
1379 /*******************************************/
1388 auto v1 = test.C68.value;
1389 auto v2 = C68.classinfo;
1390 auto v3 = test.C68.classinfo;
1394 /*******************************************/
1418 auto n2 = new NoBug2;
1420 writefln("bug %d", b.t);
1422 writefln("nobug %d", n.t);
1424 writefln("nobug2 %d", n2.t);
1428 /*******************************************/
1436 static const char[0] altsep;
1437 string s = std.string.format("test%spath", altsep);
1438 assert(s == "testpath");
1442 /*******************************************/
1448 this() { printf("C()\n"); cnt++; }
1449 ~this() { printf("~C()\n"); cnt--; }
1455 this() { printf("D()\n"); cnt++; }
1456 ~this() { printf("~D()\n"); cnt--; }
1462 this() { printf("E()\n"); cnt++; }
1463 ~this() { printf("~E()\n"); cnt--; }
1471 scope D71 d = new D71();
1472 assert(D71.cnt == 1);
1473 for (scope E71 e = new E71(); i < 5; i++)
1475 assert(D71.cnt == 1);
1476 assert(E71.cnt == 1);
1477 scope c = new C71();
1478 assert(C71.cnt == 1);
1480 assert(C71.cnt == 0);
1481 assert(E71.cnt == 0);
1482 assert(D71.cnt == 1);
1485 assert(D71.cnt == 0);
1488 /*******************************************/
1490 size_t getLength(int[] arr) { return arr.length; }
1495 immutable size_t len = getLength(arr);
1499 assert(len == 1); // ok
1500 if (len) { auto l = len; }
1501 assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline"
1504 /*******************************************/
1574 printf("Success\n");