2 // EXTRA_SOURCES: imports/std11file.d
4 extern(C
) int printf(const char*, ...);
5 extern(C
) size_t
strlen(const char*);
7 /**************************************/
13 const(char) *p
= "bar";
18 /**************************************/
26 alias Foo2
!(int).t t2
;
48 /**************************************/
61 mychar
[] line
=cast(mychar
[])cast(char[])"It is a long line.";
62 mychar
[] delimiter
=cast(mychar
[])cast(string
)"is";
67 string line
="It is a long line.";
68 string delimiter
="is";
73 byte[] line
=cast(byte[])cast(string
)"It is a long line.";
74 byte[] delimiter
=cast(byte[])cast(string
)"is";
79 wstring line
="It is a long line.";
80 wstring delimiter
="is";
84 size_t
dl=delimiter
.length
;
87 assert(line
[ptr
..pl
]==delimiter
[]);
91 /**************************************/
98 assert(p
.sizeof
== 8);
100 assert(p
.sizeof
== 4);
104 /**************************************/
113 Foo6 foo
= new Foo6();
123 /**************************************/
139 /**************************************/
146 assert(a
.length
== 5);
147 assert(a
[1] == '\n');
150 /**************************************/
153 struct Foo9
{ char c
; char bar() { return c
; } }
155 Foo9
makeFoo() { Foo9 f
; return f
; }
157 void callFoo (Foo9 a
)
167 /**************************************/
172 Foo10
makeFoo10() { Foo10 f
; return f
; }
174 void callFoo (Foo10 a
)
180 callFoo(makeFoo10());
183 /**************************************/
190 Color
eval(float x
, float y
)
204 /**************************************/
214 void foo12(out Size12 sz
)
229 assert(sz
.width
== 2);
232 /**************************************/
250 void setLayout(D13 lo
)
252 printf("lo = %p\n", lo
);
261 printf("a = %p\n", a
);
265 /**************************************/
276 /**************************************/
278 alias void delegate(int) t_func
;
293 void func(int num
) { x
= num
; }
307 /**************************************/
309 int[] foo16(byte[] a
)
320 assert(i
.length
== 3);
323 /**************************************/
330 printf("x = %g\n", x
);
334 printf("x = %g\n", x
);
338 printf("x = %g\n", x
);
344 printf("y = %g\n", y
);
348 printf("y = %g\n", y
);
352 printf("y = %g\n", y
);
358 printf("z = %Lg\n", z
);
362 printf("z = %Lg\n", z
);
366 printf("z = %Lg\n", z
);
372 /**************************************/
378 static Bar18 x
= { };
383 const Bar18 b
= Foo18
.x
;
387 /**************************************/
398 /**************************************/
402 int abc() { return 3; }
417 /**************************************/
426 /**************************************/
438 Foo22
test() { return null; }
443 override Bar22
test() { return new Bar22
; }
446 void testx22(Abc22 a
)
448 assert(a
.test() !is null);
453 Def22 d
= new Def22();
458 /**************************************/
470 //printf ("%d\n", foo23.bar.sizeof);
471 assert(foo23
.bar
.sizeof
== int.sizeof
);
475 /**************************************/
495 /**************************************/
499 { const int [] list
= [ 1, 2 ];
500 assert(list
[0] == 1);
501 assert(list
[1] == 2);
504 { const int [] list
= [ 3, 4 ];
505 assert(list
[0] == 3);
506 assert(list
[1] == 4);
511 /**************************************/
527 /**************************************/
531 shared(NODE27
) *next
;
534 static shared NODE27
[3] nodetbl
=
536 { 0,cast(shared(NODE27
)*)nodetbl
+ 1},
537 { 0,cast(shared(NODE27
)*)nodetbl
+ 2},
541 static shared NODE27
[3] nodetbl2
= [
552 /**************************************/
562 int method () { return f
.x
; }
571 /**************************************/
575 int[immutable(byte)[]] foo
;
577 static immutable(byte)[] bar
= [ 65, 66, 67 ];
580 assert(foo
[bar
] == 1);
583 /**************************************/
597 static int value
= 6;
603 printf ("%d\n", B30
.Child
.value
);
604 assert(B30
.Child
.value
== 6);
608 /**************************************/
617 /**************************************/
637 /**************************************/
647 assert(foo33
[0][1] == "hello");
651 /**************************************/
658 printf( "i:%d\n", i
);
664 printf( "i:%d\n", i
);
671 /**************************************/
683 alias Foo35
!( Bar35
) filter
;
684 } catch (Exception e
) {
685 printf( "Exception %.*s", cast(int)e
.msg
.length
, e
.msg
.ptr
);
692 /**************************************/
702 /**************************************/
735 assert(b
.a
== 0 && b
.b
== 0);
736 assert(c
.a
== 0 && c
.b
== 0 && c
.c
== 0);
737 assert(d
.a
== 0 && d
.b
== 0 && d
.c
== 0);
741 /**************************************/
745 extern(Windows
) int func18()
747 static int otherfunc()
756 assert(func18() == 18);
760 /**************************************/
774 bar39
._sub
[] subArray
;
778 for(int i
=0; i
<arr
.length
; i
++)
779 subArray
~= arr
[i
].mySub
;
789 /**************************************/
796 assert(h
== cast(void*)0);
799 /**************************************/
810 /**************************************/
838 /**************************************/
843 ulong b
= cast(ulong) a
;
844 printf("%u", cast(uint) b
);
845 assert(cast(uint) b
== 0);
853 /**************************************/
877 /**************************************/
879 void func45(string a
)
881 assert(a
.length
== 5);
889 printf("'%.*s'\n", cast(int)foo
.length
, foo
.ptr
);
890 func45(cast(string
)foo
);
893 /**************************************/
911 /**************************************/
919 Bar48
makebar48() { Bar48 b
; return b
; }
923 Bar48 b
= makebar48();
926 /**************************************/
928 void testx49() { printf("testx49()\n"); }
930 void test49() { return testx49(); }
932 /**************************************/
934 int testx50() { printf("testx50()\n"); return 3; }
936 void test50() { return cast(void)testx50(); }
938 /**************************************/
942 static typeof(this) foo()
957 static typeof(super) b
;
971 assert(B51
.b
.bar
== 3);
972 assert(B51
.b
.classinfo
== A51
.classinfo
);
979 /**************************************/
983 char get() { return 'A'; }
985 char foo() { return typeof(this).get(); }
986 char bar() { return A52
.get(); }
991 override char get() { return 'B'; }
998 assert(b
.foo() == 'A');
999 assert(b
.bar() == 'A');
1000 assert(b
.get() == 'B');
1003 /**************************************/
1007 int b() { return 1; }
1021 /**************************************/
1053 /**************************************/
1055 int foo55(int x
= 5)
1057 printf("x = %d\n", x
);
1070 /**************************************/
1076 printf("A56.x = %d\n", x
);
1083 override int foo(int x
= 7)
1085 printf("B56.x = %d\n", x
);
1102 /**************************************/
1110 printf("c = %x, w = %x, d = %x\n", c
, w
, d
);
1112 assert(w
== 0xFFFF);
1113 assert(d
== 0xFFFF);
1116 /**************************************/
1126 printf ("static constructor\n");
1132 printf ("class constructor\n");
1140 /**************************************/
1146 void rec(int n
, S61 t
)
1161 /**************************************/
1165 static A62
test(int q
=0) {
1181 /**************************************/
1185 private import imports
.std11file
;
1186 alias imports
.std11file
.getcwd getcwd
;
1192 auto s
= f
.getcwd();
1193 printf("%.*s\n", cast(int)s
.length
, s
.ptr
);
1197 /**************************************/
1214 /**************************************/
1231 /**************************************/
1232 // https://issues.dlang.org/show_bug.cgi?id=8809
1238 char foo() { return 'B'; }
1242 char test1Bx() { return B
.foo(); }
1243 char test1Cx() { return C
.foo(); }
1244 char test1Dx() { return foo(); }
1245 char test1By() { return this.B
.foo(); }
1246 char test1Cy() { return this.C
.foo(); } // cannot compile -> OK
1247 char test1Dy() { return this. foo(); }
1248 char test1Bz() { return typeof(super).foo(); }
1249 char test1Cz() { return typeof(this). foo(); }
1252 char test2Bx() { return { return B
.foo(); }(); }
1253 char test2Cx() { return { return C
.foo(); }(); }
1254 char test2Dx() { return { return foo(); }(); }
1255 char test2By() { return { return this.B
.foo(); }(); }
1256 char test2Cy() { return { return this.C
.foo(); }(); } // cannot compile -> OK
1257 char test2Dy() { return { return this. foo(); }(); }
1258 char test2Bz() { return { return typeof(super).foo(); }(); }
1259 char test2Cz() { return { return typeof(this). foo(); }(); }
1262 char test3Bx() { return (new class Object
{ char bar() { return B
.foo(); } }).bar(); }
1263 char test3Cx() { return (new class Object
{ char bar() { return C
.foo(); } }).bar(); }
1264 char test3Dx() { return (new class Object
{ char bar() { return foo(); } }).bar(); }
1266 override char foo() { return 'C'; }
1270 override char foo() { return 'D'; }
1275 assert(c
.test1Bx() == 'B');
1276 assert(c
.test1Cx() == 'C');
1277 assert(c
.test1Dx() == 'D');
1278 assert(c
.test1By() == 'B');
1279 assert(c
.test1Cy() == 'C');
1280 assert(c
.test1Dy() == 'D');
1281 assert(c
.test1Bz() == 'B'); // NG('D') -> OK
1282 assert(c
.test1Cz() == 'C');
1283 //assert(c.test1Dz() == 'D');
1285 assert(c
.test2Bx() == 'B'); // NG('D') -> OK
1286 assert(c
.test2Cx() == 'C'); // NG('D') -> OK
1287 assert(c
.test2Dx() == 'D');
1288 assert(c
.test2By() == 'B');
1289 assert(c
.test2Cy() == 'C');
1290 assert(c
.test2Dy() == 'D');
1291 assert(c
.test2Bz() == 'B'); // NG('D') -> OK
1292 assert(c
.test2Cz() == 'C'); // NG('D') -> OK
1293 //assert(c.test2Dz() == 'D');
1295 assert(c
.test3Bx() == 'B'); // NG('D') -> OK
1296 assert(c
.test3Cx() == 'C'); // NG('D') -> OK
1297 assert(c
.test3Dx() == 'D');
1300 /**************************************/
1301 // https://issues.dlang.org/show_bug.cgi?id=9734
1308 static bool test(C
) { return true; }
1310 void foo()() if (is(typeof(test(super)))) {}
1311 void bar()() if (is(typeof(super) == C
)) {}
1313 void baz()() if (is(typeof(super))) {}
1318 static assert(!__traits(compiles
, baz()));
1321 /**************************************/
1323 int main(string
[] argv
)
1389 printf("Success\n");