1 // REQUIRED_ARGS: -preview=rvaluerefparam
5 runnable/xtest46.d(165): Deprecation: alias this for classes/interfaces is deprecated
11 runnable/xtest46.d(2932): Deprecation: alias this for classes/interfaces is deprecated
12 runnable/xtest46.d(2964): Deprecation: alias this for classes/interfaces is deprecated
13 int(int i, long j = 7L)
15 C10390(C10390(C10390(<recursion>)))
25 runnable/xtest46.d(4670): Deprecation: alias this for classes/interfaces is deprecated
28 TFunction1: extern (C) void function()
33 import core
.stdc
.stdio
;
35 /******************************************/
39 int opUnary(string op
)() if (op
== "*") { return 7; }
50 /******************************************/
60 void foo2(T
...)(T args
)
62 foreach (arg
; args
[0 .. $])
65 bar2
!(typeof(arg
))(&arg
);
70 void bar2(D
)(const(void)* arg
)
72 D obj
= *cast(D
*) arg
;
76 /***************************************************/
80 immutable int maxi
= 8;
81 int[][maxi
] neighbors
= [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4],
82 [ 2, 3, 5], [ 4, 5, 6 ] ];
85 // neighbors[0].length = 0;
87 void place(int k
, uint mask
)
89 for(uint m
= 1, d
= 1; d
<= maxi
; d
++, m
<<=1)
93 foreach(nb
; neighbors
[k
])
94 if((dif
=grid
[nb
]-d
)==1 || dif
==-1) {
103 printf(" %d\n%d %d %d\n%d %d %d\n %d\n\n",
104 grid
[0], grid
[1], grid
[2], grid
[3], grid
[4], grid
[5], grid
[6], grid
[7]);
111 /***************************************************/
115 enum S5 some_constant
= {2};
124 /***************************************************/
149 assert(t
.sizeof
== 4*4);
150 assert(t
.init
.sizeof
== 4*4);
153 /***************************************************/
178 assert(t
.sizeof
== (void*).sizeof
);
179 assert(t
.init
is null);
182 /***************************************************/
184 void foo8(int n1
= __LINE__
+ 0, int n2
= __LINE__
, string s
= __FILE__
)
187 printf("n1 = %d, n2 = %d, s = %.*s\n", n1
, n2
, cast(int)s
.length
, s
.ptr
);
195 /***************************************************/
197 void foo9(int n1
= __LINE__
+ 0, int n2
= __LINE__
, string s
= __FILE__
)()
200 printf("n1 = %d, n2 = %d, s = %.*s\n", n1
, n2
, cast(int)s
.length
, s
.ptr
);
208 /***************************************************/
210 int foo10(char c
) pure nothrow
217 int function(char c
) fp
;
218 int function(char c
) pure nothrow fq
;
224 /***************************************************/
227 class Derived11
: Base11
{}
228 class MoreDerived11
: Derived11
{}
230 int fun11(Base11
) { return 1; }
231 int fun11(Derived11
) { return 2; }
241 /***************************************************/
244 interface AB
: ABC
{};
245 interface BC
: ABC
{};
246 interface AC
: ABC
{};
247 interface A
: AB
, AC
{};
248 interface B
: AB
, BC
{};
249 interface C
: AC
, BC
{};
251 int f12(AB ab
) { return 1; }
252 int f12(ABC abc
) { return 2; }
261 /***************************************************/
263 template Foo13(alias x
)
268 static assert(Foo13
!(2+1).bar
== 4);
270 template Bar13(alias x
)
275 static assert(Bar13
!("abc").bar
== "abc");
281 /***************************************************/
283 template Foo14(alias a
)
285 alias Bar14
!(a
) Foo14
;
295 auto i
= Foo14
!("hello")();
296 printf("i = %d\n", i
);
297 assert(i
== "hello".sizeof
);
299 printf("i = %d\n", i
);
303 /***************************************************/
318 printf("%d\n", foo15(4));
319 printf("%d\n", bar(4));
322 /***************************************************/
324 int foo16(int x
) { return 1; }
325 int foo16(ref int x
) { return 2; }
331 printf("i == %d\n", i
);
337 /***************************************************/
343 int foo17(A17
, ref int x
) { return 1; }
344 int foo17(B17
, ref int x
) { return 2; }
350 auto i
= foo17(c
, y
);
351 printf("i == %d\n", i
);
355 /***************************************************/
359 void foo(int x
) { foo("abc"); }
360 void foo(string s
) { } // this is hidden, but that's ok 'cuz no overlap
369 override void foo(int x
) { }
378 /***************************************************/
380 int foo19(alias int a
)() { return a
; }
385 auto i
= foo19
!(y
)();
386 printf("i == %d\n", i
);
390 printf("i == %d\n", i
);
394 /***************************************************/
396 template Foo20(int x
) if (x
& 1)
401 template Foo20(int x
) if ((x
& 1) == 0)
416 /***************************************************/
418 template isArray21(T
: U
[], U
)
420 static const isArray21
= 1;
423 template isArray21(T
)
425 static const isArray21
= 0;
428 int foo21(T
)(T x
) if (isArray21
!(T
))
433 int foo21(T
)(T x
) if (!isArray21
!(T
))
447 /***************************************************/
452 foreach (i
; x
.. y
) {}
455 /***************************************************/
457 const bool foo23
= is(typeof(function void() { }));
458 const bar23
= is(typeof(function void() { }));
462 assert(foo23
== true);
463 assert(bar23
== true);
466 /***************************************************/
481 /***************************************************/
497 int x
= bar25(foo25(3));
501 /***************************************************/
517 /***************************************************/
532 /***************************************************/
534 ref int foo28(return ref int x
) { return x
; }
542 /***************************************************/
544 void wyda(int[] a
) { printf("aaa\n"); }
545 void wyda(int[int] a
) { printf("bbb\n"); }
571 /***************************************************/
573 void foo30(D
)(D arg
) if (isIntegral
!D
)
578 struct U30(int T
) { }
592 /***************************************************/
601 override void foo(scope int* p
) { }
608 /***************************************************/
612 nothrow void foo32(int* p
)
614 //try { bar32(); } catch (Object o) { }
615 try { bar32(); } catch (Throwable o
) { }
616 try { bar32(); } catch (Exception o
) { }
625 /***************************************************/
646 /***************************************************/
651 foreach(Uint u
;1..10) {}
652 for(Uint u
=1;u
<10;u
++) {}
655 /***************************************************/
657 ref int foo35(bool condition
, return ref int lhs
, return ref int rhs
)
659 if ( condition
) return lhs
;
663 ref int bar35()(bool condition
, return ref int lhs
, return ref int rhs
)
665 if ( condition
) return lhs
;
673 foo35(a
<b
, a
, b
) = 42;
674 printf("a = %d and b = %d\n", a
, b
); // a = 42 and b = 11
675 assert(a
== 42 && b
== 11);
677 bar35(a
<b
, a
, b
) = 52;
678 printf("a = %d and b = %d\n", a
, b
);
679 assert(a
== 42 && b
== 52);
682 /***************************************************/
684 int foo36(T
...)(T ts
)
690 int foo36(T
...)(T ts
)
698 auto i
= foo36
!(int,int)(1, 2);
709 /***************************************************/
714 with({ return S(); }())
720 /***************************************************/
726 void foo37(X
)(X x
) if (is(X Y
== A37
!(U
), alias U
))
736 foo37
!(A37
!bar37
)(a2
);
739 /***************************************************/
745 printf("B's copy\n");
747 bool empty() {return false;}
749 int front() { return 1; }
750 // ref A38 opSlice() { return this; }
757 foreach (e
; a
) { if (++i
== 100) break; }
760 /***************************************************/
762 alias int function() Fun39
;
763 alias ref int function() Gun39
;
764 static assert(!is(Fun39
== Gun39
));
770 /***************************************************/
776 ref int at(int i
)() { return x40
; }
785 /***************************************************/
787 template Foo41(TList
...)
792 alias Foo41
!(immutable(ubyte)[], ubyte[]) X41
;
799 /***************************************************/
801 bool endsWith(A1
, A2
)(A1 longer
, A2 shorter
)
803 static if (is(typeof(longer
[0 .. 0] == shorter
)))
819 /***************************************************/
821 void f43(S
...)(S s
) if (S
.length
> 3)
831 /***************************************************/
833 struct S44(int x
= 1){}
835 void fun()(S44
!(1) b
) { }
843 /***************************************************/
844 // https://issues.dlang.org/show_bug.cgi?id=2006
848 string
[][] aas = [];
849 assert(aas.length
== 0);
850 aas ~= cast (string
[]) [];
851 assert(aas.length
== 1);
852 aas = aas ~ cast (string
[]) [];
853 assert(aas.length
== 2);
856 /***************************************************/
857 // https://issues.dlang.org/show_bug.cgi?id=8442
861 enum int[] fooEnum
= [];
862 immutable fooImmutable
= fooEnum
;
865 /***************************************************/
879 override const int f()
893 /***************************************************/
901 /***************************************************/
910 enum Test46
test = {};
914 /***************************************************/
916 pure int double_sqr(int x
) {
918 void do_sqr() { y
*= y
; }
925 assert(double_sqr(10) == 100);
928 /***************************************************/
930 void sort(alias less
)(string
[] r
)
934 return less("a", "a");
944 sort
!((a
, b
) { return freqs
[a
] > freqs
[b
]; })(words
);
945 sort
!((string a
, string b
) { return freqs
[a
] > freqs
[b
]; })(words
);
946 //sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words);
947 //sort!(function (a, b) { return freqs[a] > freqs[b]; })(words);
948 //sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words);
949 sort
!(delegate bool(string a
, string b
) { return freqs
[a
] > freqs
[b
]; })(words
);
957 /***************************************************/
958 // https://issues.dlang.org/show_bug.cgi?id=6408
960 static assert(!is(typeof(string
[0..1].init
)));
961 static assert(is(typeof(string
[].init
) == string
[]));
962 static assert(is(typeof(string
[][].init
) == string
[][]));
963 static assert(is(typeof(string
[][][].init
) == string
[][][]));
965 static assert(is(typeof(string
[1].init
) == string
[1]));
966 static assert(is(typeof(string
[1][1].init
) == string
[1][1]));
967 static assert(is(typeof(string
[1][1][1].init
) == string
[1][1][1]));
969 static assert(is(typeof(string
[string
].init
) == string
[string
]));
970 static assert(is(typeof(string
[string
][string
].init
) == string
[string
][string
]));
971 static assert(is(typeof(string
[string
][string
][string
].init
) == string
[string
][string
][string
]));
973 template TT6408(T
...) { alias T TT6408
; }
974 static assert(is(typeof(TT6408
!(int, int)[].init
) == TT6408
!(int, int)));
975 static assert(is(typeof(TT6408
!(int, int)[0..$].init
) == TT6408
!(int, int)));
976 static assert(is(typeof(TT6408
!(int, int)[$-1].init
) == int));
978 /***************************************************/
979 // https://issues.dlang.org/show_bug.cgi?id=9409
981 template TT9409(T
...) { alias T TT9409
; }
983 template idxTypes9409(Prefix
...)
985 TT9409
!((Prefix
[$-1])) idxTypes9409
;
988 alias idxTypes9409
!(int) Types9409
;
990 /***************************************************/
998 printf( "(ctor) &%.*s.x = %p\n", cast(int)name
.length
, name
.ptr
, &x
);
1009 auto s
= new S49("s2");
1011 printf( "&s2.x = %p\n", &s
.x
);
1012 assert(cast(void*)&s
.x
== S49
.p
);
1015 /***************************************************/
1017 auto max50(Ts
...)(Ts args
)
1019 && is(typeof(Ts
[0].init
> Ts
[1].init ? Ts
[1].init
: Ts
[0].init
)))
1021 static if (Ts
.length
== 2)
1022 return args
[1] > args
[0] ? args
[1] : args
[0];
1024 return max50(max50(args
[0], args
[1]), args
[2 .. $]);
1029 assert(max50(4, 5) == 5);
1030 assert(max50(2.2, 4.5) == 4.5);
1031 assert(max50("Little", "Big") == "Little");
1033 assert(max50(4, 5.5) == 5.5);
1034 assert(max50(5.5, 4) == 5.5);
1037 /***************************************************/
1041 static immutable int[2] array
= [ 42 ];
1043 static immutable int[1] array2
= [ 0: 42 ];
1044 enum e2
= array2
[0];
1049 /***************************************************/
1051 enum ubyte[4] a52
= [5,6,7,8];
1059 /***************************************************/
1063 size_t
func2(immutable(void)[] t
)
1069 /***************************************************/
1071 void foo54(void delegate(void[]) dg
) { }
1075 void func(void[] t
) pure { }
1078 // void func2(const(void)[] t) { }
1082 /***************************************************/
1086 synchronized void noop1() { }
1087 void noop2() shared { }
1092 auto foo
= new shared(Foo55
);
1097 /***************************************************/
1099 enum float one56
= 1 * 1;
1100 template X56(float E
) { int X56
= 2; }
1101 alias X56
!(one56
* one56
) Y56
;
1108 /***************************************************/
1112 alias shared(int) T
;
1113 assert (is(T
== shared));
1116 /***************************************************/
1125 A58
[2] rg
=[{1,2},{5,6}];
1126 assert(rg
[0].a
== 1);
1127 assert(rg
[0].b
== 2);
1128 assert(rg
[1].a
== 5);
1129 assert(rg
[1].b
== 6);
1132 /***************************************************/
1135 const foo(int i
) { return i
; }
1138 /***************************************************/
1142 enum real ONE
= 1.0;
1144 for (x
=0.0; x
<10.0; x
+=ONE
)
1150 /***************************************************/
1152 pure immutable(T
)[] fooPT(T
)(immutable(T
)[] x
, immutable(T
)[] y
){
1154 immutable(T
)[] fooState
;
1156 immutable(T
)[] bar(immutable(T
)[] x
){
1157 fooState
= "hello ";
1161 return fooState
~ bar(x
);
1168 auto s
= fooPT("p", "c");
1169 printf("%.*s\n", cast(int)s
.length
, s
.ptr
);
1172 /***************************************************/
1176 static int function(int)[] foo
= [x
=> x
];
1180 /***************************************************/
1182 int[3] foo62(int[3] a
)
1204 /***************************************************/
1209 assert(array
.length
++ == 0);
1210 assert(array
.length
== 1);
1211 assert(array
.length
-- == 1);
1212 assert(array
.length
== 0);
1215 /***************************************************/
1234 /***************************************************/
1254 /***************************************************/
1256 int[2] foo65(int[2] a
)
1267 int[2] c
= foo65(b
);
1275 /***************************************************/
1277 int[1] foo66(int[1] a
)
1287 int[1] c
= foo66(b
);
1292 /***************************************************/
1294 int[2] foo67(out int[2] a
)
1306 int[2] c
= foo67(b
);
1314 /***************************************************/
1318 digestToString(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b");
1321 void digestToString(const ubyte[16] digest
)
1323 assert(digest
[0] == 0xc3);
1324 assert(digest
[15] == 0x3b);
1327 /***************************************************/
1331 digestToString69(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b");
1334 void digestToString69(ref const ubyte[16] digest
)
1336 assert(digest
[0] == 0xc3);
1337 assert(digest
[15] == 0x3b);
1340 /***************************************************/
1344 digestToString70("1234567890123456");
1347 void digestToString70(ref const char[16] digest
)
1349 assert(digest
[0] == '1');
1350 assert(digest
[15] == '6');
1353 /***************************************************/
1355 void foo71(out shared int o
) {}
1357 /***************************************************/
1361 int bar() shared { return 1; }
1370 /***************************************************/
1374 static if (is(typeof(this) T
: shared T
))
1376 static if (is(typeof(this) U
== shared U
))
1378 static if (is(typeof(this) U
== const U
))
1380 static if (is(typeof(this) U
== immutable U
))
1382 static if (is(typeof(this) U
== const shared U
))
1385 static assert(!is(int == const));
1386 static assert(!is(int == immutable));
1387 static assert(!is(int == shared));
1389 static assert(is(int == int));
1390 static assert(is(const(int) == const));
1391 static assert(is(immutable(int) == immutable));
1392 static assert(is(shared(int) == shared));
1393 static assert(is(const(shared(int)) == shared));
1394 static assert(is(const(shared(int)) == const));
1396 static assert(!is(const(shared(int)) == immutable));
1397 static assert(!is(const(int) == immutable));
1398 static assert(!is(const(int) == shared));
1399 static assert(!is(shared(int) == const));
1400 static assert(!is(shared(int) == immutable));
1401 static assert(!is(immutable(int) == const));
1402 static assert(!is(immutable(int) == shared));
1410 template Barc(T
: const(T
))
1415 template Bari(T
: immutable(T
))
1420 template Bars(T
: shared(T
))
1425 template Barsc(T
: shared(const(T
)))
1437 // 5*5 == 25 combinations, plus 2 for swapping const and shared
1439 static assert(is(Bar
!(T
) == T
));
1440 static assert(is(Bar
!(const(T
)) == const(T
)));
1441 static assert(is(Bar
!(immutable(T
)) == immutable(T
)));
1442 static assert(is(Bar
!(shared(T
)) == shared(T
)));
1443 static assert(is(Bar
!(shared(const(T
))) == shared(const(T
))));
1445 static assert(is(Barc
!(const(T
)) == T
));
1446 static assert(is(Bari
!(immutable(T
)) == T
));
1447 static assert(is(Bars
!(shared(T
)) == T
));
1448 static assert(is(Barsc
!(shared(const(T
))) == T
));
1450 static assert(is(Barc
!(T
) == T
));
1451 static assert(is(Barc
!(immutable(T
)) == T
));
1452 static assert(is(Barc
!(const(shared(T
))) == shared(T
)));
1453 static assert(is(Barsc
!(immutable(T
)) == T
));
1455 static assert(is(Bars
!(const(shared(T
))) == const(T
)));
1456 static assert(is(Barsc
!(shared(T
)) == T
));
1458 Bars
!(shared(const(T
))) b
;
1459 pragma(msg
, typeof(b
));
1461 static assert(is(Bars
!(shared(const(T
))) == const(T
)));
1462 static assert(is(Barc
!(shared(const(T
))) == shared(T
)));
1464 static assert(!is(Bari
!(T
)));
1465 static assert(!is(Bari
!(const(T
))));
1466 static assert(!is(Bari
!(shared(T
))));
1467 static assert(!is(Bari
!(const(shared(T
)))));
1469 static assert(is(Barc
!(shared(T
))));
1471 static assert(!is(Bars
!(T
)));
1472 static assert(!is(Bars
!(const(T
))));
1473 static assert(!is(Bars
!(immutable(T
))));
1474 static assert(!is(Barsc
!(T
)));
1475 static assert(!is(Barsc
!(const(T
))));
1478 /***************************************************/
1481 alias void function(int) A74
;
1484 alias void function(int) pure nothrow B74
;
1485 alias pure nothrow void function(int) C74
;
1496 /***************************************************/
1501 foreach (const key
, const val
; aa
) {}
1502 foreach (size_t key
, size_t val
; aa
) {}
1505 /***************************************************/
1509 pure static void raise(string s
)
1511 throw new Exception(s
);
1520 } catch (Exception e
)
1527 /***************************************************/
1533 (which ? x
: y
) += 5;
1537 /***************************************************/
1541 auto a
= ["hello", "world"];
1542 pragma(msg
, typeof(a
));
1551 /***************************************************/
1555 auto array
= [0, 2, 4, 6, 8, 10];
1556 array
= array
[0 .. $ - 2]; // Right-shrink by two elements
1557 assert(array
== [0, 2, 4, 6]);
1558 array
= array
[1 .. $]; // Left-shrink by one element
1559 assert(array
== [2, 4, 6]);
1560 array
= array
[1 .. $ - 1]; // Shrink from both sides
1561 assert(array
== [4]);
1564 /***************************************************/
1568 auto a
= [87, 40, 10];
1570 assert(a
== [87, 40, 10, 42]);
1572 assert(a
== [87, 40, 10, 42, 5, 17]);
1575 /***************************************************/
1580 struct nested
{ int a
; int fun() { return b
; } }
1581 static assert(!__traits(compiles
, { nested x
= { 3, null }; }));
1584 assert(g
.fun() == 12345);
1585 assert(h
.fun() == 12345);
1588 /***************************************************/
1592 auto array
= new int[10];
1593 array
.length
+= 1000;
1594 assert(array
.length
== 1010);
1596 assert(array
.length
== 101);
1598 assert(array
.length
== 100);
1600 assert(array
.length
== 101);
1602 assert(array
.length
== 102);
1604 assert(array
.length
== 2);
1606 assert(array
.length
== 4);
1608 assert(array
.length
== 8);
1610 assert(array
.length
== 4);
1611 array
.length
>>>= 1;
1612 assert(array
.length
== 2);
1614 assert(array
.length
== 0);
1625 (*foo()).length
+= 2;
1626 assert(array
.length
== 2);
1629 /***************************************************/
1633 int[3] a
= [1, 2, 3];
1636 assert(b
[1] == 2); // b is an independent copy of a
1637 int[3] fun(int[3] x
, int[3] y
) {
1638 // x and y are copies of the arguments
1642 auto c
= fun(a
, b
); // c has type int[3]
1643 assert(c
== [100, 42, 3]);
1644 assert(b
== [1, 2, 3]); // b is unaffected by fun
1647 /***************************************************/
1651 auto a1
= [ "Jane":10.0, "Jack":20, "Bob":15 ];
1652 auto a2
= a1
; // a1 and a2 refer to the same data
1653 a1
["Bob"] = 100; // Changing a1
1654 assert(a2
["Bob"] == 100); //is same as changing a2
1655 a2
["Sam"] = 3.5; //and vice
1656 assert(a2
["Sam"] == 3.5); // versa
1659 /***************************************************/
1668 static assert(!is(typeof(a
~= "b"w
)));
1669 static assert(!is(typeof(a
~= "c"d
)));
1670 static assert(!is(typeof(b
~= "a"c
)));
1672 static assert(!is(typeof(b
~= "c"d
)));
1673 static assert(!is(typeof(c
~= "a"c
)));
1674 static assert(!is(typeof(c
~= "b"w
)));
1682 /***************************************************/
1684 void bump(ref int x
) { ++x
; }
1693 /***************************************************/
1700 /***************************************************/
1702 auto foo84
= [1, 2.4];
1706 pragma(msg
, typeof([1, 2.4]));
1707 static assert(is(typeof([1, 2.4]) == double[]));
1709 pragma(msg
, typeof(foo84
));
1710 static assert(is(typeof(foo84
) == double[]));
1713 /***************************************************/
1717 dstring c
= "V\u00E4rld";
1719 assert(c
== "V\u00E4rld!");
1721 assert(c
== "@V\u00E4rld!");
1723 wstring w
= "V\u00E4rld";
1725 assert(w
== "V\u00E4rld!");
1727 assert(w
== "@V\u00E4rld!");
1729 string s
= "V\u00E4rld";
1731 assert(s
== "V\u00E4rld!");
1733 assert(s
== "@V\u00E4rld!");
1736 /***************************************************/
1740 int[][] a
= [ [1], [2,3], [4] ];
1741 int[][] w
= [ [1, 2], [3], [4, 5], [] ];
1742 int[][] x
= [ [], [1, 2], [3], [4, 5], [] ];
1745 /***************************************************/
1747 // https://issues.dlang.org/show_bug.cgi?id=3379
1749 T1
[] find(T1
, T2
)(T1
[] longer
, T2
[] shorter
)
1750 if (is(typeof(longer
[0 .. 1] == shorter
) : bool))
1752 while (longer
.length
>= shorter
.length
) {
1753 if (longer
[0 .. shorter
.length
] == shorter
) break;
1754 longer
= longer
[1 .. $];
1761 && is(typeof(a
[1] > a
[0] ? a
[1] : a
[0]))
1763 && is(typeof(max(max(a
[0], a
[1]), a
[2 .. $])))) {
1764 static if (T
.length
== 2) {
1765 return a
[1] > a
[0] ? a
[1] : a
[0];
1767 return max(max(a
[0], a
[1]), a
[2 .. $]);
1771 // Cases which would ICE or segfault
1773 static void cat(Frog
)(Frog f
) if (true)
1778 Bulldog
!(int).cat(0);
1783 double[] d1
= [ 6.0, 1.5, 2.4, 3 ];
1784 double[] d2
= [ 1.5, 2.4 ];
1785 assert(find(d1
, d2
) == d1
[1 .. $]);
1786 assert(find(d1
, d2
) == d1
[1 .. $]); // Check for memory corruption
1787 assert(max(4, 5) == 5);
1788 assert(max(3, 4, 5) == 5);
1791 /***************************************************/
1793 template test4284(alias v
) { enum test4284
= v
.length
== 0; }
1794 static assert(test4284
!(cast(string
)null));
1795 static assert(test4284
!(cast(string
[])null));
1797 /***************************************************/
1801 void opDispatch(string s
, T
)(T i
)
1803 printf("S.opDispatch('%.*s', %d)\n", cast(int)s
.length
, s
.ptr
, i
);
1809 void opDispatch(string s
)(int i
)
1811 printf("C.opDispatch('%.*s', %d)\n", cast(int)s
.length
, s
.ptr
, i
);
1817 template opDispatch(string s
)
1819 enum int opDispatch
= 8;
1826 s
.opDispatch
!("hello")(7);
1833 printf("d.foo = %d\n", d
.foo
);
1837 /***************************************************/
1842 int bar() { return x
; }
1845 printf("%zd\n", s
.sizeof
);
1846 assert(s
.sizeof
== 4);
1849 /***************************************************/
1853 void opDispatch( string name
, T
... )( T values
)
1855 assert(values
[0] == 3.14);
1861 s
.opDispatch
!("foo")( 3.14 );
1865 /***************************************************/
1867 struct A7439(int r
, int c
)
1871 alias float[R
* C
] Data
;
1875 this(Data ar
){ _data
= ar
; }
1877 pure ref float opIndex(size_t rr
, size_t cc
){ return _data
[cc
+ rr
* C
]; }
1882 A7439
!(2, 2) a
= A7439
!(2, 2)([8, 3, 2, 9]);
1883 a
[0,0] -= a
[0,0] * 2.0;
1886 /***************************************************/
1888 void foo91(uint line
= __LINE__
) { printf("%d\n", line
); }
1893 printf("%d\n", __LINE__
);
1896 /***************************************************/
1898 bool fun13468(Object e
, typeof(null) needle
)
1900 return (e
== needle
);
1905 assert(fun13468(null, null));
1908 /***************************************************/
1910 auto ref foo92(ref int x
) { return x
; }
1911 int bar92(ref int x
) { return x
; }
1916 int i
= bar92(foo92(x
));
1920 /***************************************************/
1924 public int foo() const
1932 const Foo93 bar
= Foo93();
1933 enum bla
= bar
.foo();
1937 /***************************************************/
1940 extern(C
++) class C1687
1947 auto c
= new C1687();
1948 assert(c
.__vptr
[0] == (&c
.func
).funcptr
);
1951 /***************************************************/
1959 pure nothrow Foo94
makeFoo(const int x
, const int y
)
1961 return Foo94(x
, y
, 3.0);
1966 auto f
= makeFoo(1, 2);
1972 /***************************************************/
1986 @disable void foo95() { }
1990 @disable this(this);
1998 @disable void foo95A() { }
2004 static assert(!__traits(compiles
, t
= s
));
2005 static assert(!__traits(compiles
, foo95()));
2009 static assert(!__traits(compiles
, v
= u
));
2010 static assert(!__traits(compiles
, foo95A()));
2013 /***************************************************/
2015 struct S96(alias init
)
2017 int[] content
= init
;
2024 //writeln(s1.content);
2025 //writeln(s2.content);
2026 assert(!is(typeof(s1
) == typeof(s2
)));
2029 /***************************************************/
2033 const bool opEquals(ref const A97
) { return true; }
2034 ref A97
opUnary(string op
)() if (op
== "++")
2043 foreach (e
; a
.. b
) {
2047 /***************************************************/
2051 auto a
= new int[2];
2052 // the name "length" should not pop up in an index expression
2053 static assert(!is(typeof(a
[length
- 1])));
2056 /***************************************************/
2060 void bar99(string i
)
2064 void function(string
) foo99(string i
)
2071 foo99 (s99
~= "a") (s99
~= "b");
2072 assert(s99
== "ab");
2075 /***************************************************/
2076 // https://issues.dlang.org/show_bug.cgi?id=5081
2080 static pure immutable(int[]) x1()
2082 int[] a
= new int[](10);
2085 static pure immutable(int[]) x2(int len
)
2087 int[] a
= new int[](len
);
2090 static pure immutable(int[]) x3(immutable(int[]) org
)
2092 int[] a
= new int[](org
.length
);
2096 immutable a1
= x1();
2097 immutable a2
= x2(10);
2098 immutable a3
= x3([1,2]);
2100 static pure int[] y1()
2102 return new int[](10);
2105 immutable b1
= y1();
2108 /***************************************************/
2114 /* Testing order of evaluation */
2115 void delegate(string
, string
) fun(string
) {
2117 return delegate void(string x
, string y
) { s
~= "e"; };
2119 fun(s
~= "a")(s
~= "c", s
~= "d");
2120 assert(s
== "abcde", s
);
2123 /***************************************************/
2127 int[] d1
= [ 6, 1, 2 ];
2128 byte[] d2
= [ 6, 1, 2 ];
2134 /***************************************************/
2144 void popAny() { empty
= true; }
2145 alias popAny popFront
;
2146 alias popAny popBack
;
2149 foreach(int i
; S()) assert(i
== 7);
2151 foreach(i
; S()) assert(i
== 2);
2152 foreach_reverse(i
; S()) assert(i
== "yes!");
2155 /***************************************************/
2157 static assert([1,2,3] == [1.0,2,3]);
2159 /***************************************************/
2161 int transmogrify(uint) { return 1; }
2162 int transmogrify(long) { return 2; }
2166 assert(transmogrify(42) == 1);
2169 /***************************************************/
2179 int* p
= &(*x
+= 1);
2191 /***************************************************/
2193 ref int bump105(return ref int x
) { return ++x
; }
2198 bump105(bump105(x
)); // two increments
2202 /***************************************************/
2204 pure int genFactorials(int n
) {
2205 static pure int factorial(int n
) {
2207 return factorial(2);
2209 return factorial(n
);
2212 /***************************************************/
2219 assert(a
.init
== [0,0,0,0,0,0]);
2222 /***************************************************/
2230 auto z
= true ? b
: c
;
2231 //writeln(typeof(z).stringof);
2232 static assert(is(typeof(z
) == const(A109
)));
2235 /***************************************************/
2238 struct Foo110(T
, alias V
= Boo
!T
)
2240 pragma(msg
, V
.stringof
);
2241 static const s
= V
.stringof
;
2243 alias Foo110
!double B110
;
2244 alias Foo110
!int A110
;
2246 static assert(B110
.s
== "Boo!double");
2247 static assert(A110
.s
== "Boo!int");
2249 /***************************************************/
2253 static assert(is(byte[typeof(int.init
).sizeof
] == byte[4]));
2254 static assert(is(byte[typeof(return).sizeof
] == byte[4]));
2258 /***************************************************/
2260 // https://issues.dlang.org/show_bug.cgi?id=3716
2263 auto k1
= true ?
[1,2] : []; // OK
2264 auto k2
= true ?
[[1,2]] : [[]];
2265 auto k3
= true ?
[] : [[1,2]];
2266 auto k4
= true ?
[[[]]] : [[[1,2]]];
2267 auto k5
= true ?
[[[1,2]]] : [[[]]];
2268 auto k6
= true ?
[] : [[[]]];
2269 static assert(!is(typeof(true ?
[[[]]] : [[1,2]]))); // Must fail
2272 /***************************************************/
2273 // https://issues.dlang.org/show_bug.cgi?id=658
2295 /***************************************************/
2300 void[] v
= [id
] ~ [id
];
2303 /***************************************************/
2304 // https://issues.dlang.org/show_bug.cgi?id=4303
2306 template foo112() if (__traits(compiles
,undefined
))
2308 enum foo112
= false;
2311 template foo112() if (true)
2316 pragma(msg
,__traits(compiles
,foo112
!()));
2317 static assert(__traits(compiles
,foo112
!()));
2319 const bool bar112
= foo112
!();
2322 /***************************************************/
2330 void opAssign(File113 rhs
) { }
2346 auto filter113(File113
.ByLine rs
)
2350 this(File113
.ByLine r
) { }
2358 auto f
= File113(1);
2359 auto rx
= f
.byLine();
2360 auto file
= filter113(rx
);
2363 /***************************************************/
2365 template foo114(fun
...)
2367 auto foo114(int[] args
)
2373 pragma(msg
, typeof(foo114
!"a + b"([1,2,3])));
2375 /***************************************************/
2376 // https://issues.dlang.org/show_bug.cgi?id=3935
2379 void opBinary(string op
)(Foo other
) {
2380 pragma(msg
, "op: " ~ op
);
2391 /***************************************************/
2392 // https://issues.dlang.org/show_bug.cgi?id=2477
2394 void foo116(T
,)(T t
) { T x
; }
2398 int[] data
= [1,2,3,]; // OK
2400 data
= [ 1,2,3, ]; // fails
2407 /***************************************************/
2412 char[8] x
= "helloabc";
2422 assert(g
[0] && g
[1] && g
[0].x
== g
[1].x
);
2428 /***************************************************/
2429 // https://issues.dlang.org/show_bug.cgi?id=4291
2433 mixin declareVariable
;
2435 mixin declareFunction
;
2438 template declareVariable() { int var
; }
2439 template declareFunction()
2441 int readVar() { return var
; }
2444 /***************************************************/
2445 // https://issues.dlang.org/show_bug.cgi?id=4177
2447 pure real log118(real x
) {
2454 enum x118
= log118(4.0);
2458 /***************************************************/
2466 /***************************************************/
2468 pure void foo(int *p
)
2480 /***************************************************/
2481 // https://issues.dlang.org/show_bug.cgi?id=4866
2483 immutable int[3] statik
= [ 1, 2, 3 ];
2484 enum immutable(int)[] dynamic
= statik
;
2486 static assert(is(typeof(dynamic
) == immutable(int)[]));
2487 static if (! is(typeof(dynamic
) == immutable(int)[]))
2489 static assert(0); // (7)
2491 pragma(msg
, "!! ", typeof(dynamic
));
2493 /***************************************************/
2494 // https://issues.dlang.org/show_bug.cgi?id=2943
2512 assert(foo2
.a
== foo
.a
);
2515 /***************************************************/
2516 // https://issues.dlang.org/show_bug.cgi?id=4641
2525 ss
[0] = S123
.init
; // This line causes Range Violation.
2528 /***************************************************/
2529 // https://issues.dlang.org/show_bug.cgi?id=2451
2533 void opAssign(Foo124 x
) { z
= 2;}
2538 this(this){ z
= 17; }
2542 Foo124
[string
] stuff
;
2543 stuff
["foo"] = Foo124
.init
;
2544 assert(stuff
["foo"].z
== 3);
2545 stuff
["foo"] = Foo124
.init
;
2546 assert(stuff
["foo"].z
== 2);
2548 Bar124
[string
] stuff2
;
2551 assert(stuff2
["dog"].z
== 17);
2554 /***************************************************/
2558 void bug5071(short d
, ref short c
) {
2566 auto useless
= &closure
;
2575 /***************************************************/
2579 static Foo126
opCall(in Foo126 _f
) pure
2585 /***************************************************/
2589 struct S
{ invariant() { throw new Exception(""); } }
2597 /***************************************************/
2601 if(0) mixin("auto x = 2;");
2605 /***************************************************/
2607 struct Tuple127(S
...)
2613 alias Tuple127
!(int, int) Foo127
;
2622 /***************************************************/
2625 alias const Bug4434
* IceConst4434
;
2626 alias shared Bug4434
* IceShared4434
;
2627 alias shared Bug4434
[] IceSharedArray4434
;
2628 alias immutable Bug4434
* IceImmutable4434
;
2629 alias shared const Bug4434
* IceSharedConst4434
;
2631 alias int MyInt4434
;
2632 alias const MyInt4434
[3] IceConstInt4434
;
2634 alias immutable string
[] Bug4830
;
2636 /***************************************************/
2637 // https://issues.dlang.org/show_bug.cgi?id=4254
2639 void bub(const inout int other
) {}
2647 /***************************************************/
2649 pure nothrow @safe auto bug4915a() { return 0; }
2650 pure nothrow @safe int bug4915b() { return bug4915a(); }
2654 pure nothrow @safe int d() { return 0; }
2655 int e() pure nothrow @safe { return d(); }
2658 /***************************************************/
2659 // https://issues.dlang.org/show_bug.cgi?id=5164
2661 static if (is(int Q
== int, Z
...)) { }
2663 /***************************************************/
2664 // https://issues.dlang.org/show_bug.cgi?id=5195
2666 alias typeof(foo5195
) food5195
;
2667 const int * foo5195
= null;
2668 alias typeof(foo5195
) good5195
;
2669 static assert( is (food5195
== good5195
));
2671 /***************************************************/
2679 void test5332() { auto x
= var5332
; }
2682 /***************************************************/
2683 // https://issues.dlang.org/show_bug.cgi?id=5191
2687 void add(T
)(T value
) nothrow
2689 this.value
+= value
;
2702 auto foo
= Foo129(5);
2703 assert(foo
.value
== 5);
2706 printf("%d\n", foo
.value
);
2707 assert(foo
.value
== 7);
2710 printf("%d\n", foo
.value
);
2711 assert(foo
.value
== 10);
2714 printf("%d\n", foo
.value
);
2715 assert(foo
.value
== 13);
2717 void delegate (int) nothrow dg
= &foo
.add!(int);
2719 assert(foo
.value
== 20);
2722 /***************************************************/
2723 // https://issues.dlang.org/show_bug.cgi?id=6169
2725 auto ctfefunc6169() { return "{}"; }
2726 enum ctfefptr6169
= &ctfefunc6169
;
2727 int ctfefunc6169a() { return 1; }
2728 template x6169(string c
) { alias int x6169
; }
2729 template TT6169(T
...) { alias T TT6169
; }
2730 @property ctfeprop6169() { return "g"; }
2732 void test6169() pure @safe
2734 enum a
= ctfefunc6169();
2735 static b
= ctfefunc6169();
2736 x6169
!(ctfefunc6169()) tt
;
2737 mixin(ctfefunc6169());
2738 static if(ctfefunc6169()) {}
2739 pragma(msg
, ctfefunc6169());
2745 auto g
= mixin('"' ~ ctfefunc6169() ~ '"');
2746 //auto h = import("testx.d" ~ false ? ctfefunc() : "");
2747 alias TT6169
!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i
;
2748 alias TT6169
!(int, int)[ctfefunc6169a()] j
;
2749 int[ctfefunc6169a()+1] k
;
2750 alias int[ctfefunc6169a()] l
;
2753 //case ctfefunc6169a(): // Can't do this because of case variables
2754 case ctfefunc6169a()+1:
2756 case ctfefunc6169a()+2:
2760 static assert(ctfefunc6169a());
2761 void fun(int i
: ctfefunc6169a() = ctfefunc6169a(), alias j
)() if (ctfefunc6169a()) {}
2762 fun
!(ctfefunc6169a(), ctfefunc6169())();
2763 enum z
= ctfefptr6169();
2765 auto p
= mixin(ctfeprop6169
);
2768 /***************************************************/
2769 // https://issues.dlang.org/show_bug.cgi?id=10506
2771 void impureFunc10506() {}
2772 string
join10506(RoR
)(RoR
ror)
2775 return ror[0] ~ ror[1];
2778 void test10506() pure
2782 mixin(["foo", "bar"].join10506()~";");
2785 /***************************************************/
2787 const shared class C5107
2792 static assert(is(typeof(C5107
.x
) == const)); // okay
2793 static assert(is(typeof(C5107
.x
) == shared)); // fails!
2795 /***************************************************/
2797 immutable struct S3598
2799 static void funkcja() { }
2802 /***************************************************/
2803 // https://issues.dlang.org/show_bug.cgi?id=4211
2815 @safe void test130()
2823 /***************************************************/
2825 template Return(alias fun
)
2827 static if (is(typeof(fun
) R
== return)) alias R Return
;
2833 real square(real n
);
2835 alias Return
!( __traits(getOverloads
, I4217
, "square")[0] ) R4217
;
2836 alias Return
!( __traits(getOverloads
, I4217
, "square")[1] ) S4217
;
2838 static assert(! is(R4217
== S4217
));
2840 /***************************************************/
2841 // https://issues.dlang.org/show_bug.cgi?id=5094
2851 @property int[] get() { return [1,2,3]; }
2855 /***************************************************/
2865 auto id
= 0 ?
S7545() : -1;
2868 /***************************************************/
2869 // https://issues.dlang.org/show_bug.cgi?id=5020
2883 /***************************************************/
2884 // https://issues.dlang.org/show_bug.cgi?id=5343
2886 struct Tuple5343(Specs
...)
2896 alias Tuple5343
!(A5343
) TA5343
;
2897 alias S5343
!(A5343
) SA5343
;
2899 /***************************************************/
2900 // https://issues.dlang.org/show_bug.cgi?id=5365
2909 protected static class Factory
: IFactory
2918 _factory
= createFactory();
2921 protected IFactory
createFactory()
2926 private IFactory _factory
;
2927 @property final IFactory
factory()
2938 IFactory f
= new A133
;
2939 f
.foo(); // segfault
2942 /***************************************************/
2943 // https://issues.dlang.org/show_bug.cgi?id=5365
2971 B134 b
= a
; // b is null
2972 assert(a
._b
is b
); // fails
2975 /***************************************************/
2976 // https://issues.dlang.org/show_bug.cgi?id=5025
2989 /***************************************************/
2990 // https://issues.dlang.org/show_bug.cgi?id=5545
2992 bool enforce136(bool value
, lazy const(char)[] msg
= null) {
3004 this(byte[] input
) {
3005 foreach(elem
; input
) {
3008 printf("%d\n", i
); // Never gets incremented. Stays at 0.
3014 byte[] stuff
= [0, 1, 2];
3015 auto perm2
= Perm(stuff
);
3016 //writeln(perm2.perm); // Prints [2, 0, 0]
3017 assert(perm2
.perm
[] == [0, 1, 2]);
3020 /***************************************************/
3021 // https://issues.dlang.org/show_bug.cgi?id=4097
3024 alias typeof(&foo4097
) T4097
;
3025 static assert(is(T4097 X
: X
*) && is(X
== function));
3027 static assert(!is(X
));
3029 /***************************************************/
3030 // https://issues.dlang.org/show_bug.cgi?id=5798
3032 void assign9(ref int lhs
) pure {
3036 void assign8(ref int rhs
) pure {
3042 assign8(b
),assign9(a
);
3044 assert(b
== 8); // <-- fail
3046 assign9(b
),assign8(a
);
3048 assert(b
== 9); // <-- fail
3053 /***************************************************/
3055 // https://issues.dlang.org/show_bug.cgi?id=9366
3056 static assert(!is(typeof((void[]).init
~ cast(void)0)));
3057 static assert(!is(typeof(cast(void)0 ~ (void[]).init
)));
3059 /***************************************************/
3075 enum Size138 foo138
= {2 ,5};
3077 Size138 bar138
= foo138
;
3081 assert(bar138
.width
== 2);
3082 assert(bar138
.height
== 5);
3085 /***************************************************/
3089 import core
.stdc
.stdlib
;
3100 /***************************************************/
3102 // https://issues.dlang.org/show_bug.cgi?id=5939
3103 // https://issues.dlang.org/show_bug.cgi?id=5940
3105 template map(fun
...)
3107 auto map(double[] r
)
3111 this(double[] input
)
3124 alias typeof(map
!"a"(x
)) T
;
3126 auto b
= map
!"a"(x
);
3127 auto c
= [map
!"a"(x
)];
3132 /***************************************************/
3133 // https://issues.dlang.org/show_bug.cgi?id=5966
3135 string
[] foo5966(string
[] a
)
3141 enum var5966
= foo5966([""]);
3143 /***************************************************/
3144 // https://issues.dlang.org/show_bug.cgi?id=5975
3146 int foo5975(wstring replace
)
3153 enum X5975
= foo5975("X"w
);
3155 /***************************************************/
3156 // https://issues.dlang.org/show_bug.cgi?id=5965
3158 template mapx(fun
...) if (fun
.length
>= 1)
3160 int mapx(Range
)(Range r
)
3168 int foo(int i
) { return i
; }
3171 auto x
= mapx
!( (int a
){return foo(a
);} )(arr
);
3174 /***************************************************/
3180 foreach (ref b
; barr
)
3188 /***************************************************/
3189 // https://issues.dlang.org/show_bug.cgi?id=5771
3193 this(A
)(auto ref A a
){}
3201 /***************************************************/
3204 class test5498_B
: test5498_A
{}
3205 class test5498_C
: test5498_A
{}
3207 static assert(is(typeof([test5498_B
.init
, test5498_C
.init
]) == test5498_A
[]));
3209 /***************************************************/
3210 // https://issues.dlang.org/show_bug.cgi?id=3688
3215 this(int n
) pure { v
= n
; }
3216 const bool opCast(T
:bool)() { return true; }
3225 if (const int a
= 2)
3229 if (immutable int a
= 3)
3233 if (auto s
= S142(10))
3237 if (auto s
= const(S142
)(20))
3241 if (auto s
= immutable(S142
)(30))
3246 /***************************************************/
3247 // https://issues.dlang.org/show_bug.cgi?id=6072
3254 /***************************************************/
3255 // https://issues.dlang.org/show_bug.cgi?id=5959
3261 ref int f(){ return n
; } // NG
3265 nothrow ref int f1(){ return n
; } // OK
3269 auto ref int f2(){ return n
; } // OK
3274 /***************************************************/
3275 // https://issues.dlang.org/show_bug.cgi?id=6119
3277 void startsWith(alias pred
) () if (is(typeof(pred('c', 'd')) : bool))
3281 void startsWith(alias pred
) () if (is(typeof(pred('c', "abc")) : bool))
3287 startsWith
!((a
, b
) { return a
== b
; })();
3290 /***************************************************/
3294 import core
.stdc
.stdio
;
3295 printf("hello world 145\n");
3301 static import core
.stdc
.stdio
;
3302 core
.stdc
.stdio
.printf("hello world 146\n");
3305 /***************************************************/
3306 // https://issues.dlang.org/show_bug.cgi?id=5856
3310 void f() { printf("X.f mutable\n"); }
3311 void f() const { printf("X.f const\n"); }
3313 void g()() { printf("X.g mutable\n"); }
3314 void g()() const { printf("X.g const\n"); }
3316 void opOpAssign(string op
)(int n
) { printf("X+= mutable\n"); }
3317 void opOpAssign(string op
)(int n
) const { printf("X+= const\n"); }
3323 xm
.f(); // prints "X.f mutable"
3324 xm
.g(); // prints "X.g mutable"
3325 xm
+= 10; // should print "X+= mutable" (1)
3328 xc
.f(); // prints "X.f const"
3329 xc
.g(); // prints "X.g const"
3330 xc
+= 10; // should print "X+= const" (2)
3334 /***************************************************/
3340 int foo(int a
) { return 0; }
3341 int foo(float a
) { return 1; }
3343 int bar(float a
) { return 1; }
3344 int bar(int a
) { return 0; }
3349 override int foo(float a
) { return 2; }
3353 override int bar(float a
) { return 2; }
3358 auto f1
= cast(int delegate(int))&x
.foo
;
3359 auto f2
= cast(int delegate(float))&x
.foo
;
3360 int delegate(int) f3
= &x
.foo
;
3361 int delegate(float) f4
= &x
.foo
;
3371 auto f1
= cast(int delegate(int))&x
.foo
;
3372 auto f2
= cast(int delegate(float))&x
.foo
;
3373 int delegate(int) f3
= &x
.foo
;
3374 int delegate(float) f4
= &x
.foo
;
3384 auto f1
= cast(int delegate(int))&x
.bar
;
3385 auto f2
= cast(int delegate(float))&x
.bar
;
3386 int delegate(int) f3
= &x
.bar
;
3387 int delegate(float) f4
= &x
.bar
;
3397 auto f1
= cast(int delegate(int))&x
.bar
;
3398 auto f2
= cast(int delegate(float))&x
.bar
;
3399 int delegate(int) f3
= &x
.bar
;
3400 int delegate(float) f4
= &x
.bar
;
3409 /***************************************************/
3418 scope C13182 c
= new C13182();
3421 /***************************************************/
3422 // https://issues.dlang.org/show_bug.cgi?id=5897
3424 struct A148
{ int n
; }
3427 this(A148 a
){ n
= a
.n
, m
= a
.n
*2; }
3432 static C148
opCall(A148 a
)
3435 b
.n
= a
.n
, b
.m
= a
.n
*2;
3443 auto b
= cast(B148
)a
;
3444 assert(b
.n
== 10 && b
.m
== 20);
3445 auto c
= cast(C148
)a
;
3446 assert(c
.n
== 10 && c
.m
== 20);
3449 /***************************************************/
3450 // https://issues.dlang.org/show_bug.cgi?id=4969
3452 class MyException
: Exception
3456 super("An exception!");
3462 throw new MyException
;
3465 void cantthrow() nothrow
3469 catch(MyException me
)
3475 /***************************************************/
3476 // https://issues.dlang.org/show_bug.cgi?id=2356
3481 printf("x[] = [%d %d %d]\n", x
[0], x
[1], x
[2]);
3482 assert(x
[0] == 1 && x
[1] == 2 && x
[2] == 3);
3488 this(this) { ++pblit
; printf("postblit: %d\n", n
); }
3491 S
[3] s
= [S(1), s2
, S(3)];
3492 assert(s
[0].n
== 1 && s
[1].n
== 2 && s
[2].n
== 3);
3493 printf("s[].n = [%d %d %d]\n", s
[0].n
, s
[1].n
, s
[2].n
);
3494 assert(S
.pblit
== 1);
3498 printf("v[] = [%d %d %d, ..., %d]\n", v
[0], v
[1], v
[2], v
[$-1]);
3499 foreach (ref a
; v
) assert(a
== 0);
3502 int[3] y
= [n
, n
, n
];
3503 printf("y[] = [%d %d %d]\n", y
[0], y
[1], y
[2]);
3504 assert(y
[0] == 5 && y
[1] == 5 && y
[2] == 5);
3506 S
[3] z
= [s2
, s2
, s2
];
3507 assert(z
[0].n
== 2 && z
[1].n
== 2 && z
[2].n
== 2);
3508 printf("z[].n = [%d %d %d]\n", z
[0].n
, z
[1].n
, z
[2].n
);
3509 assert(S
.pblit
== 1 + 3);
3517 ref int[0] bar() { static int[1] sa
; return *cast(int[0]*)&sa
; }
3521 /***************************************************/
3522 // https://issues.dlang.org/show_bug.cgi?id=13652
3528 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3529 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3530 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3531 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3532 [9, 7, 0, 0, 0, 0, 0, 8, 3]];
3533 assert(arr
[0][0] == 0 && arr
[0][1] == 0 && arr
[0][2] == 0 &&
3534 arr
[0][3] == 0 && arr
[0][4] == 1 && arr
[0][5] == 5 &&
3535 arr
[0][6] == 8 && arr
[0][7] == 0 && arr
[0][8] == 7);
3536 assert(arr
[1][0] == 0 && arr
[1][1] == 3 && arr
[1][2] == 8 &&
3537 arr
[1][3] == 0 && arr
[1][4] == 2 && arr
[1][5] == 0 &&
3538 arr
[1][6] == 0 && arr
[1][7] == 6 && arr
[1][8] == 0);
3539 assert(arr
[2][0] == 0 && arr
[2][1] == 0 && arr
[2][2] == 7 &&
3540 arr
[2][3] == 0 && arr
[2][4] == 6 && arr
[2][5] == 8 &&
3541 arr
[2][6] == 9 && arr
[2][7] == 4 && arr
[2][8] == 0);
3542 assert(arr
[3][0] == 0 && arr
[3][1] == 0 && arr
[3][2] == 0 &&
3543 arr
[3][3] == 0 && arr
[3][4] == 0 && arr
[3][5] == 1 &&
3544 arr
[3][6] == 2 && arr
[3][7] == 9 && arr
[3][8] == 0);
3545 assert(arr
[4][0] == 9 && arr
[4][1] == 7 && arr
[4][2] == 0 &&
3546 arr
[4][3] == 0 && arr
[4][4] == 0 && arr
[4][5] == 0 &&
3547 arr
[4][6] == 0 && arr
[4][7] == 8 && arr
[4][8] == 3);
3551 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3552 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3553 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3554 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3555 [9, 7, 0, 0, 0, 0, 0, 8, 3],
3556 [0, 2, 1, 6, 0, 0, 0, 0, 0],
3557 [0, 6, 9, 5, 4, 0, 3, 0, 0],
3558 [0, 4, 0, 0, 8, 0, 6, 5, 0],
3559 [2, 0, 5, 9, 3, 0, 0, 0, 0]];
3560 assert(tbl
[0][0] == 0 && tbl
[0][1] == 0 && tbl
[0][2] == 0 &&
3561 tbl
[0][3] == 0 && tbl
[0][4] == 1 && tbl
[0][5] == 5 &&
3562 tbl
[0][6] == 8 && tbl
[0][7] == 0 && tbl
[0][8] == 7);
3563 assert(tbl
[1][0] == 0 && tbl
[1][1] == 3 && tbl
[1][2] == 8 &&
3564 tbl
[1][3] == 0 && tbl
[1][4] == 2 && tbl
[1][5] == 0 &&
3565 tbl
[1][6] == 0 && tbl
[1][7] == 6 && tbl
[1][8] == 0);
3566 assert(tbl
[2][0] == 0 && tbl
[2][1] == 0 && tbl
[2][2] == 7 &&
3567 tbl
[2][3] == 0 && tbl
[2][4] == 6 && tbl
[2][5] == 8 &&
3568 tbl
[2][6] == 9 && tbl
[2][7] == 4 && tbl
[2][8] == 0);
3569 assert(tbl
[3][0] == 0 && tbl
[3][1] == 0 && tbl
[3][2] == 0 &&
3570 tbl
[3][3] == 0 && tbl
[3][4] == 0 && tbl
[3][5] == 1 &&
3571 tbl
[3][6] == 2 && tbl
[3][7] == 9 && tbl
[3][8] == 0);
3572 assert(tbl
[4][0] == 9 && tbl
[4][1] == 7 && tbl
[4][2] == 0 &&
3573 tbl
[4][3] == 0 && tbl
[4][4] == 0 && tbl
[4][5] == 0 &&
3574 tbl
[4][6] == 0 && tbl
[4][7] == 8 && tbl
[4][8] == 3);
3575 assert(tbl
[5][0] == 0 && tbl
[5][1] == 2 && tbl
[5][2] == 1 &&
3576 tbl
[5][3] == 6 && tbl
[5][4] == 0 && tbl
[5][5] == 0 &&
3577 tbl
[5][6] == 0 && tbl
[5][7] == 0 && tbl
[5][8] == 0);
3578 assert(tbl
[6][0] == 0 && tbl
[6][1] == 6 && tbl
[6][2] == 9 &&
3579 tbl
[6][3] == 5 && tbl
[6][4] == 4 && tbl
[6][5] == 0 &&
3580 tbl
[6][6] == 3 && tbl
[6][7] == 0 && tbl
[6][8] == 0);
3581 assert(tbl
[7][0] == 0 && tbl
[7][1] == 4 && tbl
[7][2] == 0 &&
3582 tbl
[7][3] == 0 && tbl
[7][4] == 8 && tbl
[7][5] == 0 &&
3583 tbl
[7][6] == 6 && tbl
[7][7] == 5 && tbl
[7][8] == 0);
3584 assert(tbl
[8][0] == 2 && tbl
[8][1] == 0 && tbl
[8][2] == 5 &&
3585 tbl
[8][3] == 9 && tbl
[8][4] == 3 && tbl
[8][5] == 0 &&
3586 tbl
[8][6] == 0 && tbl
[8][6] == 0 && tbl
[8][8] == 0);
3589 /***************************************************/
3590 // https://issues.dlang.org/show_bug.cgi?id=11238
3596 //printf("%d,%d\n", m[0], m[1]);
3597 assert(m
[0] == 4 && m
[1] == 6);
3599 m
= [m
[1], m
[0]]; // swap
3600 assert(m
[0] == 6 && m
[1] == 4);
3601 //printf("%d,%d\n", m[0], m[1]);
3603 m
= [m
[1], m
[0]]; // swap
3604 //printf("%d,%d\n", m[0], m[1]);
3605 assert(m
[0] == 4 && m
[1] == 6);
3608 /***************************************************/
3621 /***************************************************/
3626 int foo() { return 0; }
3633 override typeof(super).X
foo() { return 1; }
3635 alias typeof(this) athis
;
3636 alias typeof(this).b thisb
;
3637 alias typeof(super).a supera
;
3638 alias typeof(super).foo superfoo
;
3639 alias typeof(this).foo thisfoo
;
3644 alias typeof(this) athis
;
3649 auto x
= X2540
.athis
.init
;
3650 static assert(is(typeof(x
) == X2540
));
3652 B2540 b
= new B2540();
3654 assert(&b
.a
== &b
.supera
);
3655 assert(&b
.b
== &b
.thisb
);
3656 assert(b
.thisfoo() == 1);
3659 /***************************************************/
3663 int foo() { return 0; }
3666 class C14348
: B14348
3668 override int foo() { return 1; }
3670 alias superfoo
= typeof(super).foo
;
3671 alias thisfoo
= typeof(this).foo
;
3676 alias foo
= typeof(return).foo
; // currently doesn't work.
3677 assert(&B14348
.foo
is &C14348
.superfoo
);
3678 assert(&C14348
.foo
is &C14348
.thisfoo
);
3682 /***************************************************/
3683 // https://issues.dlang.org/show_bug.cgi?id=7295
3688 @property ref int refCountedPayload() return { return member
; }
3689 alias refCountedPayload
this;
3692 void foo7295(S
)(immutable S t
, int qq
) pure { }
3693 void foo7295(S
)(S s
) pure { }
3701 /***************************************************/
3702 // https://issues.dlang.org/show_bug.cgi?id=5659
3709 static assert(is(typeof(true ? a
: b
) == const(char)));
3710 static assert(is(typeof([a
, b
][0]) == const(char)));
3714 /***************************************************/
3715 // https://issues.dlang.org/show_bug.cgi?id=1373
3719 static assert(typeof(func1373a
).stringof
== "void()");
3720 static assert(typeof(func1373a
).mangleof
== "FZv");
3721 static assert(!__traits(compiles
, typeof(func1373a
).alignof
));
3722 static assert(!__traits(compiles
, typeof(func1373a
).init
));
3723 static assert(!__traits(compiles
, typeof(func1373a
).offsetof
));
3725 void func1373b(int n
){}
3727 static assert(typeof(func1373b
).stringof
== "void(int n)");
3728 static assert(typeof(func1373b
).mangleof
== "FiZv");
3729 static assert(!__traits(compiles
, typeof(func1373b
).alignof
));
3730 static assert(!__traits(compiles
, typeof(func1373b
).init
));
3731 static assert(!__traits(compiles
, typeof(func1373b
).offsetof
));
3733 /***************************************************/
3735 void bar150(T
)(T n
) { }
3737 @safe void test150()
3742 /***************************************************/
3746 static struct x
{ static int y
; }
3748 assert(x
.y
!in [1:0]);
3751 /***************************************************/
3753 void bar151(T
)(T n
) { }
3755 nothrow void test151()
3760 /***************************************************/
3762 @property int coo() { return 1; }
3763 @property auto doo(int i
) { return i
; }
3765 @property int eoo() { return 1; }
3766 @property auto ref hoo(int i
) { return i
; }
3768 // https://issues.dlang.org/show_bug.cgi?id=3359
3770 int goo(int i
) pure { return i
; }
3771 auto ioo(int i
) pure { return i
; }
3772 auto ref boo(int i
) pure nothrow { return i
; }
3775 auto hoo(int i
) pure { return i
; }
3776 const boo(int i
) nothrow { return i
; }
3777 auto coo(int i
) const { return i
; }
3778 auto doo(int i
) immutable { return i
; }
3779 auto eoo(int i
) shared { return i
; }
3782 // https://issues.dlang.org/show_bug.cgi?id=4706
3785 @property auto ref front() {
3789 @property void front(T num
) {}
3798 /***************************************************/
3799 // https://issues.dlang.org/show_bug.cgi?id=6733
3801 void bug6733(int a
, int b
) pure nothrow { }
3808 /***************************************************/
3809 // https://issues.dlang.org/show_bug.cgi?id=3799
3817 static assert(!__traits(isStaticFunction
, bar
));
3820 /***************************************************/
3821 // https://issues.dlang.org/show_bug.cgi?id=3632
3826 assert(f
is float.init
);
3828 assert(d
is double.init
);
3830 assert(r
is real.init
);
3832 assert(float.nan
is float.nan
);
3833 assert(double.nan
is double.nan
);
3834 assert(real.nan
is real.nan
);
3837 /***************************************************/
3839 __gshared
int global3632
= 1;
3848 this(T g
) { if (__ctfe || global3632
) f
= g
; }
3850 auto nan
= W(T
.nan
);
3851 auto nan2
= W(T
.nan
);
3852 auto init
= W(T
.init
);
3853 auto init2
= W(T
.init
);
3854 auto zero
= W(cast(T
)0);
3855 auto zero2
= W(cast(T
)0);
3856 auto nzero2
= W(-cast(T
)0);
3859 assert(!(nan
== nan2
));
3860 assert(!(nan
== init2
));
3861 assert(!(init
== init2
));
3862 assert( (zero
== zero2
));
3863 assert( (zero
== nzero2
));
3866 assert(!(nan
.f
== nan2
.f
));
3867 assert(!(nan
.f
== init2
.f
));
3868 assert(!(init
.f
== init2
.f
));
3869 assert( (zero
.f
== zero2
.f
));
3870 assert( (zero
.f
== nzero2
.f
));
3873 assert( (nan
is nan2
));
3874 assert( (nan
is init2
));
3875 assert( (init
is init2
));
3876 assert( (zero
is zero2
));
3877 assert(!(zero
is nzero2
));
3880 assert( (nan
.f
is nan2
.f
));
3881 assert( (nan
.f
is init2
.f
));
3882 assert( (init
.f
is init2
.f
));
3883 assert( (zero
.f
is zero2
.f
));
3884 assert(!(zero
.f
is nzero2
.f
));
3887 assert(!(nan
!is nan2
));
3888 assert( (nan
is init2
));
3889 assert(!(init
!is init2
));
3890 assert(!(zero
!is zero2
));
3891 assert( (zero
!is nzero2
));
3894 assert(!(nan
.f
!is nan2
.f
));
3895 assert( (nan
.f
is init2
.f
));
3896 assert(!(init
.f
!is init2
.f
));
3897 assert(!(zero
.f
!is zero2
.f
));
3898 assert( (zero
.f
!is nzero2
.f
));
3901 assert(W
.init
is W
.init
);
3906 auto rtF
= test!float();
3907 enum ctF
= test!float();
3908 auto rtD
= test!double();
3909 enum ctD
= test!double();
3910 auto rtR
= test!real();
3911 enum ctR
= test!real();
3913 assert(float.nan
!is -float.nan
);
3914 assert(double.nan
!is -double.nan
);
3915 assert(real.nan
!is -real.nan
);
3918 /***************************************************/
3938 /***************************************************/
3939 // https://issues.dlang.org/show_bug.cgi?id=3147
3957 /***************************************************/
3958 // https://issues.dlang.org/show_bug.cgi?id=2486
3962 void foo(ref int[] arr
) {}
3964 int[] arr
= [1,2,3];
3966 static assert(__traits(compiles
, foo(arr
[1..2])));
3971 auto ref opSlice(){ return a
[]; } // line 4
3975 // opSlice should return rvalue
3976 static assert(is(typeof(&S
.opSlice
) == int[] function() pure nothrow @nogc @safe));
3977 static assert(__traits(compiles
, foo(s
[])));
3980 /***************************************************/
3982 extern(C
++) class C15080
3988 __gshared c15080
= new C15080();
3992 assert(c15080
.x
== 1);
3993 assert(c15080
.y
== 2);
3996 /***************************************************/
3997 // https://issues.dlang.org/show_bug.cgi?id=2521
3999 immutable int val
= 23;
4000 const int val2
= 23;
4002 ref immutable(int) func2521_() {
4005 ref immutable(int) func2521_2() {
4008 ref immutable(int) func2521_3() {
4011 ref const(int) func2521_4() {
4014 ref const(int) func2521_5() {
4017 auto ref func2521_6() {
4024 /***************************************************/
4032 class A
{ abstract MA
foo(); }
4033 interface I
{ MB
foo(); }
4036 override MC
foo() { return null; }
4040 override MC
foo() { return null; }
4044 /***************************************************/
4045 // https://issues.dlang.org/show_bug.cgi?id=5962
4049 auto g()(){ return 1; }
4050 const auto g()(){ return 2; }
4056 assert(ms
.g() == 1);
4057 auto cs
= const(S156
)();
4058 assert(cs
.g() == 2);
4061 /***************************************************/
4065 const(char)* s
= "abc"[0..$-1];
4066 assert(s
[2] == '\0');
4069 /***************************************************/
4071 void test6708(const ref int y
)
4077 /***************************************************/
4078 // https://issues.dlang.org/show_bug.cgi?id=4258
4081 Vec4258
opOpAssign(string Op
)(auto ref Vec4258 other
) if (Op
== "+") {
4084 Vec4258
opBinary(string Op
:"+")(Vec4258 other
) {
4086 return result
+= other
;
4091 v
+= Vec4258() + Vec4258(); // line 12
4094 // regression fix test
4098 int opPostInc()() if (false) { return 0; }
4101 int opAdd(R
)(R rhs
) if (false) { return 0; }
4102 int opAdd_r(R
)(R rhs
) if (false) { return 0; }
4105 int opCmp(R
)(R rhs
) if (false) { return 0; }
4108 int opAddAssign(R
)(R rhs
) if (false) { return 0; }
4111 // binary commutive 1
4112 int opAdd_r(R
)(R rhs
) if (false) { return 0; }
4115 int opOpAssign(string op
, R
)(R rhs
) if (false) { return 0; }
4118 // binary commutive 2
4119 int opAdd(R
)(R rhs
) if (false) { return 0; }
4121 static assert(!is(typeof(Foo4258
.init
++)));
4122 static assert(!is(typeof(Foo4258
.init
+ 1)));
4123 static assert(!is(typeof(1 + Foo4258
.init
)));
4124 static assert(!is(typeof(Foo4258
.init
< Foo4258
.init
)));
4125 static assert(!is(typeof(Foo4258
.init
+= 1)));
4126 static assert(!is(typeof(Bar4258
.init
+ 1)));
4127 static assert(!is(typeof(Bar4258
.init
+= 1)));
4128 static assert(!is(typeof(1 + Baz4258
.init
)));
4130 /***************************************************/
4131 // https://issues.dlang.org/show_bug.cgi?id=4539
4135 static assert(!__traits(compiles
, "hello" = "red"));
4137 void foo1(ref string s
){}
4138 void foo2(ref const char[10] s
){}
4139 void foo3(ref char[5] s
){}
4141 void foo4(ref const char[5] s
)
4143 assert(s
[0] == 'h');
4144 assert(s
[4] == 'o');
4146 void foo5(ref const ubyte[5] s
)
4148 assert(s
[0] == 0xc3);
4149 assert(s
[4] == 0x61);
4152 static assert(__traits(compiles
, foo1("hello")));
4153 static assert(!__traits(compiles
, foo2("hello")));
4154 static assert(!__traits(compiles
, foo3("hello")));
4156 // same as test68, 69, 70
4158 foo5(cast(ubyte[5])"\xc3\xfc\xd3\xd7\x61");
4161 //static assert(!__traits(compiles, parse!int("10") == 10));
4164 /***************************************************/
4165 // https://issues.dlang.org/show_bug.cgi?id=1471
4170 string bar
= "BOOM"[n
..$-1];
4171 assert(bar
== "BOO");
4174 /***************************************************/
4176 deprecated @disable int bug6389
;
4177 static assert(!is(typeof(bug6389
= bug6389
)));
4179 /***************************************************/
4192 auto x
= single() ~ list
;
4195 /***************************************************/
4199 static const int x
= 8;
4203 /***************************************************/
4204 // https://issues.dlang.org/show_bug.cgi?id=5437
4206 template EnumMembers5437(E
)
4208 template TypeTuple(T
...){ alias T TypeTuple
; }
4210 alias TypeTuple
!("A", "B") EnumMembers5437
;
4212 template IntValue5437()
4214 int IntValue5437
= 10;
4220 alias EnumMembers5437
!Foo members
; // OK
4221 enum n1
= members
.length
; // OK
4222 enum n2
= (EnumMembers5437
!Foo
).length
; // NG, type -> symbol
4224 enum s1
= IntValue5437
!().sizeof
; // OK
4225 enum s2
= (IntValue5437
!()).sizeof
; // NG, type -> expression
4228 /***************************************************/
4229 // https://issues.dlang.org/show_bug.cgi?id=1962
4234 class C
{ abstract void x(); }
4235 assert(C
.classinfo
.create() is null);
4238 /***************************************************/
4239 // https://issues.dlang.org/show_bug.cgi?id=6228
4244 const(int)* ptr
= &val
;
4246 auto x
= (*ptr
) ^^ temp
;
4249 /***************************************************/
4253 try { throw new Exception(""); }
4254 catch (Exception e
) static assert(1);
4258 static assert(test7544());
4260 /***************************************************/
4264 int q() const pure {
4273 int q() const pure {
4280 int q6230(ref const S6230 s
) pure { // <-- Currently OK
4283 int q6230(ref const C6230 c
) pure { // <-- Currently OK
4286 void r6230(ref S6230 s
) pure {
4289 void r6230(ref C6230 c
) pure {
4292 bool test6230pure() pure {
4295 assert(q6230(s
) == 4);
4300 assert(q6230(c
) == 6);
4316 assert(test6230pure());
4319 /***************************************************/
4323 struct S
{ auto opSlice() { return this; } }
4326 static assert(!is(typeof(a
[] = s
[])));
4328 static assert(is(typeof(b
[] = [new immutable(int)])));
4329 char[] c
= new char[](5);
4333 /***************************************************/
4334 // https://issues.dlang.org/show_bug.cgi?id=5046
4338 auto va
= S5046
!("", int)();
4339 auto vb
= makeS5046
!("", int)();
4342 struct S5046(alias p
, T
)
4345 T
fun() { return s
; } // (10)
4348 S5046
!(p
, T
) makeS5046(alias p
, T
)()
4350 return typeof(return)();
4353 /***************************************************/
4354 // https://issues.dlang.org/show_bug.cgi?id=6335
4359 this()(int n
){ value
= n
; }
4363 S6335 s
= S6335(10);
4366 /***************************************************/
4368 struct S6295(int N
) {
4370 const nothrow pure @safe f() { return x
.length
; }
4374 auto bar(T
: S6295
!(N
), int N
)(T x
) {
4378 assert(bar(x
) == 4);
4381 /***************************************************/
4383 template TT4536(T
...) { alias T TT4536
; }
4387 auto x
= TT4536
!(int, long, [1, 2]).init
;
4388 assert(x
[0] is int.init
);
4389 assert(x
[1] is long.init
);
4390 assert(x
[2] is [1, 2].init
);
4393 /***************************************************/
4401 pure int bug6284a() {
4405 b
+= a
; // should be ok.
4409 pure int bug6284b() {
4418 pure int bug6284c() {
4428 assert(bug6284a() == 8);
4429 assert(bug6284b() == 8);
4430 assert(bug6284c() == 8);
4433 /***************************************************/
4438 void f6293(in C6293
[] a
) pure {
4439 auto x0
= a
[0].token
;
4440 assert(x0
is a
[0].token
.token
.token
);
4441 assert(x0
is (&x0
).token
);
4443 assert(x0
is (p1
- 1).token
);
4445 assert(x0
is a
[c
].token
);
4453 /***************************************************/
4454 // https://issues.dlang.org/show_bug.cgi?id=3733
4458 int foo() { return 1; }
4459 int foo() shared { return 2; }
4461 int bar() { return foo(); }
4465 auto c
= new C3733();
4466 assert(c
.bar() == 1);
4469 /***************************************************/
4470 // https://issues.dlang.org/show_bug.cgi?id=4392
4474 int foo() const { return 1; }
4475 int foo() { return 2; }
4477 int bar() const { return foo(); }
4481 auto c
= new C4392();
4482 assert(c
.bar() == 1);
4485 /***************************************************/
4486 // https://issues.dlang.org/show_bug.cgi?id=6220
4489 struct Foobar
{ real x
; real y
; real z
;}
4491 foreach(i
,member
; __traits(allMembers
, Foobar
)) {
4492 case member
: break;
4498 /***************************************************/
4499 // https://issues.dlang.org/show_bug.cgi?id=5799
4504 int *u
= &(a ? a
: (a ? a
: a
));
4508 /***************************************************/
4509 // https://issues.dlang.org/show_bug.cgi?id=6529
4511 enum Foo6529
: char { A
='a' }
4512 ref const(Foo6529
) func6529(const(Foo6529
)[] arr
){ return arr
[0]; }
4514 /***************************************************/
4518 const arr
= [ 1,2,3 ];
4520 auto jhk
= new int[arr
[i
]]; // "need size of rightmost array, not type arr[i]"
4523 /***************************************************/
4525 template X157(alias x
)
4530 template Parent(alias foo
)
4532 alias X157
!(__traits(parent
, foo
)) Parent
;
4535 template ParameterTypeTuple(alias foo
)
4537 static if (is(typeof(foo
) P
== function))
4538 alias P ParameterTypeTuple
;
4540 static assert(0, "argument has no parameters");
4543 template Mfp(alias foo
)
4545 auto Mfp
= function(Parent
!foo self
, ParameterTypeTuple
!foo i
) { return self
.foo(i
); };
4550 int foo(int i
, int y
) { return i
+ a
+ y
; }
4555 auto c
= new C157();
4556 auto mfp
= Mfp
!(C157
.foo
);
4557 auto i
= mfp(c
, 1, 7);
4561 /***************************************************/
4562 // https://issues.dlang.org/show_bug.cgi?id=6473
4571 void build(Eins6473 devices
= Eins6473())
4576 void build(Eins6473 devices
= Eins6473())
4581 void build(Eins6473 devices
= Eins6473())
4585 /***************************************************/
4587 uint rol11417(uint n
)(in uint x
)
4589 return x
<< n | x
>> 32 - n
;
4592 uint ror11417(uint n
)(in uint x
)
4594 return x
>> n | x
<< 32 - n
;
4599 assert(rol11417
!1(0x8000_0000) == 0x1);
4600 assert(ror11417
!1(0x1) == 0x8000_0000);
4603 /***************************************************/
4611 auto f1
= new const(Foo
)(1);
4612 auto f2
= new immutable(Foo
)(1);
4613 auto f3
= new shared(Foo
)(1);
4614 auto f4
= const(Foo
)(1);
4615 auto f5
= immutable(Foo
)(1);
4616 auto f6
= shared(Foo
)(1);
4617 static assert(is(typeof(f1
) == const(Foo
)*));
4618 static assert(is(typeof(f2
) == immutable(Foo
)*));
4619 static assert(is(typeof(f3
) == shared(Foo
)*));
4620 static assert(is(typeof(f4
) == const(Foo
)));
4621 static assert(is(typeof(f5
) == immutable(Foo
)));
4622 static assert(is(typeof(f6
) == shared(Foo
)));
4626 this(int x
) const pure {}
4628 auto g1
= new const(Bar
)(1);
4629 auto g2
= new immutable(Bar
)(1);
4630 auto g3
= new shared(Bar
)(1);
4631 auto g4
= const(Bar
)(1);
4632 auto g5
= immutable(Bar
)(1);
4633 auto g6
= shared(Bar
)(1);
4634 static assert(is(typeof(g1
) == const(Bar
)*));
4635 static assert(is(typeof(g2
) == immutable(Bar
)*));
4636 static assert(is(typeof(g3
) == shared(Bar
)*));
4637 static assert(is(typeof(g4
) == const(Bar
)));
4638 static assert(is(typeof(g5
) == immutable(Bar
)));
4639 static assert(is(typeof(g6
) == shared(Bar
)));
4643 this()(int x
) const pure {}
4645 auto h1
= new const(Baz
)(1);
4646 auto h2
= new immutable(Baz
)(1);
4647 auto h3
= new shared(const(Baz
))(1);
4648 auto h4
= const(Baz
)(1);
4649 auto h5
= immutable(Baz
)(1);
4650 auto h6
= shared(const(Baz
))(1);
4651 static assert(is(typeof(h1
) == const(Baz
)*));
4652 static assert(is(typeof(h2
) == immutable(Baz
)*));
4653 static assert(is(typeof(h3
) == shared(const(Baz
))*));
4654 static assert(is(typeof(h4
) == const(Baz
)));
4655 static assert(is(typeof(h5
) == immutable(Baz
)));
4656 static assert(is(typeof(h6
) == shared(const(Baz
))));
4659 /***************************************************/
4660 // https://issues.dlang.org/show_bug.cgi?id=6630
4668 this() { b
= new B(); }
4680 assert(a
.b
!is null);
4683 assert(a
.b
!is null);
4686 /***************************************************/
4699 /***************************************************/
4700 // https://issues.dlang.org/show_bug.cgi?id=6690
4702 T
useLazy6690(T
)(lazy T val
)
4705 // val is converted to delegate call, but it is typed as int delegate() - not @safe!
4707 void test6690() @safe
4710 // Error: safe function 'test6690' cannot call system function 'useLazy6690'
4713 /***************************************************/
4717 immutable static int[int] dict
;
4718 immutable static int value
;
4720 shared static this()
4726 alias Hoge6691
!() H6691
;
4728 /***************************************************/
4733 struct Y
{ double u
; }
4736 double[2] r
= v
[] * x
[0];
4737 //double[2] s = v[] * z++;
4738 //double[2] t = v[] * z--;
4739 double[2] a
= v
[] * ++z
;
4740 double[2] b
= v
[] * --z
;
4741 double[2] c
= v
[] * y
.u
;
4743 double[2] d
= v
[] * x
[0];
4744 double[2] e
= v
[] * (v
[] ~ z
)[0];
4748 /***************************************************/
4749 // https://issues.dlang.org/show_bug.cgi?id=2953
4751 template Tuple2953(T
...)
4755 template Range2953(int b
)
4757 alias Tuple2953
!(1) Range2953
;
4761 Tuple2953
!(int, int) args
;
4762 foreach( x
; Range2953
!(args
.length
) ){ }
4769 /***************************************************/
4770 // https://issues.dlang.org/show_bug.cgi?id=2997
4772 abstract class B2997
{ void foo(); }
4773 interface I2997
{ void bar(); }
4774 abstract class C2997
: B2997
, I2997
{}
4775 //pragma(msg, __traits(allMembers, C).stringof);
4779 enum ObjectMembers
= ["toString","toHash","opCmp","opEquals","Monitor","factory"];
4781 static assert([__traits(allMembers
, C2997
)] == ["foo"] ~ ObjectMembers
~ ["bar"]);
4784 /***************************************************/
4785 // https://issues.dlang.org/show_bug.cgi?id=6596
4787 extern (C
) int function() pfunc6596
;
4788 extern (C
) int cfunc6596(){ return 0; }
4789 static assert(typeof(pfunc6596
).stringof
== "extern (C) int function()");
4790 static assert(typeof(cfunc6596
).stringof
== "extern (C) int()");
4793 /***************************************************/
4794 // https://issues.dlang.org/show_bug.cgi?id=4423
4798 this(string phrase
, int num
)
4800 this.phrase
= phrase
;
4804 int opCmp(const ref S4423 rhs
)
4806 if (phrase
< rhs
.phrase
)
4808 else if (phrase
> rhs
.phrase
)
4813 else if (num
> rhs
.num
)
4825 a
= S4423("hello", 1),
4826 b
= S4423("goodbye", 45),
4827 c
= S4423("world", 22),
4833 assert(e
.phrase
== "hello");
4836 assert(e
.phrase
== "goodbye");
4839 /***************************************************/
4840 // https://issues.dlang.org/show_bug.cgi?id=4647
4844 final int run() { printf("Timer.run()\n"); fun(); return 1; };
4848 interface Application
4850 final int run() { printf("Application.run()\n"); fun(); return 2; };
4854 class TimedApp
: Timer
, Application
4859 printf("TimedApp.fun()\n");
4865 class SubTimedApp
: TimedApp
4871 printf("SubTimedApp.fun()\n");
4879 //Test access to TimedApps base interfaces
4880 auto app
= new TimedApp();
4881 assert((cast(Application
)app
).run() == 2);
4882 assert((cast(Timer
)app
).run() == 1);
4883 assert(app
.Timer
.run() == 1); // error, no Timer property
4884 assert(app
.Application
.run() == 2); // error, no Application property
4885 assert(app
.run() == 1); // This would call Timer.run() if the two calls
4886 // above were commented out
4887 assert(app
.funCalls
== 5);
4889 assert(app
.TimedApp
.fun() == 2);
4890 assert(app
.funCalls
== 6);
4892 //Test direct access to SubTimedApp interfaces
4893 auto app2
= new SubTimedApp();
4894 assert((cast(Application
)app2
).run() == 2);
4895 assert((cast(Timer
)app2
).run() == 1);
4896 assert(app2
.Application
.run() == 2);
4897 assert(app2
.Timer
.run() == 1);
4898 assert(app2
.funCalls
== 0);
4899 assert(app2
.subFunCalls
== 4);
4901 assert(app2
.fun() == 1);
4902 assert(app2
.SubTimedApp
.fun() == 1);
4903 assert(app2
.funCalls
== 0);
4904 assert(app2
.subFunCalls
== 6);
4906 //Test access to SubTimedApp interfaces via TimedApp
4907 auto app3
= new SubTimedApp();
4908 (cast(Timer
)cast(TimedApp
)app3
).run();
4909 app3
.TimedApp
.Timer
.run();
4910 assert((cast(Application
)cast(TimedApp
)app3
).run() == 2);
4911 assert((cast(Timer
)cast(TimedApp
)app3
).run() == 1);
4912 assert(app3
.TimedApp
.Application
.run() == 2);
4913 assert(app3
.TimedApp
.Timer
.run() == 1);
4914 assert(app3
.funCalls
== 0);
4915 assert(app3
.subFunCalls
== 6);
4918 /***************************************************/
4920 template T1064(E
...) { alias E T1064
; }
4922 int[] var1064
= [ T1064
!(T1064
!(T1064
!(1, 2), T1064
!(), T1064
!(3)), T1064
!(4, T1064
!(T1064
!(T1064
!(T1064
!(5)))), T1064
!(T1064
!(T1064
!(T1064
!())))),6) ];
4926 assert(var1064
== [1,2,3,4,5,6]);
4929 /***************************************************/
4930 // https://issues.dlang.org/show_bug.cgi?id=5696
4932 template Seq5696(T
...){ alias T Seq5696
; }
4933 template Pred5696(T
) { alias T Pred5696
; } // TOKtemplate
4934 template Scope5696(int n
){ template X(T
) { alias T X
; } } // TOKimport
4935 T
foo5696(T
)(T x
) { return x
; }
4938 foreach (pred
; Seq5696
!(Pred5696
, Pred5696
))
4940 static assert(is(pred
!int == int));
4943 foreach (scop
; Seq5696
!(Scope5696
!0, Scope5696
!1))
4945 static assert(is(scop
.X
!int == int));
4948 alias Seq5696
!(foo5696
, foo5696
) funcs
;
4949 assert(funcs
[0](0) == 0);
4950 assert(funcs
[1](1) == 1);
4951 foreach (i
, fn
; funcs
)
4957 /***************************************************/
4958 // https://issues.dlang.org/show_bug.cgi?id=5933
4960 int dummyfunc5933();
4961 alias typeof(dummyfunc5933
) FuncType5933
;
4963 struct S5933a
{ auto x() { return 0; } }
4964 static assert(is(typeof(&S5933a
.init
.x
) == int delegate() pure nothrow @nogc @safe));
4966 struct S5933b
{ auto x() { return 0; } }
4967 //static assert(is(typeof(S5933b.init.x) == FuncType5933));
4969 struct S5933c
{ auto x() { return 0; } }
4970 static assert(is(typeof(&S5933c
.x
) == int function()));
4972 struct S5933d
{ auto x() { return 0; } }
4973 static assert(is(typeof(S5933d
.x
) == FuncType5933
));
4976 class C5933a
{ auto x() { return 0; } }
4977 static assert(is(typeof(&(new C5933b()).x
) == int delegate() pure nothrow @nogc @safe));
4979 class C5933b
{ auto x() { return 0; } }
4980 //static assert(is(typeof((new C5933b()).x) == FuncType5933));
4982 class C5933c
{ auto x() { return 0; } }
4983 static assert(is(typeof(&C5933c
.x
) == int function()));
4985 class C5933d
{ auto x() { return 0; } }
4986 static assert(is(typeof(C5933d
.x
) == FuncType5933
));
4988 /***************************************************/
4989 // https://issues.dlang.org/show_bug.cgi?id=6084
4991 template TypeTuple6084(T
...){ alias T TypeTuple6084
; }
4994 int foo(int x
)() { return x
; }
4995 foreach(i
; TypeTuple6084
!(0))
4999 /***************************************************/
5000 // https://issues.dlang.org/show_bug.cgi?id=6763
5002 template TypeTuple6763(TList
...)
5004 alias TList TypeTuple6763
;
5007 alias TypeTuple6763
!(int) T6763
;
5009 void f6763( T6763
) { } ///
5010 void c6763(const T6763
) { } ///T now is (const int)
5011 void r6763(ref T6763
) { } ///T now is(ref const int)
5012 void i6763(in T6763
) { } ///Uncomment to get an Assertion failure in 'mtype.c'
5013 void o6763(out T6763
) { } ///ditto
5019 f6763(0); //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int)
5021 r6763(n
); static assert(__traits(compiles
, r6763(0)));
5023 o6763(n
); static assert(!__traits(compiles
, o6763(0)));
5025 // https://issues.dlang.org/show_bug.cgi?id=6755
5026 static assert(typeof(f6763
).stringof
== "void(int _param_0)");
5027 static assert(typeof(c6763
).stringof
== "void(const(int) _param_0)");
5028 static assert(typeof(r6763
).stringof
== "void(ref int _param_0)");
5029 static assert(typeof(i6763
).stringof
== "void(in int _param_0)");
5030 static assert(typeof(o6763
).stringof
== "void(out int _param_0)");
5033 /***************************************************/
5034 // https://issues.dlang.org/show_bug.cgi?id=6695
5040 static assert(is(typeof(this) == X6695
));
5044 static assert(is(typeof(this) == const(X6695
)));
5046 void ifunc() immutable
5048 static assert(is(typeof(this) == immutable(X6695
)));
5052 static assert(is(typeof(this) == shared(X6695
)));
5054 void scfunc() shared const
5056 static assert(is(typeof(this) == shared(const(X6695
))));
5060 static assert(is(typeof(this) == inout(X6695
)));
5062 void swfunc() shared inout
5064 static assert(is(typeof(this) == shared(inout(X6695
))));
5067 static assert(is(typeof(this) == X6695
));
5070 /***************************************************/
5071 // https://issues.dlang.org/show_bug.cgi?id=6087
5073 template True6087(T
)
5075 immutable True6087
= true;
5079 static assert( True6087
!(typeof(this)) );
5084 static assert( is(typeof(this) == Bar6087
) );
5087 /***************************************************/
5088 // https://issues.dlang.org/show_bug.cgi?id=6848
5092 class Bar6848
: Foo6848
5094 void func() immutable
5096 static assert(is(typeof(this) == immutable(Bar6848
))); // immutable(Bar6848)
5098 static assert(is(typeof(t
) == immutable(Bar6848
))); // immutable(Bar6848)
5100 static assert(is(typeof(super) == immutable(Foo6848
))); // Foo6848 instead of immutable(Foo6848)
5102 static assert(is(typeof(s
) == immutable(Foo6848
))); // Foo6848 instead of immutable(Foo6848)
5106 /***************************************************/
5114 static assert(is(cent) && is(ucent) ||
!is(cent) && !is(ucent));
5115 static if (is(cent))
5116 static assert(__traits(compiles
, { cent x
; }));
5118 static assert(!__traits(compiles
, { cent x
; }));
5120 /***************************************************/
5121 // https://issues.dlang.org/show_bug.cgi?id=6847
5123 template True6847(T
)
5125 immutable True6847
= true;
5130 class Bar6847
: Foo6847
5132 static assert( True6847
!(typeof(super)) );
5133 static assert( is(typeof(super) == Foo6847
) );
5136 /***************************************************/
5137 // https://issues.dlang.org/show_bug.cgi?id=6488
5141 template to(T
) if (__traits(isIntegral
,T
))
5149 template to(T
) if (__traits(isFloating
,T
))
5157 const long seconds()
5170 /***************************************************/
5171 // https://issues.dlang.org/show_bug.cgi?id=6565
5173 void foo6565(out int[2][2] m
) {}
5177 int[2][2] mat
= [[1, 2], [3, 4]];
5179 assert(mat
== [[0, 0], [0, 0]]);
5182 /***************************************************/
5183 // https://issues.dlang.org/show_bug.cgi?id=6836
5185 template map6836(fun
...) if (fun
.length
>= 1)
5187 auto map6836(Range
)(Range r
)
5196 /***************************************************/
5198 string
func12864() { return ['a', 'b', 'c']; }
5200 void test12864(string s
)
5212 /***************************************************/
5216 int[int][] aaa = [[1: 2]];
5217 int[string
][] a2
= [["cc":0], ["DD":10]];
5220 /***************************************************/
5221 // https://issues.dlang.org/show_bug.cgi?id=6837
5232 @property ref T
get(){ return storage
; }
5236 int front6837(int[] arr
){ return arr
[0]; }
5238 void popFront6837(ref int[] arr
){ arr
= arr
[1..$]; }
5242 assert([1,2,3].front6837
== 1);
5244 auto r1
= Ref6837a
!(int[])([1,2,3]);
5245 assert(r1
.front6837() == 1); // ng
5246 assert(r1
.front6837
== 1); // ok
5247 r1
.popFront6837(); // ng
5248 r1
.storage
.popFront6837(); // ok
5250 auto r2
= Ref6837b
!(int[])([1,2,3]);
5251 assert(r2
.front6837() == 1); // ng
5252 assert(r2
.front6837
== 1); // ok
5253 r2
.popFront6837(); // ng
5254 r2
.get
.popFront6837(); // ng
5255 r2
.get().popFront6837(); // ok
5258 /***************************************************/
5259 // https://issues.dlang.org/show_bug.cgi?id=6927
5261 @property int[] foo6927()
5265 int[] bar6927(int[] a
)
5271 bar6927(foo6927
); // OK
5272 foo6927
.bar6927(); // line 9, Error
5275 /***************************************************/
5281 return Foo6813(_indices
.abc());
5287 struct SortedRange(alias pred
)
5291 return SortedRange();
5296 auto ind
= SortedRange
!({ })();
5297 auto a
= Foo6813
!(typeof(ind
))();
5300 /***************************************************/
5302 struct Interval6753
{ int a
,b
; }
5306 @trusted @property auto byInterval() const
5308 return cast(const(Interval6753
)[])arr
;
5312 /***************************************************/
5313 // https://issues.dlang.org/show_bug.cgi?id=6859
5318 bool isHage() const @property;
5321 abstract void fuga()
5329 class Child6859
: Parent6859
5331 override bool isHage() const @property
5335 override void fuga()
5343 auto t
= new Child6859
;
5348 /***************************************************/
5349 // https://issues.dlang.org/show_bug.cgi?id=6910
5351 template Test6910(alias i
, B
)
5359 case 0://IndexOf!(t, B.Types):
5361 pragma(msg
, __traits(allMembers
, t
));
5362 pragma(msg
, __traits(hasMember
, t
, "m"));
5363 static assert(__traits(hasMember
, t
, "m")); // test
5373 static struct Bag(S
...)
5383 alias Test6910
!(i
, Bag
!(A
)).fn func
;
5386 /***************************************************/
5404 assert("abc" !is b
);
5413 /***************************************************/
5414 // https://issues.dlang.org/show_bug.cgi?id=6902
5418 static assert(is(typeof({
5419 return int.init
; // int, long, real, etc.
5422 int f() pure nothrow { assert(0); }
5423 alias int T() pure nothrow @safe @nogc;
5424 static if(is(typeof(&f
) DT
== delegate))
5426 static assert(is(DT
* == T
*)); // ok
5428 // Error: static assert (is(pure nothrow int() == pure nothrow int())) is false
5429 static assert(is(DT
== T
));
5433 /***************************************************/
5434 // https://issues.dlang.org/show_bug.cgi?id=6330
5438 void opAssign(S6330 s
) @disable
5440 assert(0); // This fails.
5448 static assert(!is(typeof({ s2
= s
; })));
5451 /***************************************************/
5470 /***************************************************/
5471 // https://issues.dlang.org/show_bug.cgi?id=5311
5475 private static int globalData
;
5477 void breaksPure() pure const
5479 static assert(!__traits(compiles
, { globalData
++; })); // SHOULD BE ERROR
5480 static assert(!__traits(compiles
, { C5311
.globalData
++; }));// SHOULD BE ERROR
5481 static assert(!__traits(compiles
, { this.globalData
++; })); // SHOULD BE ERROR
5483 static assert(!__traits(compiles
, { int a
= this.globalData
; }));
5486 static void breaksPure5311a(C5311 x
) pure
5488 static assert(!__traits(compiles
, { x
.globalData
++; })); // SHOULD BE ERROR
5490 static assert(!__traits(compiles
, { int a
= x
.globalData
; }));
5495 private static int globalData
;
5497 void breaksPure() pure const
5499 static assert(!__traits(compiles
, { globalData
++; })); // SHOULD BE ERROR
5500 static assert(!__traits(compiles
, { S5311
.globalData
++; }));// SHOULD BE ERROR
5501 static assert(!__traits(compiles
, { this.globalData
++; })); // SHOULD BE ERROR
5503 static assert(!__traits(compiles
, { int a
= this.globalData
; }));
5506 static void breaksPure5311b(S5311 x
) pure
5508 static assert(!__traits(compiles
, { x
.globalData
++; })); // SHOULD BE ERROR
5510 static assert(!__traits(compiles
, { int a
= x
.globalData
; }));
5513 /***************************************************/
5514 // https://issues.dlang.org/show_bug.cgi?id=6868
5516 @property bool empty6868(T
)(in T
[] a
) @safe pure nothrow
5524 static if (is(char[1 + Range
.empty6868
])) // Line 9
5525 enum bool isInfinite
= true;
5530 /***************************************************/
5531 // https://issues.dlang.org/show_bug.cgi?id=2856
5533 struct foo2856
{ static void opIndex(int i
) { printf("foo\n"); } }
5534 struct bar2856(T
) { static void opIndex(int i
) { printf("bar\n"); } }
5539 bar2856
!(float)[1]; // Error (# = __LINE__)
5540 alias bar2856
!(float) B
;
5544 /***************************************************/
5549 static assert(S
.sizeof
== 1);
5553 *cast(ubyte*)&a
= 1;
5554 *cast(ubyte*)&b
= 2;
5559 static assert(S() == S());
5560 static assert(S() is S());
5561 static assert(!(S() != S()));
5562 static assert(!(S() !is S()));
5565 /***************************************************/
5566 // https://issues.dlang.org/show_bug.cgi?id=3091
5568 void test3091(inout int = 0)
5572 auto pm
= new Foo
; static assert(is( typeof( pm
) == Foo
* ));
5573 auto pc
= new const Foo
; static assert(is( typeof( pc
) == const(Foo
) * ));
5574 auto pw
= new inout Foo
; static assert(is( typeof( pw
) == inout(Foo
) * ));
5575 auto psm
= new shared Foo
; static assert(is( typeof(psm
) == shared(Foo
) * ));
5576 auto psc
= new shared const Foo
; static assert(is( typeof(psc
) == shared(const(Foo
))* ));
5577 auto psw
= new shared inout Foo
; static assert(is( typeof(psw
) == shared(inout(Foo
))* ));
5578 auto pi
= new immutable Foo
; static assert(is( typeof( pi
) == immutable(Foo
) * ));
5580 auto m
= Foo(); static assert(is( typeof( m
) == Foo
));
5581 auto c
= const Foo(); static assert(is( typeof( c
) == const(Foo
) ));
5582 auto w
= inout Foo(); static assert(is( typeof( w
) == inout(Foo
) ));
5583 auto sm
= shared Foo(); static assert(is( typeof(sm
) == shared(Foo
) ));
5584 auto sc
= shared const Foo(); static assert(is( typeof(sc
) == shared(const(Foo
)) ));
5585 auto sw
= shared inout Foo(); static assert(is( typeof(sw
) == shared(inout(Foo
)) ));
5586 auto i
= immutable Foo(); static assert(is( typeof( i
) == immutable(Foo
) ));
5589 /***************************************************/
5590 // https://issues.dlang.org/show_bug.cgi?id=6837
5596 static assert(is(Id6837
!(shared const int) == shared const int));
5597 static assert(is(Id6837
!(shared inout int) == shared inout int));
5599 /***************************************************/
5600 // https://issues.dlang.org/show_bug.cgi?id=6056 fixup
5602 template ParameterTypeTuple6056(func
)
5604 static if (is(func Fptr
: Fptr
*) && is(Fptr P
== function))
5605 alias P ParameterTypeTuple6056
;
5607 static assert(0, "argument has no parameters");
5610 extern(C
) alias void function() fpw_t
;
5612 alias void function(fpw_t fp
) cb_t
;
5614 void bar6056(ParameterTypeTuple6056
!(cb_t
) args
) {
5615 pragma (msg
, "TFunction1: " ~ typeof(args
[0]).stringof
);
5618 extern(C
) void foo6056() { }
5625 /***************************************************/
5626 // https://issues.dlang.org/show_bug.cgi?id=6356
5633 alias f6356
!() g6356
; // comment this out to eliminate the errors
5635 pure nothrow @safe int i6356()
5642 assert(i6356() == 1);
5645 /***************************************************/
5646 // https://issues.dlang.org/show_bug.cgi?id=7108
5648 static assert(!__traits(hasMember
, int, "x"));
5649 static assert( __traits(hasMember
, int, "init"));
5651 /***************************************************/
5652 // https://issues.dlang.org/show_bug.cgi?id=7073
5656 string
f(int[] arr
...)
5662 /***************************************************/
5663 // https://issues.dlang.org/show_bug.cgi?id=7104
5667 typeof(new class {}) c
;
5671 /***************************************************/
5672 // https://issues.dlang.org/show_bug.cgi?id=7150
5678 this(T
)(T thing
, int i
)
5680 this(thing
, i
> 0); // Error: constructor call must be in a constructor
5683 this(T
)(T thing
, bool b
)
5691 auto a
= A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating
5692 assert(A7150
.cnt
== 2);
5695 /***************************************************/
5696 // https://issues.dlang.org/show_bug.cgi?id=7159
5698 alias void delegate() Void7159
;
5700 class HomeController7159
{
5702 return cast(Void7159
)&HomeController7159
.displayDefault
;
5704 auto displayDefault() {
5709 /***************************************************/
5710 // https://issues.dlang.org/show_bug.cgi?id=7160
5712 class HomeController
{
5717 foreach (m
; __traits(derivedMembers
, HomeController
)) {
5725 /***************************************************/
5726 // https://issues.dlang.org/show_bug.cgi?id=7168
5739 enum ObjectMembers
= ["toString","toHash","opCmp","opEquals","Monitor","factory"];
5741 static assert([__traits(allMembers
, X
)] == ["foo"]~ObjectMembers
); // pass
5742 static assert([__traits(allMembers
, Y
)] == ["bar", "foo"]~ObjectMembers
); // fail
5743 static assert([__traits(allMembers
, Y
)] != ["bar", "foo"]); // fail
5746 /***************************************************/
5747 // https://issues.dlang.org/show_bug.cgi?id=7170
5749 T
to7170(T
)(string x
) { return 1; }
5752 // auto i = to7170!int("1"); // OK
5753 auto j
= "1".to7170
!int(); // NG, Internal error: e2ir.c 683
5756 /***************************************************/
5757 // https://issues.dlang.org/show_bug.cgi?id=7196
5759 auto foo7196(int x
){return x
;}
5760 auto foo7196(double x
){return x
;}
5764 auto x
= (&foo7196
)(1); // ok
5765 auto y
= (&foo7196
)(1.0); // fail
5768 /***************************************************/
5769 // https://issues.dlang.org/show_bug.cgi?id=7285
5775 return (true) ? ab
: [0, 0]; // Error
5777 return (true) ?
[0, 0] : ab
; // OK
5782 auto sa
= spam7285();
5785 /***************************************************/
5786 // https://issues.dlang.org/show_bug.cgi?id=14737
5791 enum string
[2] a1
= ["d", "e"];
5792 enum b1x
= ["a", "b", "c"] ~ a1
; // Tarray vs Tsarray
5793 enum b1y
= a1
~ ["a", "b", "c"]; // Tsarray vs Tarray
5794 static assert(is(typeof(b1x
) == string
[]));
5795 static assert(is(typeof(b1y
) == string
[]));
5796 static assert(b1x
== ["a", "b", "c", "d", "e"]);
5797 static assert(b1y
== ["d", "e", "a", "b", "c"]);
5800 string
[2] a2
= ["d", "e"];
5801 auto b2x
= ["a", "b", "c"] ~ a2
; // Tarray vs Tsarray
5802 auto b2y
= a2
~ ["a", "b", "c"]; // Tsarray vs Tarray
5803 static assert(is(typeof(b2x
) == string
[]));
5804 static assert(is(typeof(b2y
) == string
[]));
5805 assert(b2x
== ["a", "b", "c", "d", "e"]);
5806 assert(b2y
== ["d", "e", "a", "b", "c"]);
5809 /***************************************************/
5810 // https://issues.dlang.org/show_bug.cgi?id=7321
5814 static assert(is(typeof((){})==void function()pure nothrow @nogc @safe)); // ok
5815 static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe)); // fail
5818 /***************************************************/
5822 pure void foo1() { }
5823 const void foo2() { }
5824 nothrow void foo3() { }
5825 @safe void foo4() { }
5830 override void foo1() { }
5831 override void foo2() const { }
5832 override void foo3() { }
5833 override void foo4() { }
5836 /***************************************************/
5837 // https://issues.dlang.org/show_bug.cgi?id=9231
5839 class B9231
{ void foo() inout pure {} }
5840 class D9231
: B9231
{ override void foo() inout {} }
5842 /***************************************************/
5843 // https://issues.dlang.org/show_bug.cgi?id=3282
5852 class Derived3282
: Base3282
5856 return "Derived.f()";
5858 /*override*/ string
f() const
5860 return "Derived.f() const";
5866 auto x
= new Base3282
;
5867 assert(x
.f() == "Base.f()");
5868 auto y
= new Derived3282
;
5869 assert(y
.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const.
5870 auto z
= new const(Derived3282
);
5871 assert(z
.f() == "Derived.f() const");
5874 /***************************************************/
5875 // https://issues.dlang.org/show_bug.cgi?id=7534
5879 int foo(){ return 1; }
5883 override int foo(){ return 2; }
5884 /*override*/ int foo() const { return 3; }
5885 // Error: D.foo multiple overrides of same function
5889 C7534 mc
= new C7534();
5890 assert(mc
.foo() == 1);
5892 D7534 md
= new D7534();
5893 assert(md
.foo() == 2);
5895 assert(mc
.foo() == 2);
5897 const(D7534
) cd
= new const(D7534
)();
5898 assert(cd
.foo() == 3);
5900 assert(md
.foo() == 2);
5903 /***************************************************/
5904 // https://issues.dlang.org/show_bug.cgi?id=7534
5905 // return type covariance
5910 int value
; this(int n
){ value
= n
; }
5915 X7534
foo(){ return new X7534(); }
5919 override Y7534
foo(){ return new Y7534(1); }
5920 /*override*/ Y7534
foo() const { return new Y7534(2); }
5925 auto mv
= new V7534();
5926 assert(typeid(mv
.foo()) == typeid(X7534
));
5928 auto mw
= new W7534();
5929 assert(typeid(mw
.foo()) == typeid(Y7534
));
5930 assert(mw
.foo().value
== 1);
5932 assert(typeid(mv
.foo()) == typeid(Y7534
));
5933 assert((cast(Y7534
)mv
.foo()).value
== 1);
5935 auto cw
= new const(W7534
)();
5936 assert(typeid(cw
.foo()) == typeid(Y7534
));
5937 assert(cw
.foo().value
== 2);
5940 /***************************************************/
5941 // https://issues.dlang.org/show_bug.cgi?id=7562
5946 mixin ProxyOf
!value
;
5948 mixin template ProxyOf(alias a
)
5961 void test1(this X
)(){}
5962 void test2(this Y
)(){}
5965 /***************************************************/
5967 import core
.stdc
.stdlib
;
5969 void test13427(void* buffer
= alloca(100))
5973 /***************************************************/
5974 // https://issues.dlang.org/show_bug.cgi?id=7583
5976 template Tup7583(E
...) { alias E Tup7583
; }
5980 Tup7583
!(float, char) field
;
5991 static assert (bug7583());
5993 /***************************************************/
5994 // https://issues.dlang.org/show_bug.cgi?id=7618
5996 void test7618(const int x
= 1)
5998 int func(ref int x
) { return 1; }
5999 static assert(!__traits(compiles
, func(x
)));
6000 // Error: function test.foo.func (ref int _param_0) is not callable using argument types (const(int))
6002 int delegate(ref int) dg
= (ref int x
) => 1;
6003 static assert(!__traits(compiles
, dg(x
)));
6004 // --> no error, bad!
6006 int function(ref int) fp
= (ref int x
) => 1;
6007 static assert(!__traits(compiles
, fp(x
)));
6008 // --> no error, bad!
6011 /***************************************************/
6012 // https://issues.dlang.org/show_bug.cgi?id=7621
6017 char[] A
= "hello".dup
;
6018 uint[immutable char[4u]] dict
;
6019 dict
[*cast(immutable char[4]*)(A
[0 .. N
].ptr
)] = 0; // OK
6020 dict
[*cast(immutable char[N
]*)(A
[0 .. N
].ptr
)] = 0; // line 6, error
6023 /***************************************************/
6024 // https://issues.dlang.org/show_bug.cgi?id=7682
6026 template ConstOf7682(T
)
6028 alias const(T
) ConstOf7682
;
6030 bool pointsTo7682(S
)(ref const S source
) @trusted pure nothrow
6036 shared(ConstOf7682
!(int[])) x
; // line A
6038 struct S3
{ int[10] a
; }
6040 shared(int[]) sh3sub
= sh3
.a
[];
6041 assert(pointsTo7682(sh3sub
)); // line B
6044 /***************************************************/
6045 // https://issues.dlang.org/show_bug.cgi?id=7735
6047 void a7735(void[][] data
...)
6050 assert(data
.length
== 1);
6054 void b7735(void[][] data
...)
6057 assert(data
.length
== 1);
6061 void c7735(void[][] data
...)
6064 assert(data
.length
== 1);
6073 /***************************************************/
6080 void test7823(A7823 a
= A7823
.b
) { }
6082 /***************************************************/
6083 // https://issues.dlang.org/show_bug.cgi?id=7871
6091 //auto findSplitBefore(R1)(R1 haystack)
6092 auto findSplitBefore7871(string haystack
)
6094 return Tuple7871(haystack
);
6099 string line
= `<bookmark href="https://stuff">`;
6100 auto a
= findSplitBefore7871(line
[0 .. $])[0];
6103 /***************************************************/
6104 // https://issues.dlang.org/show_bug.cgi?id=7906
6108 static assert(!__traits(compiles
, { enum s
= [string
.min
]; }));
6111 /***************************************************/
6112 // https://issues.dlang.org/show_bug.cgi?id=7907
6118 template Id7907(alias E
)
6125 static assert(!__traits(compiles
, { alias Id7907
!([string
.min
]) X
; }));
6128 /***************************************************/
6129 // https://issues.dlang.org/show_bug.cgi?id=1175
6140 I1
getI() { return new I2
; }
6143 /***************************************************/
6144 // https://issues.dlang.org/show_bug.cgi?id=8004
6148 auto n
= (int n
= 10){ return n
; }();
6152 /***************************************************/
6153 // https://issues.dlang.org/show_bug.cgi?id=8064
6158 ref uint acc(size_t i
) {
6161 auto arryacc
= &acc
;
6162 arryacc(3) = 5; // same error
6165 /***************************************************/
6166 // https://issues.dlang.org/show_bug.cgi?id=8220
6169 static assert(!__traits(compiles
, foo8220(typeof(0)))); // fail
6171 /***************************************************/
6173 void func8105(in ref int x
) { }
6179 /***************************************************/
6181 template ParameterTypeTuple159(alias foo
)
6183 static if (is(typeof(foo
) P
== __parameters
))
6184 alias P ParameterTypeTuple159
;
6186 static assert(0, "argument has no parameters");
6189 int func159(int i
, long j
= 7) { return 3; }
6191 alias ParameterTypeTuple159
!func159 PT
;
6193 int bar159(PT
) { return 4; }
6195 pragma(msg
, typeof(bar159
));
6198 PT
[1] boo159(PT
[1..2] a
) { return a
[0]; }
6202 assert(bar159(1) == 4);
6203 assert(boo159() == 7);
6206 /***************************************************/
6207 // https://issues.dlang.org/show_bug.cgi?id=8283
6213 struct FooContainer
{
6218 union Buf
{ FooContainer result
; }
6228 /***************************************************/
6229 // https://issues.dlang.org/show_bug.cgi?id=8395
6234 this(T
: long)(T x
) { v
= x
* 2; }
6244 /***************************************************/
6245 // https://issues.dlang.org/show_bug.cgi?id=5749
6253 //printf("this = %p, %d: i=%d\n", &this, x, i);
6257 A
bar(int x
, ref int i
)
6259 //printf("this = %p, %d: i=%d\n", &this, x, i);
6265 static int inc1(ref int i
) { return ++i
; }
6266 static ref int inc2(ref int i
) { return ++i
; }
6270 //printf("&a = %p\n", &a);
6272 i
= 0; a
.foo(1, ++i
).foo(2, ++i
); // OK <-- 2 1
6273 i
= 0; a
.bar(1, ++i
).bar(2, ++i
); // OK <-- 2 2
6274 i
= 0; a
.foo(1, inc1(i
)).foo(2, inc1(i
)); // OK <-- 2 1
6275 i
= 0; a
.bar(1, inc2(i
)).bar(2, inc2(i
)); // OK <-- 2 2
6278 A
getVal() { static A a
; return a
; }
6279 i
= 0; getVal().foo(1, ++i
).foo(2, ++i
); // OK <-- 2 1
6280 i
= 0; getVal().bar(1, ++i
).bar(2, ++i
); // OK <-- 2 2
6281 i
= 0; getVal().foo(1, inc1(i
)).foo(2, inc1(i
)); // OK <-- 2 1
6282 i
= 0; getVal().bar(1, inc2(i
)).bar(2, inc2(i
)); // OK <-- 2 2
6285 ref A
getRef() { static A a
; return a
; }
6286 i
= 0; getRef().foo(1, ++i
).foo(2, ++i
); // OK <-- 2 1
6287 i
= 0; getRef().bar(1, ++i
).bar(2, ++i
); // OK <-- 2 2
6288 i
= 0; getRef().foo(1, inc1(i
)).foo(2, inc1(i
)); // OK <-- 2 1
6289 i
= 0; getRef().bar(1, inc2(i
)).bar(2, inc2(i
)); // OK <-- 2 2
6292 /***************************************************/
6293 // https://issues.dlang.org/show_bug.cgi?id=8396
6299 static extern(C
) int bar(int a
, int b
)
6301 //printf("a = %d, b = %d\n", a, b);
6305 static auto getFunc(int n
)
6311 static struct Tuple
{ int _a
, _b
; }
6312 static Tuple
foo(int n
)
6319 assert(bar(foo(1).tupleof
) == 2);
6322 assert(getFunc(1)(foo(2).tupleof
) == 3);
6325 /***************************************************/
6327 enum E160
: ubyte { jan
= 1 }
6332 E160 _month
= E160
.jan
;
6335 this(int year
, int month
, int day
) pure
6337 _year
= cast(short)year
;
6338 _month
= cast(E160
)month
;
6339 _day
= cast(ubyte)day
;
6349 this(int hour
, int minute
, int second
= 0) pure
6351 _hour
= cast(ubyte)hour
;
6352 _minute
= cast(ubyte)minute
;
6353 _second
= cast(ubyte)second
;
6362 this(int year
, int month
, int day
,
6363 int hour
= 0, int minute
= 0, int second
= 0) pure
6365 _date
= D160(year
, month
, day
);
6366 _tod
= T160(hour
, minute
, second
);
6370 void foo160(DT160 dateTime
)
6372 printf("test7 year %d, day %d\n", dateTime
._date
._year
, dateTime
._date
._day
);
6373 assert(dateTime
._date
._year
== 1999);
6374 assert(dateTime
._date
._day
== 6);
6379 auto dateTime
= DT160(1999, 7, 6, 12, 30, 33);
6380 printf("test5 year %d, day %d\n", dateTime
._date
._year
, dateTime
._date
._day
);
6381 assert(dateTime
._date
._year
== 1999);
6382 assert(dateTime
._date
._day
== 6);
6383 foo160(DT160(1999, 7, 6, 12, 30, 33));
6386 /***************************************************/
6387 // https://issues.dlang.org/show_bug.cgi?id=8437
6391 struct PostParserState
{
6395 static struct UploadedFile
{
6396 string contentFilename
;
6400 /***************************************************/
6401 // https://issues.dlang.org/show_bug.cgi?id=8665
6403 auto foo8665a(bool val
)
6410 auto foo8665b(bool val
)
6420 static assert(is(typeof(foo8665a(true)) == double));
6421 static assert(is(typeof(foo8665b(false)) == double));
6422 assert(foo8665a(true) == 42); // assertion failure
6423 assert(foo8665b(true) == 42); // assertion failure
6424 assert(foo8665a(false) == 1.5);
6425 assert(foo8665b(false) == 1.5);
6427 static assert(foo8665a(true) == 42);
6428 static assert(foo8665b(true) == 42);
6429 static assert(foo8665a(false) == 1.5);
6430 static assert(foo8665b(false) == 1.5);
6433 /***************************************************/
6435 int foo8108(int, int);
6437 int foo8108(int a
, int b
)
6447 /***************************************************/
6448 // https://issues.dlang.org/show_bug.cgi?id=8360
6464 assert(check
== 1337);
6474 Foo8360
makeFoo8360()
6484 // The message part 'makeFoo().str()' should not be evaluated at all.
6485 assert(length
< 5, makeFoo8360().str());
6488 /***************************************************/
6489 // https://issues.dlang.org/show_bug.cgi?id=8361
6493 string bar
= "hello";
6499 assert(true, Foo8361().bar
);
6502 /***************************************************/
6503 // https://issues.dlang.org/show_bug.cgi?id=6141
6504 // https://issues.dlang.org/show_bug.cgi?id=8526
6508 static void takeADelegate(void delegate()) {}
6509 auto items
= new int[1];
6511 foreach (ref item
; items
)
6513 // both asserts fail
6515 assert(&item
== items
.ptr
);
6517 takeADelegate({ auto x
= &item
; });
6520 foreach(ref val
; [3])
6522 auto dg
= { int j
= val
; };
6523 assert(&val
!= null); // Assertion failure
6527 static void f(lazy int) {}
6529 auto dg
= { int j
= i
; };
6530 foreach(ref val
; [3])
6533 assert(&val
!= null); // Assertion failure
6540 static void call(void delegate() dg
) { dg(); }
6545 assert(i
== 0); // fails, i is corrupted
6552 assert(n
== 0); // fails, n is corrupted
6557 /***************************************************/
6559 template ParameterTuple(alias func
)
6561 static if(is(typeof(func
) P
== __parameters
))
6562 alias P ParameterTuple
;
6567 int foo161(ref float y
);
6571 alias PT
= ParameterTuple
!foo161
;
6572 auto x
= __traits(identifier
, PT
);
6576 /***************************************************/
6577 // https://issues.dlang.org/show_bug.cgi?id=7175
6581 struct S
{ ubyte[0] arr
; }
6583 assert(s
.arr
.ptr
!is null);
6584 assert(cast(void*)s
.arr
.ptr
is cast(void*)&s
);
6587 /***************************************************/
6588 // https://issues.dlang.org/show_bug.cgi?id=8819
6592 void[1] sa1
= (void[1]).init
;
6593 assert((cast(ubyte*)sa1
.ptr
)[0] == 0);
6595 void[4] sa4
= [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4];
6596 assert((cast(ubyte*)sa4
.ptr
)[0] == 1);
6597 assert((cast(ubyte*)sa4
.ptr
)[1] == 2);
6598 assert((cast(ubyte*)sa4
.ptr
)[2] == 3);
6599 assert((cast(ubyte*)sa4
.ptr
)[3] == 4);
6601 auto sa22
= (void[2][2]).init
;
6602 static assert(sa22
.sizeof
== ubyte.sizeof
* 2 * 2);
6603 ubyte[4]* psa22
= cast(ubyte[4]*)sa22
.ptr
;
6604 assert((*psa22
)[0] == 0);
6605 assert((*psa22
)[1] == 0);
6606 assert((*psa22
)[2] == 0);
6607 assert((*psa22
)[3] == 0);
6610 /***************************************************/
6611 // https://issues.dlang.org/show_bug.cgi?id=8897
6615 static mixin M8897
!(int);
6616 static class causesAnError
{}
6619 template M8897 ( E
) { }
6621 /***************************************************/
6622 // https://issues.dlang.org/show_bug.cgi?id=8917
6628 int[3] b
= a
[] + a2
[];
6631 /***************************************************/
6632 // https://issues.dlang.org/show_bug.cgi?id=8945
6634 struct S8945
// or `class`, or `union`
6636 struct S0(T
) { int i
; }
6637 struct S1(T
) { this(int){} }
6642 auto cs0a
= const S8945
.S0
!int(); // ok
6643 auto cs0b
= const S8945
.S0
!int(1); // ok
6644 auto cs1
= const S8945
.S1
!int(1); // ok
6646 auto s0a
= S8945
.S0
!int(); // Error: struct S0 does not overload ()
6647 auto s0b
= S8945
.S0
!int(1); // Error: struct S0 does not overload ()
6648 auto s1
= S8945
.S1
!int(1); // Error: struct S1 does not overload ()
6651 /***************************************************/
6655 static int generateMethodStubs( Class
)()
6659 foreach( m
; __traits( allMembers
, Class
) )
6661 static if( is( typeof( mixin( m
) ) ) && is( typeof( mixin( m
) ) == function ) )
6663 pragma(msg
, __traits( getOverloads
, Class
, m
));
6670 enum int ttt
= generateMethodStubs
!( S162
)();
6681 /***************************************************/
6684 static class C
{ int x
; int y
; }
6686 immutable C c
= new C();
6687 shared C c2
= new C();
6688 shared const C c3
= new C();
6690 class D
{ int x
; int y
; }
6692 assert(!__traits(compiles
, d
= new D()));
6694 static struct S
{ int x
; int y
; }
6696 immutable S
* s
= new S();
6697 shared S
* s2
= new S();
6698 shared const S
* s3
= new S();
6701 assert(__traits(compiles
, s4
= new immutable(S
)()));
6703 struct T
{ int x
; int y
; }
6705 assert(!__traits(compiles
, t
= new T()));
6707 immutable int* pi
= new int();
6708 immutable void* pv
= new int();
6710 immutable int[] ai
= new int[1];
6711 immutable void[] av
= new int[2];
6714 /***************************************************/
6716 { ubyte i
= ubyte.max
; }
6718 enum E9000
= S9000
.init
;
6720 /***************************************************/
6722 mixin template DefineCoreType(string type
)
6728 static void instance()
6737 mixin DefineCoreType
!("");
6740 mixin template A164()
6753 /***************************************************/
6754 // https://issues.dlang.org/show_bug.cgi?id=9428
6758 int[2][] items
= [[1, 2]];
6761 auto r1
= items
~ [x
];
6762 assert(r1
.length
== 2);
6763 assert(r1
[0][0] == 1);
6764 assert(r1
[0][1] == 2);
6765 assert(r1
[1][0] == 3);
6766 assert(r1
[1][1] == 4);
6768 auto r2
= items
~ x
;
6769 assert(r2
.length
== 2);
6770 assert(r2
[0][0] == 1);
6771 assert(r2
[0][1] == 2);
6772 assert(r2
[1][0] == 3);
6773 assert(r2
[1][1] == 4);
6775 auto r3
= [x
] ~ items
;
6776 assert(r3
.length
== 2);
6777 assert(r3
[0][0] == 3);
6778 assert(r3
[0][1] == 4);
6779 assert(r3
[1][0] == 1);
6780 assert(r3
[1][1] == 2);
6782 auto r4
= x
~ items
;
6783 assert(r4
.length
== 2);
6784 assert(r4
[0][0] == 3);
6785 assert(r4
[0][1] == 4);
6786 assert(r4
[1][0] == 1);
6787 assert(r4
[1][1] == 2);
6790 /***************************************************/
6791 // https://issues.dlang.org/show_bug.cgi?id=9477
6793 template Tuple9477(T
...) { alias T Tuple9477
; }
6794 template Select9477(bool b
, T
, U
) { static if (b
) alias T Select9477
; else alias U Select9477
; }
6798 static bool isEq (T1
, T2
)(T1 s1
, T2 s2
) { return s1
== s2
; }
6799 static bool isNeq(T1
, T2
)(T1 s1
, T2 s2
) { return s1
!= s2
; }
6801 // Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9748
6803 // Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9756
6804 auto checkOrder(bool dyn
, uint expected
)()
6806 assert(order
==expected
);
6808 // Use temporary ("v") to work around https://issues.dlang.org/show_bug.cgi?id=9402
6809 auto v
= cast(Select9477
!(dyn
, string
, char[1]))"a";
6813 foreach (b1
; Tuple9477
!(false, true))
6814 foreach (b2
; Tuple9477
!(false, true))
6816 version (D_PIC
) {} else version (D_PIE
) {} else // Work around https://issues.dlang.org/show_bug.cgi?id=9754
6818 assert( isEq (cast(Select9477
!(b1
, string
, char[0]))"" , cast(Select9477
!(b2
, string
, char[0]))"" ));
6819 assert(!isNeq(cast(Select9477
!(b1
, string
, char[0]))"" , cast(Select9477
!(b2
, string
, char[0]))"" ));
6821 assert(!isEq (cast(Select9477
!(b1
, string
, char[0]))"" , cast(Select9477
!(b2
, string
, char[1]))"a" ));
6822 assert( isNeq(cast(Select9477
!(b1
, string
, char[0]))"" , cast(Select9477
!(b2
, string
, char[1]))"a" ));
6825 assert( isEq (cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[1]))"a" ));
6826 assert(!isNeq(cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[1]))"a" ));
6828 assert(!isEq (cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[1]))"b" ));
6829 assert( isNeq(cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[1]))"b" ));
6831 assert(!isEq (cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[2]))"aa"));
6832 assert( isNeq(cast(Select9477
!(b1
, string
, char[1]))"a", cast(Select9477
!(b2
, string
, char[2]))"aa"));
6834 // Note: order of evaluation was not followed before this patch
6835 // (thus, the test below will fail without the patch).
6836 // Although the specification mentions that as implementation-defined behavior,
6837 // I understand that this isn't by design, but rather an inconvenient aspect of DMD
6838 // that has been moved to the specification.
6840 bool result
= checkOrder
!(b1
, 0)() == checkOrder
!(b2
, 1)();
6845 // need largest natural alignment to avoid unaligned access on
6846 // some architectures, double in this case.
6847 align(8) ubyte[64] a1
, a2
;
6848 foreach (T
; Tuple9477
!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double))
6850 auto s1
= cast(T
[])(a1
[]);
6851 auto s2
= cast(T
[])(a2
[]);
6855 assert(s1
[0..$-1]==s2
[0..$-1]);
6860 /***************************************************/
6861 // https://issues.dlang.org/show_bug.cgi?id=9504
6870 enum size_t num
= 123;
6875 template GetSym9504(alias sym
) { static assert(__traits(isSame
, sym
, Bar9504
.Abc
)); }
6876 template GetExp9504(size_t n
) { static assert(n
== Bar9504
.num
); }
6877 template GetTyp9504(T
) { static assert(is(T
== Bar9504
.Def
)); }
6879 alias GetSym9504
!(typeof(Bar9504
.init
).Abc
) X9504
; // NG
6880 alias GetExp9504
!(typeof(Bar9504
.init
).num
) Y9504
; // NG
6881 alias GetTyp9504
!(typeof(Bar9504
.init
).Def
) Z9504
;
6885 alias GetSym9504
!(typeof(return).Abc
) V9504
; // NG
6886 alias GetExp9504
!(typeof(return).num
) W9504
; // NG
6887 alias GetTyp9504
!(typeof(return).Def
) X9504
;
6891 /***************************************************/
6892 // https://issues.dlang.org/show_bug.cgi?id=9538
6897 auto ti
= typeid(x
.ptr
);
6900 /***************************************************/
6901 // https://issues.dlang.org/show_bug.cgi?id=9539
6907 assert(**ptr
== 10);
6914 int*[] arr
= [null];
6915 static assert(!__traits(compiles
, p
= arr
)); // bad!
6918 /***************************************************/
6919 // https://issues.dlang.org/show_bug.cgi?id=9700
6921 mixin template Proxy9700(alias a
)
6923 auto ref opOpAssign(string op
, V
)(V v
) { return a
+= v
; } // NG
6924 //auto ref opOpAssign(string op, V)(V v) { a += v; } // OK
6929 invariant() { assert(value
>= 0); }
6930 mixin Proxy9700
!value
;
6934 MyInt9700 a
= { 2 };
6935 a
*= 3; // object.Error: Access Violation
6938 /***************************************************/
6939 // https://issues.dlang.org/show_bug.cgi?id=9834
6944 void set(void delegate() h
) pure { dg
= h
; } // AV occurs
6945 void call() { dg(); }
6956 ev
.set((){ o
.toString(); });
6962 /***************************************************/
6963 // https://issues.dlang.org/show_bug.cgi?id=9859
6965 void test9859(inout int[] arr
)
6967 auto dg1
= { foreach (i
, e
; arr
) { } };
6970 void foo() { auto v
= arr
; auto w
= arr
[0]; }
6971 void bar(inout int i
) { auto v
= arr
[i
]; }
6994 auto dg1
= { auto v
= arr
; };
7006 /***************************************************/
7007 // https://issues.dlang.org/show_bug.cgi?id=9912
7009 template TypeTuple9912(Stuff
...)
7011 alias Stuff TypeTuple9912
;
7017 alias TypeTuple9912
!i t
;
7028 /***************************************************/
7029 // https://issues.dlang.org/show_bug.cgi?id=9883
7033 @property size_t
p9883(T
)() { return 0; }
7036 @property size_t
p9883(T
)() { return 0; }
7041 auto n1
= p9883
!int; // OK
7042 auto n2
= s
.p9883
!int; // OK
7043 auto a1
= new int[p9883
!int]; // Error: need size of rightmost array, not type p!(int)
7044 auto a2
= new int[s
.p9883
!int]; // Error: no property 'p!(int)' for type 'S'
7048 /***************************************************/
7049 // https://issues.dlang.org/show_bug.cgi?id=10091
7058 auto arr
= cast(ubyte[1]) S10091
.e
;
7061 /***************************************************/
7071 /***************************************************/
7072 // https://issues.dlang.org/show_bug.cgi?id=9130
7074 class S9130
{ void bar() { } }
7076 import core
.stdc
.stdio
: printf
;
7083 @property void meta(alias m
)()
7086 printf("length = %zd\n", md
.ai
.length
);
7087 printf("ptr = %p\n", md
.ai
.ptr
);
7093 meta
!(__traits(getOverloads
, S9130
, "bar")[0]);
7097 /***************************************************/
7098 // https://issues.dlang.org/show_bug.cgi?id=10390
7100 class C10390
{ this() { this.c
= this; } C10390 c
; }
7101 const c10390
= new C10390();
7102 pragma(msg
, c10390
);
7104 /***************************************************/
7105 // https://issues.dlang.org/show_bug.cgi?id=10542
7109 this() nothrow pure @safe { }
7112 class D10542
: B10542
7116 void test10542() nothrow pure @safe
7121 /***************************************************/
7122 // https://issues.dlang.org/show_bug.cgi?id=10539
7127 int* p1
= a
.ptr
.ptr
; // OK <- error
7128 int* p2
= (*a
.ptr
).ptr
; // OK
7132 /***************************************************/
7139 __gshared
byte glob
;
7143 this(ubyte _d
, ubyte _m
, ubyte _y
, TimeOfDay _tod
= TimeOfDay
.init
)
7158 DateTime date1
= DateTime(0, 0, 0);
7160 assert(date1
== date2
);
7163 /***************************************************/
7165 immutable(char)[4] bar7254(int i
)
7169 immutable(char)[4] r
; return r
;
7177 assert(bar7254(0) == "1234");
7180 /***************************************************/
7182 struct S11075() { int x
= undefined_expr
; }
7184 class C11075() { int x
= undefined_expr
; }
7186 interface I11075() { enum int x
= undefined_expr
; }
7190 static assert(!is(typeof(S11075
!().x
)));
7191 static assert(!is(typeof(S11075
!().x
)));
7193 static assert(!is(typeof(C11075
!().x
)));
7194 static assert(!is(typeof(C11075
!().x
)));
7196 static assert(!is(typeof(I11075
!().x
)));
7197 static assert(!is(typeof(I11075
!().x
)));
7200 /***************************************************/
7201 // https://issues.dlang.org/show_bug.cgi?id=11181
7205 auto a
= ["a", "b"];
7207 static assert(!is(typeof([a
, "x"])));
7208 static assert(!is(typeof(true ? a
: "x")));
7210 static assert(!is(typeof(true ? a
[0 .. $] : "x")));
7211 static assert(!is(typeof([a
[0 .. $], "x"])));
7214 /***************************************************/
7215 // https://issues.dlang.org/show_bug.cgi?id=11317
7224 void test(ref uint x
) {}
7225 static assert(__traits(compiles
, test(fun())));
7230 /***************************************************/
7231 // https://issues.dlang.org/show_bug.cgi?id=11888
7237 static ubyte* foo(size_t
* len
)
7240 return cast(ubyte*)&val
;
7244 ubyte[] t
= foo(&size
)[0..size
];
7245 assert(t
.ptr
is cast(void*)&val
);
7246 assert(t
.length
== 8);
7249 int[3] sa1
= [1,2,3];
7250 int[1] sa2
= sa1
[1..2]; // convert slice to Tsarray
7251 assert(sa2
.length
== 1);
7252 assert(sa2
[0] == 2);
7255 /***************************************************/
7256 // https://issues.dlang.org/show_bug.cgi?id=12036
7258 template T12036(alias a
)
7272 assert(s
.value
== "");
7275 /***************************************************/
7276 // https://issues.dlang.org/show_bug.cgi?id=12153
7282 (b ? i
: j
)[] = [4];
7287 (b ? k
: l
)[0..1][0..1] = [4];
7291 /***************************************************/
7292 // https://issues.dlang.org/show_bug.cgi?id=12498
7308 /***************************************************/
7309 // https://issues.dlang.org/show_bug.cgi?id=12900
7323 /***************************************************/
7324 // https://issues.dlang.org/show_bug.cgi?id=12929
7338 /***************************************************/
7339 // https://issues.dlang.org/show_bug.cgi?id=12937
7343 void[1] sa2
= cast(void[])[cast(ubyte)1]; // ICE!
7344 assert((cast(ubyte[])sa2
[])[0] == 1);
7347 /***************************************************/
7348 // https://issues.dlang.org/show_bug.cgi?id=13154
7352 int[3] ints
= [2 , 1 , 0 , 1 ][0..3];
7353 float[3] floats0
= [2f , 1f , 0f , 1f ][0..3];
7354 float[3] floats1
= [2.0 , 1.0 , 0.0 , 1.0 ][0..3]; // fails!
7355 float[3] floats2
= [2.0f, 1.0f, 0.0f, 1.0f][0..3];
7356 assert(ints
== [2, 1, 0]);
7357 assert(floats0
== [2, 1, 0]);
7358 assert(floats1
== [2, 1, 0]); // fail!
7359 assert(floats1
!= [0, 0, 0]); // fail!
7360 assert(floats2
== [2, 1, 0]);
7363 /***************************************************/
7364 // https://issues.dlang.org/show_bug.cgi?id=13437
7366 ubyte[4] foo13437() { return [1,2,3,4]; }
7370 auto n
= cast(ubyte[4])foo13437()[]; // OK <- ICE: e2ir.c 4616
7371 static assert(is(typeof(n
) == ubyte[4]));
7372 assert(n
== [1,2,3,4]);
7375 /***************************************************/
7376 // https://issues.dlang.org/show_bug.cgi?id=13472
7387 auto b
= test[0..2] ~ null ~ test[2..$];
7388 assert(b
.length
== 5);
7391 /***************************************************/
7392 // https://issues.dlang.org/show_bug.cgi?id=13476
7394 template ParameterTypeTuple13476(func
...)
7396 static if (is(typeof(*func
[0]) P
== function))
7397 alias ParameterTypeTuple13476
= P
;
7399 static assert(0, "argument has no parameters");
7404 __gshared
extern(C
) void function(int) nothrow someFunc13476
= &Stub13476
!someFunc13476
;
7406 extern(C
) auto Stub13476(alias func
)(ParameterTypeTuple13476
!func args
)
7409 extern(C
) void function(int) nothrow impl
= (i
) { };
7410 return (func
= impl
)(args
);
7413 __gshared
extern(C
) void function(int) nothrow someFunc13476Alt
= &Stub13476Alt
!someFunc13476AltP
;
7414 __gshared
extern(C
) void function(int) nothrow* someFunc13476AltP
= &someFunc13476Alt
;
7416 extern(C
) auto Stub13476Alt(alias func
)(int args
) nothrow
7419 extern(C
) void function(int) nothrow impl
= (i
) {};
7420 return (*func
= impl
)(args
);
7425 assert(flag13476
== 0);
7428 assert(flag13476
== 1);
7430 assert(flag13476
== 1);
7432 someFunc13476Alt(42);
7433 assert(flag13476
== 2);
7434 someFunc13476Alt(43);
7435 assert(flag13476
== 2);
7438 /***************************************************/
7439 // https://issues.dlang.org/show_bug.cgi?id=14038
7441 static immutable ubyte[string
] wordsAA14038
;
7442 shared static this()
7444 wordsAA14038
["zero"] = 0;
7447 /***************************************************/
7448 // https://issues.dlang.org/show_bug.cgi?id=14192
7452 shared int[int] map
;
7456 /***************************************************/
7457 // https://issues.dlang.org/show_bug.cgi?id=13720
7466 this(TimeOfDay13720 dateTime
, FracSec13720 fracSec
)
7471 struct TimeOfDay13720
7476 void assertThrown13720(T
)(lazy T
) {}
7480 assertThrown13720(SysTime13720(TimeOfDay13720
.init
, FracSec13720(-1)));
7483 /***************************************************/
7484 // https://issues.dlang.org/show_bug.cgi?id=13952
7502 Reg13952 reg
; // size == 4
7503 Imm13952 imm
; // size == 8
7507 this(Reg13952 r
) { reg
= r
; }
7510 Opnd13952
opnd13952(Reg13952 reg
)
7512 return Opnd13952(reg
);
7518 auto op
= opnd13952(reg
);
7519 auto buf
= (cast(ubyte*)&op
)[0 .. op
.sizeof
];
7522 // import std.stdio;
7523 // writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]);
7524 // writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]);
7526 foreach (e
; buf
) assert(e
== 0);
7529 /***************************************************/
7530 // https://issues.dlang.org/show_bug.cgi?id=14165
7538 /***************************************************/
7539 // https://issues.dlang.org/show_bug.cgi?id=13985
7553 class C13985
: I13985
7560 class D13985
: C13985
7570 auto d
= new D13985();
7574 /***************************************************/
7575 // https://issues.dlang.org/show_bug.cgi?id=14211
7577 extern(C
++) // all derived classes won't have invariants
7585 final class C14211
: B14211
7591 auto c
= new C14211();
7592 *cast(void**)c
= null;
7593 c
.func(); // called without vtbl access
7596 /***************************************************/
7597 // https://issues.dlang.org/show_bug.cgi?id=14552
7599 template map14552(fun
...)
7601 template AppliedReturnType(alias f
)
7603 alias typeof(f(0)) AppliedReturnType
;
7606 auto map14552(int[] r
)
7608 assert(!is(AppliedReturnType
!fun
));
7609 return MapResult14552
!fun();
7613 struct MapResult14552(alias fun
)
7625 [1].map14552
!(j
=> new Inner
);
7630 /***************************************************/
7631 // https://issues.dlang.org/show_bug.cgi?id=14853
7633 struct Queue14853(T
)
7637 T mfPayload
= T
.init
;
7640 typeof(this)* mfPrev
;
7641 shared(typeof(this)*) mfShPrev
;
7645 typeof(this)* mfNext
;
7646 shared(typeof(this)*) mfShNext
;
7652 void pfPut(T v
, Node
* r
= null)
7654 shared n
= new Node(v
); // problem!
7660 auto b1
= new Queue14853
!uint;
7663 /********************************************************/
7664 // https://issues.dlang.org/show_bug.cgi?id=15045
7668 void testName(T
, bool r
, string name
)()
7672 static assert(r
== is(typeof(mixin("T."~name
))));
7673 static assert(r
== is(typeof(mixin("t."~name
))));
7674 static assert(r
== __traits(compiles
, mixin("T."~name
)));
7675 static assert(r
== __traits(compiles
, mixin("t."~name
)));
7676 static assert(r
== mixin("__traits(compiles, T."~name
~")"));
7677 static assert(r
== mixin("__traits(compiles, t."~name
~")"));
7679 static assert(r
== __traits(hasMember
, T
, name
) );
7680 static assert(r
== __traits(hasMember
, t
, name
) );
7681 static assert(r
== __traits(compiles
, __traits(getMember
, T
, name
) ));
7682 static assert(r
== __traits(compiles
, __traits(getMember
, t
, name
) ));
7683 static assert(r
== __traits(compiles
, __traits(getOverloads
, T
, name
) ));
7684 static assert(r
== __traits(compiles
, __traits(getOverloads
, t
, name
) ));
7686 void test(T
, bool r
)()
7688 testName
!(T
, r
, "__ctor")();
7689 testName
!(T
, r
, "__dtor")();
7690 testName
!(T
, r
, "__xdtor")();
7691 testName
!(T
, r
, "__postblit")();
7692 testName
!(T
, r
, "__xpostblit")();
7704 auto opDispatch(string name
, A
...)(A args
) { }
7708 X
get() { return X(); };
7713 X
opDot() { return X(); };
7722 /***************************************************/
7723 // https://issues.dlang.org/show_bug.cgi?id=15116
7725 alias TypeTuple15116(T
...) = T
;
7729 TypeTuple15116
!(int, int) tup
;
7740 auto x1
= s
.tup
; // OK
7741 auto x2
= s
.mix
.tup
; // OK <- NG
7744 /***************************************************/
7745 // https://issues.dlang.org/show_bug.cgi?id=15117
7749 int y
= { typeof(this)* s
; return s ? s
.mix
.y
: 0; }();
7754 int x
= { typeof(this)* s
; return s ? s
.x
: 0; }(); // OK
7756 mixin Mix15117 mix
; // OK <- NG
7759 /***************************************************/
7760 // https://issues.dlang.org/show_bug.cgi?id=15126
7765 int opDispatch(string prop
)() const { return 0; }
7766 int opDispatch(string prop
)() { return 0; }
7769 template isCustomSerializable15126(T
)
7771 enum isCustomSerializable15126
= T
.init
.toRepresentation();
7774 alias bug15126
= isCustomSerializable15126
!Json15126
;
7776 /***************************************************/
7777 // https://issues.dlang.org/show_bug.cgi?id=15141
7781 abstract void method();
7784 class B15141
: A15141
{ }
7788 auto a
= Object
.factory(__MODULE__
~ ".A15141");
7790 auto b
= Object
.factory(__MODULE__
~ ".B15141");
7791 assert(b
is null); // OK <- oops
7794 /***************************************************/
7795 // https://issues.dlang.org/show_bug.cgi?id=15366
7797 enum E15366
: bool { A
, B
};
7801 void func1(E15366 e
) {}
7803 void func2(E15366 a
, E15366 b
)
7805 func1(cast(E15366
)(a
&& b
));
7806 func1(cast(E15366
)(a || b
));
7808 auto x1
= cast(E15366
)(a
&& b
);
7809 auto x2
= cast(E15366
)(a || b
);
7813 /***************************************************/
7814 // https://issues.dlang.org/show_bug.cgi?id=15369
7816 struct MsgTable15369
7818 const(char)[] ident
;
7822 MsgTable15369
[] msgTable15369
=
7829 auto id
= msgTable15369
[0].ident
;
7830 auto p
= msgTable15369
[0].name
;
7832 // a string literal "" should be zero-terminated
7849 // Common type for const derived classes
7850 auto constCommon
= true ? cb
: cc
;
7851 static assert(is(typeof(constCommon
) == const(A
)));
7853 // Common type for immutable derived classes
7854 auto immutableCommon
= true ? ib
: ic
;
7855 static assert(is(typeof(immutableCommon
) == immutable(A
)));
7857 // Common type for mixed const/immutable derived classes
7858 auto mixed1
= true ? cb
: ic
;
7859 static assert(is(typeof(mixed1
) == const(A
)));
7860 auto mixed2
= true ? ib
: cc
;
7861 static assert(is(typeof(mixed2
) == const(A
)));
7863 // Common type for mixed mutable/immutable derived classes
7864 auto mixed3
= true ? b
: ic
;
7865 static assert(is(typeof(mixed3
) == const(A
)));
7866 auto mixed4
= true ? ib
: c
;
7867 static assert(is(typeof(mixed4
) == const(A
)));
7869 // Array literal type deduction
7870 auto arr1
= [ new immutable(B
), new C
];
7871 auto arr2
= [ new B
, new const(C
) ];
7872 auto arr3
= [ new immutable(B
), new immutable(C
) ];
7873 static assert(is(typeof(arr1
) == const(A
)[]));
7874 static assert(is(typeof(arr2
) == const(A
)[]));
7875 static assert(is(typeof(arr3
) == immutable(A
)[]));
7878 /***************************************************/
7879 // https://issues.dlang.org/show_bug.cgi?id=15961
7881 struct SliceOverIndexed15961(T
)
7883 enum assignableIndex
= T
.init
;
7886 struct Grapheme15961
7888 SliceOverIndexed15961
!Grapheme15961
opSlice()
7899 /***************************************************/
7900 // https://issues.dlang.org/show_bug.cgi?id=16022
7904 enum Type
{ Colon
, Comma
}
7906 return type
== Type
.Comma
;
7909 bool test16022_structs()
7917 enum Type
{ Colon
= A(0, "zero"), Comma
= A(1, "one") }
7919 return type
== Type
.Comma
;
7922 /***************************************************/
7923 // https://issues.dlang.org/show_bug.cgi?id=16233
7925 enum valueConvertible(T1
, T2
) = blah
;
7927 struct Checked(T
, Hook
)
7929 bool opEquals(U
)(Checked
!(U
, Hook
) rhs
)
7931 alias R
= typeof(payload
+ rhs
.payload
);
7932 static if (valueConvertible
!(T
, R
))
7941 Checked
!(Checked
!(int, void), void) x1
;
7944 /***************************************************/
7945 // https://issues.dlang.org/show_bug.cgi?id=16466
7954 printf("S.alignof: %zx, r.alignof: %zx\n", S
.alignof
, r
.alignof
);
7955 assert(S
.alignof
== r
.alignof
);
7958 /***************************************************/
7960 // https://issues.dlang.org/show_bug.cgi?id=16408
7962 char[1] SDL_GetKeyName_buffer
;
7964 const(char)[] SDL_GetKeyName(char k
)
7966 pragma(inline
, false);
7967 SDL_GetKeyName_buffer
[0] = k
;
7968 return SDL_GetKeyName_buffer
[];
7971 void formattedWrite(const(char)[] strW
, const(char)[] strA
, const(char)[] strC
)
7973 pragma(inline
, false);
7975 assert(strW
== "W");
7976 assert(strA
== "A");
7977 assert(strC
== "C");
7982 pragma(inline
, false);
7984 SDL_GetKeyName('W').idup
,
7985 SDL_GetKeyName('A').idup
,
7986 SDL_GetKeyName('C').idup
7990 /***************************************************/
7991 // https://issues.dlang.org/show_bug.cgi?id=17349
7997 // Specify attribute inferred for dg1/dg2
7998 int bar(void delegate(ref int*) pure nothrow @nogc @safe) { return 1; }
7999 int bar(void delegate(ref const int*) pure nothrow @nogc @safe) const { return 2; }
8002 void dg1(ref int*) { }
8003 void dg2(ref const int*) { }
8012 /***************************************************/
8013 // https://issues.dlang.org/show_bug.cgi?id=17915
8017 static class MyClass
8019 S17915
!MyClass m_member
;
8030 static struct Canary
8032 int x
= 0x900D_900D
;
8043 assert(u
.method() == Canary
.init
);
8046 /***************************************************/
8369 printf("Success\n");