diff options
Diffstat (limited to 'gcc/testsuite/gdc.test/runnable')
368 files changed, 14215 insertions, 6025 deletions
diff --git a/gcc/testsuite/gdc.test/runnable/A16.d b/gcc/testsuite/gdc.test/runnable/A16.d index f65335393b4..e89e71493fe 100644 --- a/gcc/testsuite/gdc.test/runnable/A16.d +++ b/gcc/testsuite/gdc.test/runnable/A16.d @@ -1,6 +1,13 @@ -// EXTRA_SOURCES: imports/A16a.d +/* +EXTRA_SOURCES: imports/A16a.d +RUN_OUTPUT: +--- +class AA16 +class B16 +--- +*/ -import std.stdio; +import core.stdc.stdio; class AA16 { diff --git a/gcc/testsuite/gdc.test/runnable/Same.d b/gcc/testsuite/gdc.test/runnable/Same.d index 85025e77c4e..a4c6f0f8317 100644 --- a/gcc/testsuite/gdc.test/runnable/Same.d +++ b/gcc/testsuite/gdc.test/runnable/Same.d @@ -1,5 +1,12 @@ -// EXTRA_SOURCES: imports/Other.d -// PERMUTE_ARGS: +/* +EXTRA_SOURCES: imports/Other.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Same +other +--- +*/ module Same; // makes no difference if removed import core.stdc.stdio; diff --git a/gcc/testsuite/gdc.test/runnable/a17.d b/gcc/testsuite/gdc.test/runnable/a17.d index 79eeecfeb14..21f4f38e46d 100644 --- a/gcc/testsuite/gdc.test/runnable/a17.d +++ b/gcc/testsuite/gdc.test/runnable/a17.d @@ -1,8 +1,14 @@ -// EXTRA_SOURCES: imports/a17a.d +/* +EXTRA_SOURCES: imports/a17a.d +RUN_OUTPUT: +--- +barx +--- +*/ module a17; -import std.stdio; +import core.stdc.stdio; private import imports.a17a; diff --git a/gcc/testsuite/gdc.test/runnable/a18.d b/gcc/testsuite/gdc.test/runnable/a18.d index 4d8b000a138..f568982acee 100644 --- a/gcc/testsuite/gdc.test/runnable/a18.d +++ b/gcc/testsuite/gdc.test/runnable/a18.d @@ -1,6 +1,12 @@ -// COMPILE_SEPARATELY -// EXTRA_SOURCES: imports/a18a.d -// PERMUTE_ARGS: +/* +COMPILE_SEPARATELY +EXTRA_SOURCES: imports/a18a.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Test enumerator +--- +*/ import imports.a18a; diff --git a/gcc/testsuite/gdc.test/runnable/a21.d b/gcc/testsuite/gdc.test/runnable/a21.d index 6b3be9d814c..65806c4ee63 100644 --- a/gcc/testsuite/gdc.test/runnable/a21.d +++ b/gcc/testsuite/gdc.test/runnable/a21.d @@ -1,7 +1,14 @@ -// EXTRA_SOURCES: imports/a21a.d -// PERMUTE_ARGS: +/* +EXTRA_SOURCES: imports/a21a.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +goodFunc +badFunc +--- +*/ -import std.stdio; +import core.stdc.stdio; import imports.a21a; @@ -26,4 +33,3 @@ int main() return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/aliasassign.d b/gcc/testsuite/gdc.test/runnable/aliasassign.d new file mode 100644 index 00000000000..986cccc4db8 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/aliasassign.d @@ -0,0 +1,31 @@ + + +template AliasSeq(T...) { alias AliasSeq = T; } + +template staticMap(alias F, T...) +{ + alias A = AliasSeq!(); + static foreach (t; T) + A = AliasSeq!(A, F!t); + alias staticMap = A; +} + +template Qual(alias T) +{ + alias Qual = T; +} + +void test() +{ + int x = 3; + int y = 4; + + alias XY = staticMap!(Qual, x, y); + assert(XY[0] == 3); + assert(XY[1] == 4); +} + +void main() +{ + test(); +} diff --git a/gcc/testsuite/gdc.test/runnable/aliasthis.d b/gcc/testsuite/gdc.test/runnable/aliasthis.d index ee8e6a13ce0..cc12f55935d 100644 --- a/gcc/testsuite/gdc.test/runnable/aliasthis.d +++ b/gcc/testsuite/gdc.test/runnable/aliasthis.d @@ -132,7 +132,7 @@ struct Iter bool empty() { return true; } void popFront() { } ref Tup!(int, int) front() { return *new Tup!(int, int); } - ref Iter opSlice() { return this; } + ref Iter opSlice() return { return this; } } void test4() @@ -153,7 +153,7 @@ void test5() } /**********************************************/ -// 4617 +// https://issues.dlang.org/show_bug.cgi?id=4617 struct S4617 { @@ -215,7 +215,7 @@ void test4617b() } /**********************************************/ -// 4773 +// https://issues.dlang.org/show_bug.cgi?id=4773 void test4773() { @@ -233,7 +233,7 @@ void test4773() } /**********************************************/ -// 5188 +// https://issues.dlang.org/show_bug.cgi?id=5188 void test5188() { @@ -434,7 +434,7 @@ void test7() static assert(!__traits(compiles, { switch (c1) { default: } })); static assert(!__traits(compiles, { switch (c3) { default: } })); - // Bugzilla 12537: function arguments with IFTI + // https://issues.dlang.org/show_bug.cgi?id=12537: function arguments with IFTI void eq12537()(Object lhs) {} const C0 cc0; const C1 cc1; @@ -445,7 +445,8 @@ void test7() } /***************************************************/ -// 11875 - endless recursion in Type::deduceType +// https://issues.dlang.org/show_bug.cgi?id=11875 +// endless recursion in Type::deduceType struct T11875x(C) { @@ -467,7 +468,7 @@ class D11875c { T11875y!D11875b c; alias c this; } static assert(is(D11875c : T11875y!D, D) && is(D == D11875b)); /***************************************************/ -// 11930 +// https://issues.dlang.org/show_bug.cgi?id=11930 class BarObj11930 {} @@ -492,7 +493,7 @@ void test11930() } /***************************************************/ -// 2781 +// https://issues.dlang.org/show_bug.cgi?id=2781 struct Tuple2781a(T...) { T data; @@ -594,7 +595,7 @@ void test2781() } /**********************************************/ -// 6546 +// https://issues.dlang.org/show_bug.cgi?id=6546 void test6546() { @@ -643,7 +644,7 @@ void test6546() } /**********************************************/ -// 6736 +// https://issues.dlang.org/show_bug.cgi?id=6736 void test6736() { @@ -661,7 +662,7 @@ void test6736() } /**********************************************/ -// 2777 +// https://issues.dlang.org/show_bug.cgi?id=2777 struct ArrayWrapper(T) { T[] array; @@ -698,7 +699,7 @@ void test2777b() } /****************************************/ -// 2787 +// https://issues.dlang.org/show_bug.cgi?id=2787 struct Base2787 { @@ -715,7 +716,7 @@ struct Derived2787 } /***********************************/ -// 5679 +// https://issues.dlang.org/show_bug.cgi?id=5679 void test5679() { @@ -736,7 +737,7 @@ void test5679() } /***********************************/ -// 6508 +// https://issues.dlang.org/show_bug.cgi?id=6508 void test6508() { @@ -791,7 +792,7 @@ void test6508x() } /***********************************/ -// 6369 +// https://issues.dlang.org/show_bug.cgi?id=6369 void test6369a() { @@ -869,7 +870,7 @@ void test6369d() } /**********************************************/ -// 6434 +// https://issues.dlang.org/show_bug.cgi?id=6434 struct Variant6434{} @@ -890,7 +891,7 @@ void test6434() } /**************************************/ -// 6366 +// https://issues.dlang.org/show_bug.cgi?id=6366 void test6366() { @@ -965,7 +966,7 @@ void test6366() } /***************************************************/ -// 6711 +// https://issues.dlang.org/show_bug.cgi?id=6711 void test6711() { @@ -989,7 +990,7 @@ void test6711() } /**********************************************/ -// 12161 +// https://issues.dlang.org/show_bug.cgi?id=12161 class A12161 { @@ -1011,7 +1012,7 @@ void test12161() } /**********************************************/ -// 6759 +// https://issues.dlang.org/show_bug.cgi?id=6759 struct Range { @@ -1037,7 +1038,7 @@ void test6759() } /**********************************************/ -// 6479 +// https://issues.dlang.org/show_bug.cgi?id=6479 struct Memory6479 { @@ -1053,7 +1054,7 @@ mixin template Wrapper6479() } /**********************************************/ -// 6832 +// https://issues.dlang.org/show_bug.cgi?id=6832 void test6832() { @@ -1071,7 +1072,7 @@ void test6832() } /**********************************************/ -// 6928 +// https://issues.dlang.org/show_bug.cgi?id=6928 void test6928() { @@ -1094,7 +1095,7 @@ void test6928() } /**********************************************/ -// 6929 +// https://issues.dlang.org/show_bug.cgi?id=6929 struct S6929 { @@ -1114,7 +1115,7 @@ void test6929() } /***************************************************/ -// 7136 +// https://issues.dlang.org/show_bug.cgi?id=7136 void test7136() { @@ -1140,7 +1141,7 @@ void test7136() } /***************************************************/ -// 7731 +// https://issues.dlang.org/show_bug.cgi?id=7731 struct A7731 { @@ -1183,7 +1184,7 @@ void test7731() } /***************************************************/ -// 7808 +// https://issues.dlang.org/show_bug.cgi?id=7808 struct Nullable7808(T) { @@ -1213,7 +1214,7 @@ void test7808() } /***************************************************/ -// 7945 +// https://issues.dlang.org/show_bug.cgi?id=7945 struct S7945 { @@ -1232,7 +1233,8 @@ void test7945() } /***************************************************/ -// 15674 - alias this on out parameter, consistent with 7945 case +// https://issues.dlang.org/show_bug.cgi?id=15674 +// alias this on out parameter, consistent with 7945 case struct S15674 { @@ -1251,7 +1253,7 @@ void test15674() } /***************************************************/ -// 7979 +// https://issues.dlang.org/show_bug.cgi?id=7979 void test7979() { @@ -1291,7 +1293,7 @@ void test7979() } /***************************************************/ -// 7992 +// https://issues.dlang.org/show_bug.cgi?id=7992 struct S7992 { @@ -1314,7 +1316,7 @@ void test7992() } /***************************************************/ -// 8169 +// https://issues.dlang.org/show_bug.cgi?id=8169 void test8169() { @@ -1339,7 +1341,7 @@ void test8169() } /***************************************************/ -// 8735 +// https://issues.dlang.org/show_bug.cgi?id=8735 struct S8735(alias Arg) { @@ -1360,11 +1362,11 @@ void test8735() int n = s; assert(n == 1); - // 11502 case + // https://issues.dlang.org/show_bug.cgi?id=11502 static void f(int i); S8735!f sf; - // 9709 case + // https://issues.dlang.org/show_bug.cgi?id=9709 alias A = Tuple9709!(1,int,"foo"); A a; //static assert(A[0] == 1); @@ -1376,7 +1378,7 @@ void test8735() } /***************************************************/ -// 9174 +// https://issues.dlang.org/show_bug.cgi?id=9174 void test9174() { @@ -1390,7 +1392,7 @@ void test9174() } /***************************************************/ -// 9177 +// https://issues.dlang.org/show_bug.cgi?id=9177 struct S9177 { @@ -1400,7 +1402,7 @@ struct S9177 pragma(msg, is(S9177 : int)); /***************************************************/ -// 9858 +// https://issues.dlang.org/show_bug.cgi?id=9858 struct S9858() { @@ -1418,7 +1420,7 @@ void test9858() } /***************************************************/ -// 9873 +// https://issues.dlang.org/show_bug.cgi?id=9873 void test9873() { @@ -1453,7 +1455,7 @@ void test9873() } /***************************************************/ -// 10178 +// https://issues.dlang.org/show_bug.cgi?id=10178 void test10178() { @@ -1473,7 +1475,7 @@ void test10178() } /***************************************************/ -// 10179 +// https://issues.dlang.org/show_bug.cgi?id=10179 void test10179() { @@ -1493,7 +1495,7 @@ void test10179() } /***************************************************/ -// 9890 +// https://issues.dlang.org/show_bug.cgi?id=9890 void test9890() { @@ -1519,7 +1521,7 @@ void test9890() } /***************************************************/ -// 10004 +// https://issues.dlang.org/show_bug.cgi?id=10004 void test10004() { @@ -1541,7 +1543,7 @@ void test10004() } /***************************************************/ -// 10180 +// https://issues.dlang.org/show_bug.cgi?id=10180 template TypeTuple10180(TL...) { alias TypeTuple10180 = TL; } @@ -1580,7 +1582,7 @@ void test10180() } /***************************************************/ -// 10456 +// https://issues.dlang.org/show_bug.cgi?id=10456 void test10456() { @@ -1596,7 +1598,7 @@ struct S10456 } /***************************************************/ -// 11261 +// https://issues.dlang.org/show_bug.cgi?id=11261 template Tuple11261(Specs...) { @@ -1686,7 +1688,7 @@ void test11261() } /***************************************************/ -// 11333 +// https://issues.dlang.org/show_bug.cgi?id=11333 alias id11333(a...) = a; @@ -1712,7 +1714,22 @@ void test11333() } /***************************************************/ -// 11800 +// https://issues.dlang.org/show_bug.cgi?id=11538 + +struct NullableRef11538(T) +{ + T* _value; + inout(T) get() inout { return *_value; } + alias get this; +} + +struct S11538 +{ + NullableRef11538!S11538 parent; +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=11800 struct A11800 { @@ -1739,7 +1756,7 @@ void test11800() } /***************************************************/ -// 12008 +// https://issues.dlang.org/show_bug.cgi?id=12008 struct RefCounted12008(T) { @@ -1792,7 +1809,7 @@ struct Group12008 } /***************************************************/ -// 12038 +// https://issues.dlang.org/show_bug.cgi?id=12038 bool f12038(void* p) { return true; } @@ -1803,7 +1820,7 @@ struct S12038 } /***************************************************/ -// 13490 +// https://issues.dlang.org/show_bug.cgi?id=13490 struct S13490 { @@ -1830,7 +1847,7 @@ void test13490() } /***************************************************/ -// 11355 +// https://issues.dlang.org/show_bug.cgi?id=11355 struct A11355 { @@ -1855,7 +1872,7 @@ void test11355() } /***************************************************/ -// 13009 +// https://issues.dlang.org/show_bug.cgi?id=13009 struct T13009 { @@ -1909,7 +1926,7 @@ void test13009() } /***************************************************/ -// 14806 +// https://issues.dlang.org/show_bug.cgi?id=14806 struct Nullable14806 { @@ -1926,18 +1943,18 @@ struct Foo14806(T) void test14806() { Foo14806!int a, b; - assert(a != b); + assert(a == b); // ==> a.tupleof != b.tupleof // ==> a.bar != b.bar || a.baz.get() != b.baz.get() Foo14806!string c, d; - assert(c != d); + assert(c == d); // ==> c.tupleof != d.tupleof // ==> c.bar != d.bar || c.baz.get() != d.baz.get() } /***************************************************/ -// 14948 +// https://issues.dlang.org/show_bug.cgi?id=14948 struct RefCounted14948(T) { @@ -1967,7 +1984,7 @@ void test14948() } /***************************************************/ -// 15292 +// https://issues.dlang.org/show_bug.cgi?id=15292 struct NullableRef15292(T) { @@ -1998,6 +2015,93 @@ struct S15292 /***************************************************/ +struct S19284a { int x; } +struct S19284b +{ + S19284a s; + alias s this; + int t; + void f() + { + void wrapped() + { + x = 1; + t = 1; + } + wrapped(); // <-- 'x' not found, whereas 's.x' works fine + } + + void f1() + { + x = 2; + } + + void f2() + { + int x; + void wrapped() + { + x = 7; + } + wrapped(); + assert(x == 7); + } + + void f3() + { + void wrapped() + { + void wrapped2() + { + x = 5; + } + wrapped2(); + } + wrapped(); + } +} + +void test19284() +{ + S19284b t; + + // nested function modifies alias this + t.f(); + assert(t.x == 1); + assert(t.t == 1); + + // member function modifies alias this + t.f1(); + assert(t.x == 2); + + // nested function does not modify alias this when it is shadowd by a local variable + t.f2(); + assert(t.x == 2); + + // multiple levels of nesting + t.f3(); + assert(t.x == 5); +} + +// 16633 + +class Item +{ + alias children this; + Item[] children; + void populate() + { + children ~= new Item(); // Item is seen as [] + assert(children.length == 1); + } +} + +void test16633() +{ + Item root = new Item(); + root.populate; +} + int main() { test1(); @@ -2054,6 +2158,8 @@ int main() test13490(); test11355(); test14806(); + test19284(); + test16633(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/arrayop.d b/gcc/testsuite/gdc.test/runnable/arrayop.d index 8c6b083fd30..4c0836a96dc 100644 --- a/gcc/testsuite/gdc.test/runnable/arrayop.d +++ b/gcc/testsuite/gdc.test/runnable/arrayop.d @@ -48,28 +48,28 @@ template Floating(T) abc = null; A()[] = B()[] + C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); assert(a[0] == 5); assert(a[1] == 7); assert(a[2] == 9); abc = null; A()[] = B()[] + 4; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = 4 + B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = D() + B()[]; - assert(abc == "DBA"); + assert(abc == "ADB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); @@ -77,7 +77,7 @@ template Floating(T) a = [11, 22, 33]; abc = null; A()[] += B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 12); assert(a[1] == 24); assert(a[2] == 36); @@ -115,14 +115,14 @@ template Floating(T) a = [11, 22, 33]; abc = null; A()[] += 4 + B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 16); assert(a[1] == 28); assert(a[2] == 40); abc = null; A()[] = B()[] - C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == -3); assert(a[1] == -3); @@ -130,7 +130,7 @@ template Floating(T) abc = null; A()[] = -B()[] - C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == -5); assert(a[1] == -7); @@ -138,7 +138,7 @@ template Floating(T) abc = null; A()[] = B()[] + C()[] * 4; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 17); assert(a[1] == 22); @@ -146,7 +146,7 @@ template Floating(T) abc = null; A()[] = B()[] + C()[] * B()[]; - assert(abc == "BCBA"); + assert(abc == "ABCB"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 5); assert(a[1] == 12); @@ -154,7 +154,7 @@ template Floating(T) abc = null; A()[] = B()[] + C()[] / 2; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 3); assert(a[1] == 4.5); @@ -162,7 +162,7 @@ template Floating(T) abc = null; A()[] = B()[] + C()[] % 2; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 1); assert(a[1] == 3); @@ -226,28 +226,28 @@ template Integral(T) abc = null; A()[] = B()[] + C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); assert(a[0] == 5); assert(a[1] == 7); assert(a[2] == 9); abc = null; A()[] = B()[] + 4; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = 4 + B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = D() + B()[]; - assert(abc == "DBA"); + assert(abc == "ADB"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); @@ -255,7 +255,7 @@ template Integral(T) a = [11, 22, 33]; abc = null; A()[] += B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 12); assert(a[1] == 24); assert(a[2] == 36); @@ -311,14 +311,14 @@ template Integral(T) a = [11, 22, 33]; abc = null; A()[] += 4 + B()[]; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 16); assert(a[1] == 28); assert(a[2] == 40); abc = null; A()[] = B()[] - C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == -3); assert(a[1] == -3); @@ -326,7 +326,7 @@ template Integral(T) abc = null; A()[] = -B()[] - C()[]; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == -5); assert(a[1] == -7); @@ -334,7 +334,7 @@ template Integral(T) abc = null; A()[] = B()[] + C()[] * 4; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 17); assert(a[1] == 22); @@ -342,7 +342,7 @@ template Integral(T) abc = null; A()[] = B()[] + C()[] * B()[]; - assert(abc == "BCBA"); + assert(abc == "ABCB"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 5); assert(a[1] == 12); @@ -350,7 +350,7 @@ template Integral(T) abc = null; A()[] = B()[] + C()[] / 2; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 3); assert(a[1] == 4); @@ -358,7 +358,7 @@ template Integral(T) abc = null; A()[] = B()[] + C()[] % 2; - assert(abc == "BCA"); + assert(abc == "ABC"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 1); assert(a[1] == 3); @@ -366,28 +366,28 @@ template Integral(T) abc = null; A()[] = ~B()[]; - assert(abc == "BA"); - assert(a[0] == ~cast(T)1); - assert(a[1] == ~cast(T)2); - assert(a[2] == ~cast(T)3); + assert(abc == "AB"); + assert(a[0] == cast(T) ~1); + assert(a[1] == cast(T) ~2); + assert(a[2] == cast(T) ~3); abc = null; A()[] = B()[] & 2; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 0); assert(a[1] == 2); assert(a[2] == 2); abc = null; A()[] = B()[] | 2; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 3); assert(a[1] == 2); assert(a[2] == 3); abc = null; A()[] = B()[] ^ 2; - assert(abc == "BA"); + assert(abc == "AB"); assert(a[0] == 3); assert(a[1] == 0); assert(a[2] == 1); @@ -439,7 +439,7 @@ void test4662() } /***************************************************/ -// 5284 +// https://issues.dlang.org/show_bug.cgi?id=5284 void bug5284_1() { @@ -550,7 +550,7 @@ void test8390() { } /************************************************************************/ -// 8651 +// https://issues.dlang.org/show_bug.cgi?id=8651 void test8651() { @@ -605,7 +605,7 @@ void test8651() } /************************************************************************/ -// 9656 +// https://issues.dlang.org/show_bug.cgi?id=9656 void test9656() { @@ -628,14 +628,14 @@ void test9656() { int[] ma = [1,2,3]; - immutable ia = ma.dup; + immutable ia = ma.idup; } { static struct V { int val; } V[] ma = [V(1), V(2)]; - immutable ia = ma.dup; + immutable ia = ma.idup; } { @@ -651,7 +651,7 @@ void test9656() } /************************************************************************/ -// 10282 +// https://issues.dlang.org/show_bug.cgi?id=10282 void test10282() { @@ -669,7 +669,7 @@ void test10282() } /************************************************************************/ -// 10433 +// https://issues.dlang.org/show_bug.cgi?id=10433 void test10433() { @@ -684,7 +684,7 @@ void test10433() } /************************************************************************/ -// 10684 +// https://issues.dlang.org/show_bug.cgi?id=10684 void test10684a() { @@ -716,7 +716,7 @@ void test10684b() } /************************************************************************/ -// 11376 +// https://issues.dlang.org/show_bug.cgi?id=11376 template TL11376(T...) { @@ -732,7 +732,7 @@ auto sumArrs11376(T0, T1)(T0[] a, T1[] b) static assert(!__traits(compiles, sumArrs11376(TL11376!(string[], string).init))); /************************************************************************/ -// 11525 +// https://issues.dlang.org/show_bug.cgi?id=11525 void test11525() { @@ -756,7 +756,7 @@ void test11525() } /************************************************************************/ -// 12250 +// https://issues.dlang.org/show_bug.cgi?id=12250 void f12250(inout int[] p, inout int[] q, int[] r) { @@ -774,7 +774,7 @@ void test12250() } /************************************************************************/ -// 12179 +// https://issues.dlang.org/show_bug.cgi?id=12179 void test12179() { @@ -792,7 +792,7 @@ void test12179() foo(a[] |= a[]); foo(a[] ^^= a[]); - // from issue 11992 + // from https://issues.dlang.org/show_bug.cgi?id=11992 int[] arr1; int[][] arr2; arr1 ~= (a[] = [1] + a[]); // OK @@ -800,7 +800,7 @@ void test12179() } /************************************************************************/ -// 12780 +// https://issues.dlang.org/show_bug.cgi?id=12780 void test12780() { @@ -854,7 +854,7 @@ void test12780() } /************************************************************************/ -// 13497 +// https://issues.dlang.org/show_bug.cgi?id=13497 void test13497() { @@ -866,7 +866,7 @@ void test13497() } /************************************************************************/ -// 14649 +// https://issues.dlang.org/show_bug.cgi?id=14649 void test14649() { @@ -891,7 +891,7 @@ void test14649() } /************************************************************************/ -// 14851 +// https://issues.dlang.org/show_bug.cgi?id=14851 void test14851() { diff --git a/gcc/testsuite/gdc.test/runnable/auto1.d b/gcc/testsuite/gdc.test/runnable/auto1.d index e68b06380ef..ea023836bf2 100644 --- a/gcc/testsuite/gdc.test/runnable/auto1.d +++ b/gcc/testsuite/gdc.test/runnable/auto1.d @@ -1,3 +1,16 @@ +/* +RUN_OUTPUT: +--- +Foo.~this() +Foo.~this() +Foo.~this() +Foo.~this() +A2.this() +Hello world. +A2.~this() +Success +--- +*/ import core.stdc.stdio; diff --git a/gcc/testsuite/gdc.test/runnable/b10562.d b/gcc/testsuite/gdc.test/runnable/b10562.d new file mode 100644 index 00000000000..cf79d164461 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b10562.d @@ -0,0 +1,93 @@ +void main() +{ + { + int[3] ok = 3; + assert(ok == [ 3, 3, 3]); + + ok = 1; + assert(ok == [ 1, 1, 1]); + + int[][] da2; + assert(da2 == []); + } + { + int[3][2] a; + assert(a == [ [ 0, 0, 0 ], [ 0, 0, 0 ] ]); + + int[3][2] b = 4; + assert(b == [ [ 4, 4, 4 ], [ 4, 4, 4 ] ]); + + // b = 9; + // assert(b == [ [ 9, 9, 9 ], [ 9, 9, 9 ] ]); + + int[3][2] c = [ 1, 2, 3 ]; + assert(c == [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]); + + c = [ 5, 6, 7 ]; + assert(c == [ [ 5, 6, 7 ], [ 5, 6, 7 ] ]); + + int[3][2] d = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + assert(d == [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]); + } + { + int[3][2][4] a; + assert(a == [ [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ] ]); + + // a = 1; + // assert(a == [ [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], + // [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], + // [ [ 1, 1, 1 ], [ 1, 1, 1 ] ], + // [ [ 1, 1, 1 ], [ 1, 1, 1 ] ] ]); + + int[3][2][4] b = [ 1, 2, 3 ]; + assert(b == [ [ [ 1, 2, 3 ], [ 1, 2, 3 ] ], + [ [ 1, 2, 3 ], [ 1, 2, 3 ] ], + [ [ 1, 2, 3 ], [ 1, 2, 3 ] ], + [ [ 1, 2, 3 ], [ 1, 2, 3 ] ] ]); + + // b = [ 4, 5, 6]; + // assert(b == [ [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + // [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + // [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + // [ [ 4, 5, 6 ], [ 4, 5, 6 ] ] ]); + + int[3][2][4] c = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + assert(c == [ [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ]); + + c = [ [ 4, 5, 6 ], [ 7, 8, 9 ] ]; + assert(c == [ [ [ 4, 5, 6 ], [ 7, 8, 9 ] ], + [ [ 4, 5, 6 ], [ 7, 8, 9 ] ], + [ [ 4, 5, 6 ], [ 7, 8, 9 ] ], + [ [ 4, 5, 6 ], [ 7, 8, 9 ] ] ]); + } + { + int[3] val = [4, 5, 6]; + int[3][2][4] a = val[]; + + assert(a == [ [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + [ [ 4, 5, 6 ], [ 4, 5, 6 ] ], + [ [ 4, 5, 6 ], [ 4, 5, 6 ] ] ]); + } + { + // https://issues.dlang.org/show_bug.cgi?id=10562 + int[3] value = [ 1, 2, 3 ]; + int[3][2] a = value; // <-- COMPILATION ERROR + assert(a == [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]); + } + { + // https://issues.dlang.org/show_bug.cgi?id=20465 + int[][3][2] arr; + assert(arr == [[ null, null, null ], [ null, null, null ]]); + + // int[] slice = [ 1 ]; + // arr = slice; + // assert(arr == [[ slice, slice, slice ], [ slice, slice, slice ]]); + } +} diff --git a/gcc/testsuite/gdc.test/runnable/b16360.d b/gcc/testsuite/gdc.test/runnable/b16360.d new file mode 100644 index 00000000000..50c28e6d7c9 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b16360.d @@ -0,0 +1,50 @@ +// REQUIRED_ARGS: -inline + +pragma(inline, true) +auto foo() +{ + static struct U + { + int a = 42; + float b; + } + U u; + return u.a; +} + +pragma(inline, true) +T bitCast(T, S)(auto ref S s) +{ + union BitCaster + { + S ss; + T tt; + } + BitCaster bt; + bt.ss = s; + return bt.tt; +} + +pragma(inline, true) +int withFuncCalls() +{ + static struct WithFuncCalls + { + int v; + pragma(inline, true) + int call(){return v;} + pragma(inline, true) + void otherCall(){v++;} + } + auto bt = WithFuncCalls(50); + bt.v += -9; + bt.otherCall(); + return bt.call(); +} + +void main() +{ + assert(foo == 42); + assert(bitCast!int(1.0f) == 0x3f800000); + assert(withFuncCalls() == 42); +} diff --git a/gcc/testsuite/gdc.test/runnable/b18034.d b/gcc/testsuite/gdc.test/runnable/b18034.d new file mode 100644 index 00000000000..3981aafdbc4 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b18034.d @@ -0,0 +1,28 @@ +// REQUIRED_ARGS: -O +import core.simd; + +static if (__traits(compiles, { void16 a; ushort8 b; })) +{ + void check(void16 a) + { + foreach (x; (cast(ushort8)a).array) + { + assert(x == 1); + } + } + + void make(ushort x) + { + ushort8 v = ushort8(x); + check(v); + } + + void main() + { + make(1); + } +} +else +{ + void main() { } +} diff --git a/gcc/testsuite/gdc.test/runnable/b19584.d b/gcc/testsuite/gdc.test/runnable/b19584.d new file mode 100644 index 00000000000..8eb790e0370 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b19584.d @@ -0,0 +1,13 @@ +/* +REQUIRED_ARGS: -O +*/ +void main() +{ + int a = 711; + assert(182215 == (a | (a << 8))); + assert(182727 == (a * (1 + (1 << 8)))); + + int b = 31; + assert(511 == (b | (b << 4))); + assert(527 == (b * (1 + (1 << 4)))); +} diff --git a/gcc/testsuite/gdc.test/runnable/b20470.d b/gcc/testsuite/gdc.test/runnable/b20470.d new file mode 100644 index 00000000000..73d8d10ff04 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b20470.d @@ -0,0 +1,97 @@ +// https://issues.dlang.org/show_bug.cgi?id=20470 + +alias AliasSeq(Args...) = Args; + +int g, h; + +void test0() +{ + static struct S + { + int a, b; + float c = 0, d = 0; + alias fields = AliasSeq!(a, b, c, d); + alias ints = AliasSeq!(a, b); + alias floats = AliasSeq!(c, d); + alias reversed = AliasSeq!(d, c, b, a); + alias globals = AliasSeq!(g, h); + + alias properties = AliasSeq!(e, f); + @property int e() { return a; } + @property void e(int i) { a = i; } + @property float f() { return c; } + @property void f(float j) { c = j; } + } + + S s; + assert(s.fields == AliasSeq!(0, 0, 0, 0)); + s.ints = AliasSeq!(1, 2); + assert(s.fields == AliasSeq!(1, 2, 0, 0)); + s.floats = AliasSeq!(3, 4); + assert(s.fields == AliasSeq!(1, 2, 3, 4)); + + int a, b; + float c, d; + AliasSeq!(d, c, b, a) = s.reversed; + assert(AliasSeq!(a, b, c, d) == AliasSeq!(1, 2, 3, 4)); + + s.globals = AliasSeq!(30, 40); + assert(g == 30 && h == 40); + + // Propagating `this` to functions and properties within tuples will be a breaking change. + // See `test2()` below for an example of existing code that would need to be fixed. + + //s.properties = AliasSeq!(11, 12); + //assert(s.e == 11 && s.f == 12); +} + +class Nested(Vars...) +{ + int a, b; + alias outervars = Vars; + alias fields = AliasSeq!(a, b); + alias all = AliasSeq!(a, b, Vars); +} + +auto makeNested() +{ + static class C + { + bool b; + double d; + auto nested() { return new Nested!(b, d)(); } + } + return new C().nested(); +} + +void test1() +{ + auto n = makeNested(); + n.fields = AliasSeq!(1, 2); + n.outervars = AliasSeq!(true, 1.3); + assert(n.all == AliasSeq!(1, 2, true, 1.3)); +} + +void test2() +{ + // backwards compatibility test for functions within tuples + + static struct S + { + void f(); + void g(); + alias funcs = AliasSeq!(f, g); + } + + S s; + alias voidTf = void(); + foreach (f; s.funcs) + static assert(is(typeof(f) == voidTf)); +} + +void main() +{ + test0(); + test1(); + test2(); +} diff --git a/gcc/testsuite/gdc.test/runnable/b20890.d b/gcc/testsuite/gdc.test/runnable/b20890.d new file mode 100644 index 00000000000..9b208da3f77 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b20890.d @@ -0,0 +1,48 @@ +module b20890; +// https://issues.dlang.org/show_bug.cgi?id=20890 + +struct S0 { } +void format0(string spec, S0[1] s) +{ + assert (spec == "lengthy"); +} +struct S1 { ubyte m = 42; } +void format1(string spec, S1[1] s) +{ + assert (spec == "lengthy"); + assert (s[0].m == 42); +} +struct S2 { ushort m = 42; } +void format2(string spec, S2[1] s) +{ + assert (spec == "lengthy"); + assert (s[0].m == 42); +} +struct S4 { uint m = 42; } +void format4(string spec, S4[1] s) +{ + assert (spec == "lengthy"); + assert (s[0].m == 42); +} +struct S8 { ulong m = 42; } +void format8(string spec, S8[1] s) +{ + assert (spec == "lengthy"); + assert (s[0].m == 42); +} +struct S42 { ubyte[42] m = [42]; } +void format42(string spec, S42[1] s) +{ + assert (spec == "lengthy"); + assert (s[0].m[0] == 42); +} + +void main() +{ + { S0[1] s; format0("lengthy", s); } + { S1[1] s; format1("lengthy", s); } + { S2[1] s; format2("lengthy", s); } + { S4[1] s; format4("lengthy", s); } + { S8[1] s; format8("lengthy", s); } + {S42[1] s;format42("lengthy", s); } +} diff --git a/gcc/testsuite/gdc.test/runnable/b26.d b/gcc/testsuite/gdc.test/runnable/b26.d index e32533b2b48..54e28daaa26 100644 --- a/gcc/testsuite/gdc.test/runnable/b26.d +++ b/gcc/testsuite/gdc.test/runnable/b26.d @@ -2,7 +2,7 @@ // EXTRA_SOURCES: imports/b26a.d // PERMUTE_ARGS: -// 382 +// https://issues.dlang.org/show_bug.cgi?id=382 struct List(T) { interface A {} diff --git a/gcc/testsuite/gdc.test/runnable/b6400.d b/gcc/testsuite/gdc.test/runnable/b6400.d new file mode 100644 index 00000000000..8b1018400f2 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/b6400.d @@ -0,0 +1,69 @@ +/* TEST_OUTPUT: +--- +Foo +Bar +Foo +Bar +Bar +Foo +Bar +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=6400 + +enum int base(string name) = 10 * (name[$-1] - '0'); +struct Foo { int opDispatch(string name)() { pragma(msg, "Foo"); return base!name + 1; } } +struct Bar { int opDispatch(string name)() { pragma(msg, "Bar"); return base!name + 2; } } +struct Baz { } + +void main() +{ + assert(test()); + static assert(test()); +} + +bool test() +{ + auto foo = new Foo; + auto bar = new Bar; + auto baz = new Baz; + + with (foo) + { + assert(f1() == 11); + with (baz) assert(f1() == 11); + with (bar) + { + assert(f2() == 22); + with (baz) assert(f2() == 22); + with (foo) + { + assert(f3() == 31); + with (baz) assert(f3() == 31); + with (bar) + { + assert(f4() == 42); + with (baz) assert(f4() == 42); + with (baz) + { + assert(f5() == 52); + with (baz) assert(f5() == 52); + } + with (foo) + { + assert(f6() == 61); + with (baz) assert(f6() == 61); + } + with (bar) + { + assert(f7() == 72); + with (baz) assert(f7() == 72); + } + } + } + } + } + + return true; +} diff --git a/gcc/testsuite/gdc.test/runnable/bench1.d b/gcc/testsuite/gdc.test/runnable/bench1.d index 74b24a4c6c1..d19ba9a9262 100644 --- a/gcc/testsuite/gdc.test/runnable/bench1.d +++ b/gcc/testsuite/gdc.test/runnable/bench1.d @@ -1,5 +1,12 @@ -// REQUIRED_ARGS: -// EXECUTE_ARGS: 10000 +/* +REQUIRED_ARGS: +EXECUTE_ARGS: 10000 +RUN_OUTPUT: +--- +count = 10000 +70000 +--- +*/ extern(C) int printf(const char *, ...); extern(C) int atoi(const char *); @@ -18,7 +25,7 @@ extern(C) int atoi(const char *); s ~= "hello\n"; for (loop = 0; loop < count; loop ++) s ~= "h"; - printf ("%d\n", s.length); + printf ("%llu\n", cast(ulong) s.length); //printf("%.*s\n", s[0..100]); assert(s.length == count * (6 + 1)); s.length = 3; @@ -27,4 +34,3 @@ extern(C) int atoi(const char *); s.length = 1000; return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/betterc.d b/gcc/testsuite/gdc.test/runnable/betterc.d new file mode 100644 index 00000000000..0da798bf119 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/betterc.d @@ -0,0 +1,202 @@ +/* REQUIRED_ARGS: -betterC + PERMUTE_ARGS: + */ + + +void test(int ij) +{ + assert(ij); +#line 100 "anotherfile" + assert(ij,"it is not zero"); +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18010 + +void test1() +{ + int[10] a1 = void; + int[10] a2 = void; + a1[] = a2[]; +} + +void test2(int[] a1, int[] a2) +{ + a1[] = a2[]; +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17843 + +struct S +{ + double d = 0.0; + int[] x; +} + +/*******************************************/ + +extern (C) void main() +{ + test(1); + test18472(); + testRuntimeLowerings(); + test18457(); +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17605 + +extern (C) void test17605() +{ + int a; + enum bool works = __traits(compiles, { a = 1; }); + a = 1; +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18472 + +void test18472() +{ + version(D_LP64) + { + enum b = typeid(size_t) is typeid(ulong); + } + else + { + enum b = typeid(size_t) is typeid(uint); + } + + assert(b); +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18493 + +struct S18493 +{ + this(this) nothrow { } // Since this is attributed with `nothrow` there should be no error about using + // try-catch with -betterC + ~this() { } +} + +struct S18493_2 +{ + S18493 s1; + S18493 s2; +} + +/****************************************************** + * tests to ensure there is sufficient runtime support + * in imported object.d + */ +mixin template initArray() +{ + static if (is(T == bool)) + { + T[6] a1 = [true, false, true, true, false, true]; + } + else static if (is(T == Sint)) + { + T[6] a1 = [Sint(1), Sint(2), Sint(3), Sint(1), Sint(2), Sint(3)]; + } + else + { + T[6] a1 = [1,2,3,1,2,3]; + } +} + +struct Sint +{ + int x; + this(int v) { x = v;} +} + +void testRuntimeLowerings() +{ + // test call to `object.__equals` + void test__equals(T)() + { + mixin initArray; + + assert(a1[0..3] == a1[3..$]); + } + + test__equals!int; + test__equals!uint; + test__equals!long; + test__equals!ulong; + test__equals!short; + test__equals!ushort; + test__equals!byte; + test__equals!dchar; + test__equals!wchar; + test__equals!ubyte; + test__equals!char; + test__equals!(const char); + test__equals!bool; + test__equals!Sint; + + // test call to `object.__cmp` + void test__cmp(T)() + { + mixin initArray; + + assert(a1[0..3] >= a1[3..$]); + assert(a1[0..3] <= a1[3..$]); + } + + test__cmp!int; + test__cmp!uint; + test__cmp!long; + test__cmp!ulong; + test__cmp!short; + test__cmp!ushort; + test__cmp!byte; + test__cmp!dchar; + test__cmp!wchar; + test__cmp!ubyte; + test__cmp!char; + test__cmp!(const char); + test__cmp!bool; + test__cmp!Sint; + + // test call to `object.__switch`` + auto s = "abc"; + switch(s) + { + case "abc": + break; + default: + break; + } +} + +/**********************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18457 + +__gshared int dtor; + +struct S18457 +{ + int a = 3; + ~this() { a = 0; ++dtor; } +} + +S18457 myFunction() +{ + S18457 s = S18457(); + return s; +} + +void test18457() +{ + { + S18457 s = myFunction(); + assert(s.a == 3); + assert(dtor == 0); + } + assert(dtor == 1); +} + diff --git a/gcc/testsuite/gdc.test/runnable/bettercUnittest.d b/gcc/testsuite/gdc.test/runnable/bettercUnittest.d new file mode 100644 index 00000000000..ace2c1422db --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/bettercUnittest.d @@ -0,0 +1,38 @@ +/* +REQUIRED_ARGS: -betterC -unittest +PERMUTE_ARGS: +EXTRA_SOURCES: extra-files/moreBettercUnittests.d +*/ + +import moreBettercUnittests; + +unittest +{ + sum |= 0x1; +} + +unittest +{ + sum |= 0x10; +} + +extern (C) int main() +{ + uint count; + + static foreach (alias unit; __traits(getUnitTests, bettercUnittest)) + { + unit(); + count++; + } + + static foreach (alias unit; __traits(getUnitTests, moreBettercUnittests)) + { + unit(); + count++; + } + + assert(count == 4); + assert(sum == 0x1111); + return sum == 0x1111 ? 0 : 1; +} diff --git a/gcc/testsuite/gdc.test/runnable/bitops.d b/gcc/testsuite/gdc.test/runnable/bitops.d index eb51f0f475f..28a18c4a767 100644 --- a/gcc/testsuite/gdc.test/runnable/bitops.d +++ b/gcc/testsuite/gdc.test/runnable/bitops.d @@ -7,7 +7,7 @@ import core.bitop; void test1() { - size_t array[2]; + size_t[2] array; uint x; version (D_LP64) size_t bitToUse = 67; @@ -16,35 +16,35 @@ else array[0] = 2; array[1] = 0x100; - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); x = btc(array.ptr, bitToUse); - printf("btc(array, %d) = %d\n", bitToUse, x); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("btc(array, %zd) = %d\n", bitToUse, x); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); assert(x == 0); assert(array[0] == 0x2 && array[1] == 0x108); x = btc(array.ptr, bitToUse); - printf("btc(array, %d) = %d\n", bitToUse, x); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("btc(array, %zd) = %d\n", bitToUse, x); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); x = bts(array.ptr, bitToUse); - printf("bts(array, %d) = %d\n", bitToUse, x); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("bts(array, %zd) = %d\n", bitToUse, x); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); assert(x == 0); assert(array[0] == 2 && array[1] == 0x108); x = btr(array.ptr, bitToUse); - printf("btr(array, %d) = %d\n", bitToUse, x); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("btr(array, %zd) = %d\n", bitToUse, x); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); x = bt(array.ptr, 1); printf("bt(array, 1) = %d\n", x); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); } @@ -69,17 +69,19 @@ void test2() /*****************************************************/ version (DigitalMars) -void test3() -{ uint v; - int b; - - b = inp(b); - b = inpw(b); - b = inpl(b); - - b = outp(v, cast(ubyte)b); - b = outpw(v, cast(ushort)b); - b = outpl(v, b); +{ + void test3() + { uint v; + int b; + + b = inp(b); + b = inpw(b); + b = inpl(b); + + b = outp(v, cast(ubyte)b); + b = outpw(v, cast(ushort)b); + b = outpl(v, b); + } } /*****************************************************/ @@ -95,25 +97,25 @@ void test4() void test5() { - size_t array[2]; + size_t[2] array; array[0] = 2; array[1] = 0x100; printf("btc(array, 35) = %d\n", btc(array.ptr, 35)); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); printf("btc(array, 35) = %d\n", btc(array.ptr, 35)); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); printf("bts(array, 35) = %d\n", bts(array.ptr, 35)); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); printf("btr(array, 35) = %d\n", btr(array.ptr, 35)); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); printf("bt(array, 1) = %d\n", bt(array.ptr, 1)); - printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); + printf("array = [0]:x%zx, [1]:x%zx\n", array[0], array[1]); } diff --git a/gcc/testsuite/gdc.test/runnable/bug11155.d b/gcc/testsuite/gdc.test/runnable/bug11155.d index afe4208ebaf..b346ce2ca48 100644 --- a/gcc/testsuite/gdc.test/runnable/bug11155.d +++ b/gcc/testsuite/gdc.test/runnable/bug11155.d @@ -1,6 +1,6 @@ // PERMUTE_ARGS: -version(D_SIMD) +static if (__traits(compiles, __vector(float[4]))) { alias float4 = __vector(float[4]); diff --git a/gcc/testsuite/gdc.test/runnable/bug19652.d b/gcc/testsuite/gdc.test/runnable/bug19652.d new file mode 100644 index 00000000000..e922b5926a4 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/bug19652.d @@ -0,0 +1,22 @@ + +struct Base { + int i; +} + +struct A { + Base base; + alias base this; +} + +struct B { + A a; + alias a this; +} + +auto otherTest(inout ref Base block) @nogc { assert(0); } +auto otherTest(inout ref A block) @nogc {} + +void main() { + B* thingie; + otherTest(*thingie); +} diff --git a/gcc/testsuite/gdc.test/runnable/bug7068.d b/gcc/testsuite/gdc.test/runnable/bug7068.d index 70e351e8154..75ea5bf2b8d 100644 --- a/gcc/testsuite/gdc.test/runnable/bug7068.d +++ b/gcc/testsuite/gdc.test/runnable/bug7068.d @@ -1,4 +1,5 @@ -// PERMUTE_ARGS: -inline -g -O -d +// REQUIRED_ARGS: -d +// PERMUTE_ARGS: -inline -g -O void main() { auto darray1 = new int*[](10); diff --git a/gcc/testsuite/gdc.test/runnable/builtin.d b/gcc/testsuite/gdc.test/runnable/builtin.d index 44817b16ee0..a7f09a378d6 100644 --- a/gcc/testsuite/gdc.test/runnable/builtin.d +++ b/gcc/testsuite/gdc.test/runnable/builtin.d @@ -1,7 +1,5 @@ // RUNNABLE_PHOBOS_TEST - -import std.stdio; -import std.math; +import core.math; import core.bitop; version (DigitalMars) @@ -12,30 +10,31 @@ version (DigitalMars) version = AnyX86; } +bool isClose(real lhs, real rhs, real maxRelDiff = 1e-09L, real maxAbsDiff = 0.0) +{ + if (lhs == rhs) + return true; + if (lhs == lhs.infinity || rhs == rhs.infinity || + lhs == -lhs.infinity || rhs == -rhs.infinity) + return false; + + auto diff = fabs(lhs - rhs); + return diff <= maxRelDiff*fabs(lhs) + || diff <= maxRelDiff*fabs(rhs) + || diff <= maxAbsDiff; +} + /*******************************************/ void test1() { - writefln("%a", sin(6.8L)); auto f = 6.8L; - writefln("%a", sin(f)); assert(sin(f) == sin(6.8L)); - static assert(approxEqual(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2)); + static assert(isClose(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2)); - writefln("%a", cos(6.8L)); f = 6.8L; - writefln("%a", cos(f)); assert(cos(f) == cos(6.8L)); - static assert(approxEqual(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1)); - - writefln("%a", tan(6.8L)); - f = 6.8L; - writefln("%a", tan(f)); - version (Win64) - { } - else - assert(tan(f) == tan(6.8L)); - static assert(approxEqual(tan(6.8L), 0x1.22fd752af75cd08cp-1)); + static assert(isClose(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1)); } /*******************************************/ @@ -55,7 +54,7 @@ void test2() assert(i == 2); } -/**** Bug 5703 *****************************/ +/**** https://issues.dlang.org/show_bug.cgi?id=5703 ****/ static assert({ int a = 0x80; @@ -113,7 +112,5 @@ int main() test1(); test2(); test3(); - - printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/cassert.d b/gcc/testsuite/gdc.test/runnable/cassert.d deleted file mode 100644 index 8c767508495..00000000000 --- a/gcc/testsuite/gdc.test/runnable/cassert.d +++ /dev/null @@ -1,17 +0,0 @@ -/* REQUIRED_ARGS: -betterC - PERMUTE_ARGS: - */ - - -void test(int ij) -{ - assert(ij); -#line 100 "anotherfile" - assert(ij,"it is not zero"); -} - -extern (C) int main() -{ - test(1); - return 0; -} diff --git a/gcc/testsuite/gdc.test/runnable/casting.d b/gcc/testsuite/gdc.test/runnable/casting.d index 233cc94f634..1eb262c5c68 100644 --- a/gcc/testsuite/gdc.test/runnable/casting.d +++ b/gcc/testsuite/gdc.test/runnable/casting.d @@ -1,9 +1,15 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); template Seq(T...) { alias T Seq; } /***************************************************/ -// 3133 +// https://issues.dlang.org/show_bug.cgi?id=3133 void test3133() { @@ -12,7 +18,7 @@ void test3133() } /***************************************************/ -// 7504 +// https://issues.dlang.org/show_bug.cgi?id=7504 void test7504() pure nothrow @safe { @@ -56,7 +62,7 @@ C7504 create7504(T...)(T input) } /***************************************************/ -// 8119 +// https://issues.dlang.org/show_bug.cgi?id=8119 struct S8119; @@ -73,7 +79,7 @@ void test8119() } /***************************************************/ -// 8645 +// https://issues.dlang.org/show_bug.cgi?id=8645 template TypeTuple8645(TL...) { @@ -88,7 +94,7 @@ void test8645() } /***************************************************/ -// 10497 +// https://issues.dlang.org/show_bug.cgi?id=10497 struct S10497; @@ -99,7 +105,7 @@ void test10497(S10497** s) } /***************************************************/ -// 10793 +// https://issues.dlang.org/show_bug.cgi?id=10793 struct RealFoo10793 { @@ -116,7 +122,7 @@ void test10793() } /***************************************************/ -// 10834 +// https://issues.dlang.org/show_bug.cgi?id=10834 void test10834() { @@ -137,7 +143,7 @@ void test10834() } /***************************************************/ -// 10842 +// https://issues.dlang.org/show_bug.cgi?id=10842 template Test10842(F, T) { @@ -162,30 +168,12 @@ template Test10842(F, T) void test10842() { - foreach (From; Seq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) - { - foreach (To; Seq!(ifloat, idouble, ireal)) - { - if (!Test10842!(From, To).test()) - assert(0); - } - } - - foreach (From; Seq!(ifloat, idouble, ireal)) - { - foreach (To; Seq!(/*bool*, */byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) - { - if (!Test10842!(From, To).test()) - assert(0); - } - } - if (!Test10842!(typeof(null), string).test()) // 10842 assert(0); } /***************************************************/ -// 11722 +// https://issues.dlang.org/show_bug.cgi?id=11722 class C11722 { @@ -199,7 +187,7 @@ void test11722() } /***************************************************/ -// 14218 +// https://issues.dlang.org/show_bug.cgi?id=14218 void test14218() { @@ -214,18 +202,11 @@ void test14218() version (DigitalMars) { // Questionable but currently accepted by DMD (but not GDC). - foreach (To; Seq!( float, double, real, - ifloat, idouble, ireal)) + foreach (To; Seq!( float, double, real)) { auto x = cast(To)null; assert(x == 0); // 0i } - - // Internal error: backend/el.c in el_long() - //foreach (To; Seq!(cfloat, cdouble, creal)) - //{ - // static assert(!__traits(compiles, { auto x = cast(To)null; })); - //} } } diff --git a/gcc/testsuite/gdc.test/runnable/circular.d b/gcc/testsuite/gdc.test/runnable/circular.d deleted file mode 100644 index 8fdc8aa7d49..00000000000 --- a/gcc/testsuite/gdc.test/runnable/circular.d +++ /dev/null @@ -1,25 +0,0 @@ -// REQUIRED_ARGS: -d -// PERMUTE_ARGS: -dw -// EXTRA_SOURCES: imports/circularA.d -// This bug is typedef-specific. - -// Bugzilla 4543 - -import core.stdc.stdio; -import imports.circularA; - -class bclass {}; -alias bclass Tclass; - -struct bstruct {} -alias bstruct Tstruct; - - -/************************************/ - -int main() -{ - printf("Success\n"); - return 0; -} - diff --git a/gcc/testsuite/gdc.test/runnable/closure.d b/gcc/testsuite/gdc.test/runnable/closure.d index 1ed10e2c031..af304c1f38a 100644 --- a/gcc/testsuite/gdc.test/runnable/closure.d +++ b/gcc/testsuite/gdc.test/runnable/closure.d @@ -689,7 +689,7 @@ void test22() } /************************************/ -// 1759 +// https://issues.dlang.org/show_bug.cgi?id=1759 void test1759() { @@ -724,7 +724,7 @@ void test1759() } /************************************/ -// 1841 +// https://issues.dlang.org/show_bug.cgi?id=1841 int delegate() foo1841() { @@ -768,7 +768,7 @@ void test1841() } /************************************/ -// 5911 +// https://issues.dlang.org/show_bug.cgi?id=5911 void writeln5911(const(char)[] str) {} @@ -791,7 +791,7 @@ void test5911() } /************************************/ -// 9685 +// https://issues.dlang.org/show_bug.cgi?id=9685 auto get9685a(alias fun)() { @@ -844,7 +844,7 @@ void test9685b() } /************************************/ -// 12406 +// https://issues.dlang.org/show_bug.cgi?id=12406 auto createDg12406() { @@ -898,7 +898,7 @@ void test12406() } /************************************/ -// 14730 +// https://issues.dlang.org/show_bug.cgi?id=14730 void test14730() { diff --git a/gcc/testsuite/gdc.test/runnable/complex.d b/gcc/testsuite/gdc.test/runnable/complex.d index 78fe574b310..50e793e21e6 100644 --- a/gcc/testsuite/gdc.test/runnable/complex.d +++ b/gcc/testsuite/gdc.test/runnable/complex.d @@ -1,27 +1,43 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: - -import std.stdio; -import std.math; +/* +REQUIRED_ARGS: -d +TEST_OUTPUT: +--- +--- +*/ + +import core.stdc.math : isnan, signbit; import core.stdc.stdio; -/***************************************/ +template AliasSeq(T...) { alias T AliasSeq; } -void test1() -{ - creal c = 3.0 + 4.0i; - c = sqrt(c); - printf("re = %Lg, im = %Lg\n", c.re, c.im); - assert(c.re == 2.0); - assert(c.im == 1.0); +/************************************/ - float f = sqrt(25.0f); - assert(f == 5.0); - double d = sqrt(4.0); - assert(d == 2.0); - real r = sqrt(9.0L); - assert(r == 3.0); -} +static assert(-(6i) == -6i); +static assert(-(1 + 6i) == -1 - 6i); + +static assert(!3.7i == 0); +static assert(!0.0i == 1); +static assert(!(2+3.7i) == 0); +static assert(!(0+3.7i) == 0); +static assert(!(2+0.0i) == 0); +static assert(!(0+0.0i) == 1); + +static assert(-6i + 2i == -4i); +static assert(6i - 1i == 5i); + +static assert((3.6 + 7.2i) / (1 + 0i) == 3.6 + 7.2i); +static assert((3.6 + 7.2i) / (0.0 + 1i) == 7.2 - 3.6i); + +static assert((7.2i < 6.2i) == 0); + +static assert((7.2i == 6.2i) == 0); +static assert((7.2i != 6.2i) == 1); + +static assert((7.2i == 7.2i) == 1); +static assert((7.2i != 7.2i) == 0); + +static assert((5.1 is 5.1i) == 0); +static assert((5.1 !is 5.1i) == 1); /***************************************/ @@ -227,11 +243,11 @@ void test12() { real x = 3; creal a = (2 + 4i) % 3; - writeln(a); + printf("%Lg %Lgi\n", a.re, a.im); assert(a == 2 + 1i); creal b = (2 + 4i) % x; - writeln(b); + printf("%Lg %Lgi\n", b.re, b.im); assert(b == a); } @@ -241,7 +257,7 @@ void test13() { ireal a = 5i; ireal b = a % 2; - writeln(b); + printf("%Lg %Lgi\n", b.re, b.im); assert(b == 1i); } @@ -405,6 +421,974 @@ void test15() assert(bar15r(1.0L, 2.0Li) == 1.0L + 2.0Li); } +/************************************/ + +void test16() +{ + real n = -0.0; + const real m = -0.0; + + creal c = -0.0 + 3i; + creal d = n + 3i; + creal e = m + 3i; + + assert(signbit(c.re) != 0); + assert(signbit(d.re) != 0); + assert(signbit(e.re) != 0); +} + +/************************************/ + +void test17() +{ + void test(cdouble v) + { + auto x2 = cdouble(v); + assert(x2 == v); + } + test(1.2+3.4i); +} + +/************************************/ + +template factorial18(float n, cdouble c, string sss, string ttt) +{ + static if (n == 1) + const float factorial18 = 1; + else + const float factorial18 = n * 2; +} + +template bar18(wstring abc, dstring def) +{ + const int x = 3; +} + +void test18() +{ + float f = factorial18!(4.25, 6.8+3i, "hello", null); + printf("%g\n", f); + assert(f == 8.5); + int i = bar18!("abc"w, "def"d).x; + printf("%d\n", i); + assert(i == 3); +} + +/*****************************************/ + +void test19() +{ + float f; + double d; + real r; + + if (f > ifloat.max) + goto Loverflow; + if (d > ifloat.max) + goto Loverflow; + if (r > ifloat.max) + goto Loverflow; + + if (ifloat.max < f) + goto Loverflow; + if (ifloat.max < d) + goto Loverflow; + if (ifloat.max < r) + goto Loverflow; + + return; + + Loverflow: + return; +} + +/*****************************************/ + +void test20() +{ + double d = 1; + cdouble cd = 1+0i; + assert(cd == 1.0 + 0i); +} + +/*****************************************/ + +void test21() +{ + cdouble[] a; + cdouble[] b; + foreach(ref cdouble d; b) + { + d = -a[0]; + for(;;){} + } +} + +/*************************************/ + +void test22() +{ + static creal[] params = [1+0i, 3+0i, 5+0i]; + + printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im); + printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im); + printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im); + + creal[] sums = new creal[3]; + sums[] = 0+0i; + + foreach(creal d; params) + { + creal prod = d; + + printf("prod = %Lf + %Lfi\n", prod.re, prod.im); + for(int i; i<2; i++) + { + sums[i] += prod; + prod *= d; + } + sums[2] += prod; + } + + printf("sums[0] = %Lf + %Lfi", sums[0].re, sums[0].im); + assert(sums[0].re==9); + assert(sums[0].im==0); + assert(sums[1].re==35); + assert(sums[1].im==0); + assert(sums[2].re==153); + assert(sums[2].im==0); +} + +/*******************************************/ + +cdouble y23; + +cdouble f23(cdouble x) +{ + return (y23 = x); +} + +void test23() +{ + f23(1.0+2.0i); + assert(y23 == 1.0+2.0i); +} + +/*************************************/ + +ifloat func_24_1(ifloat f, double d) +{ +// f /= cast(cdouble)d; + return f; +} + +ifloat func_24_2(ifloat f, double d) +{ + f = cast(ifloat)(f / cast(cdouble)d); + return f; +} + +float func_24_3(float f, double d) +{ +// f /= cast(cdouble)d; + return f; +} + +float func_24_4(float f, double d) +{ + f = cast(float)(f / cast(cdouble)d); + return f; +} + +void test24() +{ + ifloat f = func_24_1(10i, 8); + printf("%fi\n", f); +// assert(f == 1.25i); + + f = func_24_2(10i, 8); + printf("%fi\n", f); + assert(f == 1.25i); + + float g = func_24_3(10, 8); + printf("%f\n", g); +// assert(g == 1.25); + + g = func_24_4(10, 8); + printf("%f\n", g); + assert(g == 1.25); +} + +/*******************************************/ + +void test25() +{ + ireal x = 4.0Li; + ireal y = 4.0Li; + ireal z = 4Li; + creal c = 4L + 0Li; +} + +/*************************************/ + +string toString26(cdouble z) +{ + char[ulong.sizeof*8] buf; + + auto len = snprintf(buf.ptr, buf.sizeof, "%f+%fi", z.re, z.im); + return buf[0 .. len].idup; +} + +void test26() +{ + static cdouble[] A = [1+0i, 0+1i, 1+1i]; + string s; + + foreach( cdouble z; A ) + { + s = toString26(z); + printf("%.*s ", cast(int)s.length, s.ptr); + } + printf("\n"); + + for(int ii=0; ii<A.length; ii++ ) + A[ii] += -1i*A[ii]; + + assert(A[0] == 1 - 1i); + assert(A[1] == 1 + 1i); + assert(A[2] == 2); + + foreach( cdouble z; A ) + { + s = toString26(z); + printf("%.*s ", cast(int)s.length, s.ptr); + } + printf("\n"); +} + +/*************************************/ + +void test27() +{ + creal z = 1. + 2.0i; + + real r = z.re; + assert(r == 1.0); + + real i = z.im; + assert(i == 2.0); + + assert(r.im == 0.0); + assert(r.re == 1.0); + + assert(i.re == 2.0); + assert(i.im == 0.0i); +} + +/*************************************/ + +void test28() +{ + alias cdouble X; + X four = cast(X) (4.0i + 0.4); +} + +/*************************************/ + +void test29() +{ + ireal a = 6.5i % 3i; + printf("%Lfi %Lfi\n", a, a - .5i); + assert(a == .5i); + + a = 6.5i % 3; + printf("%Lfi %Lfi\n", a, a - .5i); + assert(a == .5i); + + real b = 6.5 % 3i; + printf("%Lf %Lf\n", b, b - .5); + assert(b == .5); + + b = 6.5 % 3; + printf("%Lf %Lf\n", b, b - .5); + assert(b == .5); +} + +/*************************************/ + +void test30() +{ + cfloat f = 1+0i; + f %= 2fi; + printf("%f + %fi\n", f.re, f.im); + assert(f == 1 + 0i); + + cdouble d = 1+0i; + d %= 2i; + printf("%f + %fi\n", d.re, d.im); + assert(d == 1 + 0i); + + creal r = 1+0i; + r %= 2i; + printf("%Lf + %Lfi\n", r.re, r.im); + assert(r == 1 + 0i); +} + +/*************************************/ + +void test31() +{ + cfloat f = 1+0i; + f %= 2i; + printf("%f + %fi\n", f.re, f.im); + assert(f == 1); + + cdouble d = 1+0i; + d = d % 2i; + printf("%f + %fi\n", d.re, d.im); + assert(d == 1); + + creal r = 1+0i; + r = r % 2i; + printf("%Lf + %Lfi\n", r.re, r.im); + assert(r == 1); +} + +/*************************************/ + +void assertEqual(real* a, real* b, string file = __FILE__, size_t line = __LINE__) +{ + auto x = cast(ubyte*)a; + auto y = cast(ubyte*)b; + + // Only compare the 10 value bytes, the padding bytes are of undefined + // value. + version (X86) enum count = 10; + else version (X86_64) enum count = 10; + else enum count = real.sizeof; + for (size_t i = 0; i < count; i++) + { + if (x[i] != y[i]) + { + printf("%02zd: %02x %02x\n", i, x[i], y[i]); + import core.exception; + throw new AssertError(file, line); + } + } +} + +void assertEqual(creal* a, creal* b, string file = __FILE__, size_t line = __LINE__) +{ + assertEqual(cast(real*)a, cast(real*)b, file, line); + assertEqual(cast(real*)a + 1, cast(real*)b + 1, file, line); +} + +void test32() +{ + creal a = creal.nan; + creal b = real.nan + ireal.nan; + assertEqual(&a, &b); + + real c= real.nan; + real d=a.re; + assertEqual(&c, &d); + + d=a.im; + assertEqual(&c, &d); +} + +/*************************************/ + +void test33() +{ + creal a = creal.infinity; + creal b = real.infinity + ireal.infinity; + assertEqual(&a, &b); + + real c = real.infinity; + real d=a.re; + assertEqual(&c, &d); + + d=a.im; + assertEqual(&c, &d); +} + +/*************************************/ + +void test34() +{ + creal a = creal.nan; + creal b = creal.nan; + b = real.nan + ireal.nan; + assertEqual(&a, &b); + + real c = real.nan; + real d=a.re; + assertEqual(&c, &d); + + d=a.im; + assertEqual(&c, &d); +} + +/*************************************/ + +ireal x35; + +void foo35() +{ + x35 = -x35; +} + +void bar35() +{ + return foo35(); +} + +void test35() +{ + x35=2i; + bar35(); + assert(x35==-2i); +} + +/*************************************/ + +void test36() +{ + ireal imag = 2.5i; + printf ("test of imag*imag = %Lf\n",imag*imag); + assert(imag * imag == -6.25); +} + +/*************************************/ + +void test37() +{ + creal z1 = 1. - 2.0i; + ireal imag_part = z1.im/1i; +} + +/***********************************/ + +void test38() +{ + ireal imag = 2.5i; + //printf ("test of imag*imag = %Lf\n",imag*imag); + real f = imag * imag; + assert(f == -6.25); +} + +/***********************************/ + +void test39() +{ + creal z = 1 + 2.5i; + real e = z.im; + + printf ("e = %Lf\n", e); + assert(e == 2.5); +} + +/***********************************/ + +void test40() +{ + ifloat b = cast(ifloat)1i; + assert(b == 1.0i); + + ifloat c = 2fi; + assert(c == 2.0i); + + c = 0fi; + assert(c == 0i); +} + +/***************************************************/ + +void test41() +{ + creal a=1.3L+9.7Li; + assert(a.re == 1.3L); + assert(a.im == 9.7L); +} + +/***************************************************/ + +void test42() +{ + creal c = 2.7L + 0i; + assert(c.re==2.7L); + assert(c.im==0.0L); +} + +/***********************************/ + +void test43() +{ + creal C,Cj; + real y1,x1; + + C = x1 + y1*1i + Cj; + C = 1i*y1 + x1 + Cj; + C = Cj + 1i*y1 + x1; + C = y1*1i + Cj + x1; + C = 1i*y1 + Cj; + C = Cj + 1i*y1; +} + +/***************************************************/ + +void test44() +{ + ifloat f = 1.0fi; +// f *= 2.0fi; // illegal but compiles + printf("%g\n", f); +// assert(f == 0i); +} + +/******************************************************/ + +void test45() +{ + TypeInfo ti; + + ti = typeid(ifloat[]); + assert(!(ti is null)); + ti = typeid(idouble[]); + assert(!(ti is null)); + ti = typeid(ireal[]); + assert(!(ti is null)); + + ti = typeid(cfloat[]); + assert(!(ti is null)); + ti = typeid(cdouble[]); + assert(!(ti is null)); + ti = typeid(creal[]); + assert(!(ti is null)); +} + +/******************************************************/ + +void test46() +{ + TypeInfo ti = typeid(ifloat*); + assert(!(ti is null)); + assert(ti.tsize==(ifloat*).sizeof); + assert(ti.toString()=="ifloat*"); +} + +/******************************************************/ + +void test47() +{ + TypeInfo ti = typeid(cfloat*); + assert(!(ti is null)); + assert(ti.tsize==(cfloat*).sizeof); + assert(ti.toString()=="cfloat*"); +} + +/******************************************************/ + +void test48() +{ + TypeInfo ti = typeid(idouble*); + assert(!(ti is null)); + assert(ti.tsize==(idouble*).sizeof); + assert(ti.toString()=="idouble*"); +} + +/******************************************************/ + +void test49() +{ + TypeInfo ti = typeid(cdouble*); + assert(!(ti is null)); + assert(ti.tsize==(cdouble*).sizeof); + assert(ti.toString()=="cdouble*"); +} + +/***********************************/ + +void foo51(creal a) +{ + assert(a == -8i); +} + +void test51() +{ + assert((2-2i)*(2-2i) == -8i); + + cdouble a = (2-2i)*(2-2i); + assert(a == -8i); + + foo51((2-2i)*(2-2i)); +} + +/******************************************************/ + +void test52() +{ + TypeInfo ti = typeid(ireal*); + assert(!(ti is null)); + assert(ti.tsize==(ireal*).sizeof); + assert(ti.toString()=="ireal*"); +} + +/******************************************************/ + +void test53() +{ + TypeInfo ti = typeid(creal*); + assert(!(ti is null)); + assert(ti.tsize==(creal*).sizeof); + assert(ti.toString()=="creal*"); +} + +/*******************************************/ + +auto init(T)(T val) { return 1; } + +void test54() +{ + // See built-in 'init' property + assert(10i .init is idouble.nan); + + // x.init() has parens, so it runs UFCS call + assert(10i .init() == 1); + + // x.init!YYY matches templatized UFCS call. + assert(10i .init!idouble() == 1); +} + +/*******************************************/ + +creal x55; + +void foo55() +{ + x55 = -x55; +} + +void bar55() +{ + return foo55(); +} + +void test55() +{ + x55 = 2.0L + 0.0Li; + bar55(); + assert(x55 == -2.0L + 0.0Li); +} + +/***************************************************/ + +template Q(s...) { alias s q; } + +void test56() +{ + enum complex80 = Q!( 1+1.0i ).q.stringof; +} + +/********************************************************/ + +void test57() +{ + assert(__traits(isArithmetic, ifloat) == true); + assert(__traits(isArithmetic, idouble) == true); + assert(__traits(isArithmetic, ireal) == true); + assert(__traits(isArithmetic, cfloat) == true); + assert(__traits(isArithmetic, cdouble) == true); + assert(__traits(isArithmetic, creal) == true); + + assert(__traits(isScalar, ifloat) == true); + assert(__traits(isScalar, idouble) == true); + assert(__traits(isScalar, ireal) == true); + assert(__traits(isScalar, cfloat) == true); + assert(__traits(isScalar, cdouble) == true); + assert(__traits(isScalar, creal) == true); + + assert(__traits(isFloating, ifloat) == true); + assert(__traits(isFloating, idouble) == true); + assert(__traits(isFloating, ireal) == true); + assert(__traits(isFloating, cfloat) == true); + assert(__traits(isFloating, cdouble) == true); + assert(__traits(isFloating, creal) == true); + + assert(__traits(isIntegral, ifloat) == false); + assert(__traits(isIntegral, idouble) == false); + assert(__traits(isIntegral, ireal) == false); + assert(__traits(isIntegral, cfloat) == false); + assert(__traits(isIntegral, cdouble) == false); + assert(__traits(isIntegral, creal) == false); + + assert(__traits(isUnsigned, ifloat) == false); + assert(__traits(isUnsigned, idouble) == false); + assert(__traits(isUnsigned, ireal) == false); + assert(__traits(isUnsigned, cfloat) == false); + assert(__traits(isUnsigned, cdouble) == false); + assert(__traits(isUnsigned, creal) == false); + + assert(__traits(isAssociativeArray, ifloat) == false); + assert(__traits(isAssociativeArray, idouble) == false); + assert(__traits(isAssociativeArray, ireal) == false); + assert(__traits(isAssociativeArray, cfloat) == false); + assert(__traits(isAssociativeArray, cdouble) == false); + assert(__traits(isAssociativeArray, creal) == false); + + assert(__traits(isStaticArray, ifloat) == false); + assert(__traits(isStaticArray, idouble) == false); + assert(__traits(isStaticArray, ireal) == false); + assert(__traits(isStaticArray, cfloat) == false); + assert(__traits(isStaticArray, cdouble) == false); + assert(__traits(isStaticArray, creal) == false); + + assert(__traits(isAbstractClass, ifloat) == false); + assert(__traits(isAbstractClass, idouble) == false); + assert(__traits(isAbstractClass, ireal) == false); + assert(__traits(isAbstractClass, cfloat) == false); + assert(__traits(isAbstractClass, cdouble) == false); + assert(__traits(isAbstractClass, creal) == false); +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=3382 + +real toreal(ireal x){ return x.im; } + +void test3382() +{ + assert(1.4i.toreal() == 1.4); +} + +/***************************************************/ + +alias ireal BUG3919; +alias typeof(BUG3919.init*BUG3919.init) ICE3919; +alias typeof(BUG3919.init/BUG3919.init) ICE3920; + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=8454 + +double sqrt8454(double d) { return d/2; } +void foo8454(cdouble m) {} + +void test8454() +{ + foo8454(0 - sqrt8454(1.0) * 1i); +} + +/************************************/ +// https://issues.dlang.org/show_bug.cgi?id=9046 + +void test9046() +{ + foreach (T; AliasSeq!(ifloat, idouble, ireal, cfloat, cdouble, creal)) + foreach (U; AliasSeq!(T, const T, immutable T, shared T, shared const T, inout T, shared inout T)) + { + static assert(is(typeof(U.init) == U)); + } +} + +/********************************************/ +// https://issues.dlang.org/show_bug.cgi?id=9112 + +void test9112a() // T() and T(v) +{ + void test(T)(T v) + { + foreach (string qual; AliasSeq!("", "const ", "immutable ")) + { + mixin("alias U = "~qual~T.stringof~";"); + //pragma(msg, U); + + mixin("auto x1 = "~qual~T.stringof~"();"); // U() default construction syntax + mixin("auto x2 = "~qual~T.stringof~"(v);"); // U(v) + static assert(!__traits(compiles, mixin(qual~T.stringof~"(v, v)"))); // U(v, v) + static assert(is(typeof(x1) == U)); + static assert(is(typeof(x2) == U)); + static if ( is(typeof(U.nan) : real)) assert( isnan(x1.re) && !isnan(x1.im), U.stringof); + static if ( is(typeof(U.nan) : ireal)) assert(!isnan(x1.re) && isnan(x1.im), U.stringof); + static if ( is(typeof(U.nan) : creal)) assert( isnan(x1.re) && isnan(x1.im), U.stringof); + static if (!is(typeof(U.nan))) assert( x1 == U.init, U.stringof); + assert(x2 == v, U.stringof); + } + } + test!(ifloat )(1.4142i); + test!(idouble)(1.4142i); + test!(ireal )(1.4142i); + test!(cfloat )(1.2+3.4i); + test!(cdouble)(1.2+3.4i); + test!(creal )(1.2+3.4i); + + static assert(!__traits(compiles, double(3.14i))); +} + +void test9112b() // new T(v) +{ + void test(T)(T v) + { + foreach (string qual; AliasSeq!("", "const ", "immutable ")) + { + mixin("alias U = "~qual~T.stringof~";"); + //pragma(msg, U); + + mixin("auto p1 = new "~qual~T.stringof~"();"); // U() default construction syntax + mixin("auto p2 = new "~qual~T.stringof~"(v);"); // U(v) + static assert(!__traits(compiles, mixin("new "~qual~T.stringof~"(v, v)"))); // U(v, v) + static assert(is(typeof(p1) == U*)); + static assert(is(typeof(p2) == U*)); + assert( p1 !is null); + assert( p2 !is null); + auto x1 = *p1; + auto x2 = *p2; + static if ( is(typeof(U.nan) : real)) assert( isnan(x1.re) && !isnan(x1.im), U.stringof); + static if ( is(typeof(U.nan) : ireal)) assert(!isnan(x1.re) && isnan(x1.im), U.stringof); + static if ( is(typeof(U.nan) : creal)) assert( isnan(x1.re) && isnan(x1.im), U.stringof); + static if (!is(typeof(U.nan))) assert( x1 == U.init, U.stringof); + assert(x2 == v, U.stringof); + } + } + + test!(ifloat )(1.4142i); + test!(idouble)(1.4142i); + test!(ireal )(1.4142i); + test!(cfloat )(1.2+3.4i); + test!(cdouble)(1.2+3.4i); + test!(creal )(1.2+3.4i); + + static assert(!__traits(compiles, new double(3.14i))); +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=10639 + +struct S1 +{ + cdouble val; +} + +void formatTest(S1 s, double re, double im) +{ + assert(s.val.re == re); + assert(s.val.im == im); +} + +void test10639() +{ + S1 s = S1(3+2.25i); + formatTest(s, 3, 2.25); +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=10842 + +template Test10842(F, T) +{ + bool res; + F from() + { + res = true; + return F.init; + } + T to() + { + // The cast operand had incorrectly been eliminated + return cast(T)from(); + } + bool test() + { + res = false; + to(); + return res; + } +} + +void test10842() +{ + foreach (From; AliasSeq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) + { + foreach (To; AliasSeq!(ifloat, idouble, ireal)) + { + if (!Test10842!(From, To).test()) + assert(0); + } + } + + foreach (From; AliasSeq!(ifloat, idouble, ireal)) + { + foreach (To; AliasSeq!(/*bool*, */byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) + { + if (!Test10842!(From, To).test()) + assert(0); + } + } +} + +/***************************************************/ + +void test10927() +{ + static assert( (1+2i) ^^ 3 == -11 - 2i ); + auto a = (1+2i) ^^ 3; +} + +/******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=13252 + +alias TypeTuple13252(T...) = T; + +static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat )); +static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble)); + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=14218 + +void test14218() +{ + version (DigitalMars) + { + // Questionable but currently accepted by DMD (but not GDC). + foreach (To; AliasSeq!(ifloat, idouble, ireal)) + { + auto x = cast(To)null; + assert(x == 0); // 0i + } + + // Internal error: backend/el.c in el_long() + //foreach (To; AliasSeq!(cfloat, cdouble, creal)) + //{ + // static assert(!__traits(compiles, { auto x = cast(To)null; })); + //} + } +} + +/******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15653 + +alias TypeTuple15653(T...) = T; + +void test15653() +{ + void foo(U, T)(const T x) { static assert(is(T == U)); } + void bar(U, T)(immutable T x) { static assert(is(T == U)); } + + struct X { int a; long[2] b; } + struct Y { int* a; long[] b; } + + foreach (U; TypeTuple15653!( + ifloat, idouble, ireal, + cfloat, cdouble, creal)) + { + foo!U(U.init); // OK + bar!U(U.init); // Was error, now OK + + U u; + foo!U(u); // OK + bar!U(u); // Was error, now OK + } +} + /***************************************/ // https://issues.dlang.org/show_bug.cgi?id=17087 @@ -427,11 +1411,108 @@ void test17677() } /***************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17677 + +float getreal_rcx(cfloat z) +{ + return z.re; +} +float getimag_rcx(cfloat z) +{ + return z.im; +} + +float getreal_rdx(cfloat z, int) +{ + return z.re; +} +float getimag_rdx(cfloat z, int) +{ + return z.im; +} + +float getreal_r8(cfloat z, int, int) +{ + return z.re; +} +float getimag_r8(cfloat z, int, int) +{ + return z.im; +} + +float getreal_r9(cfloat z, int, int, int) +{ + return z.re; +} +float getimag_r9(cfloat z, int, int, int) +{ + return z.im; +} + +float getreal_stack(cfloat z, int, int, int, int) +{ + return z.re; +} +float getimag_stack(cfloat z, int, int, int, int) +{ + return z.im; +} + +void test18772a() +{ + cfloat[1] A; + float[1] B; + int i = 0; + A[0] = 2.0f + 4i; + B[0] = 3.0f; + assert(6.0 == getreal_rcx(A[i] * B[i])); + assert(12.0 == getimag_rcx(A[i] * B[i])); + + assert(6.0 == getreal_rdx(A[i] * B[i], 1)); + assert(12.0 == getimag_rdx(A[i] * B[i], 1)); + + assert(6.0 == getreal_r8(A[i] * B[i], 1, 2)); + assert(12.0 == getimag_r8(A[i] * B[i], 1, 2)); + + assert(6.0 == getreal_r9(A[i] * B[i], 1, 2, 3)); + assert(12.0 == getimag_r9(A[i] * B[i], 1, 2, 3)); + + assert(6.0 == getreal_stack(A[i] * B[i], 1, 2, 3, 4)); + assert(12.0 == getimag_stack(A[i] * B[i], 1, 2, 3, 4)); +} + +void test18772b(T)() +{ + static auto getre0(T z) + { + return z.re; + } + static auto getim0(T z) + { + return z.im; + } + + T z = 3 + 4i; + auto d = z.re; + + assert(getre0(d * z) == d * 3); + assert(getim0(d * z) == d * 4); +} + +void test18772() +{ + test18772a(); + + test18772b!cfloat(); + test18772b!cdouble(); + test18772b!creal(); +} + +/***************************************/ int main(char[][] args) { - test1(); test2(); test3(); test4(); @@ -454,10 +1535,59 @@ int main(char[][] args) test7806(); test7976(); test15(); + test16(); + test17(); + test18(); + test19(); + test20(); + test21(); + test22(); + test23(); + test24(); + test25(); + test26(); + test27(); + test28(); + test29(); + test30(); + test31(); + test32(); + test33(); + test34(); + test35(); + test36(); + test37(); + test38(); + test39(); + test40(); + test41(); + test42(); + test43(); + test44(); + test45(); + test46(); + test47(); + test48(); + test49(); + test51(); + test52(); + test53(); + test54(); + test55(); + test56(); + test57(); + test8454(); + test9046(); + test9112a(); + test9112b(); + test10639(); + test10842(); + test14218(); + test15653(); test17087(); test17677(); + test18772(); printf("Success!\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/constfold.d b/gcc/testsuite/gdc.test/runnable/constfold.d index 1d259f610cf..7857eaf544a 100644 --- a/gcc/testsuite/gdc.test/runnable/constfold.d +++ b/gcc/testsuite/gdc.test/runnable/constfold.d @@ -2,32 +2,17 @@ // RUNNABLE_PHOBOS_TEST static assert(__LINE__ == 3); // fails as __LINE__ is 2 -import std.stdio; -import std.math : signbit, sqrt; +import core.stdc.math : signbit; /************************************/ static assert(-(1) == -1); -static assert(-(6i) == -6i); -static assert(-(1 + 6i) == -1 - 6i); static assert(!27 == 0); static assert(!0 == 1); static assert(!6.2 == 0); static assert(!0.0 == 1); -static assert(!3.7i == 0); -static assert(!0.0i == 1); -static assert(!(2+3.7i) == 0); -static assert(!(0+3.7i) == 0); -static assert(!(2+0.0i) == 0); -static assert(!(0+0.0i) == 1); - -static assert(-6i + 2i == -4i); -static assert(6i - 1i == 5i); - -static assert((3.6 + 7.2i) / (1 + 0i) == 3.6 + 7.2i); -static assert((3.6 + 7.2i) / (0.0 + 1i) == 7.2 - 3.6i); static assert((6 % 4) == 2); static assert((6u % 4u) == 2u); @@ -157,16 +142,9 @@ static assert((7.2 <= 6.2) == 0); static assert((7.2 > 6.2) == 1); static assert((7.2 >= 6.2) == 1); -static assert((7.2i < 6.2i) == 0); - - -static assert((7.2i == 6.2i) == 0); -static assert((7.2i != 6.2i) == 1); static assert((7.2 == 6.2) == 0); static assert((7.2 != 6.2) == 1); -static assert((7.2i == 7.2i) == 1); -static assert((7.2i != 7.2i) == 0); static assert((7.2 == 7.2) == 1); static assert((7.2 != 7.2) == 0); @@ -187,9 +165,6 @@ static assert((5.1 is 4.1) == 0); static assert((5.1 !is 5.1) == 0); static assert((5.1 !is 4.1) == 1); -static assert((5.1 is 5.1i) == 0); -static assert((5.1 !is 5.1i) == 1); - static assert((5 ? 2 : 3) == 2); static assert((0 ? 2 : 3) == 3); static assert((5.0 ? 2 : 3) == 2); @@ -208,25 +183,6 @@ static assert(['a','b','c','d'] == "abcd"); static assert("efgh" == ['e','f','g','h']); static assert("efgi" != ['e','f','g','h']); -static assert((2 ^^ 8) == 256); -static assert((3 ^^ 8.0) == 6561); -static assert((4.0 ^^ 8) == 65536); -static assert((5.0 ^^ 8.0) == 390625); - -static assert((0.5 ^^ 3) == 0.125); -static assert((1.5 ^^ 3.0) == 3.375); -static assert((2.5 ^^ 3) == 15.625); -static assert((3.5 ^^ 3.0) == 42.875); - -static assert(((-2) ^^ -5.0) == -0.031250); -static assert(((-2.0) ^^ -6) == 0.015625); -static assert(((-2.0) ^^ -7.0) == -0.0078125); - -static assert((144 ^^ 0.5) == 12); -static assert((1089 ^^ 0.5) == 33); -static assert((1764 ^^ 0.5) == 42); -static assert((650.25 ^^ 0.5) == 25.5); - void test1() { @@ -256,8 +212,6 @@ void test2() { float f = float.infinity; int i = cast(int) f; - writeln(i); - writeln(cast(int)float.max); assert(i == cast(int)float.max); assert(i == 0x80000000); } @@ -270,19 +224,8 @@ void test3() real n = -0.0; const real m = -0.0; - creal c = -0.0 + 3i; - creal d = n + 3i; - creal e = m + 3i; - - // should print "11111" - writeln(signbit(n), signbit(m), - signbit(c.re), signbit(d.re), signbit(e.re)); - - assert(signbit(n) == 1); - assert(signbit(m) == 1); - assert(signbit(c.re) == 1); - assert(signbit(d.re) == 1); - assert(signbit(e.re) == 1); + assert(signbit(n) != 0); + assert(signbit(m) != 0); } /************************************/ @@ -354,7 +297,7 @@ int foo9() { static assert(foo9()==2); /************************************/ -// Bugzilla 6077 +// https://issues.dlang.org/show_bug.cgi?id=6077 void test6077() { static string scat(string s1, string s2) @@ -424,7 +367,7 @@ int test4() static assert(test4() == 24666); /************************************/ -// 8400 +// https://issues.dlang.org/show_bug.cgi?id=8400 void test8400() { @@ -434,7 +377,7 @@ void test8400() } /************************************/ -// 8939 +// https://issues.dlang.org/show_bug.cgi?id=8939 void foo8939(T)(ref T) { } // same for `auto ref` void bar8939(ref const int) { } @@ -486,7 +429,7 @@ class C8939regression } /************************************/ -// 9058 +// https://issues.dlang.org/show_bug.cgi?id=9058 template TypeTuple9058(TL...) { alias TypeTuple9058 = TL; } template EnumMembers9058(T) @@ -504,22 +447,7 @@ void test9058() } /************************************/ -// 11159 - -void test11159() -{ - import std.math : pow; - enum ulong - e_2_pow_64 = 2uL^^64, - e_10_pow_19 = 10uL^^19, - e_10_pow_20 = 10uL^^20; - assert(e_2_pow_64 == pow(2uL, 64)); - assert(e_10_pow_19 == pow(10uL, 19)); - assert(e_10_pow_20 == pow(10uL, 20)); -} - -/************************************/ -// 12306 +// https://issues.dlang.org/show_bug.cgi?id=12306 void test12306() { @@ -540,7 +468,7 @@ void test12306() } /************************************/ -// 13977 +// https://issues.dlang.org/show_bug.cgi?id=13977 void test13977() { @@ -570,7 +498,7 @@ void test13977() } /************************************/ -// 13978 +// https://issues.dlang.org/show_bug.cgi?id=13978 void test13978() { @@ -616,7 +544,7 @@ void test3697or() } /************************************/ -// 14459 +// https://issues.dlang.org/show_bug.cgi?id=14459 void test14459() { @@ -665,11 +593,9 @@ int main() test8400(); test8939(); test9058(); - test11159(); test13977(); test13978(); test14459(); - printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/cppdtor.d b/gcc/testsuite/gdc.test/runnable/cppdtor.d new file mode 100644 index 00000000000..0592d448b1f --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/cppdtor.d @@ -0,0 +1,143 @@ +/* +https://issues.dlang.org/show_bug.cgi?id=21693 + +RUN_OUTPUT: +--- +CppA: +1: CppA.~this +CppB: +2: CppB.~this +2: CppA.~this +CppC: +3: CppC.~this +3: CppB.~this +3: CppA.~this +CppC: +4: CppC.~this +4: CppB.~this +4: CppA.~this +CppNoDestruct: +DA: +1: DA.~this +DB: +2: DB.~this +2: DA.~this +DC: +3: DC.~this +3: DB.~this +3: DA.~this +DC: +4: DC.~this +4: DB.~this +4: DA.~this +--- +*/ + +extern (C) int printf(scope const char*, ...); + +extern (C++) class CppA +{ + int num; + this(int num) + { + this.num = num; + } + + ~this() + { + printf("%d: CppA.~this\n", num); + } +} + +extern (C++) class CppB : CppA +{ + this(int num) + { + super(num); + } + + ~this() + { + printf("%d: CppB.~this\n", num); + } +} + +extern (C++) class CppC : CppB +{ + this(int num) + { + super(num); + } + + ~this() + { + printf("%d: CppC.~this\n", num); + } +} + +extern (D) class DA +{ + int num; + this(int num) + { + this.num = num; + } + + ~this() + { + printf("%d: DA.~this\n", num); + } +} + +extern (D) class DB : DA +{ + this(int num) + { + super(num); + } + + ~this() + { + printf("%d: DB.~this\n", num); + } +} + +extern (D) class DC : DB +{ + this(int num) + { + super(num); + } + + ~this() + { + printf("%d: DC.~this\n", num); + } +} + +extern (C++) class CppNoDestruct +{ + int num; + this(int num) + { + this.num = num; + } +} + +void main() +{ + printf("CppA:\n"); { scope a = new CppA(1); } + printf("CppB:\n"); { scope CppA b = new CppB(2); } + printf("CppC:\n"); { scope CppA c = new CppC(3); } + printf("CppC:\n"); { scope CppB c2 = new CppC(4); } + + printf("CppNoDestruct:\n"); + { + scope const nd = new CppNoDestruct(1); + } + + printf("DA:\n"); { scope a = new DA(1); } + printf("DB:\n"); { scope DA b = new DB(2); } + printf("DC:\n"); { scope DA c = new DC(3); } + printf("DC:\n"); { scope DB c2 = new DC(4); } +} diff --git a/gcc/testsuite/gdc.test/runnable/ctorpowtests.d b/gcc/testsuite/gdc.test/runnable/ctorpowtests.d index 89f846a96e5..f2cf5d8fe0c 100644 --- a/gcc/testsuite/gdc.test/runnable/ctorpowtests.d +++ b/gcc/testsuite/gdc.test/runnable/ctorpowtests.d @@ -3,23 +3,32 @@ int magicVariable() { - if (__ctfe) - return 3; + if (__ctfe) + return 3; - shared int var = 2; - return var; + shared int var = 2; + return var; } static assert(magicVariable()==3); -void main() +/************************************/ +// https://issues.dlang.org/show_bug.cgi?id=11159 + +void test11159() { - assert(!__ctfe); - assert(magicVariable()==2); + import std.math : pow; + enum ulong + e_2_pow_64 = 2uL^^64, + e_10_pow_19 = 10uL^^19, + e_10_pow_20 = 10uL^^20; + assert(e_2_pow_64 == pow(2uL, 64)); + assert(e_10_pow_19 == pow(10uL, 19)); + assert(e_10_pow_20 == pow(10uL, 20)); } -// bug 991 -- invalid. -// bug 3500 -- is this related to 2127? +// https://issues.dlang.org/show_bug.cgi?id=991 -- invalid. +// https://issues.dlang.org/show_bug.cgi?id=3500 -- is this related to 2127? // Tests for ^^ // TODO: These tests should not require import std.math. @@ -32,6 +41,25 @@ static assert( 2.0 ^^ 3 == 8.0); static assert( 2.0 ^^ 4 == 16.0); static assert( 2 ^^ 4 == 16); +static assert((2 ^^ 8) == 256); +static assert((3 ^^ 8.0) == 6561); +static assert((4.0 ^^ 8) == 65536); +static assert((5.0 ^^ 8.0) == 390625); + +static assert((0.5 ^^ 3) == 0.125); +static assert((1.5 ^^ 3.0) == 3.375); +static assert((2.5 ^^ 3) == 15.625); +static assert((3.5 ^^ 3.0) == 42.875); + +static assert(((-2) ^^ -5.0) == -0.031250); +static assert(((-2.0) ^^ -6) == 0.015625); +static assert(((-2.0) ^^ -7.0) == -0.0078125); + +static assert((144 ^^ 0.5) == 12); +static assert((1089 ^^ 0.5) == 33); +static assert((1764 ^^ 0.5) == 42); +static assert((650.25 ^^ 0.5) == 25.5); + // Check the typing rules. static assert( is (typeof(2.0^^7) == double)); static assert( is (typeof(7^^3) == int)); @@ -78,13 +106,16 @@ static assert( 2 ^^ 3 ^^ 2 == 2 ^^ 9); static assert( 2.0 ^^ -3 ^^ 2 == 2.0 ^^ -9); // 1 ^^ n is always 1, even if n is negative -static assert( 1 ^^ -5 == 1); +static assert( 1 ^^ -5.0 == 1); -// -1 ^^ n gets transformed into n & 1 ? -1 : 1 -// even if n is negative -static assert( (-1) ^^ -5 == -1); -static assert( (-1) ^^ -4 == 1); -static assert( (-1) ^^ 0 == 1); +// -1.0 ^^ n is either 1 or -1 if n is integral. +static assert( (-1.0) ^^ -5 == -1); +static assert( (-1.0) ^^ -4 == 1); +static assert( (-1.0) ^^ 0 == 1); +// -1.0 ^^ n is otherwise always NaN. +static assert( (-1.0) ^^ -5.5 is double.nan); +static assert( (-1.0) ^^ -4.4 is double.nan); +static assert( (-1.0) ^^ -0.1 is double.nan); // n ^^ 0 is always 1 static assert( (-5) ^^ 0 == 1); @@ -100,7 +131,7 @@ static assert( 9 ^^ -1.0 == 1.0 / 9); static assert( !is(typeof(2 ^^ -5))); static assert( !is(typeof((-2) ^^ -4))); -// Bug 3535 +// https://issues.dlang.org/show_bug.cgi?id=3535 struct StructWithCtor { this(int _n) { @@ -232,3 +263,12 @@ int anotherPowTest() double x = 5.0; return x^^4 > 2.0 ? 3: 2; } + +/************************************/ + +void main() +{ + assert(!__ctfe); + assert(magicVariable()==2); + test11159(); +} diff --git a/gcc/testsuite/gdc.test/runnable/declaration.d b/gcc/testsuite/gdc.test/runnable/declaration.d index 0dbd2876d4e..5be76fac6d7 100644 --- a/gcc/testsuite/gdc.test/runnable/declaration.d +++ b/gcc/testsuite/gdc.test/runnable/declaration.d @@ -15,7 +15,7 @@ Success extern(C) int printf(const char*, ...); /***************************************************/ -// 6475 +// https://issues.dlang.org/show_bug.cgi?id=6475 class Foo6475(Value) { @@ -34,7 +34,7 @@ void test6475() } /***************************************************/ -// 6905 +// https://issues.dlang.org/show_bug.cgi?id=6905 void test6905() { @@ -62,7 +62,7 @@ void test6905() } /***************************************************/ -// 7019 +// https://issues.dlang.org/show_bug.cgi?id=7019 struct S7019 { @@ -106,7 +106,7 @@ void test7019() } /***************************************************/ -// 7239 +// https://issues.dlang.org/show_bug.cgi?id=7239 struct vec7239 { @@ -145,7 +145,7 @@ void test10635() } /***************************************************/ -// 8123 +// https://issues.dlang.org/show_bug.cgi?id=8123 void test8123() { @@ -169,7 +169,7 @@ void test8123() } /***************************************************/ -// 8147 +// https://issues.dlang.org/show_bug.cgi?id=8147 enum A8147 { a, b, c } @@ -195,7 +195,7 @@ void test8147() } /***************************************************/ -// 8410 +// https://issues.dlang.org/show_bug.cgi?id=8410 void test8410() { @@ -207,7 +207,7 @@ void test8410() } /***************************************************/ -// 8942 +// https://issues.dlang.org/show_bug.cgi?id=8942 alias const int A8942_0; static assert(is(A8942_0 == const int)); // passes @@ -230,7 +230,7 @@ void test8942() } /***************************************************/ -// 10144 +// https://issues.dlang.org/show_bug.cgi?id=10144 final class TNFA10144(char_t) { @@ -258,7 +258,7 @@ class C10144 /***************************************************/ -// 10142 +// https://issues.dlang.org/show_bug.cgi?id=10142 class File10142 { @@ -291,7 +291,7 @@ void test10142() } /***************************************************/ -// 11421 +// https://issues.dlang.org/show_bug.cgi?id=11421 void test11421() { @@ -308,7 +308,7 @@ void test11421() } /***************************************************/ -// 13776 +// https://issues.dlang.org/show_bug.cgi?id=13776 enum a13776(T) = __traits(compiles, { T; }); @@ -364,7 +364,7 @@ void test13776() } /***************************************************/ -// 14090 +// https://issues.dlang.org/show_bug.cgi?id=14090 template Packed14090(Args...) { @@ -389,7 +389,7 @@ template RoundRobin14090() alias roundRobin14090 = RoundRobin14090!(); /***************************************************/ -// 13950 +// https://issues.dlang.org/show_bug.cgi?id=13950 template Tuple13950(T...) { alias T Tuple13950; } diff --git a/gcc/testsuite/gdc.test/runnable/delegate.d b/gcc/testsuite/gdc.test/runnable/delegate.d index a371e1cee3d..1eed53abb40 100644 --- a/gcc/testsuite/gdc.test/runnable/delegate.d +++ b/gcc/testsuite/gdc.test/runnable/delegate.d @@ -1,4 +1,19 @@ -// REQUIRED_ARGS: +/* +REQUIRED_ARGS: +RUN_OUTPUT: +--- +47 47 +47 47 +48 48 +48 48 +i = 1 +6 +here 3 +here 3 +here 3 +Success +--- +*/ import core.stdc.stdio; @@ -187,7 +202,7 @@ void test9() } /********************************************************/ -// 8257 +// https://issues.dlang.org/show_bug.cgi?id=8257 struct S8257 { static int g() { @@ -227,8 +242,8 @@ void test10() class A12 { public: - int delegate(int, int) dgs[4]; - int function(int, int) fps[4]; + int delegate(int, int)[4] dgs; + int function(int, int)[4] fps; int delegate(int, int) dg; int function(int, int) fp; int f(int x, int y) { @@ -263,7 +278,7 @@ void test12() } /********************************************************/ -// 1570 +// https://issues.dlang.org/show_bug.cgi?id=1570 class A13 { @@ -291,7 +306,24 @@ void test13() } /********************************************************/ -// 2472 + +enum dg14 = delegate { ++a14; b14 += 2; }; + +int a14, b14; + +void test14() +{ + a14 = b14 = 10; + + auto var = dg14; + var(); + + assert(a14 == 11); + assert(b14 == 12); +} + +/********************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=2472 class A2472 { @@ -348,6 +380,7 @@ int main() test10(); test12(); test13(); + test14(); test2472(); test8257(); testAssign(); diff --git a/gcc/testsuite/gdc.test/runnable/dhry.d b/gcc/testsuite/gdc.test/runnable/dhry.d new file mode 100644 index 00000000000..f772d6160ad --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/dhry.d @@ -0,0 +1,931 @@ +/* +PERMUTE_ARGS: +REQUIRED_ARGS: -release -O -g -inline +DISABLED: freebsd dragonflybsd + +Deprecation caused by https://issues.dlang.org/show_bug.cgi?id=20645 +*/ + +/* + ************************************************************************* + * + * "DHRYSTONE" Benchmark Program + * ----------------------------- + * + * Version: C, Version 2.1 + * + * File: dhry.h (part 1 of 3) + * + * Date: May 25, 1988 + * + * Author: Reinhold P. Weicker + * Siemens Nixdorf Inf. Syst. + * STM OS 32 + * Otto-Hahn-Ring 6 + * W-8000 Muenchen 83 + * Germany + * Phone: [+49]-89-636-42436 + * (8-17 Central European Time) + * UUCP: weicker@ztivax.uucp@unido.uucp + * Internet: weicker@ztivax.siemens.com + * + * Original Version (in Ada) published in + * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984), + * pp. 1013 - 1030, together with the statistics + * on which the distribution of statements etc. is based. + * + * In this C version, the following C library functions are + * used: + * - strcpy, strcmp (inside the measurement loop) + * - printf, scanf (outside the measurement loop) + * + * Collection of Results: + * Reinhold Weicker (address see above) and + * + * Rick Richardson + * PC Research. Inc. + * 94 Apple Orchard Drive + * Tinton Falls, NJ 07724 + * Phone: (201) 834-1378 (9-17 EST) + * UUCP: ...!uunet!pcrat!rick + * + * Please send results to Rick Richardson and/or Reinhold Weicker. + * Complete information should be given on hardware and software + * used. Hardware information includes: Machine type, CPU, type and + * size of caches; for microprocessors: clock frequency, memory speed + * (number of wait states). Software information includes: Compiler + * (and runtime library) manufacturer and version, compilation + * switches, OS version. The Operating System version may give an + * indication about the compiler; Dhrystone itself performs no OS + * calls in the measurement loop. + * + * The complete output generated by the program should be mailed + * such that at least some checks for correctness can be made. + * + ************************************************************************* + * + * History: This version C/2.1 has been made for two reasons: + * + * 1) There is an obvious need for a common C version of + * Dhrystone, since C is at present the most popular system + * programming language for the class of processors + * (microcomputers, minicomputers) where Dhrystone is used + * most. There should be, as far as possible, only one C + * version of Dhrystone such that results can be compared + * without restrictions. In the past, the C versions + * distributed by Rick Richardson (Version 1.1) and by + * Reinhold Weicker had small (though not significant) + * differences. + * + * 2) As far as it is possible without changes to the + * Dhrystone statistics, optimizing compilers should be + * prevented from removing significant statements. + * + * This C version has been developed in cooperation with + * Rick Richardson (Tinton Falls, NJ), it incorporates many + * ideas from the "Version 1.1" distributed previously by + * him over the UNIX network Usenet. + * I also thank Chaim Benedelac (National Semiconductor), + * David Ditzel (SUN), Earl Killian and John Mashey (MIPS), + * Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley) + * for their help with comments on earlier versions of the + * benchmark. + * + * Changes: In the initialization part, this version follows mostly + * Rick Richardson's version distributed via Usenet, not the + * version distributed earlier via floppy disk by Reinhold + * Weicker. As a concession to older compilers, names have + * been made unique within the first 8 characters. Inside the + * measurement loop, this version follows the version + * previously distributed by Reinhold Weicker. + * + * At several places in the benchmark, code has been added, + * but within the measurement loop only in branches that + * are not executed. The intention is that optimizing + * compilers should be prevented from moving code out of the + * measurement loop, or from removing code altogether. Since + * the statements that are executed within the measurement + * loop have NOT been changed, the numbers defining the + * "Dhrystone distribution" (distribution of statements, + * operand types and locality) still hold. Except for + * sophisticated optimizing compilers, execution times for + * this version should be the same as for previous versions. + * + * Since it has proven difficult to subtract the time for the + * measurement loop overhead in a correct way, the loop check + * has been made a part of the benchmark. This does have + * an impact - though a very minor one - on the distribution + * statistics which have been updated for this version. + * + * All changes within the measurement loop are described + * and discussed in the companion paper "Rationale for + * Dhrystone version 2". + * + * Because of the self-imposed limitation that the order and + * distribution of the executed statements should not be + * changed, there are still cases where optimizing compilers + * may not generate code for some statements. To a certain + * degree, this is unavoidable for small synthetic + * benchmarks. Users of the benchmark are advised to check + * code listings whether code is generated for all statements + * of Dhrystone. + * + * Version 2.1 is identical to version 2.0 distributed via + * the UNIX network Usenet in March 1988 except that it + * corrects some minor deficiencies that were found by users + * of version 2.0. The only change within the measurement + * loop is that a non-executed "else" part was added to the + * "if" statement in Func_3, and a non-executed "else" part + * removed from Proc_3. + * + ************************************************************************* + * + * Defines: The following "Defines" are possible: + * -DROPT (default: Not defined) + * As an approximation to what an average C + * programmer might do, the "register" storage class + * is applied (if enabled by -DROPT) + * - for local variables, if they are used + * (dynamically) five or more times + * - for parameters if they are used (dynamically) + * six or more times + * Note that an optimal "register" strategy is + * compiler-dependent, and that "register" + * declarations do not necessarily lead to faster + * execution. + * -DNOSTRUCTASSIGN (default: Not defined) + * Define if the C compiler does not support + * assignment of structures. + * -DNOENUMS (default: Not defined) + * Define if the C compiler does not support + * enumeration types. + * + ************************************************************************* + * + * Compilation model and measurement (IMPORTANT): + * + * This C version of Dhrystone consists of three files: + * - dhry.h (this file, containing global definitions and comments) + * - dhry_1.c (containing the code corresponding to Ada package Pack_1) + * - dhry_2.c (containing the code corresponding to Ada package Pack_2) + * + * The following "ground rules" apply for measurements: + * - Separate compilation + * - No procedure merging + * - Otherwise, compiler optimizations are allowed but should be + * indicated + * - Default results are those without register declarations + * See the companion paper "Rationale for Dhrystone Version 2" for a more + * detailed discussion of these ground rules. + * + * For 16-Bit processors (e.g. 80186, 80286), times for all compilation + * models ("small", "medium", "large" etc.) should be given if possible, + * together with a definition of these models for the compiler system + * used. + * + ************************************************************************* + * + * Dhrystone (C version) statistics: + * + * [Comment from the first distribution, updated for version 2. + * Note that because of language differences, the numbers are slightly + * different from the Ada version.] + * + * The following program contains statements of a high level programming + * language (here: C) in a distribution considered representative: + * + * assignments 52 (51.0 %) + * control statements 33 (32.4 %) + * procedure, function calls 17 (16.7 %) + * + * 103 statements are dynamically executed. The program is balanced with + * respect to the three aspects: + * + * - statement type + * - operand type + * - operand locality + * operand global, local, parameter, or constant. + * + * The combination of these three aspects is balanced only approximately. + * + * 1. Statement Type: + * ----------------- number + * + * V1 = V2 9 + * (incl. V1 = F(..) + * V = Constant 12 + * Assignment, 7 + * with array element + * Assignment, 6 + * with record component + * -- + * 34 34 + * + * X = Y +|-|"&&"|"|" Z 5 + * X = Y +|-|"==" Constant 6 + * X = X +|- 1 3 + * X = Y *|/ Z 2 + * X = Expression, 1 + * two operators + * X = Expression, 1 + * three operators + * -- + * 18 18 + * + * if .... 14 + * with "else" 7 + * without "else" 7 + * executed 3 + * not executed 4 + * for ... 7 | counted every time + * while ... 4 | the loop condition + * do ... while 1 | is evaluated + * switch ... 1 + * break 1 + * declaration with 1 + * initialization + * -- + * 34 34 + * + * P (...) procedure call 11 + * user procedure 10 + * library procedure 1 + * X = F (...) + * function call 6 + * user function 5 + * library function 1 + * -- + * 17 17 + * --- + * 103 + * + * The average number of parameters in procedure or function calls + * is 1.82 (not counting the function values as implicit parameters). + * + * + * 2. Operators + * ------------ + * number approximate + * percentage + * + * Arithmetic 32 50.8 + * + * + 21 33.3 + * - 7 11.1 + * * 3 4.8 + * / (int div) 1 1.6 + * + * Comparison 27 42.8 + * + * == 9 14.3 + * /= 4 6.3 + * > 1 1.6 + * < 3 4.8 + * >= 1 1.6 + * <= 9 14.3 + * + * Logic 4 6.3 + * + * && (AND-THEN) 1 1.6 + * | (OR) 1 1.6 + * ! (NOT) 2 3.2 + * + * -- ----- + * 63 100.1 + * + * + * 3. Operand Type (counted once per operand reference): + * --------------- + * number approximate + * percentage + * + * Integer 175 72.3 % + * Character 45 18.6 % + * Pointer 12 5.0 % + * String30 6 2.5 % + * Array 2 0.8 % + * Record 2 0.8 % + * --- ------- + * 242 100.0 % + * + * When there is an access path leading to the final operand (e.g. a + * record component), only the final data type on the access path is + * counted. + * + * + * 4. Operand Locality: + * ------------------- + * number approximate + * percentage + * + * local variable 114 47.1 % + * global variable 22 9.1 % + * parameter 45 18.6 % + * value 23 9.5 % + * reference 22 9.1 % + * function result 6 2.5 % + * constant 55 22.7 % + * --- ------- + * 242 100.0 % + * + * + * The program does not compute anything meaningful, but it is + * syntactically and semantically correct. All variables have a value + * assigned to them before they are used as a source operand. + * + * There has been no explicit effort to account for the effects of a + * cache, or to balance the use of long or short displacements for code + * or data. + * + ************************************************************************* + */ + +import core.stdc.stdio; +import core.stdc.string; +import core.stdc.stdlib; +import std.string; + + +/* Compiler and system dependent definitions: */ + +const double Mic_secs_Per_Second = 1000000.0; + /* Berkeley UNIX C returns process times in seconds/HZ */ + +enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5} +alias int Enumeration; + /* for boolean and enumeration types in Ada, Pascal */ + +/* General definitions: */ + +const int StrLen = 30; + +alias int One_Thirty; +alias int One_Fifty; +alias char Capital_Letter; +alias bool Boolean; +alias char[StrLen] Str_30; +alias int[50] Arr_1_Dim; +alias int[50][50] Arr_2_Dim; + +struct record +{ + record *Ptr_Comp; + Enumeration Discr; + union V { + struct V1 { + Enumeration Enum_Comp; + int Int_Comp; + char[StrLen] Str_Comp; + } + V1 var_1; + struct V2 { + Enumeration E_Comp_2; + char [StrLen] Str_2_Comp; + } + V2 var_2; + struct V3 { + char Ch_1_Comp; + char Ch_2_Comp; + } + V3 var_3; + } + V variant; +} + +alias record Rec_Type; +alias record *Rec_Pointer; + + +/* Global Variables: */ + +Rec_Pointer Ptr_Glob, + Next_Ptr_Glob; +int Int_Glob; +Boolean Bool_Glob; +char Ch_1_Glob, + Ch_2_Glob; +int[50] Arr_1_Glob; +int[50][50] Arr_2_Glob; + +char[StrLen] Reg_Define = "Register option selected."; + +/* variables for time measurement: */ + +const int Too_Small_Time = 2; + /* Measurements should last at least 2 seconds */ + +double Begin_Time, + End_Time, + User_Time; + +double Microseconds, + Dhrystones_Per_Second, + Vax_Mips; + +/* end of variables for time measurement */ + + +void main () +/*****/ + + /* main program, corresponds to procedures */ + /* Main and Proc_0 in the Ada version */ +{ + One_Fifty Int_1_Loc; + One_Fifty Int_2_Loc; + One_Fifty Int_3_Loc; + char Ch_Index; + Enumeration Enum_Loc; + Str_30 Str_1_Loc; + Str_30 Str_2_Loc; + int Run_Index; + int Number_Of_Runs; + +/+ + FILE *Ap; + + /* Initializations */ + + if ((Ap = fopen("dhry.res","a+")) == null) + { + printf("Can not open dhry.res\n\n"); + exit(1); + } ++/ + + Next_Ptr_Glob = cast(Rec_Pointer) malloc (Rec_Type.sizeof); + Ptr_Glob = cast(Rec_Pointer) malloc (Rec_Type.sizeof); + + Ptr_Glob.Ptr_Comp = Next_Ptr_Glob; + Ptr_Glob.Discr = Ident_1; + Ptr_Glob.variant.var_1.Enum_Comp = Ident_3; + Ptr_Glob.variant.var_1.Int_Comp = 40; +// strcpy (Ptr_Glob.variant.var_1.Str_Comp, +// "DHRYSTONE PROGRAM, SOME STRING"); +// strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); + Ptr_Glob.variant.var_1.Str_Comp[] = "DHRYSTONE PROGRAM, SOME STRING"; + Str_1_Loc[] = "DHRYSTONE PROGRAM, 1'ST STRING"; + + Arr_2_Glob [8][7] = 10; + /* Was missing in published program. Without this statement, */ + /* Arr_2_Glob [8][7] would have an undefined value. */ + /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ + /* overflow may occur for this array element. */ + + printf ("\n"); + printf ("Dhrystone Benchmark, Version 2.1 (Language: D)\n"); + printf ("\n"); + printf ("Please give the number of runs through the benchmark: "); + { + int n; + //scanf ("%d", &n); + n = 10000000; + Number_Of_Runs = n; + } + printf ("\n"); + + printf ("Execution starts, %d runs through Dhrystone\n",Number_Of_Runs); + + /***************/ + /* Start timer */ + /***************/ + + Begin_Time = dtime(); + + for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) + { + + Proc_5(); + Proc_4(); + /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ + Int_1_Loc = 2; + Int_2_Loc = 3; + //strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); + Str_2_Loc[] = "DHRYSTONE PROGRAM, 2'ND STRING"; + Enum_Loc = Ident_2; + Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc); + /* Bool_Glob == 1 */ + while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ + { + Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; + /* Int_3_Loc == 7 */ + Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc); + /* Int_3_Loc == 7 */ + Int_1_Loc += 1; + } /* while */ + /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ + Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); + /* Int_Glob == 5 */ + Proc_1 (Ptr_Glob); + for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) + /* loop body executed twice */ + { + if (Enum_Loc == Func_1 (Ch_Index, 'C')) + /* then, not executed */ + { + Proc_6 (Ident_1, &Enum_Loc); + //strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); + Str_2_Loc[] = "DHRYSTONE PROGRAM, 3'RD STRING"; + Int_2_Loc = Run_Index; + Int_Glob = Run_Index; + } + } + /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ + Int_2_Loc = Int_2_Loc * Int_1_Loc; + Int_1_Loc = Int_2_Loc / Int_3_Loc; + Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; + /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ + Proc_2 (&Int_1_Loc); + /* Int_1_Loc == 5 */ + + } /* loop "for Run_Index" */ + + /**************/ + /* Stop timer */ + /**************/ + + End_Time = dtime(); + + printf ("Execution ends\n"); + printf ("\n"); + printf ("Final values of the variables used in the benchmark:\n"); + printf ("\n"); + printf ("Int_Glob: %d\n", Int_Glob); + printf (" should be: %d\n", 5); + printf ("Bool_Glob: %d\n", Bool_Glob); + printf (" should be: %d\n", 1); + printf ("Ch_1_Glob: %c\n", Ch_1_Glob); + printf (" should be: %c\n", 'A'); + printf ("Ch_2_Glob: %c\n", Ch_2_Glob); + printf (" should be: %c\n", 'B'); + printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); + printf (" should be: %d\n", 7); + printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); + printf (" should be: Number_Of_Runs + 10\n"); + printf ("Ptr_Glob.\n"); + printf (" Ptr_Comp: %d\n", cast(int) Ptr_Glob.Ptr_Comp); + printf (" should be: (implementation-dependent)\n"); + printf (" Discr: %d\n", Ptr_Glob.Discr); + printf (" should be: %d\n", 0); + printf (" Enum_Comp: %d\n", Ptr_Glob.variant.var_1.Enum_Comp); + printf (" should be: %d\n", 2); + printf (" Int_Comp: %d\n", Ptr_Glob.variant.var_1.Int_Comp); + printf (" should be: %d\n", 17); + printf (" Str_Comp: %.*s\n", cast(int)Ptr_Glob.variant.var_1.Str_Comp.length, Ptr_Glob.variant.var_1.Str_Comp.ptr); + printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); + printf ("Next_Ptr_Glob.\n"); + printf (" Ptr_Comp: %d\n", cast(int) Next_Ptr_Glob.Ptr_Comp); + printf (" should be: (implementation-dependent), same as above\n"); + printf (" Discr: %d\n", Next_Ptr_Glob.Discr); + printf (" should be: %d\n", 0); + printf (" Enum_Comp: %d\n", Next_Ptr_Glob.variant.var_1.Enum_Comp); + printf (" should be: %d\n", 1); + printf (" Int_Comp: %d\n", Next_Ptr_Glob.variant.var_1.Int_Comp); + printf (" should be: %d\n", 18); + printf (" Str_Comp: %.*s\n", cast(int)Next_Ptr_Glob.variant.var_1.Str_Comp.length, Next_Ptr_Glob.variant.var_1.Str_Comp.ptr); + printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); + printf ("Int_1_Loc: %d\n", Int_1_Loc); + printf (" should be: %d\n", 5); + printf ("Int_2_Loc: %d\n", Int_2_Loc); + printf (" should be: %d\n", 13); + printf ("Int_3_Loc: %d\n", Int_3_Loc); + printf (" should be: %d\n", 7); + printf ("Enum_Loc: %d\n", Enum_Loc); + printf (" should be: %d\n", 1); + printf ("Str_1_Loc: %.*s\n", cast(int)Str_1_Loc.length, Str_1_Loc.ptr); + printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); + printf ("Str_2_Loc: %.*s\n", cast(int)Str_2_Loc.length, Str_2_Loc.ptr); + printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); + printf ("\n"); + + User_Time = End_Time - Begin_Time; + + if (User_Time < Too_Small_Time) + { + printf ("Measured time too small to obtain meaningful results\n"); + printf ("Please increase number of runs\n"); + printf ("\n"); + } + else + { + Microseconds = User_Time * Mic_secs_Per_Second + / cast(double) Number_Of_Runs; + Dhrystones_Per_Second = cast(double) Number_Of_Runs / User_Time; + Vax_Mips = Dhrystones_Per_Second / 1757.0; + + printf ("Register option selected? NO\n"); + strcpy(Reg_Define.ptr, "Register option not selected."); + printf ("Microseconds for one run through Dhrystone: "); + printf ("%7.1f \n", Microseconds); + printf ("Dhrystones per Second: "); + printf ("%10.1f \n", Dhrystones_Per_Second); + printf ("VAX MIPS rating = %10.3f \n",Vax_Mips); + printf ("\n"); + + /+ + fprintf(Ap,"\n"); + fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: D)\n"); + fprintf(Ap,"%.*s\n",Reg_Define.length, Reg_Define.ptr); + fprintf(Ap,"Microseconds for one loop: %7.1f\n",Microseconds); + fprintf(Ap,"Dhrystones per second: %10.1f\n",Dhrystones_Per_Second); + fprintf(Ap,"VAX MIPS rating: %10.3f\n",Vax_Mips); + fclose(Ap); + +/ + + } + +} + +void Proc_1 (Rec_Pointer Ptr_Val_Par) +/******************/ + + /* executed once */ +{ + Rec_Pointer Next_Record = Ptr_Val_Par.Ptr_Comp; + /* == Ptr_Glob_Next */ + /* Local variable, initialized with Ptr_Val_Par.Ptr_Comp, */ + /* corresponds to "rename" in Ada, "with" in Pascal */ + + *Ptr_Val_Par.Ptr_Comp = *Ptr_Glob; + Ptr_Val_Par.variant.var_1.Int_Comp = 5; + Next_Record.variant.var_1.Int_Comp + = Ptr_Val_Par.variant.var_1.Int_Comp; + Next_Record.Ptr_Comp = Ptr_Val_Par.Ptr_Comp; + Proc_3 (&Next_Record.Ptr_Comp); + /* Ptr_Val_Par.Ptr_Comp.Ptr_Comp + == Ptr_Glob.Ptr_Comp */ + if (Next_Record.Discr == Ident_1) + /* then, executed */ + { + Next_Record.variant.var_1.Int_Comp = 6; + Proc_6 (Ptr_Val_Par.variant.var_1.Enum_Comp, + &Next_Record.variant.var_1.Enum_Comp); + Next_Record.Ptr_Comp = Ptr_Glob.Ptr_Comp; + Proc_7 (Next_Record.variant.var_1.Int_Comp, 10, + &Next_Record.variant.var_1.Int_Comp); + } + else /* not executed */ + *Ptr_Val_Par = *Ptr_Val_Par.Ptr_Comp; +} /* Proc_1 */ + +void Proc_2 (One_Fifty *Int_Par_Ref) +/******************/ + /* executed once */ + /* *Int_Par_Ref == 1, becomes 4 */ +{ + One_Fifty Int_Loc; + Enumeration Enum_Loc; + + Int_Loc = *Int_Par_Ref + 10; + do /* executed once */ + if (Ch_1_Glob == 'A') + /* then, executed */ + { + Int_Loc -= 1; + *Int_Par_Ref = Int_Loc - Int_Glob; + Enum_Loc = Ident_1; + } /* if */ + while (Enum_Loc != Ident_1); /* true */ +} /* Proc_2 */ + + +void Proc_3 (Rec_Pointer *Ptr_Ref_Par) +/******************/ + /* executed once */ + /* Ptr_Ref_Par becomes Ptr_Glob */ + +{ + if (Ptr_Glob != null) + /* then, executed */ + *Ptr_Ref_Par = Ptr_Glob.Ptr_Comp; + Proc_7 (10, Int_Glob, &Ptr_Glob.variant.var_1.Int_Comp); +} /* Proc_3 */ + +void Proc_4 () /* without parameters */ +/*******/ + /* executed once */ +{ + Boolean Bool_Loc; + + Bool_Loc = Ch_1_Glob == 'A'; + Bool_Glob = Bool_Loc | Bool_Glob; + Ch_2_Glob = 'B'; +} /* Proc_4 */ + + +void Proc_5 () /* without parameters */ +/*******/ + /* executed once */ +{ + Ch_1_Glob = 'A'; + Bool_Glob = false; +} /* Proc_5 */ + + +void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par) +/*********************************/ + /* executed once */ + /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ +{ + *Enum_Ref_Par = Enum_Val_Par; + if (! Func_3 (Enum_Val_Par)) + /* then, not executed */ + *Enum_Ref_Par = Ident_4; + final switch (Enum_Val_Par) + { + case Ident_1: + *Enum_Ref_Par = Ident_1; + break; + case Ident_2: + if (Int_Glob > 100) + /* then */ + *Enum_Ref_Par = Ident_1; + else *Enum_Ref_Par = Ident_4; + break; + case Ident_3: /* executed */ + *Enum_Ref_Par = Ident_2; + break; + case Ident_4: break; + case Ident_5: + *Enum_Ref_Par = Ident_3; + break; + } /* switch */ +} /* Proc_6 */ + + +void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref) +/**********************************************/ + /* executed three times */ + /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ + /* Int_Par_Ref becomes 7 */ + /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */ + /* Int_Par_Ref becomes 17 */ + /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ + /* Int_Par_Ref becomes 18 */ +{ + One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 2; + *Int_Par_Ref = Int_2_Par_Val + Int_Loc; +} /* Proc_7 */ + + +void Proc_8 (ref Arr_1_Dim Arr_1_Par_Ref, ref Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val) +/*********************************************************************/ + /* executed once */ + /* Int_Par_Val_1 == 3 */ + /* Int_Par_Val_2 == 7 */ +{ + One_Fifty Int_Index; + One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 5; + Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val; + Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc]; + Arr_1_Par_Ref [Int_Loc+30] = Int_Loc; + for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index) + Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc; + Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1; + Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc]; + Int_Glob = 5; +} /* Proc_8 */ + + +Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val) +/*************************************************/ + /* executed three times */ + /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ + /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ + /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ +{ + Capital_Letter Ch_1_Loc; + Capital_Letter Ch_2_Loc; + + Ch_1_Loc = Ch_1_Par_Val; + Ch_2_Loc = Ch_1_Loc; + if (Ch_2_Loc != Ch_2_Par_Val) + /* then, executed */ + return (Ident_1); + else /* not executed */ + { + Ch_1_Glob = Ch_1_Loc; + return (Ident_2); + } +} /* Func_1 */ + + +Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) +/*************************************************/ + /* executed once */ + /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ + /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ +{ + One_Thirty Int_Loc; + Capital_Letter Ch_Loc; + + Int_Loc = 2; + while (Int_Loc <= 2) /* loop body executed once */ + if (Func_1 (Str_1_Par_Ref[Int_Loc], + Str_2_Par_Ref[Int_Loc+1]) == Ident_1) + /* then, executed */ + { + Ch_Loc = 'A'; + Int_Loc += 1; + } /* if, while */ + if (Ch_Loc >= 'W' && Ch_Loc < 'Z') + /* then, not executed */ + Int_Loc = 7; + if (Ch_Loc == 'R') + /* then, not executed */ + return (true); + else /* executed */ + { + //if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0) + //if (memcmp (Str_1_Par_Ref, Str_2_Par_Ref, 30) > 0) + if (Str_1_Par_Ref > Str_2_Par_Ref) + /* then, not executed */ + { + Int_Loc += 7; + Int_Glob = Int_Loc; + return (true); + } + else /* executed */ + return (false); + } /* if Ch_Loc */ +} /* Func_2 */ + + +Boolean Func_3 (Enumeration Enum_Par_Val) +/***************************/ + /* executed once */ + /* Enum_Par_Val == Ident_3 */ +{ + Enumeration Enum_Loc; + + Enum_Loc = Enum_Par_Val; + if (Enum_Loc == Ident_3) + /* then, executed */ + return (true); + else /* not executed */ + return (false); +} /* Func_3 */ + +version (Windows) +{ + import core.sys.windows.winbase; + + double dtime() + { + double q; + + q = cast(double)GetTickCount() * 1.0e-03; + + return q; + } +} + +version (linux) +{ + import core.stdc.time; + + double dtime() + { + double q; + + q = cast(double)time(null); + + return q; + } +} + +version (OSX) // supplied by Anders F Bjorklund +{ + import core.sys.posix.sys.time; + + double dtime() + { + double q; + timeval tv; + + gettimeofday(&tv,null); + q = cast(double)tv.tv_sec + cast(double)tv.tv_usec * 1.0e-6; + + return q; + } +} + +version (NetBSD) +{ + import core.sys.posix.sys.time; + + double dtime() + { + double q; + timeval tv; + + gettimeofday(&tv,null); + q = cast(double)tv.tv_sec + cast(double)tv.tv_usec * 1.0e-6; + + return q; + } +} diff --git a/gcc/testsuite/gdc.test/runnable/eh.d b/gcc/testsuite/gdc.test/runnable/eh.d index b3077a2e96f..7e7ec19eb30 100644 --- a/gcc/testsuite/gdc.test/runnable/eh.d +++ b/gcc/testsuite/gdc.test/runnable/eh.d @@ -104,7 +104,7 @@ printf("catch, i = %d\n", i); } } - printf("iterations %d totals: %ld, %ld\n", cIterations, total_x, total_nox); + printf("iterations %d totals: %lld, %lld\n", cIterations, total_x, total_nox); } int fn2_nox() @@ -170,7 +170,7 @@ void test4() catch(Exception e) { auto es = e.toString(); - printf("%.*s\n", es.length, es.ptr); + printf("%.*s\n", cast(int)es.length, es.ptr); b++; } finally @@ -213,7 +213,7 @@ void test4() { d++; string es = e.toString; - printf("%.*s\n", es.length, es.ptr); + printf("%.*s\n", cast(int)es.length, es.ptr); } assert(a == 2); @@ -255,7 +255,7 @@ void test4() { q3++; string es = e.toString; - printf("%.*s\n", es.length, es.ptr); + printf("%.*s\n", cast(int)es.length, es.ptr); } assert(q0 == 1); @@ -287,7 +287,7 @@ void test5() result ~= cast(char)('a' + i); } } - printf("--- %.*s", result.length, result.ptr); + printf("--- %.*s", cast(int)result.length, result.ptr); if (result != "tctbta") assert(0); } @@ -352,6 +352,38 @@ void test7() /**************************************************** * Exception chaining tests. See also test4.d + * Don writes about the complexity: + +I can explain this, since I did the original implementation. +When I originally implemented this, I discovered that the idea of +"chained exceptions" was hopeless naive. The idea was that while +processing one exception, if you encounter a second one, and you +chain them together. Then you get a third, fourth, etc. + +The problem is that it's much more complicated than that. Each of +the exceptions can be a chain of exceptions themselves. This means +that you don't end up with a chain of exceptions, but rather a tree +of exceptions. That's why there are those really nasty test cases +in the test suite. + +The examples in the test suite are very difficult to understand if +you expect it to be a simple chain! + +On the one hand, I was very proud that I was able to work out the +barely-documented behaviour of Windows SEH, and it was really +thorough. In the initial implementation, all the complexity +was covered. It wasn't the bugfix-driven-development which dmd +usually operates under <g>. + +But on the other hand, once you can see all of the complexity, +exception chaining becomes much less convincing as a concept. Sure, +the full exception tree is available in the final exception which +you catch. But, is it of any use? I doubt it very much. +It's pretty clearly a nett loss to the language, it increases +complexity with negligible benefit. Fortunately in this case, the +cost isn't really high. + +https://digitalmars.com/d/archives/digitalmars/D/Dicebot_on_leaving_D_It_is_anarchy_driven_development_in_all_its_317950.html#N318305 ****************************************************/ int result1513; @@ -379,6 +411,15 @@ void bug1513b() assert(e.msg == "d"); assert(e.next.msg == "f"); assert(!e.next.next); + int i; + foreach (u; e) + { + if (i) + assert(u.msg == "f"); + else + assert(u.msg == "d"); + ++i; + } } } @@ -658,7 +699,7 @@ void test9() } /****************************************************/ -// 10964 +// https://issues.dlang.org/show_bug.cgi?id=10964 void test10964() { @@ -836,6 +877,137 @@ void test17481() /****************************************************/ +// a nothrow function, even though it is not marked as nothrow +void test12() +{ + int i = 3; + try + { + try + { + ++i; + goto L10; + } + finally + { + i *= 2; + printf("f1\n"); + } + } + finally + { + i += 5; + printf("f2\n"); + } + +L10: + printf("3\n"); + assert(i == (3 + 1) * 2 + 5); +} + +/****************************************************/ + +void foo13() { } + +void test13() +{ + int i = 3; + try + { + try + { + foo13(); // compiler assumes it throws + ++i; + goto L10; + } + finally + { + i *= 2; + printf("f1\n"); + } + } + finally + { + i += 5; + printf("f2\n"); + } + +L10: + printf("3\n"); + assert(i == (3 + 1) * 2 + 5); +} + +/****************************************************/ + +// https://issues.dlang.org/show_bug.cgi?id=10966 + +void bug10966a(void* p) +{ + void* pstart = p; + + try + { + p = null; + throw new Exception("dummy"); + } + catch (Throwable o) + { + assert(p != pstart); + } +} + +void bug10966b() +{ + int x = 0; + int i = 0; + try + { + i = 1; + throw new Exception("dummy"); + } + catch (Throwable o) + { + x = i; + } + assert(x == 1); +} + +void test10966() +{ + int s; + bug10966a(&s); + bug10966b(); +} + +/****************************************************/ + +// https://issues.dlang.org/show_bug.cgi?id=11049 + +void test11049() +{ + int[] arr = [1,2,3]; + +#line 4100 "foo" + try { auto n = arr[3]; } + catch (Error e) + { + //printf("e.file = %s\n", e.file.ptr); + assert(e.file == "foo"); // fails + assert(e.line == 4100); + } + +#line 4200 "bar" + try { auto a = arr[3..9]; } + catch (Error e) + { + //printf("e.file = %s\n", e.file.ptr); + assert(e.file == "bar"); // fails + assert(e.line == 4200); + } +} + +/****************************************************/ + int main() { printf("start\n"); @@ -860,6 +1032,10 @@ int main() test10(); test11(); test17481(); + test12(); + test13(); + test10966(); + test11049(); printf("finish\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/entity1.d b/gcc/testsuite/gdc.test/runnable/entity1.d index 39211934110..feeb1ee1536 100644 --- a/gcc/testsuite/gdc.test/runnable/entity1.d +++ b/gcc/testsuite/gdc.test/runnable/entity1.d @@ -136,7 +136,7 @@ int main(){ return 0; } -// Bug 5221 +// https://issues.dlang.org/show_bug.cgi?id=5221 static assert('\✓'==10003); static assert('\≲'==8818); static assert('\№'==8470); diff --git a/gcc/testsuite/gdc.test/runnable/evalorder.d b/gcc/testsuite/gdc.test/runnable/evalorder.d index 8b56cc7af59..6805ee2e649 100644 --- a/gcc/testsuite/gdc.test/runnable/evalorder.d +++ b/gcc/testsuite/gdc.test/runnable/evalorder.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); void test14040() diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/lib13742a.d b/gcc/testsuite/gdc.test/runnable/extra-files/lib13742a.d new file mode 100644 index 00000000000..762559bc12c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/extra-files/lib13742a.d @@ -0,0 +1,6 @@ +module lib13742a; + +void performLocked(alias PROC)() +{ + PROC(); +} diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/lib13742b.d b/gcc/testsuite/gdc.test/runnable/extra-files/lib13742b.d new file mode 100644 index 00000000000..03163b5504e --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/extra-files/lib13742b.d @@ -0,0 +1,8 @@ +module lib13742b; +import lib13742a; + +void clear() +{ + void foo() {} // nested function + performLocked!foo; // template from other module (preceding on command line) +} diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/minimal/object.d b/gcc/testsuite/gdc.test/runnable/extra-files/minimal/object.d new file mode 100644 index 00000000000..bc8b3729739 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/extra-files/minimal/object.d @@ -0,0 +1,8 @@ +module object; + +extern(C) void _Dmain(); + +extern(C) void main() +{ + _Dmain(); +} diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/moreBettercUnittests.d b/gcc/testsuite/gdc.test/runnable/extra-files/moreBettercUnittests.d new file mode 100644 index 00000000000..1597a16d8db --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/extra-files/moreBettercUnittests.d @@ -0,0 +1,11 @@ +__gshared uint sum; + +unittest +{ + sum |= 0x100; +} + +unittest +{ + sum |= 0x1000; +} diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/test13742.d b/gcc/testsuite/gdc.test/runnable/extra-files/test13742.d new file mode 100644 index 00000000000..3666bb24998 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/extra-files/test13742.d @@ -0,0 +1,6 @@ +import lib13742b; + +void main() +{ + clear(); +} diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/teststdio.txt b/gcc/testsuite/gdc.test/runnable/extra-files/teststdio.txt deleted file mode 100644 index 9a5f6b1290d..00000000000 --- a/gcc/testsuite/gdc.test/runnable/extra-files/teststdio.txt +++ /dev/null @@ -1,6 +0,0 @@ -asdfasdf -a -sdf -asdf - - diff --git a/gcc/testsuite/gdc.test/runnable/fix20466.d b/gcc/testsuite/gdc.test/runnable/fix20466.d new file mode 100644 index 00000000000..afc8349d22d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/fix20466.d @@ -0,0 +1,40 @@ +/* REQUIRED_ARGS: -O -fPIC + * DISABLED: win32 win64 + */ +// https://issues.dlang.org/show_bug.cgi?id=20466 + +extern (C++) final class Parameter +{ + ulong storageClass; + void* type; +} + +extern (C++) final class IfStatement +{ + Parameter prm; +} + +extern (C++) final class Visitor +{ + void visit(IfStatement s) + { + if (Parameter p = s.prm) + { + ulong stc = p.storageClass; + if (!p.type && !stc) + stc = 1L << 8; + assert(!(stc & (1L << 34))); + } + } +} + +int main() +{ + auto p = new Parameter; + p.storageClass = 1L << 2; + auto s = new IfStatement; + s.prm = p; + auto v = new Visitor; + v.visit(s); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/fix22115.d b/gcc/testsuite/gdc.test/runnable/fix22115.d new file mode 100644 index 00000000000..2344bcc1a0c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/fix22115.d @@ -0,0 +1,70 @@ +/* PERMUTE_ARGS: -O -inline + */ +// https://issues.dlang.org/show_bug.cgi?id=22115 + + +int sx; +void sss() { ++sx; } + +static if (1) +{ + struct S { int a; } + + void test1(S* s) + { + if (s.a == 3 ? s : null) + sss(); + } +} + +static if (1) +{ + extern (C++) class Exp + { + int a; + + void func() { } + final inout(AddExp) isAddExp() inout { return a == 3 ? cast(typeof(return))this : null; } + } + + extern (C++) class AddExp : Exp + { + } + + void test2(Exp e) + { + if (e.isAddExp()) + sss(); + } +} + + +int main() +{ + static if (1) + { + S s; + s.a = 3; + test1(&s); + assert(sx == 1); + s.a = 2; + test1(&s); + assert(sx == 1); + } + sx = 1; + + static if (1) + { + auto c = new AddExp(); + c.a = 3; + test2(c); + assert(sx == 2); + auto ae = c.isAddExp(); + assert(ae && ae.a == 3); + c.a = 2; + test2(c); + assert(sx == 2); + } + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/foreach.d b/gcc/testsuite/gdc.test/runnable/foreach.d index 331c927504a..f0d1ea9ba9c 100644 --- a/gcc/testsuite/gdc.test/runnable/foreach.d +++ b/gcc/testsuite/gdc.test/runnable/foreach.d @@ -1,3 +1,22 @@ +/* +RUN_OUTPUT: +--- +u = 17 +u = 1 +u = 1 +u = 1 +u = 1 +a[0] = 21 +a[1] = 22 +a[2] = 23 +a[] = 21 +a[] = 22 +a[] = 23 +a = 63, b = 47, c = 83 +a = 63, b = 48, c = 83 +Success +--- +*/ import core.stdc.stdio; @@ -209,16 +228,26 @@ void test7() a["foo"] = 3; a["bar"] = 4; + bool sawBar, sawFoo; foreach (string s, uint v; a) { - printf("a[%.*s] = %d\n", s.length, s.ptr, v); if (s == "bar") + { assert(v == 4); + assert(!sawBar); + sawBar = true; + } else if (s == "foo") + { assert(v == 3); + assert(!sawFoo); + sawFoo = true; + } else assert(0); } + assert(sawBar); + assert(sawFoo); } diff --git a/gcc/testsuite/gdc.test/runnable/foreach2.d b/gcc/testsuite/gdc.test/runnable/foreach2.d index 34edb41edaf..b30d1519704 100644 --- a/gcc/testsuite/gdc.test/runnable/foreach2.d +++ b/gcc/testsuite/gdc.test/runnable/foreach2.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ import core.stdc.stdio; diff --git a/gcc/testsuite/gdc.test/runnable/foreach3.d b/gcc/testsuite/gdc.test/runnable/foreach3.d index e167217e7a3..3c9c288b9e4 100644 --- a/gcc/testsuite/gdc.test/runnable/foreach3.d +++ b/gcc/testsuite/gdc.test/runnable/foreach3.d @@ -1,9 +1,15 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ import core.stdc.stdio; struct Foo { - uint array[2]; + uint[2] array; int opApply(int delegate(ref uint) dg) { diff --git a/gcc/testsuite/gdc.test/runnable/foreach4.d b/gcc/testsuite/gdc.test/runnable/foreach4.d index 8c9d4218d6e..f2e19439647 100644 --- a/gcc/testsuite/gdc.test/runnable/foreach4.d +++ b/gcc/testsuite/gdc.test/runnable/foreach4.d @@ -1,6 +1,4 @@ -// RUNNABLE_PHOBOS_TEST import core.stdc.stdio; -import std.stdio; alias bool bit; @@ -8,7 +6,7 @@ alias bool bit; class Foo { - uint array[2]; + uint[2] array; int opApply(int delegate(ref uint) dg) { @@ -363,7 +361,7 @@ void test12() j = 0; foreach (size_t i, dchar d; "hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -397,7 +395,7 @@ void test13() j = 0; foreach (size_t i, wchar d; "hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -431,7 +429,7 @@ void test14() j = 0; foreach (size_t i, char d; cast(wstring)"hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -465,7 +463,7 @@ void test15() j = 0; foreach (size_t i, dchar d; cast(wstring)"hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -499,7 +497,7 @@ void test16() j = 0; foreach (size_t i, char d; cast(dstring)"hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -533,7 +531,7 @@ void test17() j = 0; foreach (size_t i, wchar d; cast(dstring)"hello") { - printf("i = %d, d = x%x\n", i, d); + printf("i = %d, d = x%x\n", cast(int)i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); @@ -577,7 +575,7 @@ void test18() void test19() { - string string = x"F0 9D 83 93"; + string string = "\xF0\x9D\x83\x93"; int count=0; dchar tmp; @@ -615,18 +613,18 @@ void test20() void foo21(string[] args) { - printf("args.length = %d\n", args.length); + printf("args.length = %d\n", cast(int)args.length); assert(args.length == 3); foreach (i, arg; args) { assert(typeid(typeof(i)) == typeid(size_t)); assert(typeid(typeof(arg)) == typeid(string)); - writefln("args[%d] = '%s'", i, arg); + printf("args[%d] = '%.*s'\n", cast(int)i, cast(int)arg.length, arg.ptr); } foreach (arg; args) { assert(typeid(typeof(arg)) == typeid(string)); - writefln("args[] = '%s'", arg); + printf("args[] = '%.*s'\n", cast(int)arg.length, arg.ptr); } } @@ -654,24 +652,24 @@ void test22() { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); - writefln("map[%s] = %s", key, value); + printf("map[%.*s] = %d\n", cast(int)key.length, key.ptr, value); } foreach (key, int value; map) { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); - writefln("map[%s] = %s", key, value); + printf("map[%.*s] = %d\n", cast(int)key.length, key.ptr, value); } foreach (string key, value; map) { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); - writefln("map[%s] = %s", key, value); + printf("map[%.*s] = %d\n", cast(int)key.length, key.ptr, value); } foreach (value; map) { assert(typeid(typeof(value)) == typeid(int)); - writefln("map[] = %s", value); + printf("map[] = %d\n", value); } } @@ -679,7 +677,7 @@ void test22() class Foo23 { - int array[2]; + int[2] array; int opApply(int delegate(ref int) dg) { @@ -719,7 +717,7 @@ void test23() assert(typeid(typeof(u)) == typeid(int)); i++; u++; - //writefln("u = %d", u); + //printf("u = %d\n", u); assert((i == 1) ? u == 74 : u == 83); } assert(i == 2); @@ -732,7 +730,7 @@ void test23() assert(typeid(typeof(u)) == typeid(int)); i++; u++; - writefln("u = %d", u); + //printf("u = %d\n", u); assert((i == 3) ? u == 74 : u == 83); assert(j == i - 3); } @@ -777,7 +775,6 @@ void test25() { foreach (string s; aarray) { - writeln(s); assert(s == "b"); } }; @@ -790,7 +787,7 @@ void test25() struct Foo26 { - uint array[2]; + uint[2] array; int forward(int delegate(ref uint) dg) { @@ -833,7 +830,7 @@ void test26() foreach (u; &a.forward) { - writeln(u); + printf("%d\n", u); i++; u++; } @@ -843,7 +840,7 @@ void test26() foreach (uint u; &a.reverse) { - writeln(u); + printf("%d\n", u); } } diff --git a/gcc/testsuite/gdc.test/runnable/foreach5.d b/gcc/testsuite/gdc.test/runnable/foreach5.d index 003a34a8e6d..59b88ec88cb 100644 --- a/gcc/testsuite/gdc.test/runnable/foreach5.d +++ b/gcc/testsuite/gdc.test/runnable/foreach5.d @@ -1,4 +1,5 @@ /* +EXTRA_FILES: imports/test15777a.d imports/test15777b.d TEST_OUTPUT: --- int @@ -14,6 +15,8 @@ test7406() extern(C) int printf(const char* fmt, ...); +alias AliasSeq(X...) = X; + /***************************************/ void test1() @@ -43,7 +46,7 @@ void test1() } /***************************************/ -// 2411 +// https://issues.dlang.org/show_bug.cgi?id=2411 struct S2411 { @@ -68,7 +71,7 @@ void test2411() } /***************************************/ -// 2442 +// https://issues.dlang.org/show_bug.cgi?id=2442 template canForeach(T, E) { @@ -148,7 +151,7 @@ void test2442() } /***************************************/ -// 2443 +// https://issues.dlang.org/show_bug.cgi?id=2443 struct S2443 { @@ -175,7 +178,7 @@ void test2443() } /***************************************/ -// 3187 +// https://issues.dlang.org/show_bug.cgi?id=3187 class Collection { @@ -200,7 +203,7 @@ void test3187() } /***************************************/ -// 4090 +// https://issues.dlang.org/show_bug.cgi?id=4090 void test4090a() { @@ -244,7 +247,7 @@ void test4090b() } /***************************************/ -// 5605 +// https://issues.dlang.org/show_bug.cgi?id=5605 struct MyRange { @@ -255,7 +258,7 @@ struct MyRange return true; } - @property ref int front() + @property ref int front() return { return theOnlyOne; } @@ -282,7 +285,7 @@ void test5605() } /***************************************/ -// 7004 +// https://issues.dlang.org/show_bug.cgi?id=7004 void func7004(A...)(A args) { @@ -296,7 +299,7 @@ void test7004() } /***************************************/ -// 7406 +// https://issues.dlang.org/show_bug.cgi?id=7406 template TypeTuple7406(T...) { @@ -327,7 +330,7 @@ void test7406() } /***************************************/ -// 6659 +// https://issues.dlang.org/show_bug.cgi?id=6659 void test6659() { @@ -417,7 +420,7 @@ void test6659c() /***************************************/ -// 10221 +// https://issues.dlang.org/show_bug.cgi?id=10221 void test10221() { @@ -446,7 +449,7 @@ void test10221() } /***************************************/ -// 7814 +// https://issues.dlang.org/show_bug.cgi?id=7814 struct File7814 { @@ -475,7 +478,7 @@ void test7814() } /***************************************/ -// 10049 +// https://issues.dlang.org/show_bug.cgi?id=10049 struct ByLine10049 { @@ -515,7 +518,7 @@ void test11955() } /******************************************/ -// 6652 +// https://issues.dlang.org/show_bug.cgi?id=6652 void test6652() { @@ -616,7 +619,7 @@ void test6652() } /***************************************/ -// 8595 +// https://issues.dlang.org/show_bug.cgi?id=8595 struct OpApply8595 { @@ -636,7 +639,7 @@ string test8595() } /***************************************/ -// 9068 +// https://issues.dlang.org/show_bug.cgi?id=9068 struct Foo9068 { @@ -723,7 +726,7 @@ loop_with_dtors: } /***************************************/ -// 11885 +// https://issues.dlang.org/show_bug.cgi?id=11885 struct Foo11885 { @@ -810,7 +813,7 @@ loop_with_dtors: } /***************************************/ -// 10475 +// https://issues.dlang.org/show_bug.cgi?id=10475 void test10475a() { @@ -888,7 +891,7 @@ void test10475b() } /***************************************/ -// 11291 +// https://issues.dlang.org/show_bug.cgi?id=11291 void test11291() { @@ -917,7 +920,7 @@ void test11291() } /***************************************/ -// 12103 +// https://issues.dlang.org/show_bug.cgi?id=12103 alias TypeTuple12103(TL...) = TL; @@ -945,7 +948,7 @@ void test12103() } /***************************************/ -// 12739 +// https://issues.dlang.org/show_bug.cgi?id=12739 struct S12739 { @@ -963,7 +966,7 @@ void test12739() nothrow } /***************************************/ -// 12932 +// https://issues.dlang.org/show_bug.cgi?id=12932 void test12932() @nogc { @@ -976,7 +979,7 @@ void test12932() @nogc } /***************************************/ -// 13756 +// https://issues.dlang.org/show_bug.cgi?id=13756 void test13756() { @@ -1046,7 +1049,7 @@ void test13756() } /***************************************/ -// 14653 +// https://issues.dlang.org/show_bug.cgi?id=14653 static string result14653; @@ -1098,6 +1101,81 @@ void test14653() } /***************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15777 + +template funA15777() +{ + import imports.test15777a; + alias funA15777 = fun; +} + +template funB15777() +{ + import imports.test15777b; + alias funB15777 = fun; +} + +template funAB15777() +{ + import imports.test15777a; + import imports.test15777b; + alias funAB15777 = fun; +} + +void foo15777(alias tpl)() +{ + alias seq = AliasSeq!(tpl!()); + // Make alias of 'overload set' in tuple elements + static assert(seq.length == 1); + foreach (i, n; seq) + { + static assert(__traits(identifier, seq[i]) == "fun"); + } +} + +void test15777() +{ + foo15777!funA15777; + foo15777!funB15777; + foo15777!funAB15777; +} + +/***************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17041 + +auto ref int[2] foo17041(A...)(auto ref A args) +{ + foreach(a; args) + { + a = [12, 22]; + } + foreach(ref a; args) + { + a = [31, 41]; + return args[0]; + } +} + +void test17041() +{ + int[2] x = [10, 20]; + foreach(a; AliasSeq!(x)) + { + a = [11, 21]; + } + assert(x == [10, 20]); // test by value + foreach(ref a; AliasSeq!(x)) + { + a = [30, 40]; + } + assert(x == [30, 40]); // test by ref value + + assert(foo17041(x) == [31, 41]); // test lvalue + assert(x == [31, 41]); + assert(foo17041(cast(int[2]) [10, 20]) == [31, 41]); // test rvalue +} + +/***************************************/ int main() { @@ -1125,10 +1203,10 @@ int main() test11291(); test12103(); test12739(); - printf("test12932()\n"); test12932(); test13756(); test14653(); + test17041(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/funclit.d b/gcc/testsuite/gdc.test/runnable/funclit.d index c299badec15..25b4e6e512c 100644 --- a/gcc/testsuite/gdc.test/runnable/funclit.d +++ b/gcc/testsuite/gdc.test/runnable/funclit.d @@ -176,7 +176,7 @@ void test4() // function/delegate inference + overload resolution assert(nbaz4({ }) == 1); assert(nbaz4({ v = 1; }) == 2); - assert(nbaz4({ sfoo(); }) == 1); // Bugzilla 8836 + assert(nbaz4({ sfoo(); }) == 1); // https://issues.dlang.org/show_bug.cgi?id=8836 assert(nbaz4({ nfoo(); }) == 2); assert(tbaz4({ }) == 1); @@ -354,7 +354,7 @@ void test11() } /***************************************************/ -// 3235 +// https://issues.dlang.org/show_bug.cgi?id=3235 void test3235() { @@ -365,7 +365,7 @@ void test3235() } /***************************************************/ -// 6714 +// https://issues.dlang.org/show_bug.cgi?id=6714 void foo6714x(int function (int, int) a){} void bar6714x(int delegate (int, int) a){} @@ -384,7 +384,7 @@ void test6714() } /***************************************************/ -// 7193 +// https://issues.dlang.org/show_bug.cgi?id=7193 void test7193() { @@ -394,7 +394,8 @@ void test7193() } /***************************************************/ -// 7207 : on CastExp +// https://issues.dlang.org/show_bug.cgi?id=7207 +// on CastExp void test7202() { @@ -403,7 +404,7 @@ void test7202() } /***************************************************/ -// 7288 +// https://issues.dlang.org/show_bug.cgi?id=7288 void test7288() { @@ -411,7 +412,7 @@ void test7288() auto foo() { int x; - return () => { return x; }; + return () { return () => x; }; } pragma(msg, typeof(&foo)); alias int delegate() pure nothrow @nogc @safe delegate() pure nothrow @nogc @safe delegate() pure nothrow @safe Dg; @@ -420,7 +421,7 @@ void test7288() } /***************************************************/ -// 7499 +// https://issues.dlang.org/show_bug.cgi?id=7499 void test7499() { @@ -431,7 +432,7 @@ void test7499() } /***************************************************/ -// 7500 +// https://issues.dlang.org/show_bug.cgi?id=7500 void test7500() { @@ -440,7 +441,7 @@ void test7500() } /***************************************************/ -// 7525 +// https://issues.dlang.org/show_bug.cgi?id=7525 void test7525() { @@ -462,7 +463,7 @@ void test7525() } /***************************************************/ -// 7582 +// https://issues.dlang.org/show_bug.cgi?id=7582 void test7582() { @@ -474,7 +475,7 @@ void test7582() } /***************************************************/ -// 7649 +// https://issues.dlang.org/show_bug.cgi?id=7649 void test7649() { @@ -486,7 +487,7 @@ void test7649() } /***************************************************/ -// 7650 +// https://issues.dlang.org/show_bug.cgi?id=7650 void test7650() { @@ -513,7 +514,7 @@ void test7650() } /***************************************************/ -// 7705 +// https://issues.dlang.org/show_bug.cgi?id=7705 void test7705() { @@ -529,7 +530,7 @@ void test7705() } /***************************************************/ -// 7713 +// https://issues.dlang.org/show_bug.cgi?id=7713 void foo7713(T)(T delegate(in Object) dlg) {} @@ -539,7 +540,7 @@ void test7713() } /***************************************************/ -// 7743 +// https://issues.dlang.org/show_bug.cgi?id=7743 auto foo7743a() { @@ -564,7 +565,7 @@ void test7743() } /***************************************************/ -// 7761 +// https://issues.dlang.org/show_bug.cgi?id=7761 enum dg7761 = (int a) pure => 2 * a; @@ -575,7 +576,7 @@ void test7761() } /***************************************************/ -// 7941 +// https://issues.dlang.org/show_bug.cgi?id=7941 void test7941() { @@ -583,7 +584,7 @@ void test7941() } /***************************************************/ -// 8005 +// https://issues.dlang.org/show_bug.cgi?id=8005 void test8005() { @@ -615,7 +616,7 @@ void test8198() } /***************************************************/ -// 8226 +// https://issues.dlang.org/show_bug.cgi?id=8226 immutable f8226 = (int x) => x * 2; @@ -625,7 +626,7 @@ void test8226() } /***************************************************/ -// 8241 +// https://issues.dlang.org/show_bug.cgi?id=8241 auto exec8241a(alias a = function(x) => x, T...)(T as) { @@ -644,7 +645,7 @@ void test8241() } /***************************************************/ -// 8242 +// https://issues.dlang.org/show_bug.cgi?id=8242 template exec8242(alias a, T...) { @@ -664,7 +665,7 @@ void test8242() } /***************************************************/ -// 8315 +// https://issues.dlang.org/show_bug.cgi?id=8315 void test8315() { @@ -677,7 +678,7 @@ if (is(typeof(pred(1)) == bool)) {} /***************************************************/ -// 8397 +// https://issues.dlang.org/show_bug.cgi?id=8397 void test8397() { @@ -688,7 +689,7 @@ void test8397() } /***************************************************/ -// 8496 +// https://issues.dlang.org/show_bug.cgi?id=8496 void test8496() { @@ -700,7 +701,7 @@ void test8496() } /***************************************************/ -// 8575 +// https://issues.dlang.org/show_bug.cgi?id=8575 template tfunc8575(func...) { @@ -720,7 +721,7 @@ void test8575() } /***************************************************/ -// 9153 +// https://issues.dlang.org/show_bug.cgi?id=9153 void writeln9153(string s){} @@ -737,7 +738,7 @@ void test9153() } /***************************************************/ -// 9393 +// https://issues.dlang.org/show_bug.cgi?id=9393 template ifThrown9393a(E) { @@ -761,7 +762,7 @@ void test9393() } /***************************************************/ -// 9415 +// https://issues.dlang.org/show_bug.cgi?id=9415 void test9415() { @@ -771,7 +772,7 @@ void test9415() } /***************************************************/ -// 9628 +// https://issues.dlang.org/show_bug.cgi?id=9628 template TypeTuple9628(TL...) { alias TypeTuple9628 = TL; } void map9628(alias func)() { func(0); } @@ -805,7 +806,7 @@ void test9628() } /***************************************************/ -// 9928 +// https://issues.dlang.org/show_bug.cgi?id=9928 void test9928() { @@ -813,7 +814,7 @@ void test9928() } /***************************************************/ -// 10133 +// https://issues.dlang.org/show_bug.cgi?id=10133 ptrdiff_t countUntil10133(alias pred, R)(R haystack) { @@ -855,7 +856,7 @@ void test10133() } /***************************************************/ -// 10219 +// https://issues.dlang.org/show_bug.cgi?id=10219 void test10219() { @@ -904,7 +905,7 @@ void test10219() } /***************************************************/ -// 10288 +// https://issues.dlang.org/show_bug.cgi?id=10288 T foo10288(T)(T x) { @@ -934,7 +935,7 @@ void test10288() @safe pure nothrow } /***************************************************/ -// 10666 +// https://issues.dlang.org/show_bug.cgi?id=10666 struct S10666 { @@ -954,7 +955,7 @@ void foo10666(S10666 s1) } /***************************************************/ -// 11081 +// https://issues.dlang.org/show_bug.cgi?id=11081 T ifThrown11081(E : Throwable, T)(T delegate(E) errorHandler) { @@ -972,7 +973,7 @@ void test11081() } /***************************************************/ -// 11220 +// https://issues.dlang.org/show_bug.cgi?id=11220 int parsePrimaryExp11220(int x) { @@ -986,7 +987,7 @@ typeof(handler(1)) parseAmbig11220(alias handler)() } /***************************************************/ -// 11230 +// https://issues.dlang.org/show_bug.cgi?id=11230 template map11230(fun...) { @@ -1022,7 +1023,7 @@ C11230 visit11230() } /***************************************************/ -// 10336 +// https://issues.dlang.org/show_bug.cgi?id=10336 struct S10336 { @@ -1041,7 +1042,7 @@ void test10336() } /***************************************************/ -// 10928 +// https://issues.dlang.org/show_bug.cgi?id=10928 struct D10928 { @@ -1065,7 +1066,7 @@ void test10928() } /***************************************************/ -// 11661 +// https://issues.dlang.org/show_bug.cgi?id=11661 void test11661() { @@ -1074,7 +1075,7 @@ void test11661() } /***************************************************/ -// 11774 +// https://issues.dlang.org/show_bug.cgi?id=11774 void f11774(T, R)(R delegate(T[]) dg) { @@ -1091,7 +1092,7 @@ void test11774() } /***************************************************/ -// 12421 +// https://issues.dlang.org/show_bug.cgi?id=12421 void test12421() { @@ -1145,7 +1146,7 @@ void test12421() } /***************************************************/ -// 12508 +// https://issues.dlang.org/show_bug.cgi?id=12508 interface A12508(T) { @@ -1182,7 +1183,7 @@ void test12508() } /***************************************************/ -// 13879 +// https://issues.dlang.org/show_bug.cgi?id=13879 void test13879() { @@ -1194,7 +1195,7 @@ void test13879() } /***************************************************/ -// 14745 +// https://issues.dlang.org/show_bug.cgi?id=14745 void test14745() { @@ -1216,7 +1217,7 @@ void test14745() } /***************************************************/ -// 15794 +// https://issues.dlang.org/show_bug.cgi?id=15794 struct Foo15794 { diff --git a/gcc/testsuite/gdc.test/runnable/functype.d b/gcc/testsuite/gdc.test/runnable/functype.d index 7aa7efdb507..28e2709ffc1 100644 --- a/gcc/testsuite/gdc.test/runnable/functype.d +++ b/gcc/testsuite/gdc.test/runnable/functype.d @@ -183,7 +183,7 @@ void testxx() } /***************************************************/ -// 3646 +// https://issues.dlang.org/show_bug.cgi?id=3646 int bar3646(int x = 10) { printf("bar %d\n", x); return x; } int bam3646(int y) { printf("bam %d\n", y); return y; } @@ -215,7 +215,7 @@ void test3646() } /***************************************************/ -// 3866 +// https://issues.dlang.org/show_bug.cgi?id=3866 void test3866() { @@ -230,7 +230,7 @@ void test3866() } /***************************************************/ -// 8579 +// https://issues.dlang.org/show_bug.cgi?id=8579 void test8579() { @@ -254,7 +254,7 @@ void test8579() } /***************************************************/ -// 14210 +// https://issues.dlang.org/show_bug.cgi?id=14210 string foo14210a(DT)(string name, DT dg) { @@ -274,7 +274,7 @@ void test14210() } /***************************************************/ -// 10734 +// https://issues.dlang.org/show_bug.cgi?id=10734 // There's no platform independent export symbol, so // test just only in Win32. @@ -297,7 +297,7 @@ void test10734() } /***************************************************/ -// 14656 +// https://issues.dlang.org/show_bug.cgi?id=14656 void test14656() { diff --git a/gcc/testsuite/gdc.test/runnable/hello.d b/gcc/testsuite/gdc.test/runnable/hello.d index 88adaa4234b..b46f59dcd13 100644 --- a/gcc/testsuite/gdc.test/runnable/hello.d +++ b/gcc/testsuite/gdc.test/runnable/hello.d @@ -5,8 +5,8 @@ extern(C) int printf(const char*, ...); int main(char[][] args) { printf("hello world\n"); - printf("args.length = %d\n", args.length); + printf("args.length = %zd\n", args.length); for (int i = 0; i < args.length; i++) - printf("args[%d] = '%.*s'\n", i, args[i].length, args[i].ptr); + printf("args[%d] = '%.*s'\n", i, cast(int)args[i].length, args[i].ptr); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/helloUTF8.d b/gcc/testsuite/gdc.test/runnable/helloUTF8.d index 78f3bcdb3dd..aed66134f09 100644 --- a/gcc/testsuite/gdc.test/runnable/helloUTF8.d +++ b/gcc/testsuite/gdc.test/runnable/helloUTF8.d @@ -1,4 +1,10 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +hello world +--- +*/ extern(C) int printf(const char *, ...); diff --git a/gcc/testsuite/gdc.test/runnable/ice15030.d b/gcc/testsuite/gdc.test/runnable/ice15030.d index 5925e745ecc..5c9587ca9f6 100644 --- a/gcc/testsuite/gdc.test/runnable/ice15030.d +++ b/gcc/testsuite/gdc.test/runnable/ice15030.d @@ -1,6 +1,7 @@ // REQUIRED_ARGS: -unittest -boundscheck=off // PERMUTE_ARGS: // EXTRA_SOURCES: imports/a15030.d imports/b15030.d +// EXTRA_FILES: imports/std15030algo.d void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/ice21696.d b/gcc/testsuite/gdc.test/runnable/ice21696.d new file mode 100644 index 00000000000..8b7a81ebd5c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/ice21696.d @@ -0,0 +1,23 @@ +module ice21696; + +// https://issues.dlang.org/show_bug.cgi?id=21696 + +double[1][1] func(double[1][1] stuff = [[1.0]]) +{ + bool myFunc() + { + if (stuff[]) + return true; + return false; + } + + if (!myFunc()) + assert(false); + + return stuff; +} + +int main() +{ + return func() != [[1.0]]; +} diff --git a/gcc/testsuite/gdc.test/runnable/ice21727.d b/gcc/testsuite/gdc.test/runnable/ice21727.d new file mode 100644 index 00000000000..5b5745f9df0 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/ice21727.d @@ -0,0 +1,46 @@ +// REQUIRED_ARGS: -m64 -O -inline +// DISABLED: win32 linux32 freebsd32 osx32 netbsd32 dragonflybsd32 +// https://issues.dlang.org/show_bug.cgi?id=21727 + +import core.simd; + +@nogc nothrow pure @safe: + +struct Float4 +{ + float4 mVector; + + pragma(inline, false) ref typeof(this) doubleInPlace() return + @nogc nothrow pure @safe + { + mVector = mVector + mVector; + return this; + } +} + +pragma(inline, false) Float4 identity(Float4 a) +{ + return a; +} + +pragma(inline, true) Float4 twoTimes(const ref Float4 a) +{ + version (D_SIMD) + return Float4(cast(float4) __simd(XMM.ADDPS, a.mVector, a.mVector)); + else // Allow non-DMD compilers to compile this test. + return Float4(a.mVector + a.mVector); +} + +pragma(inline, false) Float4 fourTimes(const Float4 a) +{ + auto x = identity(a); + auto y = x.doubleInPlace(); // This crashed in dmd.backend.cgxmm.xmmload. + auto z = twoTimes(y); + return z; +} + +void main() +{ + const c = fourTimes(Float4([5,7,11,13])); + assert(c.mVector.array == [20, 28, 44, 52]); +} diff --git a/gcc/testsuite/gdc.test/runnable/ifti.d b/gcc/testsuite/gdc.test/runnable/ifti.d index 6d669753123..0c94946c8b3 100644 --- a/gcc/testsuite/gdc.test/runnable/ifti.d +++ b/gcc/testsuite/gdc.test/runnable/ifti.d @@ -1,27 +1,26 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; +extern (C) int printf(const scope char*, ...); struct S { int x = 3; - void fun(T)(T x) { writefln("S.fun(%s)(%s)",typeid(T),x); this.x += x; } + void fun(T)(T x) { printf("S.fun(%s)(%d)\n", T.stringof.ptr, x); this.x += x; } } class Tst(TST, int v = 2) { int x = 3; int z = 4; - final private void proc(int x) { writefln("proc(%s) -> %s",x,this.x); } - void fun(T)(T x) { writefln("fun(%s)(%s) -> %s",typeid(T),x,this.x);} - void fun()() { writefln("fun()() -> %s",this.x); } - void fun2()() { writefln("fun2"); } + final private void proc(int x) { printf("proc(%d) -> %d\n", x, this.x); } + void fun(T)(T x) { printf("fun(%s)(%d) -> %d\n", T.stringof.ptr, x, this.x);} + void fun()() { printf("fun()() -> %d\n", this.x); } + void fun2()() { printf("fun2\n"); } class Inner { int y = 99; Tst outer; void f3() { z = 55; } // Make sure the correct this-ptr is used - void f1() { writefln("Inner.f1"); proc(-11); outer.proc(-11); } - void f2() { writefln("Inner.f2"); fun(-17); outer.fun(-17); } + void f1() { printf("Inner.f1\n"); proc(-11); outer.proc(-11); } + void f2() { printf("Inner.f2\n"); fun(-17); outer.fun(-17); } } Inner inner; @@ -30,38 +29,36 @@ class Tst(TST, int v = 2) { inner.outer = this; } - void callInnerf1() { writefln("callInnerf1"); inner.f1(); } - void callInnerf2() { writefln("callInnerf2"); inner.f2(); } + void callInnerf1() { printf("callInnerf1\n"); inner.f1(); } + void callInnerf2() { printf("callInnerf2\n"); inner.f2(); } // - void opAdd(T)(T x) { this.x += x; writefln("opAdd(%s)",x); } - void opPos()() { writefln("opPos()"); } - //void opPos() { writefln("xxx"); } - void opIndex(T)(T x) { writefln("opIndex[%s]",x); } + void opBinary(string op : "+", T)(T x) { this.x += x; printf("opAdd(%d)\n", x); } + void opUnary(string op : "+")() { printf("opPos()\n"); } + //void opPos() { printf("xxx"); } + void opIndex(T)(T x) { printf("opIndex[%d]\n",x); } void opIndex(A,B,C)(A a, B b, C c) { - writefln("opIndex[(%s)%s,(%s)%s,(%s)%s]",typeid(A),a, - typeid(B),b,typeid(C),c); + printf("opIndex[(%s) %d, (%s) %d, (%s) %d]\n", A.stringof.ptr, a, + B.stringof.ptr,b,C.stringof.ptr,c); } - static if (v > 1) { - void opCall(A = int, B = float)(A a = 1, B b = 8.2) { writefln("opCall(%s,%s)",a,b); this.x++; } - + void opCall(A = int, B = float)(A a = 1, B b = 8.2) { printf("opCall(%d, %d)\n",a,b); this.x++; } } - void opSlice(A,B)(A a, B b) { writefln("opSlice(%s,%s)",a,b); } - void opSlice()() { writefln("opSlice()"); } + void opSlice(A,B)(A a, B b) { printf("opSlice(%d, %d)\n",a,b); } + void opSlice()() { printf("opSlice()\n"); } void opIndexAssign(A,B)(A a, B b) { - writefln("opIndexAssign((%s)%s,(%s)%s)",typeid(A),a,typeid(B),b); + printf("opIndexAssign((%s) %d, (%s) %d)\n", A.stringof.ptr, a, B.stringof.ptr, b); } void opSliceAssign(A,B,C)(A a, B b, C c) { - writefln("opSliceAssign(%s,%s,%s)",a,b,c); + printf("opSliceAssign(%.s, %d, %d)\n", a.length, a.ptr, b, c); } - bool opEquals(A)(A x) { writefln("opEquals((%s))",typeid(A));return true; } + bool opEquals(A)(A x) { printf("opEquals((%s))\n", A.stringof.ptr); return true; } int opApply(T)(int delegate(ref T)dg) { for (int i = 0; i < 5; i++) { @@ -103,8 +100,6 @@ void main() { t[]; t[1..2]; u[1..2.5]; - t[1i] = 5; - t[-4.5..7i] = "hello"; t == t; auto b = t != t; // without assignment -> "! has no effect in expression" t == u; @@ -112,10 +107,10 @@ void main() { u == u; b = u != u; foreach(int i;t) { - writefln("%s",i); + printf("%d\n", i); } foreach(double i;t) { - writefln("%s",i); + printf("%g\n", i); } } diff --git a/gcc/testsuite/gdc.test/runnable/implicit.d b/gcc/testsuite/gdc.test/runnable/implicit.d index 9170b04adb0..75b992c5c1c 100644 --- a/gcc/testsuite/gdc.test/runnable/implicit.d +++ b/gcc/testsuite/gdc.test/runnable/implicit.d @@ -1,5 +1,17 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; +/* +TEST_OUTPUT: +--- +runnable/implicit.d(162): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z1` +runnable/implicit.d(163): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z2` +--- + +RUN_OUTPUT: +--- +Success +--- +*/ + +import core.stdc.stdio; /***********************************/ @@ -150,7 +162,8 @@ void testDIP29_3() immutable z1 = pureMaker3c()[]; immutable z2 = pureMaker3c()[0..2]; - // Issue 12467 - conversion from lvalue of mutable static array to immutable slice + // https://issues.dlang.org/show_bug.cgi?id=12467 + // conversion from lvalue of mutable static array to immutable slice char[3] arr = "foo"; static assert(!__traits(compiles, { string str = arr[]; })); } @@ -182,11 +195,11 @@ void testDIP29_4() } /***********************************/ -// 14155 +// https://issues.dlang.org/show_bug.cgi?id=14155 immutable int g14155; -static this() { g14155 = 1; } +shared static this() { g14155 = 1; } int* make14155m ( int* p) pure { return null; } const(int*) make14155c ( const(int*) p) pure { return &g14155; } @@ -232,7 +245,7 @@ void test14155_for_testDIP29_4() } /***********************************/ -// 14141 +// https://issues.dlang.org/show_bug.cgi?id=14141 struct S14141 { @@ -265,7 +278,7 @@ int*[] pureFoo() pure { return null; } void testDIP29_5() pure { - { char[] s; immutable x = s.dup; } + { char[] s; immutable x = s.idup; } { immutable x = (cast(int*[])null).dup; } { immutable x = pureFoo(); } { immutable x = pureFoo().dup; } @@ -396,7 +409,7 @@ void testDIP29_6() })); } -// 14155 +// https://issues.dlang.org/show_bug.cgi?id=14155 void test14155_for_testDIP29_6() { @@ -417,7 +430,7 @@ void test14155_for_testDIP29_6() } /***********************************/ -// 13640 +// https://issues.dlang.org/show_bug.cgi?id=13640 struct S13640 { @@ -437,7 +450,7 @@ struct S13640 } /***********************************/ -// 15778 +// https://issues.dlang.org/show_bug.cgi?id=15778 void test15778() { @@ -477,5 +490,5 @@ void main() testDIP29_6(); test15778(); - writefln("Success"); + printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable/imports/A16a.d b/gcc/testsuite/gdc.test/runnable/imports/A16a.d index 9f385cc960e..e60acdc07aa 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/A16a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/A16a.d @@ -1,6 +1,6 @@ import A16; -import std.stdio; +import core.stdc.stdio; class B16 : AA16 { diff --git a/gcc/testsuite/gdc.test/runnable/imports/Other.d b/gcc/testsuite/gdc.test/runnable/imports/Other.d index cd523c02a61..81d846f31c9 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/Other.d +++ b/gcc/testsuite/gdc.test/runnable/imports/Other.d @@ -2,13 +2,12 @@ module imports.Other; // makes no difference if removed import Same; import core.stdc.stdio; -class Other : Same // segfault -// class Other : Same.Same //***UGLY ALERT*** but doesn't segfault +class Other : Same.Same { -this() -{ -printf("other\n"); -} + this() + { + printf("other\n"); + } } int main() diff --git a/gcc/testsuite/gdc.test/runnable/imports/a12037.d b/gcc/testsuite/gdc.test/runnable/imports/a12037.d index 7c25d874c42..3d6e456cc29 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/a12037.d +++ b/gcc/testsuite/gdc.test/runnable/imports/a12037.d @@ -19,29 +19,28 @@ private template CustomFloatParams(uint precision, uint exponentWidth) ) CustomFloatParams; } -struct CustomFloat(uint precision, uint exponentWidth) -if ((1 + precision + exponentWidth) % 8 == 0 && precision + exponentWidth > 0) +private union ToBinary(F) +if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real)) { -private: - union ToBinary(F) - if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real)) - { - F set; + F set; - // If on Linux or Mac, where 80-bit reals are padded, ignore the - // padding. - CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get; + // If on Linux or Mac, where 80-bit reals are padded, ignore the + // padding. + CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get; - // Convert F to the correct binary type. - static typeof(get) opCall(F value) - { - ToBinary r; - r.set = value; - return r.get; - } - alias get this; + // Convert F to the correct binary type. + static typeof(get) opCall(F value) + { + ToBinary r; + r.set = value; + return r.get; } + alias get this; +} +struct CustomFloat(uint precision, uint exponentWidth) +if ((1 + precision + exponentWidth) % 8 == 0 && precision + exponentWidth > 0) +{ public: @property bool sign() { return 1; } @property void sign(bool) {} @@ -65,7 +64,7 @@ public: @property F get(F)() if (is(F == float) || is(F == double) || is(F == real)) { - ToBinary!F result; + ToBinary result; return F.init; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/a21a.d b/gcc/testsuite/gdc.test/runnable/imports/a21a.d index 8ba14620aed..ded47dad1e5 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/a21a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/a21a.d @@ -1,6 +1,6 @@ module imports.a21a; -import std.stdio; +import core.stdc.stdio; import a21; template GoodMixin() diff --git a/gcc/testsuite/gdc.test/runnable/imports/another_module_with_tests.d b/gcc/testsuite/gdc.test/runnable/imports/another_module_with_tests.d new file mode 100644 index 00000000000..53290049e17 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/another_module_with_tests.d @@ -0,0 +1,4 @@ +module imports.another_module_with_tests; +unittest {} +unittest {} +unittest { assert(false); } diff --git a/gcc/testsuite/gdc.test/runnable/imports/depsprot_default.d b/gcc/testsuite/gdc.test/runnable/imports/depsprot_default.d deleted file mode 100644 index 2d5de351b2b..00000000000 --- a/gcc/testsuite/gdc.test/runnable/imports/depsprot_default.d +++ /dev/null @@ -1 +0,0 @@ -void pack() {} diff --git a/gcc/testsuite/gdc.test/runnable/imports/depsprot_private.d b/gcc/testsuite/gdc.test/runnable/imports/depsprot_private.d deleted file mode 100644 index be063dd66aa..00000000000 --- a/gcc/testsuite/gdc.test/runnable/imports/depsprot_private.d +++ /dev/null @@ -1 +0,0 @@ -void priv() {} diff --git a/gcc/testsuite/gdc.test/runnable/imports/depsprot_public.d b/gcc/testsuite/gdc.test/runnable/imports/depsprot_public.d deleted file mode 100644 index ad18eaf8df3..00000000000 --- a/gcc/testsuite/gdc.test/runnable/imports/depsprot_public.d +++ /dev/null @@ -1 +0,0 @@ -void pub() {} diff --git a/gcc/testsuite/gdc.test/runnable/imports/module_with_tests.d b/gcc/testsuite/gdc.test/runnable/imports/module_with_tests.d new file mode 100644 index 00000000000..c0372abc9ab --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/module_with_tests.d @@ -0,0 +1,2 @@ +module imports.module_with_tests; +unittest {} unittest { assert(false); } diff --git a/gcc/testsuite/gdc.test/runnable/imports/pubprivtmpla.d b/gcc/testsuite/gdc.test/runnable/imports/pubprivtmpla.d new file mode 100644 index 00000000000..f68bdd719bf --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/pubprivtmpla.d @@ -0,0 +1,8 @@ +module pubprivtmpla; + +struct S +{ + private int m = 42; + private int _get()() { return m; } + public alias get = _get!(); +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/std11file.d b/gcc/testsuite/gdc.test/runnable/imports/std11file.d new file mode 100644 index 00000000000..76d43be8c6c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/std11file.d @@ -0,0 +1,6 @@ +module imports.std11file; + +string getcwd() @trusted +{ + return "/dlang/test/runnable"; +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/std15017variant.d b/gcc/testsuite/gdc.test/runnable/imports/std15017variant.d index f6f7f5ea404..cf5dbf14110 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/std15017variant.d +++ b/gcc/testsuite/gdc.test/runnable/imports/std15017variant.d @@ -1,6 +1,6 @@ module imports.std15017variant; -struct VariantN(size_t maxDataSize) +struct VariantN(uint maxDataSize) { VariantN opAssign() { return this; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/template_ovs1.d b/gcc/testsuite/gdc.test/runnable/imports/template_ovs1.d index a4b2ecf2a60..465e74c6674 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/template_ovs1.d +++ b/gcc/testsuite/gdc.test/runnable/imports/template_ovs1.d @@ -1,7 +1,8 @@ module imports.template_ovs1; /***************************************************/ -// 1900 - template overload set +// https://issues.dlang.org/show_bug.cgi?id=1900 +// template overload set auto foo1900a(int num) { return 1; } auto foo1900b(T)(T arg) if (is(T : const(char)[])) { return 2; } @@ -34,7 +35,7 @@ auto merge1900(T)(int) } /***************************************************/ -// 1900 +// https://issues.dlang.org/show_bug.cgi?id=1900 class AClass1900 {} template Traits1900(T : AClass1900) { enum name = "AClass"; } @@ -47,12 +48,12 @@ template Value1900b(T) if (is(T == double)) { enum Value1900b = 1; } void Value1900b() {} /***************************************************/ -// 8352 +// https://issues.dlang.org/show_bug.cgi?id=8352 Range remove8352a(alias pred, Range)(Range range) { return range; } void remove8352b(in char[] name) {} /***************************************************/ -// 10658 +// https://issues.dlang.org/show_bug.cgi?id=10658 template Val10658(int n) { enum Val10658 = 1; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/template_ovs2.d b/gcc/testsuite/gdc.test/runnable/imports/template_ovs2.d index 5b925689e55..1c9500c8216 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/template_ovs2.d +++ b/gcc/testsuite/gdc.test/runnable/imports/template_ovs2.d @@ -1,7 +1,8 @@ module imports.template_ovs2; /***************************************************/ -// 1900 - template overload set +// https://issues.dlang.org/show_bug.cgi?id=1900 +// template overload set auto foo1900a(T)(T arg) if (is(T : const(char)[])) { return 2; } auto foo1900b(int num) { return 1; } @@ -34,7 +35,7 @@ auto merge1900(T)(string) } /***************************************************/ -// 1900 +// https://issues.dlang.org/show_bug.cgi?id=1900 class BClass1900 {} template Traits1900(T : BClass1900) { enum name = "BClass"; } @@ -47,12 +48,12 @@ template Value1900b(T) if (is(T == string)) { enum Value1900b = 2; } void Value1900b() {} /***************************************************/ -// 8352 +// https://issues.dlang.org/show_bug.cgi?id=8352 void remove8352a(in char[] name) {} Range remove8352b(alias pred, Range)(Range range) { return range; } /***************************************************/ -// 10658 +// https://issues.dlang.org/show_bug.cgi?id=10658 template Val10658(long n) { enum Val10658 = 2; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/template_ovs3.d b/gcc/testsuite/gdc.test/runnable/imports/template_ovs3.d index ca76914e76b..75beeb9cb19 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/template_ovs3.d +++ b/gcc/testsuite/gdc.test/runnable/imports/template_ovs3.d @@ -1,7 +1,8 @@ module imports.template_ovs3; /***************************************************/ -// 1900 - template overload set +// https://issues.dlang.org/show_bug.cgi?id=1900 +// template overload set import imports.template_ovs1; import imports.template_ovs2; @@ -31,6 +32,6 @@ struct S1900 } /***************************************************/ -// 1900 +// https://issues.dlang.org/show_bug.cgi?id=1900 struct Traits1900(T) if (!is(T == class)) { enum name = "any"; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test11931a.d b/gcc/testsuite/gdc.test/runnable/imports/test11931a.d index 152b38a67cd..f43ac4f1919 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test11931a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test11931a.d @@ -1,7 +1,5 @@ module imports.test11931a; -import std.stdio; - import imports.test11931d; import imports.test11931b; diff --git a/gcc/testsuite/gdc.test/runnable/imports/test11931d.d b/gcc/testsuite/gdc.test/runnable/imports/test11931d.d index 7a3ed39ed68..dc9bbb1b064 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test11931d.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test11931d.d @@ -1,7 +1,20 @@ module imports.test11931d; -import std.array; -import std.algorithm; +template filter(alias pred) +{ + auto filter(Range)(Range r) + { + struct FilterResult + { + Range array() + { + return data; + } + Range data; + } + return FilterResult(r); + } +} struct ConnectionPoint { @@ -26,5 +39,5 @@ struct Signal(T, A...) private: alias D = T delegate(A); - D _arr[]; + D[] _arr; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test13a.d b/gcc/testsuite/gdc.test/runnable/imports/test13a.d index 4b00277fba9..4512e416dcf 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test13a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test13a.d @@ -17,7 +17,7 @@ template Ordinal(T) { public T clamp(T item, T lower, T upper) in { assert(lower <= upper); - } body { + } do { return max(min(item, upper), lower); } } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test15777a.d b/gcc/testsuite/gdc.test/runnable/imports/test15777a.d new file mode 100644 index 00000000000..55ae716c67d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test15777a.d @@ -0,0 +1 @@ +void fun() {} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test15777b.d b/gcc/testsuite/gdc.test/runnable/imports/test15777b.d new file mode 100644 index 00000000000..55ae716c67d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test15777b.d @@ -0,0 +1 @@ +void fun() {} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test17181a.d b/gcc/testsuite/gdc.test/runnable/imports/test17181a.d new file mode 100644 index 00000000000..c080e9640c6 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test17181a.d @@ -0,0 +1,10 @@ +module imports.test17181a; + +int a = 0; +static this() { a = 1; } + +T abc(T)(T i) +{ + import imports.test17181b; + return i; +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test17181b.d b/gcc/testsuite/gdc.test/runnable/imports/test17181b.d new file mode 100644 index 00000000000..25e60880c76 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test17181b.d @@ -0,0 +1,3 @@ +module imports.test17181b; +import imports.test17181a; +static this() { a = 2; } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test17181c.d b/gcc/testsuite/gdc.test/runnable/imports/test17181c.d new file mode 100644 index 00000000000..1722711c6aa --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test17181c.d @@ -0,0 +1,7 @@ +module imports.test17181c; + +int getA()() +{ + import imports.test17181a; + return a; +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test18868_a.d b/gcc/testsuite/gdc.test/runnable/imports/test18868_a.d new file mode 100644 index 00000000000..275cf22de67 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test18868_a.d @@ -0,0 +1,3 @@ +shared static this() { } +import imports.test18868_fls; +alias floop = FLS!(int); diff --git a/gcc/testsuite/gdc.test/runnable/imports/test18868_fls.d b/gcc/testsuite/gdc.test/runnable/imports/test18868_fls.d new file mode 100644 index 00000000000..47142052588 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test18868_fls.d @@ -0,0 +1,33 @@ +module imports.test18868_fls; + +template FLS(T) +{ + int ctorcount = 0; + int dtorcount = 0; + int sharedctorcount = 0; + int shareddtorcount = 0; + + static this() + { + assert(ctorcount == 0); + ctorcount += 1; + } + + static ~this() + { + assert(dtorcount == 0); + dtorcount += 1; + } + + shared static this() + { + assert(sharedctorcount == 0); + sharedctorcount += 1; + } + + shared static ~this() + { + assert(shareddtorcount == 0); + shareddtorcount += 1; + } +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655b.d b/gcc/testsuite/gdc.test/runnable/imports/test19655b.d new file mode 100644 index 00000000000..83d3c9d4e74 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655b.d @@ -0,0 +1,8 @@ +import test19655c; +import test19655d; +class Garply: Grault +{ } +void main() +{ + (new Garply).func; +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655c.d b/gcc/testsuite/gdc.test/runnable/imports/test19655c.d new file mode 100644 index 00000000000..f69b7d96f87 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655c.d @@ -0,0 +1,8 @@ +import test19655f; +import test19655e; +import test19655a: Corge; +class Foo +{ + int[Foo] map; + void fun0(Corge) { } +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655d.d b/gcc/testsuite/gdc.test/runnable/imports/test19655d.d new file mode 100644 index 00000000000..992864467bd --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655d.d @@ -0,0 +1,14 @@ +import test19655f; +import test19655g; +class Grault: Bar +{ + void func() + { + func2; + } + void func1() + { + assert(false, "func1 was never called"); + } + void func2() { } +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655e.d b/gcc/testsuite/gdc.test/runnable/imports/test19655e.d new file mode 100644 index 00000000000..d497fffeddb --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655e.d @@ -0,0 +1,2 @@ +import test19655c; +int[Foo] map; diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655f.d b/gcc/testsuite/gdc.test/runnable/imports/test19655f.d new file mode 100644 index 00000000000..32a58f88b65 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655f.d @@ -0,0 +1,2 @@ +import test19655c; +import test19655g; diff --git a/gcc/testsuite/gdc.test/runnable/imports/test19655g.d b/gcc/testsuite/gdc.test/runnable/imports/test19655g.d new file mode 100644 index 00000000000..d1cacfec120 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test19655g.d @@ -0,0 +1,3 @@ +import test19655c; +class Bar: Foo +{ } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test24a.d b/gcc/testsuite/gdc.test/runnable/imports/test24a.d index e606f1c517c..d7ca719a566 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test24a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test24a.d @@ -1,3 +1,3 @@ module imports.test24a; -public import std.string; +public import imports.test24c; diff --git a/gcc/testsuite/gdc.test/runnable/imports/test24b.d b/gcc/testsuite/gdc.test/runnable/imports/test24b.d index dcb380f0323..507a848c7c2 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test24b.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test24b.d @@ -1,3 +1,3 @@ module imports.test24b; -public import std.string; +public import imports.test24c; diff --git a/gcc/testsuite/gdc.test/runnable/imports/test24c.d b/gcc/testsuite/gdc.test/runnable/imports/test24c.d new file mode 100644 index 00000000000..a6ffee05c08 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/imports/test24c.d @@ -0,0 +1,6 @@ +module imports.test24c; + +immutable(Char)[] format(Char, Args...)(in Char[] fmt, Args args) +{ + return "3"; +} diff --git a/gcc/testsuite/gdc.test/runnable/imports/test27a.d b/gcc/testsuite/gdc.test/runnable/imports/test27a.d index 75c945d0798..8a68a165ef5 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test27a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test27a.d @@ -1,10 +1,17 @@ module imports.test27a; -import std.variant; +struct Variant +{ + this(T)(T) + { + } +} -class myClass(T) { +class myClass(T) +{ public: - void func(T v) { + void func(T v) + { Variant b = Variant(v); } } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test39a.d b/gcc/testsuite/gdc.test/runnable/imports/test39a.d index 84a1530c214..4150eaf0e75 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test39a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test39a.d @@ -6,7 +6,7 @@ class Test (T) { final void show (in T[] msg) { - printf ("%.*s\n", msg.length, msg.ptr); + printf ("%.*s\n", cast(int)msg.length, msg.ptr); } } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test40a.d b/gcc/testsuite/gdc.test/runnable/imports/test40a.d index b688b9f3161..d894f45b69b 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test40a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test40a.d @@ -1,6 +1,6 @@ module imports.test40a; -import std.stdio; +import core.stdc.stdio; template Mix() { @@ -8,7 +8,7 @@ template Mix() { auto context = new Context; auto ts = context.toString; - printf("context: %.*s %p\n", ts.length, ts.ptr, context); + printf("context: %.*s %p\n", cast(int)ts.length, ts.ptr, context); context.func!(typeof(this))(); printf("returning from opCall\n"); } @@ -23,8 +23,8 @@ class Bar void someFunc(string z) { - printf("str length: %d\n", z.length); - printf("str: '%.*s'\n", z.length, z.ptr); + printf("str length: %zd\n", z.length); + printf("str: '%.*s'\n", cast(int)z.length, z.ptr); } diff --git a/gcc/testsuite/gdc.test/runnable/imports/test45a.d b/gcc/testsuite/gdc.test/runnable/imports/test45a.d index df3b8525597..d466cbe27e0 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test45a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test45a.d @@ -1,6 +1,6 @@ module imports.test45a; -import std.stdio; +import core.stdc.stdio; int foo() { diff --git a/gcc/testsuite/gdc.test/runnable/imports/test45b.d b/gcc/testsuite/gdc.test/runnable/imports/test45b.d index 371a162b114..d1b0c34ba8e 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test45b.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test45b.d @@ -1,6 +1,6 @@ module imports.test45b; -import std.stdio; +import core.stdc.stdio; int foo(int i) { diff --git a/gcc/testsuite/gdc.test/runnable/imports/test49a.d b/gcc/testsuite/gdc.test/runnable/imports/test49a.d index 57baf4be00a..cb9c9520e01 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/test49a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/test49a.d @@ -1,6 +1,6 @@ module imports.test49a; -import std.stdio; +import core.stdc.stdio; int x; diff --git a/gcc/testsuite/gdc.test/runnable/imports/testmod2a.d b/gcc/testsuite/gdc.test/runnable/imports/testmod2a.d index a59d12cf16d..a71581103b1 100644 --- a/gcc/testsuite/gdc.test/runnable/imports/testmod2a.d +++ b/gcc/testsuite/gdc.test/runnable/imports/testmod2a.d @@ -1,7 +1,7 @@ module imports.testmod2a; /**********************************/ -// bug 1904 +// https://issues.dlang.org/show_bug.cgi?id=1904 // testmod.d private void bar(alias a)() {} diff --git a/gcc/testsuite/gdc.test/runnable/inclusive_incontracts.d b/gcc/testsuite/gdc.test/runnable/inclusive_incontracts.d new file mode 100644 index 00000000000..7670b24df8b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/inclusive_incontracts.d @@ -0,0 +1,80 @@ +// REQUIRED_ARGS: -preview=inclusiveincontracts +// PERMUTE_ARGS: -O -inline + +import core.exception : AssertError; + +void main() +{ + basic_test; + multiple_incontracts_test; +} + +void basic_test() +{ + class A + { + void foo() @nogc + in (true, "foo") + { + } + } + + class B : A + { + override void foo() @nogc + in (false, "nope not foo") + { + } + } + + auto b = new B; + + try + { + b.foo; + throw new Exception("Assert expected."); + } + catch (AssertError assertError) + { + assert(assertError.line == 25); // line of invalid in-contract + assert(assertError.msg == "Logic error: in-contract was tighter than parent in-contract"); + } +} + +void multiple_incontracts_test() +{ + class A + { + void foo(int a, int b) + in (a > 0, "A::a") + in (b > 0, "B::b") + { + } + } + + class B : A + { + override void foo(int a, int b) + in (a >= 0, "B::a") + in (b > 0, "B::b") + { + } + } + + auto b = new B; + + b.foo(0, 2); + try + { + b.foo(0, 0); + throw new Exception("Assert expected."); + } + catch (AssertError assertError) { + /** + * Having found that the looser contract in B is not fulfilled, we try + * the stricter contract in A. As that one is also violated, we error. + */ + assert(assertError.line == 49); + assert(assertError.msg == "A::a"); + } +} diff --git a/gcc/testsuite/gdc.test/runnable/inline.d b/gcc/testsuite/gdc.test/runnable/inline.d index d3bb0a9b5e7..19be4792f3d 100644 --- a/gcc/testsuite/gdc.test/runnable/inline.d +++ b/gcc/testsuite/gdc.test/runnable/inline.d @@ -1,3 +1,14 @@ +/* +RUN_OUTPUT: +--- +7 +83 +4 +4 +1.000000 2.000000 3.000000 +Success +--- +*/ import core.stdc.stdio; @@ -145,7 +156,7 @@ void test7() /************************************/ -// 10833 +// https://issues.dlang.org/show_bug.cgi?id=10833 string fun10833(T...)() { foreach (v ; T) @@ -159,7 +170,7 @@ void test10833() } /************************************/ -// Bugzilla 4825 +// https://issues.dlang.org/show_bug.cgi?id=4825 int a8() { int r; @@ -178,7 +189,7 @@ void test8() { } /************************************/ -// 4841 +// https://issues.dlang.org/show_bug.cgi?id=4841 auto fun4841a() { @@ -264,7 +275,7 @@ void test4841() } /************************************/ -// 7261 +// https://issues.dlang.org/show_bug.cgi?id=7261 struct AbstractTask { @@ -287,7 +298,7 @@ struct Task } /************************************/ -// 9356 +// https://issues.dlang.org/show_bug.cgi?id=9356 void test9356() { @@ -302,7 +313,7 @@ void test9356() } /************************************/ -// 12079 +// https://issues.dlang.org/show_bug.cgi?id=12079 void test12079() { @@ -312,7 +323,7 @@ void test12079() } /************************************/ -// 12243 +// https://issues.dlang.org/show_bug.cgi?id=12243 char f12243() { return 'a'; } @@ -323,7 +334,7 @@ void test12243() } /************************************/ -// 11201 +// https://issues.dlang.org/show_bug.cgi?id=11201 struct Foo11201 { @@ -343,7 +354,7 @@ void test11201() } /************************************/ -// 11223 +// https://issues.dlang.org/show_bug.cgi?id=11223 struct Tuple11223(T...) { @@ -382,7 +393,7 @@ void test3918() } /************************************/ -// 11314 +// https://issues.dlang.org/show_bug.cgi?id=11314 struct Tuple11314(T...) { @@ -406,7 +417,7 @@ void test11314() } /************************************/ -// 11224 +// https://issues.dlang.org/show_bug.cgi?id=11224 S11224* ptr11224; @@ -438,7 +449,7 @@ void test11224() } /************************************/ -// 11322 +// https://issues.dlang.org/show_bug.cgi?id=11322 bool b11322; uint n11322; @@ -460,7 +471,7 @@ void test11322() } /************************************/ -// 11394 +// https://issues.dlang.org/show_bug.cgi?id=11394 debug(NRVO) static void* p11394a, p11394b, p11394c; @@ -497,7 +508,7 @@ void test11394() } /**********************************/ -// 12080 +// https://issues.dlang.org/show_bug.cgi?id=12080 class TZ12080 {} @@ -521,7 +532,7 @@ class Foo12080 public ST12080 sysTime() out {} - body + do { if (quux) return ST12080(); @@ -533,7 +544,7 @@ class Foo12080 } /**********************************/ -// 13503 +// https://issues.dlang.org/show_bug.cgi?id=13503 void f13503a(string[] s...) { @@ -559,7 +570,7 @@ void test13503() } /**********************************/ -// 14267 +// https://issues.dlang.org/show_bug.cgi?id=14267 // EXTRA_SOURCES: imports/a14267.d import imports.a14267; @@ -584,7 +595,7 @@ void test14267() } /**********************************/ -// 13244 +// https://issues.dlang.org/show_bug.cgi?id=13244 struct MapResult13244(alias fun) { @@ -610,7 +621,7 @@ void test13244() } /**********************************/ -// 14306 +// https://issues.dlang.org/show_bug.cgi?id=14306 struct MapResult(alias fun) { @@ -656,7 +667,7 @@ void test14306() } /**********************************/ -// 14754 +// https://issues.dlang.org/show_bug.cgi?id=14754 auto aafunc14754(string k) { @@ -694,7 +705,7 @@ void test14754() } /**********************************/ -// 14606 +// https://issues.dlang.org/show_bug.cgi?id=14606 struct S14606 { @@ -729,7 +740,7 @@ void test14606() } /**********************************/ -// 14753 +// https://issues.dlang.org/show_bug.cgi?id=14753 pragma(inline) void test14753(string) { } @@ -754,7 +765,7 @@ void test14975() } /**********************************/ -// 15210 +// https://issues.dlang.org/show_bug.cgi?id=15210 struct BigInt15210 {} @@ -809,7 +820,7 @@ void test7625() } /**********************************/ -// 9785 partial fix +// https://issues.dlang.org/show_bug.cgi?id=9785 partial fix void test9785() { @@ -829,7 +840,7 @@ void test9785() /**********************************/ -// 9785 partial fix +// https://issues.dlang.org/show_bug.cgi?id=9785 partial fix void test9785_2() { int j = 3; @@ -849,7 +860,7 @@ void test9785_2() { } /**********************************/ -// 9785 partial fix +// https://issues.dlang.org/show_bug.cgi?id=9785 partial fix void test9785_3() @nogc { @@ -879,7 +890,7 @@ void test9785_3() @nogc } /**********************************/ -// 15207 +// https://issues.dlang.org/show_bug.cgi?id=15207 struct Vec15207 { @@ -923,7 +934,7 @@ void test15207() } /**********************************/ -// 15253 +// https://issues.dlang.org/show_bug.cgi?id=15253 struct MessageType15253 { @@ -946,7 +957,7 @@ struct ProtoPackage15253 } /**********************************/ -// 15296 +// https://issues.dlang.org/show_bug.cgi?id=15296 static int x15296; @@ -1132,7 +1143,7 @@ int main() test15296b(); test15296c(); test17676(); - + printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/inner.d b/gcc/testsuite/gdc.test/runnable/inner.d index e1be7b9cbad..7bf59d24a64 100644 --- a/gcc/testsuite/gdc.test/runnable/inner.d +++ b/gcc/testsuite/gdc.test/runnable/inner.d @@ -1,5 +1,5 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; + +import core.stdc.stdio; /*******************************************************/ @@ -591,7 +591,7 @@ class Foo18 { void doSayHello() { - writefln("Betty"); + printf("Betty\n"); sayHello(); } } @@ -599,7 +599,7 @@ class Foo18 void sayHello() { - writefln("Hello"); + printf("Hello\n"); } } @@ -614,7 +614,7 @@ class Foo182 : Foo18 void test18() { Foo182 foo = new Foo182(); - writefln("This should print Hello:"); + printf("This should print Hello:\n"); foo.bar.doSayHello(); } @@ -627,7 +627,7 @@ class Foo19 { void doSayHello() { - writefln("Betty"); + printf("Betty\n"); sayHello(); } } @@ -635,7 +635,7 @@ class Foo19 void sayHello() { - writefln("Hello"); + printf("Hello\n"); } this() @@ -651,7 +651,7 @@ class Foo192 : Foo19 void test19() { Foo192 foo = new Foo192(); - writefln("This should print Hello:"); + printf("This should print Hello:\n"); foo.bar.doSayHello(); } @@ -796,7 +796,7 @@ struct S7426 } /*******************************************************/ -// 14046 +// https://issues.dlang.org/show_bug.cgi?id=14046 class A14046 { @@ -828,7 +828,7 @@ void test14046() } /*******************************************************/ -// 15839 +// https://issues.dlang.org/show_bug.cgi?id=15839 class AnimatedProgress15839(bool makeClosure) { diff --git a/gcc/testsuite/gdc.test/runnable/interface.d b/gcc/testsuite/gdc.test/runnable/interface.d index dab7beb9c28..78a712e7a23 100644 --- a/gcc/testsuite/gdc.test/runnable/interface.d +++ b/gcc/testsuite/gdc.test/runnable/interface.d @@ -1,3 +1,10 @@ +/* +TEST_OUTPUT: +--- +runnable/interface.d(41): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +runnable/interface.d(55): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import core.stdc.stdio; @@ -79,7 +86,7 @@ void test3() j.f(); K3 k = a; k.f(); - assert(&j.f == &k.f); // Bugzilla 3706 + assert(&j.f == &k.f); // https://issues.dlang.org/show_bug.cgi?id=3706 } /*******************************************/ diff --git a/gcc/testsuite/gdc.test/runnable/interface2.d b/gcc/testsuite/gdc.test/runnable/interface2.d index 85adf65b481..328f839896d 100644 --- a/gcc/testsuite/gdc.test/runnable/interface2.d +++ b/gcc/testsuite/gdc.test/runnable/interface2.d @@ -1,4 +1,11 @@ // PERMUTE_ARGS: +/* +TEST_OUTPUT: +--- +runnable/interface2.d(47): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +runnable/interface2.d(98): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ extern(C) int printf(const char*, ...); @@ -27,7 +34,7 @@ void test1() printf("f = %p\n", f); assert(cast(void*)b !is cast(void*)f); - printf("f.class = '%.*s'\n", f.classinfo.name.length, f.classinfo.name.ptr); + printf("f.class = '%.*s'\n", cast(int)f.classinfo.name.length, f.classinfo.name.ptr); assert(f.classinfo.name == "interface2.Foo"); f.bar(); @@ -341,7 +348,7 @@ class B12 : A12 { printf("B12.clone()\n"); } - body + do { return ia; } @@ -395,7 +402,7 @@ class B13 : A13 { printf("B13.clone()\n"); } - body { return ia; } + do { return ia; } } void test13() @@ -662,11 +669,11 @@ void test19() assert(cast(void*)c + (3*(void*).sizeof) == cast(void*)ifoo); string s = ifoo.classinfo.name; - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(s == "interface2.IFoo19"); s = (cast(Object)ifoo).toString; - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(s == "interface2.Child19"); } @@ -923,7 +930,8 @@ void test27() } /*******************************************************/ -// 1747 & 2013 +// https://issues.dlang.org/show_bug.cgi?id=1747 +// https://issues.dlang.org/show_bug.cgi?id=2013 void test1747() { @@ -1009,14 +1017,14 @@ bool foo4088(Test4088 x, Test4088 y) } /*******************************************************/ -// 7950 +// https://issues.dlang.org/show_bug.cgi?id=7950 template TypeTuple7950(T...){alias T TypeTuple7950;} interface I7950a {} // ok interface I7950b : I7950a, TypeTuple7950!() {} // fail /*******************************************************/ -// 10007 +// https://issues.dlang.org/show_bug.cgi?id=10007 struct A10007 {} @@ -1032,7 +1040,7 @@ class Foo10007 : IFoo10007 } /*******************************************************/ -// 10744 +// https://issues.dlang.org/show_bug.cgi?id=10744 interface A10744 { @@ -1065,7 +1073,7 @@ interface Baz10744 { } interface Qux10744 : Baz10744 { } /*******************************************************/ -// 11034 +// https://issues.dlang.org/show_bug.cgi?id=11034 class A11034(T) { diff --git a/gcc/testsuite/gdc.test/runnable/interface3.d b/gcc/testsuite/gdc.test/runnable/interface3.d index f748f72b08d..f0de22c95d0 100644 --- a/gcc/testsuite/gdc.test/runnable/interface3.d +++ b/gcc/testsuite/gdc.test/runnable/interface3.d @@ -1,4 +1,10 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +OK +--- +*/ extern(C) int printf(const char*, ...); @@ -71,5 +77,3 @@ int main() assert(Newline.OKset == 1); return 0; } - - diff --git a/gcc/testsuite/gdc.test/runnable/interpret.d b/gcc/testsuite/gdc.test/runnable/interpret.d index fe44744fcfc..a626749ee46 100644 --- a/gcc/testsuite/gdc.test/runnable/interpret.d +++ b/gcc/testsuite/gdc.test/runnable/interpret.d @@ -1,4 +1,4 @@ -/* RUNNABLE_PHOBOS_TEST +/* TEST_OUTPUT: --- true @@ -17,7 +17,8 @@ tfoo Crash! --- */ -import std.stdio; + +import core.stdc.stdio; template Tuple(A...) { @@ -813,7 +814,7 @@ void test36() string someCompileTimeFunction() { - return "writefln(\"Wowza!\");"; + return "printf(\"Wowza!\n\");"; } void test37() @@ -871,7 +872,6 @@ string UpToSpace(string x) void test40() { const y = UpToSpace("first space was after first"); - writeln(y); assert(y == "first"); } @@ -893,7 +893,6 @@ int foo41(int i) void test41() { const y = foo41(3); - writeln(y); assert(y == 6); } @@ -915,7 +914,6 @@ int foo42(int i) void test42() { const y = foo42(3); - writeln(y); assert(y == 6); } @@ -937,7 +935,6 @@ int bar(string a) void test43() { const int foo = bar("a b c d"); - writeln(foo); assert(foo == 28); } @@ -963,11 +960,11 @@ void test45() /************************************************/ -const int foo46[5] = [0,1,2,3,4]; +const int[5] foo46 = [0,1,2,3,4]; void test46() { - writeln(eval!(foo46[3])); + printf("%d\n", eval!(foo46[3])); } /************************************************/ @@ -1017,7 +1014,6 @@ dstring testd49(dstring input) void test49() { static x = testd49("hello"); - writeln(x); assert(x == "el"); } @@ -1126,26 +1122,29 @@ bool equals54(string a, string b) /************************************************/ -const string foo55[2] = ["a", "b"]; +const string[2] foo55 = ["a", "b"]; string retsth55(int i) { return foo55[i]; } void test55() { - writeln(eval!(foo55[0])); - writeln(eval!(retsth55(0))); + enum res1 = eval!(foo55[0]); + printf("%.*s\n", cast(int)res1.length, res1.ptr); + enum res2 = eval!(retsth55(0)); + printf("%.*s\n", cast(int)res2.length, res2.ptr); } /************************************************/ string retsth56(int i) { - static const string foo[2] = ["a", "b"]; + static const string[2] foo = ["a", "b"]; return foo[i]; } void test56() { - writeln(eval!(retsth56(0))); + enum result = eval!(retsth56(0)); + printf("%.*s\n", cast(int)result.length, result.ptr); } /************************************************/ @@ -1178,7 +1177,6 @@ void test58() assert(b.length == 2); assert(b[0] == 2); assert(b[1] == 3); - writeln(b); } /************************************************/ @@ -1622,7 +1620,6 @@ const string s83 = mixItemList83(); void test83() { - writeln(s83); assert(s83 == "item"); } @@ -1813,7 +1810,7 @@ string foo90(string a, string b) void test90() { static const string xxx = foo90("A", "xxx"); - printf("%.*s\n", xxx.length, xxx.ptr); + printf("%.*s\n", cast(int)xxx.length, xxx.ptr); assert(xxx == "A"); } @@ -2199,12 +2196,12 @@ struct Q { int x; char y; - int opAddAssign(int w) + int opOpAssign(string op)(int w) if (op == "+") { x += w; return x + w; } - Q opSubAssign(int w) + Q opOpAssign(string op)(int w) if (op == "-") { x -= w; version(D_Version2) { mixin("return this;"); } else { mixin("return *this;"); } @@ -2300,7 +2297,7 @@ static assert(memtest8() == 6 + 17); // --------- CTFE REF PASSING TESTS -------- -// Bugzilla 1950 - CTFE doesn't work correctly for structs passed by ref +// https://issues.dlang.org/show_bug.cgi?id=1950 - CTFE doesn't work correctly for structs passed by ref struct S1950 { int x; @@ -2412,7 +2409,8 @@ int nested2(int x) static assert(nested2(7) == 17 + 8 + 10); -// 1605 D1 & D2. break in switch with goto breaks in ctfe +// https://issues.dlang.org/show_bug.cgi?id=1605 +// D1 & D2. break in switch with goto breaks in ctfe int bug1605() { int i = 0; @@ -2430,7 +2428,8 @@ int bug1605() static assert(bug1605() == 27); -// 2564. D2 only. CTFE: the index in a tuple foreach is uninitialized (bogus error) +// https://issues.dlang.org/show_bug.cgi?id=2564 +// D2 only. CTFE: the index in a tuple foreach is uninitialized (bogus error) // NOTE: Beware of optimizer bug 3264. int bug2564() @@ -2444,7 +2443,8 @@ int bug2564() static int bug2564b = bug2564(); -// 1461 D1 + D2. Local variable as template alias parameter breaks CTFE +// https://issues.dlang.org/show_bug.cgi?id=1461 +// D1 + D2. Local variable as template alias parameter breaks CTFE void bug1461() { int x; @@ -2620,7 +2620,7 @@ int delegtest6() { DelegStruct s; s.a = 5; - FoolishStruct k[3]; + FoolishStruct[3] k; DelegType u = &s.bar; k[1].z = u; return k[1].z(3); @@ -2655,8 +2655,9 @@ static assert(lazyTest2(17) == 18); version(D_Version2) { -// Bug 4020 and 4027 are D2 only - +// https://issues.dlang.org/show_bug.cgi?id=4020 +// https://issues.dlang.org/show_bug.cgi?id=4027 +// D2 only struct PostblitCrash { int x; @@ -2814,7 +2815,7 @@ void bug4257b() } /************************************************/ -// 5117 +// https://issues.dlang.org/show_bug.cgi?id=5117 static int dummy5117 = test5117(); @@ -2853,7 +2854,7 @@ int test5117b() assert(s.value == 1); // fails, value == 0 return 0; } -ref S5117b getRef5117b(ref S5117b s) { return s; } +ref S5117b getRef5117b(return ref S5117b s) { return s; } struct S5117b { @@ -2862,7 +2863,7 @@ struct S5117b } /************************************************/ -// 6439 +// https://issues.dlang.org/show_bug.cgi?id=6439 struct A6439 { @@ -2902,7 +2903,7 @@ static assert(!is(typeof(Compileable!( }(3) )))); -// 6504 regression +// https://issues.dlang.org/show_bug.cgi?id=6504 regression void test6504() { for (int i = 0; i < 3; ++i) @@ -2913,7 +2914,7 @@ void test6504() } } -// 8818 regression +// https://issues.dlang.org/show_bug.cgi?id=8818 regression void test8818() { static bool test() @@ -3148,7 +3149,7 @@ void test108() } */ -/***** Bug 5678 *********************************/ +/***** https://issues.dlang.org/show_bug.cgi?id=5678 *****/ /* struct Bug5678 @@ -3185,7 +3186,7 @@ struct Test110s { this(int, int, int){} } auto test110 = [Test110f(1, Test110s(1, 2, 3))]; /************************************************/ -// 6907 +// https://issues.dlang.org/show_bug.cgi?id=6907 int test6907() { @@ -3219,7 +3220,7 @@ int test6907() static assert(test6907()); /************************************************/ -// 9023 +// https://issues.dlang.org/show_bug.cgi?id=9023 bool test9023() { @@ -3244,7 +3245,7 @@ bool test9023() static assert(test9023()); /************************************************/ -// 15817 +// https://issues.dlang.org/show_bug.cgi?id=15817 S[] split15817(S)(S s) { @@ -3292,11 +3293,11 @@ void test9954() } /************************************************/ -// 10483 +// https://issues.dlang.org/show_bug.cgi?id=10483 struct Bug10483 { - int val[3][4]; + int[3][4] val; } struct Outer10483 @@ -3340,7 +3341,7 @@ void test112() } /************************************************/ -// 10687 +// https://issues.dlang.org/show_bug.cgi?id=10687 enum Foo10687 : uint { A, B, C, D, E } immutable uint[5][] m10687 = [[0, 1, 2, 3, 4]]; @@ -3363,7 +3364,6 @@ void test113() static void compare(real a, real b) { - writefln("compare(%30.30f, %30.30f);", a, b); assert(fabs(a - b) < 128 * real.epsilon); } @@ -3399,7 +3399,7 @@ void test113() } /************************************************/ -// 14140 +// https://issues.dlang.org/show_bug.cgi?id=14140 struct S14140 { @@ -3442,7 +3442,7 @@ void test14140() } /************************************************/ -// 14862 +// https://issues.dlang.org/show_bug.cgi?id=14862 struct S14862 { @@ -3470,7 +3470,7 @@ void test14862() } /************************************************/ -// 15681 +// https://issues.dlang.org/show_bug.cgi?id=15681 void test15681() { @@ -3544,6 +3544,68 @@ void testToPrec() /************************************************/ +auto test20366() +{ + const(char)[] s = ['h', 'e', 'l', '\xef', '\xbd', '\x8c', 'o']; + + foreach_reverse (dchar c; s) + { + } + + return true; +} +static assert(test20366()); + +/************************************************/ + +bool test20400() +{ + char[] s = cast(char[])"1234"; + char[] ret = s[2 .. $]; + ret.length += 1; + ret[$-1] = '5'; + assert(ret == "345"); + + return true; +} +static assert(test20400()); + +/************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=21878 + +struct A21878 +{ + int i; + ref inout(int) opIndex(size_t idx) inout return { return i; } +} + +struct B21878 +{ + A21878[1] a; + ref inout(int) opIndex(size_t idx) inout return { return a[0][idx]; } +} + +bool ctfeFunc21878() +{ + A21878 a; + a[0] = 42; + assert(a[0] == 42); // OK + + B21878 b; + b[0] = 42; + assert(b[0] == 42); // OK <- fails + + return true; +} + +void test21878() +{ + enum eval = ctfeFunc21878(); + ctfeFunc21878(); // succeeds at runtime +} + +/************************************************/ + int main() { test1(); @@ -3667,6 +3729,9 @@ int main() test14140(); test14862(); test15681(); + test20366(); + test20400(); + test21878(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/interpret2.d b/gcc/testsuite/gdc.test/runnable/interpret2.d index 38242a7f3ef..77bc25cd3a3 100644 --- a/gcc/testsuite/gdc.test/runnable/interpret2.d +++ b/gcc/testsuite/gdc.test/runnable/interpret2.d @@ -1,5 +1,11 @@ - -//import std.stdio; +/* +RUN_OUTPUT: +--- +Success +--- +*/ + +//import core.stdc.stdio; extern(C) int printf(const char*, ...); template Tuple(A...) @@ -52,7 +58,7 @@ void test1() assert(z1 == 8194); } -/***** Bug 2850 *********************************/ +/***** https://issues.dlang.org/show_bug.cgi?id=2850 *****/ /* These tests are not passing, and shouldn't pass. A non-first field in a union being initialized cannot be converted to an expression, at least not until there are @@ -122,11 +128,11 @@ void test2() } } -/***** Bug 3779 *********************************/ +/***** https://issues.dlang.org/show_bug.cgi?id=3779 *****/ static const bug3779 = ["123"][0][$-1]; -/***** Bug 1880 *********************************/ +/***** https://issues.dlang.org/show_bug.cgi?id=1880 *****/ enum Property1880 {First=1,Second=2} diff --git a/gcc/testsuite/gdc.test/runnable/issue16995.d b/gcc/testsuite/gdc.test/runnable/issue16995.d new file mode 100644 index 00000000000..3b028d42bf6 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/issue16995.d @@ -0,0 +1,42 @@ +// REQUIRED_ARGS: -unittest +// COMPILE_SEPARATELY +// EXTRA_SOURCES: imports/module_with_tests.d imports/another_module_with_tests.d + +import imports.module_with_tests; +import imports.another_module_with_tests; +import core.exception: AssertError; + +shared static this() +{ + import core.runtime: Runtime, UnitTestResult; + Runtime.extendedModuleUnitTester = () => UnitTestResult.pass; +} + +void main() +{ + foreach(i, ut; __traits(getUnitTests, imports.module_with_tests)) + { + try + { + ut(); + assert(i == 0, "2nd unittest should fail"); + } + catch(AssertError e) + { + assert(i == 1, "Only 2nd unittest should fail"); + } + } + + foreach(i, ut; __traits(getUnitTests, imports.another_module_with_tests)) + { + try + { + ut(); + assert(i == 0 || i == 1, "3rd unittest should fail"); + } + catch(AssertError e) + { + assert(i == 2, "Only 3rd unittest should fail"); + } + } +} diff --git a/gcc/testsuite/gdc.test/runnable/issue8671.d b/gcc/testsuite/gdc.test/runnable/issue8671.d deleted file mode 100644 index c28e63b275b..00000000000 --- a/gcc/testsuite/gdc.test/runnable/issue8671.d +++ /dev/null @@ -1,6 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -import std.random; -void main() -{ - double t = 1.0 - uniform(0.0, 1.0); -} diff --git a/gcc/testsuite/gdc.test/runnable/lazy.d b/gcc/testsuite/gdc.test/runnable/lazy.d index c1846190aed..0bd8f96633f 100644 --- a/gcc/testsuite/gdc.test/runnable/lazy.d +++ b/gcc/testsuite/gdc.test/runnable/lazy.d @@ -1,6 +1,5 @@ -// RUNNABLE_PHOBOS_TEST import core.vararg; -import std.stdio; +import core.stdc.stdio; /*********************************************************/ @@ -105,9 +104,14 @@ void bar3(...) assert(va_arg!int(_argptr) == 14); } +void arr3(...) +{ + assert(_arguments.length == 1); + assert(va_arg!(int[])(_argptr) == [1,0,0,0,0,0,0,0,0,9]); +} + void abc3(int* p) { - writeln(*p); assert(*p == 3); } @@ -115,15 +119,13 @@ void test3() { int x = 3; dotimes3(10, abc3(&x)); - dotimes3(10, write(++x)); - writeln(); + dotimes3(10, ++x); dotimes3(1, bar3(++x)); int[10] a = new int[10]; a[0] = 1; a[$ - 1] = 9; - dotimes3(3, write(a[0..$])); - writeln(); + dotimes3(3, arr3(a[0..$])); } /*********************************************************/ @@ -133,7 +135,6 @@ int p4; void foo4(void* delegate()[] dgs...) { assert(dgs.length == 4); - writefln("%s %s", dgs[0](), cast(void*)&p4); assert(dgs[0]() == cast(void*)&p4); assert(dgs[1]() == cast(void*)&p4); assert(dgs[2]() == null); @@ -144,7 +145,6 @@ void test4() { void *abc() { - writeln(cast(void*)&p4); return cast(void*)&p4; } @@ -254,7 +254,7 @@ void test6682() } /*********************************************************/ -// 9109 +// https://issues.dlang.org/show_bug.cgi?id=9109 void test9109() { @@ -269,7 +269,7 @@ void test9109() } /*********************************************************/ -// 15835 +// https://issues.dlang.org/show_bug.cgi?id=15835 class C15835 {} diff --git a/gcc/testsuite/gdc.test/runnable/lexer.d b/gcc/testsuite/gdc.test/runnable/lexer.d index c16d7b3e240..ee2fef8f23f 100644 --- a/gcc/testsuite/gdc.test/runnable/lexer.d +++ b/gcc/testsuite/gdc.test/runnable/lexer.d @@ -53,7 +53,7 @@ void test7() } /*********************************************************/ -// 4633 +// https://issues.dlang.org/show_bug.cgi?id=4633 template Types(alias v) { @@ -71,7 +71,7 @@ void test8() /*********************************************************/ -// bug 6584 +// https://issues.dlang.org/show_bug.cgi?id=6584 version(9223372036854775807){} debug(9223372036854775807){} diff --git a/gcc/testsuite/gdc.test/runnable/link11069a.d b/gcc/testsuite/gdc.test/runnable/link11069a.d index 01b923e7497..e31cfa0bcf6 100644 --- a/gcc/testsuite/gdc.test/runnable/link11069a.d +++ b/gcc/testsuite/gdc.test/runnable/link11069a.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/std11069array.d imports/std11069container.d imports/std11069range.d imports/std11069typecons.d // REQUIRED_ARGS: -noboundscheck // <-- To remove necessity of _D7imports13std11069array7__arrayZ diff --git a/gcc/testsuite/gdc.test/runnable/link11127.d b/gcc/testsuite/gdc.test/runnable/link11127.d index 0ce963d2859..0e5118f15c9 100644 --- a/gcc/testsuite/gdc.test/runnable/link11127.d +++ b/gcc/testsuite/gdc.test/runnable/link11127.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/link11127a.d import imports.link11127a; void main() diff --git a/gcc/testsuite/gdc.test/runnable/link12037.d b/gcc/testsuite/gdc.test/runnable/link12037.d index ce5b17ff5e3..ca3e3c7c620 100644 --- a/gcc/testsuite/gdc.test/runnable/link12037.d +++ b/gcc/testsuite/gdc.test/runnable/link12037.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/a12037.d import imports.a12037; alias CustomFloat!(10, 5) Float16; diff --git a/gcc/testsuite/gdc.test/runnable/link12144.d b/gcc/testsuite/gdc.test/runnable/link12144.d index 90925563e15..e7bcf865183 100644 --- a/gcc/testsuite/gdc.test/runnable/link12144.d +++ b/gcc/testsuite/gdc.test/runnable/link12144.d @@ -1,5 +1,11 @@ // COMPILE_SEPARATELY: -g // EXTRA_SOURCES: imports/link12144a.d +/* +TEST_OUTPUT: +--- +runnable/imports/link12144a.d(31): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import imports.link12144a; diff --git a/gcc/testsuite/gdc.test/runnable/link13043.d b/gcc/testsuite/gdc.test/runnable/link13043.d index 296907442ab..561651fac6e 100644 --- a/gcc/testsuite/gdc.test/runnable/link13043.d +++ b/gcc/testsuite/gdc.test/runnable/link13043.d @@ -1,5 +1,5 @@ // PERMUTE_ARGS: -g -inline -version=bug -release -O - +// EXTRA_FILES: imports/link13043a.d import imports.link13043a; void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/link13350.d b/gcc/testsuite/gdc.test/runnable/link13350.d index bceb4b8586b..2a2b40bb1e6 100644 --- a/gcc/testsuite/gdc.test/runnable/link13350.d +++ b/gcc/testsuite/gdc.test/runnable/link13350.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern (C) int printf(const(char*) fmt, ...); static int foo(); diff --git a/gcc/testsuite/gdc.test/runnable/link13415.d b/gcc/testsuite/gdc.test/runnable/link13415.d index 00b39d1e8d6..782bb6bbd27 100644 --- a/gcc/testsuite/gdc.test/runnable/link13415.d +++ b/gcc/testsuite/gdc.test/runnable/link13415.d @@ -1,7 +1,13 @@ -// EXTRA_SOURCES: imports/link13415a.d -// REQUIRED_ARGS: -inline -// PERMUTE_ARGS: -allinst -unittest -debug -// COMPILE_SEPARATELY +/* +EXTRA_SOURCES: imports/link13415a.d +REQUIRED_ARGS: -inline +PERMUTE_ARGS: -allinst -unittest -debug +COMPILE_SEPARATELY +RUN_OUTPUT: +--- +i = 77; +--- +*/ import imports.link13415a; diff --git a/gcc/testsuite/gdc.test/runnable/link14074a.d b/gcc/testsuite/gdc.test/runnable/link14074a.d index eaf1c89ef97..200e8101e4b 100644 --- a/gcc/testsuite/gdc.test/runnable/link14074a.d +++ b/gcc/testsuite/gdc.test/runnable/link14074a.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/link14074x.d // EXTRA_SOURCES: imports/link14074y.d import imports.link14074x; import imports.link14074y; diff --git a/gcc/testsuite/gdc.test/runnable/link14074b.d b/gcc/testsuite/gdc.test/runnable/link14074b.d index fea23697fb7..a05ecdc50cf 100644 --- a/gcc/testsuite/gdc.test/runnable/link14074b.d +++ b/gcc/testsuite/gdc.test/runnable/link14074b.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/link14074z.d import imports.link14074z; void main() diff --git a/gcc/testsuite/gdc.test/runnable/link14541.d b/gcc/testsuite/gdc.test/runnable/link14541.d index 433b9d73950..7877a34448b 100644 --- a/gcc/testsuite/gdc.test/runnable/link14541.d +++ b/gcc/testsuite/gdc.test/runnable/link14541.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/link14541traits.d import imports.link14541traits; void main() diff --git a/gcc/testsuite/gdc.test/runnable/link14992.d b/gcc/testsuite/gdc.test/runnable/link14992.d index 2da97b9afa7..d024b5f7fdf 100644 --- a/gcc/testsuite/gdc.test/runnable/link14992.d +++ b/gcc/testsuite/gdc.test/runnable/link14992.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/a14992.d import imports.a14992; // do not link int test() diff --git a/gcc/testsuite/gdc.test/runnable/link15017.d b/gcc/testsuite/gdc.test/runnable/link15017.d index ec3304ec793..16187a8b404 100644 --- a/gcc/testsuite/gdc.test/runnable/link15017.d +++ b/gcc/testsuite/gdc.test/runnable/link15017.d @@ -1,5 +1,11 @@ // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/std15017variant.d +/* +TEST_OUTPUT: +--- +runnable/link15017.d(48): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import imports.std15017variant; @@ -40,6 +46,7 @@ void test() // OK <- in DeleteExp::semantic Variant10* p10; delete p10; + static assert(Variant10.__dtor.mangleof == "_D7imports15std15017variant__T8VariantNVki10ZQp6__dtorMFNaNbNiNfZv"); } void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/link6574.d b/gcc/testsuite/gdc.test/runnable/link6574.d index 53e95f21ca9..0f633f3852f 100644 --- a/gcc/testsuite/gdc.test/runnable/link6574.d +++ b/gcc/testsuite/gdc.test/runnable/link6574.d @@ -15,14 +15,18 @@ import imports.testmangle; enum Method { A, B, } +@safe @nogc pure nothrow: + +enum FZi = "FNaNbNiNfZi"; // pure nothrow @nogc @safe + int foo(Method method = Method.A)() { - static assert(foo.mangleof == "_D8link6574"~tl!"28"~"__T3fooVE"~id!("8link6574","Qs")~"6Methodi0Z"~id!("3foo","Qs")~"FZi"); + static assert(foo.mangleof == "_D8link6574"~tl!"28"~"__T3fooVE"~id!("8link6574","Qs")~"6Methodi0Z"~id!("3foo","Qs")~FZi); return 10 * foo!method(); } int foo(Method method : Method.A)() { - static assert(foo.mangleof == "_D8link6574"~tl!"29"~"__T3fooHVE"~id!("8link6574","Qt")~"6Methodi0Z"~id!("3foo","Qt")~"FZi"); + static assert(foo.mangleof == "_D8link6574"~tl!"29"~"__T3fooHVE"~id!("8link6574","Qt")~"6Methodi0Z"~id!("3foo","Qt")~FZi); return 2; } int foo(Method method : Method.B)() @@ -33,7 +37,7 @@ int foo(Method method : Method.B)() int bar(Method method = Method.B)() { - static assert(bar.mangleof == "_D8link6574"~tl!"28"~"__T3barVE"~id!("8link6574","Qs")~"6Methodi1Z"~id!("3bar","Qs")~"FZi"); + static assert(bar.mangleof == "_D8link6574"~tl!"28"~"__T3barVE"~id!("8link6574","Qs")~"6Methodi1Z"~id!("3bar","Qs")~FZi); return 10 * bar!method(); } int bar(Method method : Method.A)() @@ -43,7 +47,7 @@ int bar(Method method : Method.A)() } int bar(Method method : Method.B)() { - static assert(bar.mangleof == "_D8link6574"~tl!"29"~"__T3barHVE"~id!("8link6574","Qt")~"6Methodi1Z"~id!("3bar","Qt")~"FZi"); + static assert(bar.mangleof == "_D8link6574"~tl!"29"~"__T3barHVE"~id!("8link6574","Qt")~"6Methodi1Z"~id!("3bar","Qt")~FZi); return 3; } diff --git a/gcc/testsuite/gdc.test/runnable/link7745.d b/gcc/testsuite/gdc.test/runnable/link7745.d index fb36a9aae9e..9a0eccffef3 100644 --- a/gcc/testsuite/gdc.test/runnable/link7745.d +++ b/gcc/testsuite/gdc.test/runnable/link7745.d @@ -15,6 +15,6 @@ static assert(forceSemantic7745()); void f(C c) { auto x = &c.asdfg; } void main() { - // extra test for bug 4820 + // https://issues.dlang.org/show_bug.cgi?id=4820 nextis!(int)(); } diff --git a/gcc/testsuite/gdc.test/runnable/literal.d b/gcc/testsuite/gdc.test/runnable/literal.d index 60bac918ec8..99b177759b4 100644 --- a/gcc/testsuite/gdc.test/runnable/literal.d +++ b/gcc/testsuite/gdc.test/runnable/literal.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); @@ -165,7 +171,7 @@ void test2() } /***************************************************/ -// 13907 +// https://issues.dlang.org/show_bug.cgi?id=13907 void f13907_1(wchar[1] a) {} void f13907_2(wchar[2] a) {} @@ -185,8 +191,8 @@ void test13907() static assert(!__traits(compiles, { f13907_1("\U00010000" ); })); f13907_2("\U00010000"w); f13907_2("\U00010000"); - f13907_3("\U00010000"w); // Re-enable implicit length extension, from issue 13999 - f13907_3("\U00010000" ); // Re-enable implicit length extension, from issue 13999 + f13907_3("\U00010000"w); // Re-enable implicit length extension, from https://issues.dlang.org/show_bug.cgi?id=13999 + f13907_3("\U00010000" ); // Re-enable implicit length extension, from https://issues.dlang.org/show_bug.cgi?id=13999 assert(f13907_12("a") == 1); assert(f13907_12("ab") == 2); @@ -210,13 +216,13 @@ void test13907() static wchar[20] wsa = "hello world"; // ok static dchar[20] dsa = "hello world"; // ok - // Bugzilla 13966 + // https://issues.dlang.org/show_bug.cgi?id=13966 string[1][] arr; arr ~= ["class"]; enum immutable(char[5]) sarrstr = "class"; arr ~= [sarrstr]; - // Bugzilla 13999 + // https://issues.dlang.org/show_bug.cgi?id=13999 string[dchar[2]] aa13999 = ["あ": "bar"]; assert(aa13999["あ"] == "bar"); dchar[2] key13999 = "あ"; @@ -225,6 +231,16 @@ void test13907() assert(aa13999[key13999] == "bar"); } +ulong op12950(ulong v){return v + 12950;} + +void test12950() +{ + assert(0x00_00_00_01.op12950() == 12951); + assert(0x00_00_00_01UL.op12950() == 12951); + assert(0b00_00_00_01.op12950() == 12951); + assert(0b00_00_00_01UL.op12950() == 12951); +} + /***************************************************/ int main() @@ -232,6 +248,7 @@ int main() test1(); test2(); test13907(); + test12950(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/loopunroll.d b/gcc/testsuite/gdc.test/runnable/loopunroll.d index 19e2db2a03a..b614d1bdf7f 100644 --- a/gcc/testsuite/gdc.test/runnable/loopunroll.d +++ b/gcc/testsuite/gdc.test/runnable/loopunroll.d @@ -1,5 +1,22 @@ - -/* PERMUTE_ARGS: -O +/* +PERMUTE_ARGS: -O +RUN_OUTPUT: +--- +0 +45 +45 +45 +45 +45 +45 +45 +10 +45 +0 +5 +45 +45 +--- */ import core.stdc.stdio; diff --git a/gcc/testsuite/gdc.test/runnable/m1.d b/gcc/testsuite/gdc.test/runnable/m1.d index 49a3d15bc3e..5689ffdb367 100644 --- a/gcc/testsuite/gdc.test/runnable/m1.d +++ b/gcc/testsuite/gdc.test/runnable/m1.d @@ -1,9 +1,15 @@ -// EXTRA_SOURCES: imports/m1a.d -// PERMUTE_ARGS: +/* +EXTRA_SOURCES: imports/m1a.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Success +--- +*/ module m1; -import std.stdio; +import core.stdc.stdio; import imports.m1a; diff --git a/gcc/testsuite/gdc.test/runnable/manboy.d b/gcc/testsuite/gdc.test/runnable/manboy.d index 038622668f2..8e533074efb 100644 --- a/gcc/testsuite/gdc.test/runnable/manboy.d +++ b/gcc/testsuite/gdc.test/runnable/manboy.d @@ -1,6 +1,6 @@ // PERMUTE_ARGS: -import std.stdio; +import core.stdc.stdio; int a(int k, lazy int x1, lazy int x2, lazy int x3, lazy int x4, lazy int x5) { diff --git a/gcc/testsuite/gdc.test/runnable/mangle.d b/gcc/testsuite/gdc.test/runnable/mangle.d index 9a8420aa20b..7599e0e03c3 100644 --- a/gcc/testsuite/gdc.test/runnable/mangle.d +++ b/gcc/testsuite/gdc.test/runnable/mangle.d @@ -14,7 +14,8 @@ false import imports.testmangle; /***************************************************/ -// 10077 - pragma(mangle) +// https://issues.dlang.org/show_bug.cgi?id=10077 +// pragma(mangle) pragma(mangle, "_test10077a_") int test10077a; static assert(test10077a.mangleof == "_test10077a_"); @@ -54,7 +55,7 @@ void test10077i() } /***************************************************/ -// 13050 +// https://issues.dlang.org/show_bug.cgi?id=13050 void func13050(int); template decl13050(Arg) @@ -79,7 +80,7 @@ static assert(is(typeof(&problem13050!int) == void function(int))); static assert(is(typeof(&workaround13050!int) == void function(int))); /***************************************************/ -// 2774 +// https://issues.dlang.org/show_bug.cgi?id=2774 int foo2774(int n) { return 0; } static assert(foo2774.mangleof == "_D6mangle7foo2774FiZi"); @@ -100,7 +101,7 @@ void test2774() } /*******************************************/ -// 8847 +// https://issues.dlang.org/show_bug.cgi?id=8847 auto S8847() { @@ -294,7 +295,7 @@ static assert(typeof(f8847a()).mangleof == "S6mangle6f8847aFNaZ1S"); static assert(typeof(f8847b()).mangleof == "S6mangle6f8847bFNaZ1S"); /*******************************************/ -// 12352 +// https://issues.dlang.org/show_bug.cgi?id=12352 auto bar12352() { @@ -325,7 +326,7 @@ static assert(typeof(baz12352()) .mangleof == "C6mangle8baz12352FZ1C"); static assert(typeof(baz12352()).func.mangleof == "_D6mangle8baz12352FZ1C4funcMFZv"); /*******************************************/ -// 9525 +// https://issues.dlang.org/show_bug.cgi?id=9525 void f9525(T)(in T*) { } @@ -334,27 +335,29 @@ void test9525() enum result1 = "S6mangle8test9525FZ"~tl!"26"~"__T5test1S"~tl!"13"~id!("6mangle","QBc")~"5f9525Z"~id!("5test1","Qr")~"MFZ1S"; enum result2 = "S6mangle8test9525FZ"~tl!"26"~"__T5test2S"~tl!"13"~id!("6mangle","QBc")~"5f9525Z"~id!("5test2","Qr")~"MFNaNbZ1S"; - void test1(alias a)() + bool test1(alias a)() { static struct S {} static assert(S.mangleof == result1); S s; a(&s); // Error: Cannot convert &S to const(S*) at compile time + return true; } - static assert((test1!f9525(), true)); + enum evalTest1 = test1!f9525(); - void test2(alias a)() pure nothrow + bool test2(alias a)() pure nothrow { static struct S {} static assert(S.mangleof == result2); S s; a(&s); // Error: Cannot convert &S to const(S*) at compile time + return true; } - static assert((test2!f9525(), true)); + enum evalTest2 = test2!f9525(); } /******************************************/ -// 10249 +// https://issues.dlang.org/show_bug.cgi?id=10249 template Seq10249(T...) { alias Seq10249 = T; } @@ -390,7 +393,7 @@ static: // necessary to make overloaded symbols accessible via __traits(getOverl } /*******************************************/ -// 11718 +// https://issues.dlang.org/show_bug.cgi?id=11718 struct Ty11718(alias sym) {} @@ -431,7 +434,7 @@ void test11718() } /*******************************************/ -// 11776 +// https://issues.dlang.org/show_bug.cgi?id=11776 struct S11776(alias fun) { } @@ -454,7 +457,7 @@ void test11776() } /***************************************************/ -// 12044 +// https://issues.dlang.org/show_bug.cgi?id=12044 struct S12044(T) { @@ -481,7 +484,7 @@ void test12044() } /*******************************************/ -// 12217 +// https://issues.dlang.org/show_bug.cgi?id=12217 void test12217(int) { @@ -499,7 +502,7 @@ void test12217(int) void test12217() {} /***************************************************/ -// 12231 +// https://issues.dlang.org/show_bug.cgi?id=12231 void func12231a()() if (is(typeof({ @@ -599,6 +602,13 @@ void fooB(void delegate (void delegate()) scope dg) //pragma(msg, fooB.mangleof); static assert(typeof(fooA).mangleof != typeof(fooB).mangleof); + +/***************************************************/ + +@live int testLive() { return 42; } + +static assert(testLive.mangleof == "_D6mangle8testLiveFNmZi"); + /***************************************************/ alias noreturn = typeof(*null); @@ -608,6 +618,12 @@ static assert(funcd.mangleof == "_D6mangle5funcdFPFZNnZi"); /***************************************************/ +struct S21753 { void function() f1; } +void fun21753(S21753 v)() {} +alias fl21753 = (){}; +static assert((fun21753!(S21753(fl21753))).mangleof == "_D6mangle__T8fun21753VSQv6S21753S1f_DQBj10" ~ fl21753.stringof ~ "MFNaNbNiNfZvZQCbQp"); + +/***************************************************/ void main() { test10077h(); diff --git a/gcc/testsuite/gdc.test/runnable/mars1.d b/gcc/testsuite/gdc.test/runnable/mars1.d index 4d17d33aebf..4f38f4d3322 100644 --- a/gcc/testsuite/gdc.test/runnable/mars1.d +++ b/gcc/testsuite/gdc.test/runnable/mars1.d @@ -1,259 +1,36 @@ /* -RUNNABLE_PHOBOS_TEST -REQUIRED_ARGS: -mcpu=native -PERMUTE_ARGS: -O -inline +REQUIRED_ARGS: -mcpu=native -preview=intpromote +PERMUTE_ARGS: -O -inline -release */ import core.stdc.stdio; -void testgoto() -{ - int i; - - i = 3; - goto L4; -L3: i++; - goto L5; -L4: goto L3; -L5: assert(i == 4); -} - -int testswitch() -{ - int i; - - i = 3; - switch (i) - { - case 0: - case 1: - default: - assert(0); - case 3: - break; - } - return 0; -} - -void testdo() -{ - int x = 0; - - do - { - x++; - } while (x < 10); - printf("x == %d\n", x); - assert(x == 10); -} - - -void testbreak() -{ int i, j; - - Louter: - for (i = 0; i < 10; i++) - { - for (j = 0; j < 10; j++) - { - if (j == 3) - break Louter; - } - } - - printf("i = %d, j = %d\n", i, j); - assert(i == 0); - assert(j == 3); -} +template tuple(A...) { alias tuple = A; } /////////////////////// -int foo(string s) -{ - int i; - - i = 0; - switch (s) - { - case "hello": - i = 1; - break; - case "goodbye": - i = 2; - break; - case "goodb": - i = 3; - break; - default: - i = 10; - break; - } - return i; -} - - -void teststringswitch() -{ int i; - - i = foo("hello"); - printf("i = %d\n", i); - assert(i == 1); - - i = foo("goodbye"); - printf("i = %d\n", i); - assert(i == 2); - - i = foo("goodb"); - printf("i = %d\n", i); - assert(i == 3); - - i = foo("huzzah"); - printf("i = %d\n", i); - assert(i == 10); -} - - -/////////////////////// +// https://github.com/dlang/dmd/pull/11441 -struct Foo +long sdiv1(long l) { - int a; - char b; - long c; + return l / 2; } -Foo test(Foo f) +int sdiv2(int i) { - f.a += 1; - f.b += 3; - f.c += 4; - return f; + return i / 2; } - -void teststrarg() +void testsdiv2() { - Foo g; - g.a = 1; - g.b = 2; - g.c = 3; - - Foo q; - q = test(g); - assert(q.a == 2); - assert(q.b == 5); - assert(q.c == 7); + assert(sdiv1(10) == 5); + assert(sdiv1(-10) == -5); + assert(sdiv2(10) == 5); + assert(sdiv2(-10) == -5); } /////////////////////// -align (1) struct Foo1 -{ - align (1): - int a; - char b; - long c; -} - -struct Foo2 -{ - int a; - char b; - long c; -} - -struct Foo3 -{ - int a; - align (1) char b; - long c; -} - -struct Foo4 -{ - int a; - struct { char b; } - long c; -} - -void testsizes() -{ - printf("%d\n", Foo1.sizeof); - assert(Foo1.a.offsetof == 0); - assert(Foo1.b.offsetof == 4); - assert(Foo1.c.offsetof == 5); - assert(Foo1.sizeof == 13); - - assert(Foo2.a.offsetof == 0); - assert(Foo2.b.offsetof == 4); - assert(Foo2.c.offsetof == 8); - assert(Foo2.sizeof == 16); - - assert(Foo3.a.offsetof == 0); - assert(Foo3.b.offsetof == 4); - assert(Foo3.c.offsetof == 8); - assert(Foo3.b.sizeof == 1); - assert(Foo3.sizeof == 16); - - assert(Foo4.sizeof == 16); -} - -/////////////////////// - -size_t cond11565(size_t val) -{ - return val ? size_t.max : 0; -} - -void test11565() -{ - assert(cond11565(true) == size_t.max); -} - -/////////////////////// - -int[3] array1 = [1:1,2,0:3]; - -void testarrayinit() -{ - assert(array1[0] == 3); - assert(array1[1] == 1); - assert(array1[2] == 2); -} - -/////////////////////// - -void test13023(ulong n) -{ - static void func(bool b) {} - - ulong k = 0; - - func(k >= n / 2); - - if (k >= n / 2) - assert(0); -} - -/////////////////////// - -struct U { int a; union { char c; int d; } long b; } - -U f = { b:3, d:0x22222222, a:1 }; - -void testU() -{ - assert(f.b == 3); - assert(f.d == 0x22222222); - assert(f.c == 0x22); - assert(f.a == 1); - assert(f.sizeof == 16); - assert(U.sizeof == 16); -} - - -/////////////////////// - void testulldiv() { __gshared ulong[4][] vectors = @@ -280,19 +57,18 @@ void testulldiv() { ulong q = vectors[i][0] / vectors[i][1]; if (q != vectors[i][2]) - printf("[%d] %lld / %lld = %lld, should be %lld\n", - vectors[i][0], vectors[i][1], q, vectors[i][2]); + printf("[%zd] %lld / %lld = %lld, should be %lld\n", + i, vectors[i][0], vectors[i][1], q, vectors[i][2]); ulong r = vectors[i][0] % vectors[i][1]; if (r != vectors[i][3]) - printf("[%d] %lld %% %lld = %lld, should be %lld\n", + printf("[%zd] %lld %% %lld = %lld, should be %lld\n", i, vectors[i][0], vectors[i][1], r, vectors[i][3]); } } //////////////////////////////////////////////////////////////////////// - uint udiv10(uint x) { return x / 10; @@ -427,307 +203,498 @@ void testfastudiv() //////////////////////////////////////////////////////////////////////// -void vfunc() {} - -void test12095(int k) -{ - int e = 0; - e ? k || assert(0) : !e || vfunc(); - e ? k || assert(0) : e && vfunc(); - !e ? !e || vfunc() : k || assert(0); +// https://issues.dlang.org/show_bug.cgi?id=14936 + +long sldiv1 (long x) { return x / (1L << 1); } +long sldiv2 (long x) { return x / (1L << 2); } +long sldiv3 (long x) { return x / (1L << 3); } +long sldiv7 (long x) { return x / (1L << 7); } +long sldiv8 (long x) { return x / (1L << 8); } +long sldiv9 (long x) { return x / (1L << 9); } +long sldiv30(long x) { return x / (1L << 30); } +long sldiv31(long x) { return x / (1L << 31); } +long sldiv32(long x) { return x / (1L << 32); } +long sldiv33(long x) { return x / (1L << 33); } +long sldiv34(long x) { return x / (1L << 34); } +long sldiv62(long x) { return x / (1L << 62); } +long sldiv63(long x) { return x / (1L << 63); } + +void testsldiv() +{ + /* Test special div code for signed long divide + * by power of 2 for 32 bit targets. + */ + + // printf("63 = %llx\n", sldiv63(-0x7FFF_F8FF_FF3F_2FFFL)); + + static foreach (C; tuple!( + 1,2,3,10,300,1000, + 4_1001_2030_0030, + 0x7FFF_F8FF_FF3F_2FFFL)) + { + /* Check if runtime computation matches compile time + */ + assert(sldiv1 ( C) == C / (1L << 1)); + assert(sldiv1 (-C) == -C / (1L << 1)); + assert(sldiv2 ( C) == C / (1L << 2)); + assert(sldiv2 (-C) == -C / (1L << 2)); + assert(sldiv3 ( C) == C / (1L << 3)); + assert(sldiv3 (-C) == -C / (1L << 3)); + assert(sldiv7 ( C) == C / (1L << 7)); + assert(sldiv7 (-C) == -C / (1L << 7)); + assert(sldiv8 ( C) == C / (1L << 8)); + assert(sldiv8 (-C) == -C / (1L << 8)); + assert(sldiv9 ( C) == C / (1L << 9)); + assert(sldiv9 (-C) == -C / (1L << 9)); + + assert(sldiv30( C) == C / (1L << 30)); + assert(sldiv30(-C) == -C / (1L << 30)); + assert(sldiv31( C) == C / (1L << 31)); + assert(sldiv31(-C) == -C / (1L << 31)); + assert(sldiv32( C) == C / (1L << 32)); + assert(sldiv32(-C) == -C / (1L << 32)); + assert(sldiv33( C) == C / (1L << 33)); + assert(sldiv33(-C) == -C / (1L << 33)); + assert(sldiv34( C) == C / (1L << 34)); + assert(sldiv34(-C) == -C / (1L << 34)); + assert(sldiv62( C) == C / (1L << 62)); + assert(sldiv62(-C) == -C / (1L << 62)); + assert(sldiv63( C) == C / (1L << 63)); + assert(sldiv63(-C) == -C / (1L << 63)); + } } +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=14936 + +long slmod1 (long x) { return x % (1L << 1); } +long slmod2 (long x) { return x % (1L << 2); } +long slmod3 (long x) { return x % (1L << 3); } +long slmod7 (long x) { return x % (1L << 7); } +long slmod8 (long x) { return x % (1L << 8); } +long slmod9 (long x) { return x % (1L << 9); } +long slmod30(long x) { return x % (1L << 30); } +long slmod31(long x) { return x % (1L << 31); } +long slmod32(long x) { return x % (1L << 32); } +long slmod33(long x) { return x % (1L << 33); } +long slmod34(long x) { return x % (1L << 34); } +long slmod62(long x) { return x % (1L << 62); } +long slmod63(long x) { return x % (1L << 63); } + +void testslmod() +{ + static foreach (C; tuple!( + 1,2,3,10,300,1000, + 4_1001_2030_0030, + 0x7FFF_F8FF_FF3F_2FFFL)) + { + /* Check if runtime computation matches compile time + */ + assert(slmod1 ( C) == C % (1L << 1)); + assert(slmod1 (-C) == -C % (1L << 1)); + assert(slmod2 ( C) == C % (1L << 2)); + assert(slmod2 (-C) == -C % (1L << 2)); + assert(slmod3 ( C) == C % (1L << 3)); + assert(slmod3 (-C) == -C % (1L << 3)); + assert(slmod7 ( C) == C % (1L << 7)); + assert(slmod7 (-C) == -C % (1L << 7)); + assert(slmod8 ( C) == C % (1L << 8)); + assert(slmod8 (-C) == -C % (1L << 8)); + assert(slmod9 ( C) == C % (1L << 9)); + assert(slmod9 (-C) == -C % (1L << 9)); + + assert(slmod30( C) == C % (1L << 30)); + assert(slmod30(-C) == -C % (1L << 30)); + assert(slmod31( C) == C % (1L << 31)); + assert(slmod31(-C) == -C % (1L << 31)); + assert(slmod32( C) == C % (1L << 32)); + assert(slmod32(-C) == -C % (1L << 32)); + assert(slmod33( C) == C % (1L << 33)); + assert(slmod33(-C) == -C % (1L << 33)); + assert(slmod34( C) == C % (1L << 34)); + assert(slmod34(-C) == -C % (1L << 34)); + assert(slmod62( C) == C % (1L << 62)); + assert(slmod62(-C) == -C % (1L << 62)); + assert(slmod63( C) == C % (1L << 63)); + assert(slmod63(-C) == -C % (1L << 63)); + } +} //////////////////////////////////////////////////////////////////////// +T divC(int C, T)(T x) +{ + T y = x; + y /= C; + assert(y == x / C); + y = x; + y /= -C; + assert(y == x / -C); + return x / C; +} -bool test3918a( float t, real u ) +T modC(int C, T)(T x) { - printf("%f\n", u ); - return t && u; + T y = x; + y %= C; + assert(y == x % C); + y = x; + y %= -C; + assert(y == x % -C); + return x % C; } -bool test3918b( real t, float u ) +T remquoC(int C, T)(T x) { - printf("%f\n", t ); - return t && u; + return (x / C) | (x % C); } -void test3918() +void testfastdiv() { - assert(test3918a(float.nan, real.nan)); - assert(test3918b(real.nan, float.nan)); + static int z = 0; // prevent constant folding by optimizer + + static foreach (T; tuple!(int, long, uint, ulong)) + {{ + T u = 10000; + T r; + static foreach (C; tuple!(10, 14, 14007, -10, -14, -14007)) + { + r = divC!C(u); assert(r == u / (z + C)); + r = modC!C(u); assert(r == u % (z + C)); + r = remquoC!C(u); assert(r == ((u / (z + C) | (u % (z + C))))); + } + }} } //////////////////////////////////////////////////////////////////////// -int div10(int x) -{ - return x / 10; -} +/* Test the pattern: + * replace ((i / C1) / C2) with (i / (C1 * C2)) + * when e1 is 0 or 1 and (i2-i1) is a power of 2. + */ -int div14(int x) +void divdiv(T, T C1, T C2)(T i) { - return x / 14; + auto a = (i / C1) / C2; + auto b = i / (C1 * C2); + if (a != b) assert(0); } -int div14007(int x) +void testdivdiv() { - return x / 14007; + divdiv!(int,10,20)(30); + divdiv!(uint,10,20)(30); + divdiv!(long,10,20)(30); + divdiv!(ulong,10,20)(30); + + divdiv!(int,-10,20)(30); + divdiv!(long,-10,20)(30); + + divdiv!(int,-10,-20)(-30); + divdiv!(long,-10,-20)(-30); } -int mod10(int x) +//////////////////////////////////////////////////////////////////////// + +void testdivcmp() { - return x % 10; + // https://github.com/dlang/dmd/pull/7128 + static bool foo(uint a, uint b) + { + return cast(bool)(a / b); // convert / to >= + } + + assert(!foo(3, 4)); + assert(foo(4, 4)); + assert(foo(5, 4)); } -int mod14(int x) +///////////////////////////////////////////////////// + +void testgoto() { - return x % 14; + int i; + + i = 3; + goto L4; +L3: i++; + goto L5; +L4: goto L3; +L5: assert(i == 4); } -int mod14007(int x) +int testswitch() { - return x % 14007; + int i; + + i = 3; + switch (i) + { + case 0: + case 1: + default: + assert(0); + case 3: + break; + } + return 0; } -int remquo10(int x) +void testdo() { - return (x / 10) | (x % 10); + int x = 0; + + do + { + x++; + } while (x < 10); + printf("x == %d\n", x); + assert(x == 10); } -int remquo14(int x) -{ - return (x / 14) | (x % 14); + +void testbreak() +{ int i, j; + + Louter: + for (i = 0; i < 10; i++) + { + for (j = 0; j < 10; j++) + { + if (j == 3) + break Louter; + } + } + + printf("i = %d, j = %d\n", i, j); + assert(i == 0); + assert(j == 3); } -int remquo14007(int x) +/////////////////////// + +int foo(string s) { - return (x / 14007) | (x % 14007); + int i; + + i = 0; + switch (s) + { + case "hello": + i = 1; + break; + case "goodbye": + i = 2; + break; + case "goodb": + i = 3; + break; + default: + i = 10; + break; + } + return i; } -//////////////////// -int mdiv10(int x) -{ - return x / -10; +void teststringswitch() +{ int i; + + i = foo("hello"); + printf("i = %d\n", i); + assert(i == 1); + + i = foo("goodbye"); + printf("i = %d\n", i); + assert(i == 2); + + i = foo("goodb"); + printf("i = %d\n", i); + assert(i == 3); + + i = foo("huzzah"); + printf("i = %d\n", i); + assert(i == 10); } -int mdiv14(int x) + +/////////////////////// + +struct Foo { - return x / -14; + int a; + char b; + long c; } -int mdiv14007(int x) +Foo test(Foo f) { - return x / -14007; + f.a += 1; + f.b += 3; + f.c += 4; + return f; } -int mmod10(int x) + +void teststrarg() { - return x % -10; + Foo g; + g.a = 1; + g.b = 2; + g.c = 3; + + Foo q; + q = test(g); + assert(q.a == 2); + assert(q.b == 5); + assert(q.c == 7); } -int mmod14(int x) +/////////////////////// + +align (1) struct Foo1 { - return x % -14; + align (1): + int a; + char b; + long c; } -int mmod14007(int x) +struct Foo2 { - return x % -14007; + int a; + char b; + long c; } -int mremquo10(int x) +struct Foo3 { - return (x / -10) | (x % -10); + int a; + align (1) char b; + long c; } -int mremquo14(int x) +struct Foo4 { - return (x / -14) | (x % -14); + int a; + struct { char b; } + long c; } -int mremquo14007(int x) +void testsizes() { - return (x / -14007) | (x % -14007); -} + printf("%zd\n", Foo1.sizeof); + assert(Foo1.a.offsetof == 0); + assert(Foo1.b.offsetof == 4); + assert(Foo1.c.offsetof == 5); + assert(Foo1.sizeof == 13); -//////////////////// + assert(Foo2.a.offsetof == 0); + assert(Foo2.b.offsetof == 4); + assert(Foo2.c.offsetof == 8); + assert(Foo2.sizeof == 16); + assert(Foo3.a.offsetof == 0); + assert(Foo3.b.offsetof == 4); + assert(Foo3.c.offsetof == 8); + assert(Foo3.b.sizeof == 1); + assert(Foo3.sizeof == 16); -long ldiv10(long x) -{ - return x / 10; + assert(Foo4.sizeof == 16); } -long ldiv14(long x) -{ - return x / 14; -} +/////////////////////// -long ldiv14007(long x) +size_t cond11565(size_t val) { - return x / 14007; + return val ? size_t.max : 0; } -long lmod10(long x) +void test11565() { - return x % 10; + assert(cond11565(true) == size_t.max); } -long lmod14(long x) -{ - return x % 14; -} +/////////////////////// -long lmod14007(long x) -{ - return x % 14007; -} +int[3] array1 = [1:1,2,0:3]; -long lremquo10(long x) +void testarrayinit() { - return (x / 10) | (x % 10); + assert(array1[0] == 3); + assert(array1[1] == 1); + assert(array1[2] == 2); } -long lremquo14(long x) -{ - return (x / 14) | (x % 14); -} +/////////////////////// -long lremquo14007(long x) +void test13023(ulong n) { - return (x / 14007) | (x % 14007); + static void func(bool b) {} + + ulong k = 0; + + func(k >= n / 2); + + if (k >= n / 2) + assert(0); } +/////////////////////// -//////////////////// +struct U { int a; union { char c; int d; } long b; } +U f = { b:3, d:0x22222222, a:1 }; -long mldiv10(long x) +void testU() { - return x / -10; + assert(f.b == 3); + assert(f.d == 0x22222222); + assert(f.c == 0x22); + assert(f.a == 1); + assert(f.sizeof == 16); + assert(U.sizeof == 16); } -long mldiv14(long x) -{ - return x / -14; -} -long mldiv14007(long x) -{ - return x / -14007; -} +//////////////////////////////////////////////////////////////////////// -long mlmod10(long x) -{ - return x % -10; -} +void vfunc() {} -long mlmod14(long x) +void test12095(int k) { - return x % -14; + int e = 0; + e ? k || assert(0) : !e || vfunc(); + e ? k || assert(0) : e && vfunc(); + !e ? !e || vfunc() : k || assert(0); } -long mlmod14007(long x) -{ - return x % -14007; -} -long mlremquo10(long x) -{ - return (x / -10) | (x % -10); -} +//////////////////////////////////////////////////////////////////////// + -long mlremquo14(long x) +bool test3918a( float t, real u ) { - return (x / -14) | (x % -14); + printf("%Lf\n", u ); + return t && u; } -long mlremquo14007(long x) +bool test3918b( real t, float u ) { - return (x / -14007) | (x % -14007); + printf("%Lf\n", t ); + return t && u; } - - -void testfastdiv() +void test3918() { - { - static int x10 = 10; - static int x14 = 14; - static int x14007 = 14007; - - int u = 10000; - int r; - r = div10(u); assert(r == u/x10); - r = div14(u); assert(r == u/x14); - r = div14007(u); assert(r == u/x14007); - r = mod10(u); assert(r == u%x10); - r = mod14(u); assert(r == u%x14); - r = mod14007(u); assert(r == u%x14007); - r = remquo10(u); assert(r == ((u/x10)|(u%x10))); - r = remquo14(u); assert(r == ((u/x14)|(u%x14))); - r = remquo14007(u); assert(r == ((u/x14007)|(u%x14007))); - } - { - static int t10 = -10; - static int t14 = -14; - static int t14007 = -14007; - - int u = 10000; - int r; - r = mdiv10(u); assert(r == u/t10); - r = mdiv14(u); assert(r == u/t14); - r = mdiv14007(u); assert(r == u/t14007); - r = mmod10(u); assert(r == u%t10); - r = mmod14(u); assert(r == u%t14); - r = mmod14007(u); assert(r == u%t14007); - r = mremquo10(u); assert(r == ((u/t10)|(u%t10))); - r = mremquo14(u); assert(r == ((u/t14)|(u%t14))); - r = mremquo14007(u); assert(r == ((u/t14007)|(u%t14007))); - } - { - static long y10 = 10; - static long y14 = 14; - static long y14007 = 14007; - - long u = 10000; - long r; - r = ldiv10(u); assert(r == u/y10); - r = ldiv14(u); assert(r == u/y14); - r = ldiv14007(u); assert(r == u/y14007); - r = lmod10(u); assert(r == u%y10); - r = lmod14(u); assert(r == u%y14); - r = lmod14007(u); assert(r == u%y14007); - r = lremquo10(u); assert(r == ((u/y10)|(u%y10))); - r = lremquo14(u); assert(r == ((u/y14)|(u%y14))); - r = lremquo14007(u); assert(r == ((u/y14007)|(u%y14007))); - } - { - static long z10 = -10; - static long z14 = -14; - static long z14007 = -14007; - - long u = 10000; - long r; - r = mldiv10(u); assert(r == u/z10); - r = mldiv14(u); assert(r == u/z14); - r = mldiv14007(u); assert(r == u/z14007); - r = mlmod10(u); assert(r == u%z10); - r = mlmod14(u); assert(r == u%z14); - r = mlmod14007(u); assert(r == u%z14007); - r = mlremquo10(u); assert(r == ((u/z10)|(u%z10))); - r = mlremquo14(u); assert(r == ((u/z14)|(u%z14))); - r = mlremquo14007(u); assert(r == ((u/z14007)|(u%z14007))); - } + assert(test3918a(float.nan, real.nan)); + assert(test3918b(real.nan, float.nan)); } //////////////////////////////////////////////////////////////////////// - T docond1(T)(T l, ubyte thresh, ubyte val) { l += (thresh < val); return l; @@ -1041,25 +1008,6 @@ void testshrshl() //////////////////////////////////////////////////////////////////////// -struct S1 -{ - cdouble val; -} - -void formatTest(S1 s, double re, double im) -{ - assert(s.val.re == re); - assert(s.val.im == im); -} - -void test10639() -{ - S1 s = S1(3+2.25i); - formatTest(s, 3, 2.25); -} - -//////////////////////////////////////////////////////////////////////// - bool bt10715(in uint[] ary, size_t bitnum) { return !!(ary[bitnum >> 5] & 1 << (bitnum & 31)); // uses bt @@ -1245,6 +1193,19 @@ void test9449() if (arr[0].g != 4.0) assert(0); } +struct Point9449x +{ + float f = 0.0; + double g = 0.0; +} + +void test9449x() +{ + Point9449x[1] arr; + if (arr[0].f != 0.0) assert(0); + if (arr[0].g != 0.0) assert(0); +} + //////////////////////////////////////////////////////////////////////// // https://issues.dlang.org/show_bug.cgi?id=12057 @@ -1351,18 +1312,6 @@ void test14829() //////////////////////////////////////////////////////////////////////// -void test2() -{ - void test(cdouble v) - { - auto x2 = cdouble(v); - assert(x2 == v); - } - test(1.2+3.4i); -} - -//////////////////////////////////////////////////////////////////////// - void test3() { int[6] a; @@ -1374,7 +1323,7 @@ void test3() } //////////////////////////////////////////////////////////////////////// -// 14782 +// https://issues.dlang.org/show_bug.cgi?id=14782 void test14782() @@ -1477,7 +1426,7 @@ void test4() double sumKBN(double s = 0.0) { - import std.math : fabs; + import core.math : fabs; double c = 0.0; foreach(double x; [1, 1e100, 1, -1e100]) { @@ -1547,35 +1496,6 @@ void test16102() //////////////////////////////////////////////////////////////////////// - -/* Test the pattern: - * replace ((i / C1) / C2) with (i / (C1 * C2)) - * when e1 is 0 or 1 and (i2-i1) is a power of 2. - */ - -void divdiv(T, T C1, T C2)(T i) -{ - auto a = (i / C1) / C2; - auto b = i / (C1 * C2); - if (a != b) assert(0); -} - -void testdivdiv() -{ - divdiv!(int,10,20)(30); - divdiv!(uint,10,20)(30); - divdiv!(long,10,20)(30); - divdiv!(ulong,10,20)(30); - - divdiv!(int,-10,20)(30); - divdiv!(long,-10,20)(30); - - divdiv!(int,-10,-20)(-30); - divdiv!(long,-10,-20)(-30); -} - -//////////////////////////////////////////////////////////////////////// - void test5a(ulong x, ulong y) { int a; @@ -1663,8 +1583,904 @@ void testeqeqranges() //////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=16189 + +void test16189() +{ + ubyte[9][1] data; + uint a = 0; + loop: + data[0] = data[a]; + a--; + bool b = false; + if (b) goto loop; + assert(a == -1); // was failing with -O +} + + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=16997 + +void test16997() +{ + /* Exhaustively test all signed and unsigned byte promotions for + * - + and ~ + */ + for (int i = 0; i < 256; ++i) + { + ubyte c = cast(ubyte)i; + + int i1 = cast(int)(~c); + int i2 = cast(int)(~cast(int)c); + + //printf("%d, %d\n", i1, i2); + assert(i1 == i2); + + i1 = cast(int)(+c); + i2 = cast(int)(+cast(int)c); + assert(i1 == i2); + + i1 = cast(int)(-c); + i2 = cast(int)(-cast(int)c); + assert(i1 == i2); + } + + for (int i = 0; i < 256; ++i) + { + byte c = cast(byte)i; + + int i1 = cast(int)(~c); + int i2 = cast(int)(~cast(int)c); + + //printf("%d, %d\n", i1, i2); + assert(i1 == i2); + + i1 = cast(int)(+c); + i2 = cast(int)(+cast(int)c); + assert(i1 == i2); + + i1 = cast(int)(-c); + i2 = cast(int)(-cast(int)c); + assert(i1 == i2); + } +} + +//////////////////////////////////////////////////////////////////////// + +void test18315() // https://issues.dlang.org/show_bug.cgi?id=18315 +{ + int i = int.min; + bool b = i > 0; + assert(!b); + b = 0 < i; + assert(!b); +} + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=18461 + +void test18461() +{ + import core.bitop; + + size_t test_val = 0b0001_0000; + + if (bt(&test_val, 4) == 0) + assert(false); +} + +//////////////////////////////////////////////////////////////////////// + +void test18730() // https://issues.dlang.org/show_bug.cgi?id=18730 +{ + static if (size_t.sizeof == 8) + { + static int bt18730_64_64(in ulong* p, ulong bitnum) pure @system + { + return ((p[bitnum >> 6] & (1L << (bitnum & 63)))) != 0; + } + static int bt18730_64_32(in ulong* p, uint bitnum) pure @system + { + return ((p[bitnum >> 6] & (1L << (bitnum & 63)))) != 0; + } + static int bt18730_32_64(in uint* p, ulong bitnum) pure @system + { + return ((p[bitnum >> 5] & (1 << (bitnum & 31)))) != 0; + } + + // Check that bt_64_64 uses a 64-bit register for the offset. + { + enum bitIndex = int.max + 1L; + auto a = new ulong[](bitIndex / 64 + 1); + a[bitIndex / 64] = 1; + assert(bt18730_64_64(a.ptr, bitIndex)); + assert(!bt18730_64_64(a.ptr, bitIndex + 1)); + assert(!bt18730_64_64(a.ptr, bitIndex - 1)); + } + // Check that bt_64_32 uses a 32-bit register for the offset. + { + static int f(ulong* p, ulong bitnum) + { + return bt18730_64_32(p, cast(uint) bitnum); + } + enum bitIndex = uint.max + 1L; + assert(cast(uint) bitIndex == 0); + ulong s = 1; + assert(f(&s, bitIndex)); + } + /* Check that bt_32_64 does not become a 64-bit bt instruction. Would lead + to a segfault when trying to load 8 bytes while only 4 are accessible. */ + version (Posix) + {{ + import core.sys.posix.sys.mman; + import core.sys.posix.unistd; + // Allocate two pages. + immutable sz = 2 * sysconf(_SC_PAGESIZE); + auto m = mmap(null, sz, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); + // Discard the higher page. It becomes unreadable. + munmap(m + sz / 2, sz / 2); + // Try looking at the last 4 bytes of the readable page. + uint* p = cast(uint*) (m + sz / 2 - uint.sizeof); + bt18730_32_64(p, 0); + munmap(m, sz / 2); // Free the readable page. + }} + } +} + +//////////////////////////////////////////////////////////////////////// + +void test19497() // https://issues.dlang.org/show_bug.cgi?id=19497 +{ + { + ubyte[1024] data; + ushort* ushortPtr = cast(ushort*) data.ptr; + *ushortPtr++ = 0xfe00; + printf("ushortPtr(%p)\n", ushortPtr); + fflush(stdout); + } + + alias Seq(stuff ...) = stuff; + static foreach (T; Seq!(ubyte, ushort, uint, ulong, byte, short, int, long)) + {{ + T[2] data = 0x2A; + T* q = &data[0]; + *q++ = cast(T) 0x1122334455667788; + if (*q != 0x2A) assert(false); + }} + + { + static int toStringz(string s) { return s.length > 0 ? s[0] : 0; } + static void toAStringz(in string[] a, int* az) + { + foreach (string s; a) + { + *az++ = toStringz(s); + } + } + string[1] sa = ["abc"]; + int[2] tgt = 0x2a; + toAStringz(sa[], tgt.ptr); + if (tgt[0] != 'a') assert(false); + if (tgt[1] != 0x2a) assert(false); + } +} + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=18794 + +bool method18794(size_t* p) +{ + int bitIdx = 0; + func18794(); + return (*p & (1UL << bitIdx)) != 0; +} + +void func18794() {} + +void prep18794() +{ + asm {} + ulong[2] x = -1; +} + +void test18794() +{ + prep18794(); + size_t s; + method18794(&s); +} + +//////////////////////////////////////////////////////////////////////// + +/* Test the optimization + * (e1+c)-e2 => (e1-e2)+c + */ + +void testelmin() +{ + static void foo(int i) + { + static ubyte[4] bar() + { + ubyte[4] array; + foreach (i, ref a; array) + a = cast(ubyte)(i + 1); + return array; + } + + static void test(int i, ubyte* p) + { + foreach (j; 0 .. 4) + assert(p[i * 4 + j] == j + 1); + } + + ubyte[32] data; + data[i*4..(i+1)*4] = bar(); // optimize to single MOV + + test(i, data.ptr); + } + + foo(4); +} + +//////////////////////////////////////////////////////////////////////// + +const(char)* fastpar(string s) +{ + return s.ptr + s.length; +} + +void testfastpar() +{ + string s = "abcde"; + auto p = fastpar(s); + assert(*p == 0); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=20363 + +ulong foo20363(double d) +{ + ulong u = * cast(ulong*) &d; + return (u >> 1) & 1; +} + +void test20363() +{ + ulong u = 0b10; + if (foo20363(*cast(double*) &u) == 0) + assert(false); +} + +//////////////////////////////////////////////////////////////////////// + + +T testfooa(T)(T value) +{ + return 10 - (value * 57); // gets rewritten into (value*-57)+10 +} + +T testfoob(T)(T value) +{ + return (value * -57) + 10; +} + +void testNegConst() +{ + assert(testfooa(1) == -47); + assert(testfoob(1) == -47); + assert(testfooa(1.0) == -47); + assert(testfoob(1.0) == -47); +} + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=16317 + +int add8ret3(ref int s) +{ + s += 8; + return 3; +} + +int binAdd(int val) +{ + val = val + add8ret3(val); + return val; +} + +void test16317() +{ + assert(binAdd(1) == (1 + 3)); + static assert(binAdd(1) == (1 + 3)); +} + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=20050 + +int test20050_g = 0; +void test20050_impure_function_1() { ++test20050_g; } +void function() test20050_get_impure_function() pure +{ + static void impure_function_2() + { + ++test20050_g; + test20050_impure_function_1(); + } + return &impure_function_2; +} +void test20050() +{ + auto f = test20050_get_impure_function(); + f(); + assert(test20050_g == 2); +} + +//////////////////////////////////////////////////////////////////////// + +// http://github.com/dlang/dmd/pull/11238 + +int testCpStatic1(int y) +{ + __gshared int yyy = 7; + auto x = yyy; // no copy-propagation + if (y) + return x; + return x + 3; +} + +void testCpStatic() +{ + assert(testCpStatic1(1) == 7); + assert(testCpStatic1(0) == 10); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=20991 + +int x7; + +void bar7(int i) +{ + assert(i == x7); + ++x7; +} + +void test7() +{ + for (int i = 0; i <= 1; ++i) + bar7(i); + assert(x7 == 2); +} + +//////////////////////////////////////////////////////////////////////// + +// http://github.com/dlang/dmd/pull/11388 + +ushort byteswap(ushort x) pure +{ + // Should be detected and XCHG instruction generated + return cast(ushort) (((x >> 8) & 0xFF) | ((x << 8) & 0xFF00u)); +} + +void testbyteswap() +{ + assert(byteswap(0xF234) == 0x34F2); + static ushort xx = 0xF234; + assert(byteswap(xx) == 0x34F2); +} + +//////////////////////////////////////////////////////////////////////// + +// These should all be recognized by the compiler and generate ROL or ROR +// instructions. + +uint rol32(uint x, uint n) +{ + return (x << n) | (x >> (32 - n)); +} + +uint ror32(uint x, uint n) +{ + return (x >> n) | (x << (32 - n)); +} + +ulong rol64(ulong x, uint n) +{ + return (x << n) | (x >> (64 - n)); +} + +ulong ror64(ulong x, uint n) +{ + return (x >> n) | (x << (64 - n)); +} + +void testrolror() +{ + assert(ror32(0x0123_4567u, 4) == 0x7012_3456); + assert(rol32(0x7012_3456u, 4) == 0x0123_4567); + + assert(ror64(0x0123_4567_89AB_CDEFuL, 4) == 0xF012_3456_789A_BCDE); + assert(rol64(0xF012_3456_789A_BCDEuL, 4) == 0x0123_4567_89AB_CDEF); +} + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=20162 + +void test20162() +{ + static long f(long a) + { + assert(a == -1L); + return a; + } + + foreach (i; 1 .. 2) + { + foreach (j; 0 .. 2) + { + printf("%d %d %llx\n", i, + ((i != 0) ? -1 : +1), + f((i != 0) ? -1 : +1)); + } + } +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=3713 + +int star1(int i) +{ + return i ? star1(i - 1) : 0; +} + +int star2(int i) +{ + return i == 0 ? 0 : star2(i - 1); +} + +int star3(int i) +{ + if (i == 0) + return 0; + return i == 2 ? star3(i - 2) : star3(i - 1); +} + +int star4(int i) +{ + return (i == 0) ? 0 + : i != 2 ? star4(i - 1) + : star4(i - 2); +} + +void test3713() +{ + assert(star1(10) == 0); + assert(star2(10) == 0); + assert(star3(10) == 0); + assert(star4(10) == 0); +} + +//////////////////////////////////////////////////////////////////////// + +void testsbbrex() +{ + // special code is generated for these two cases + static long foolt(dchar c) + { + return c < 0x10000 ? 1 : 2; + } + + static long fooge(uint c) + { + return c >= 0x10000 ? 1L : 2L; + } + + assert(foolt(0) == 1); + assert(foolt(0x10000) == 2); + assert(fooge(0) == 2); + assert(fooge(0x10000) == 1); +} + + +//////////////////////////////////////////////////////////////////////// + +// https://issues.dlang.org/show_bug.cgi?id=19846 + +alias Void = byte[0]; +static immutable Void VOID; // = []; + +__gshared int x19846; + +Void print19846() +{ + //printf("This should print\n"); + x19846 = 3; + return VOID; +} + +Void identity19846(Void value, out int i) +{ + i = 7; + return value; +} + +void test19846() +{ + int i; + identity19846(print19846(), i); + //printf("i = %d\n", i); + assert(x19846 == 3); + assert(i == 7); +} + +//////////////////////////////////////////////////////////////////////// + +// Some tests for OPmemcpy + +enum N = 128; + +ubyte[N] def() +{ + ubyte[N] array; + foreach (i, ref a; array) + a = cast(ubyte)(i + 1); + return array; +} + + +void ghi(ubyte* p) +{ + foreach (i; 0 .. N) + assert(p[i] == i + 1); +} + +void testmemcpy() +{ + ubyte[N] bits; + ubyte[N] bits2; + bits2[0..N] = bits[0..N] = def(); + ghi(bits.ptr); + ghi(bits2.ptr); + + __gshared size_t n = N; + ubyte[N] bits3; + ubyte[N] bits4; + bits4[0..n] = bits3[0..n] = def(); + ghi(bits3.ptr); + ghi(bits4.ptr); +} + +//////////////////////////////////////////////////////////////////////// + + +/* Test all the cases of uses of LEA for multiplication by a constant + */ + +T testlea(uint C, T)(T x, T y) +{ + y = y * C; // cdmul() + x *= C; // cdmulass() + return x + y; +} + +void testleax(uint C)(uint X, uint Y) +{ + assert(testlea!C(X,Y) == C * (X + Y)); + assert(testlea!C(cast(long)X,cast(long)Y) == cast(long)C*X + cast(long)C*Y); +} + +void testMulLea() +{ + testleax!3(10,11); + testleax!5(10,11); + testleax!6(10,11); + testleax!9(10,11); + + testleax!10(10,11); + testleax!12(10,11); + testleax!18(10,11); + testleax!20(10,11); + testleax!24(10,11); + testleax!36(10,11); + testleax!40(10,11); + testleax!72(10,11); + + testleax!37(10,11); + testleax!74(10,11); + testleax!13(10,11); + testleax!26(10,11); +} + +//////////////////////////////////////////////////////////////////////// + +/* Test *= of register pair + */ + +void testMulAssPair() +{ + static ulong pow(ulong x, int m) + { + ulong v = x; + ulong p = 1; + while (1) + { + if (m & 1) + p *= v; + m >>= 1; + if (!m) + break; + v *= v; + } + return p; + } + + enum ulong e_10_pow_19 = 10uL^^19; + assert(e_10_pow_19 == pow(10uL, 19)); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21038 + +const(wchar)* x21038 = "xz"; +const(dchar)* name21038 = "abcd"; + +void test21038() +{ + assert((cast(size_t) x21038) % wchar.sizeof == 0); + assert((cast(size_t) name21038) % dchar.sizeof == 0); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21325 + +real f21325(const real x) pure @safe nothrow @nogc +{ + return (x != 0.0L) ? x : real.nan; +} + +void test21325() @safe +{ + ulong x = 0uL; + while(true) + { + const y = f21325(x); // should set y to real.nan + + assert(y != y); + + if (++x) + return; // good + } +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=16274 + +extern(C) int pair(short a, ushort b, byte c, ubyte d); + +struct S +{ + // provide alternate implementation of .pair() + pragma(mangle, "pair") + extern(C) static void pair(int a, int b, int c, int d) + { + //printf("%d %d %d %d\n", a, b, c, d); + assert(a == -1); + assert(b == 2); + assert(c == -3); + assert(d == 4); + } +} + +void test16274() +{ + version (X86_64) + pair(-1, 2, -3, 4); + version (X86) + pair(-1, 2, -3, 4); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=16268 + +void test16268() +{ + static void f(byte x) + { + for (byte i = 0; i <= x && i >= 0; ++i) + { + assert(i >= 0); + assert(i != -1); + //printf("%d\n", i); + } + } + + f(byte.max); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=11435 + +void test11435a() +{ + alias T = byte; + + static void fun(T c, T b, int v) + { + } + + static void abc(T[] b) + { + fun(b[0], b[1], 0); + } + + version(Windows) + { + import core.sys.windows.windows; + auto p = VirtualAlloc(null, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + } + else + { + import core.sys.posix.sys.mman; + auto p = mmap(null, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0L); + } + assert(p); + auto px = (cast(T*)(p + 4096 - 2 * T.sizeof)); + abc(px[0..2]); +} + +void test11435b() +{ + import core.sys.windows.windows; + alias T = short; + + static void fun(T c, T b, int v) + { + } + + static void abc(T[] b) + { + fun(b[0], b[1], 0); + } + + version(Windows) + { + import core.sys.windows.windows; + auto p = VirtualAlloc(null, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + } + else + { + import core.sys.posix.sys.mman; + auto p = mmap(null, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0L); + } + assert(p); + auto px = (cast(T*)(p + 4096 - 2 * T.sizeof)); + abc(px[0..2]); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21513 + +struct Stuff +{ + size_t c; // declare after items and not crash ! + ubyte[1] items; +} + +void grow(ref Stuff stuff) +{ + with (stuff) + { + const oldCapacity = c; + items.ptr[0..oldCapacity] = items.ptr[0..0]; // use literal 0 instead of + items.ptr[0] = 0; // oldcapacity and no crash ! + } +} + +void test21513() +{ + Stuff stuff; + grow(stuff); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21526 + +double f21256(double a, double b) { + double c = a + b; + return c; +} + +void test21256() +{ + union DX + { + double d; + ulong l; + } + + DX a, b; + a.l = 0x4341c37937e08000; + b.l = 0x4007ffcb923a29c7; + + DX r; + r.d = f21256(a.d, b.d); + //if (r.d != 0x1.1c37937e08001p+53) + //printf("r = %A should be 0x1.1c37937e08001p+53 %A\n", r.d, 0x1.1c37937e08001p+53); + //assert(r == 0x1.1c37937e08001p+53); + + // cannot seem to get the two to produce the same value + assert(r.l == 0x4341c37937e08001 || // value using XMM + r.l == 0x4341c37937e08002); // value using x87 +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21816 + +bool test21816a(float t) +{ + return cast(bool)t; +} + +void test21816() +{ + assert(test21816a(float.nan)); +} + +//////////////////////////////////////////////////////////////////////// +// https://issues.dlang.org/show_bug.cgi?id=21835 + +struct Point21835 +{ + float f = 3.0; + double d = 4.0; + real r = 5.0; +} + +void test21835y() +{ + Point21835[1] arr; + if (arr[0].f != 3.0) assert(0); + if (arr[0].d != 4.0) assert(0); + if (arr[0].r != 5.0) assert(0); +} + +struct Point21835x +{ + float f = 0.0; + double d = 0.0; + real r = 0.0; +} + +void test21835() +{ + test21835y(); + Point21835x[1] arr; + if (arr[0].f != 0.0) assert(0); + if (arr[0].d != 0.0) assert(0); + if (arr[0].r != 0.0) assert(0); +} + +//////////////////////////////////////////////////////////////////////// + int main() { + // All the various integer divide tests + testsdiv2(); + testulldiv(); + testfastudiv(); + testsldiv(); + testslmod(); + testfastdiv(); + testdivdiv(); + testdivcmp(); + testgoto(); testswitch(); testdo(); @@ -1675,11 +2491,8 @@ int main() testsizes(); testarrayinit(); testU(); - testulldiv(); testbittest(); test8658(); - testfastudiv(); - testfastdiv(); test3918(); test12051(); testdocond(); @@ -1695,18 +2508,17 @@ int main() test13190(); test13485(); test14436(); - test10639(); test10715(); test10678(); test7565(); test13023(0x10_0000_0000); test12833(); test9449(); + test9449x(); test12057(); test13784(); test14220(); test14829(); - test2(); test3(); test14782(); test14987(); @@ -1717,10 +2529,44 @@ int main() test13474(); test16699(); test16102(); - testdivdiv(); test5(); test6(); testeqeqranges(); + test16189(); + test16997(); + test18315(); + test18461(); + test18730(); + test19497(); + test18794(); + testelmin(); + testfastpar(); + test20363(); + testNegConst(); + test16317(); + test20050(); + testCpStatic(); + test7(); + testbyteswap(); + testrolror(); + test20162(); + test3713(); + testsbbrex(); + test19846(); + testmemcpy(); + testMulLea(); + testMulAssPair(); + test21038(); + test21325(); + test16274(); + test16268(); + test11435a(); + test11435b(); + test21513(); + test21256(); + test21816(); + test21835(); + printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/minimal.d b/gcc/testsuite/gdc.test/runnable/minimal.d new file mode 100644 index 00000000000..2f2df71f894 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/minimal.d @@ -0,0 +1,8 @@ +// DFLAGS: +// PERMUTE_ARGS: +// REQUIRED_ARGS: -defaultlib= +// EXTRA_SOURCES: extra-files/minimal/object.d + +// This test ensures an empty main can be built and executed with a minimal runtime + +void main() { } diff --git a/gcc/testsuite/gdc.test/runnable/minimal2.d b/gcc/testsuite/gdc.test/runnable/minimal2.d new file mode 100644 index 00000000000..7319463e920 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/minimal2.d @@ -0,0 +1,46 @@ +// DFLAGS: +// REQUIRED_ARGS: -defaultlib= +// EXTRA_SOURCES: extra-files/minimal/object.d + +// This test ensures that interfaces and classes can be used in a minimal +// runtime as long as they only contain shared static members. Non-shared +// static members would require a thread-local storage (TLS) implementation. + +interface I +{ + shared static int i; +} + +class A : I +{ + shared static int a; +} + +class B : A +{ + shared static int b; + + static int sumAll() + { + return b + a + i; + } +} + +void poorMansAssert(bool condition) +{ + if (!condition) + { + static char* hlt; + *hlt = 0; + } +} + +void main() +{ + B.i = 32; + B.a = 42; + B.b = 52; + + poorMansAssert(B.i == 32 || B.a == 42 || B.b == 52); + poorMansAssert(B.sumAll() == (32 + 42 + 52)); +} diff --git a/gcc/testsuite/gdc.test/runnable/mixin1.d b/gcc/testsuite/gdc.test/runnable/mixin1.d index 9d88fbd2841..d8b5516e586 100644 --- a/gcc/testsuite/gdc.test/runnable/mixin1.d +++ b/gcc/testsuite/gdc.test/runnable/mixin1.d @@ -1,7 +1,61 @@ -// RUNNABLE_PHOBOS_TEST +/* +TEST_OUTPUT: +--- +runnable/mixin1.d(948): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- + +RUN_OUTPUT: +--- +Foo3.func() +Code3.func() +Foo4.func() +Foo5.func() +b.x = 5 +x = 5 +duff_for(1, 11) +fid = 1, 2 +foo12 +foo12 +foo13 j = 1 +foo13 j = 1 +x14 = 6 +x15 = 6 +bar15() = 5 +x16 = 6 +bar() = 5 +x17 = 5 +b.x17 = 5 +x17 = 3 +x17 = 5 +x17 = 4 +x17 = 3 +x17 = 5 +in C20.f() +B22.foo() +5 +5 +a = 0 +int +int +int +int +foo 1 +foo 2 +0 0 +two +one +one +Class39 dtor +Mixed-in dtor +Mixed-in dtor +Base39 dtor +Success +--- +*/ + module mixin1; -import std.stdio; +import core.stdc.stdio; alias TypeTuple(T...) = T; @@ -680,7 +734,11 @@ class A30 { this(Type[] arr) { - foreach(Type v; arr) writeln(typeid(typeof(v))); + foreach(Type v; arr) + { + const str = typeid(typeof(v)).toString(); + printf("%.*s\n", cast(int)str.length, str.ptr); + } } } @@ -744,11 +802,6 @@ template T33( int i ) printf("foo %d\n", i ); return i; } - int opCall() - { - printf("opCall %d\n", i ); - return i; - } } @@ -766,10 +819,6 @@ void test33() assert(i == 1); i = c1.t2.foo(); assert(i == 2); - i = c1.t1(); - assert(i == 1); - i = c1.t2(); - assert(i == 2); } @@ -825,7 +874,6 @@ struct Foo36 void test36() { Foo36 f; - printf("f.sizeof = %d\n", f.sizeof); assert(f.sizeof == 12); f.a = 1; @@ -932,7 +980,7 @@ class Class39 : Base39 void test39() { - auto test = new Class39; + scope test = new Class39; } @@ -974,7 +1022,7 @@ void test41() } /*******************************************/ -// 2245 +// https://issues.dlang.org/show_bug.cgi?id=2245 template TCALL2245a(ARGS...) { @@ -1044,7 +1092,7 @@ void test2245() } /*******************************************/ -// 2481 +// https://issues.dlang.org/show_bug.cgi?id=2481 template M2481() { int i; } class Z2481a { struct { mixin M2481!(); } } @@ -1058,7 +1106,7 @@ void test2481() } /*******************************************/ -// 2740 +// https://issues.dlang.org/show_bug.cgi?id=2740 interface IFooable2740 { @@ -1144,7 +1192,7 @@ void test42() } /*******************************************/ -// 7744 +// https://issues.dlang.org/show_bug.cgi?id=7744 class ZeroOrMore7744(Expr) { @@ -1165,7 +1213,7 @@ mixin(q{ }); /*******************************************/ -// 8032 +// https://issues.dlang.org/show_bug.cgi?id=8032 mixin template T8032() { @@ -1193,7 +1241,7 @@ class B8032b : A8032b } /*********************************************/ -// 9417 +// https://issues.dlang.org/show_bug.cgi?id=9417 mixin template Foo9417() { @@ -1209,7 +1257,7 @@ void test9417() } /*******************************************/ -// 11487 +// https://issues.dlang.org/show_bug.cgi?id=11487 template X11487() { @@ -1236,7 +1284,7 @@ class C11487 } /*******************************************/ -// 11767 +// https://issues.dlang.org/show_bug.cgi?id=11767 mixin template M11767() { @@ -1262,7 +1310,7 @@ void test11767() } /*******************************************/ -// 12023 +// https://issues.dlang.org/show_bug.cgi?id=12023 void Delete12023(Object obj) {} @@ -1303,7 +1351,7 @@ void test12023() } /*******************************************/ -// 14243 +// https://issues.dlang.org/show_bug.cgi?id=14243 mixin template Mix14243a(int n) { @@ -1397,7 +1445,7 @@ int test14243() static assert(test14243()); // changed to be workable /*******************************************/ -// 10492 +// https://issues.dlang.org/show_bug.cgi?id=10492 class TestClass10492 {} diff --git a/gcc/testsuite/gdc.test/runnable/mixin2.d b/gcc/testsuite/gdc.test/runnable/mixin2.d index 26a235210c9..7679bbe5b34 100644 --- a/gcc/testsuite/gdc.test/runnable/mixin2.d +++ b/gcc/testsuite/gdc.test/runnable/mixin2.d @@ -1,4 +1,4 @@ -/* RUNNABLE_PHOBOS_TEST +/* TEST_OUTPUT: --- hello @@ -31,7 +31,7 @@ hey Success --- */ -import std.stdio; +import core.stdc.stdio; /*********************************************/ @@ -53,7 +53,7 @@ void test2() mixin(" int x = 3; for (int i = 0; i < 10; i++) - writeln(x + i, ++j); + printf(\"%d%d\n\", x + i, ++j); "); assert(j == 10); } @@ -64,7 +64,7 @@ mixin("int abc3 = 5;"); void test3() { - writeln(abc3); + printf("%d\n", abc3); assert(abc3 == 5); } @@ -73,24 +73,24 @@ void test3() mixin(" void test4() { - writeln(\"test4\"); + printf(\"test4\n\"); " ~ "}"); /*********************************************/ int x5; -scope class Foo5 +class Foo5 { this () { - writeln ("Constructor"); + printf ("Constructor\n"); assert(x5 == 0); x5++; } ~this () { - writeln ("Destructor"); + printf ("Destructor\n"); assert(x5 == 2); x5++; } @@ -100,7 +100,7 @@ void test5() { { mixin ("scope Foo5 f = new Foo5;\n"); - writeln (" Inside Scope"); + printf (" Inside Scope\n"); assert(x5 == 1); x5++; } @@ -194,7 +194,7 @@ void test10() } /*********************************************/ -// 7560 +// https://issues.dlang.org/show_bug.cgi?id=7560 class Base7560 { @@ -213,7 +213,7 @@ class Derived7560 : Base7560 } /*********************************************/ -// 10577 +// https://issues.dlang.org/show_bug.cgi?id=10577 enum sync10577; @@ -267,7 +267,7 @@ class derived10577 : base10577 } /*********************************************/ -// 10583 +// https://issues.dlang.org/show_bug.cgi?id=10583 enum sync10583; @@ -329,7 +329,7 @@ void test7156() } /*********************************************/ -// 7553 +// https://issues.dlang.org/show_bug.cgi?id=7553 template Foo7553() { @@ -358,7 +358,7 @@ void test7553() } /*********************************************/ -// 13479 +// https://issues.dlang.org/show_bug.cgi?id=13479 mixin template F13479() { @@ -392,5 +392,5 @@ void main() test7156(); test13479(); - writeln("Success"); + printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable/mod1.d b/gcc/testsuite/gdc.test/runnable/mod1.d index 3efb0cf9308..46b14ed0ec3 100644 --- a/gcc/testsuite/gdc.test/runnable/mod1.d +++ b/gcc/testsuite/gdc.test/runnable/mod1.d @@ -1,5 +1,11 @@ -// PERMUTE_ARGS: -// EXTRA_SOURCES: imports/mod2.d +/* +PERMUTE_ARGS: +EXTRA_SOURCES: imports/mod2.d +RUN_OUTPUT: +--- +EvilOne +--- +*/ // mod1.d diff --git a/gcc/testsuite/gdc.test/runnable/nan.d b/gcc/testsuite/gdc.test/runnable/nan.d index b229fd571f3..d4e4ae4ebdc 100644 --- a/gcc/testsuite/gdc.test/runnable/nan.d +++ b/gcc/testsuite/gdc.test/runnable/nan.d @@ -20,6 +20,43 @@ static assert(!(ed1 <= ed2)); bool b; + +T byCTFE(T)() +{ + T x; + return x; +} + +bool bittst(const ubyte[] ba, uint pos) +{ + uint mask = 1 << (pos % 8); + version(LittleEndian) + return (ba[pos / 8] & mask) != 0; + else + return (ba[$ - 1 - pos / 8] & mask) != 0; +} + +void test2(T)() +{ + T a = T.init, b = T.nan; + assert(a is b); + + enum c = byCTFE!T(); + assert(a is c); + + static if (T.mant_dig == 64 && T.max_exp == 16384) + enum size = 10; // x87, exclude padding + else + enum size = T.sizeof; + const pa = (cast(ubyte*) &a)[0 .. size]; + + // the highest 2 bits of the mantissa should be set, everything else zero + assert(bittst(pa, T.mant_dig - 1)); + assert(bittst(pa, T.mant_dig - 2)); + foreach(p; 0..T.mant_dig - 2) + assert(!bittst(pa, p)); +} + bool test() { real r1 = real.nan; @@ -53,5 +90,8 @@ bool test() void main() { - assert(test()); + assert(test()); + test2!float(); + test2!double(); + test2!real(); } diff --git a/gcc/testsuite/gdc.test/runnable/nested.d b/gcc/testsuite/gdc.test/runnable/nested.d index 6b2fcb06ab2..4c99c59e8a9 100644 --- a/gcc/testsuite/gdc.test/runnable/nested.d +++ b/gcc/testsuite/gdc.test/runnable/nested.d @@ -863,8 +863,8 @@ class Foo35 //writefln("y = %s", y); assert(x == 42); assert(y == 43); - //static assert(is(typeof(this.outer) == void*)); // Bugzilla 14442 - static assert(is(typeof(this.outer) == Foo35)); // Bugzilla 15839 + //static assert(is(typeof(this.outer) == void*)); // https://issues.dlang.org/show_bug.cgi?id=14442 + static assert(is(typeof(this.outer) == Foo35)); // https://issues.dlang.org/show_bug.cgi?id=15839 } }; } @@ -1485,7 +1485,20 @@ void test55() } /*******************************************/ -// 4401 + +enum dg56 = delegate { return 5; }; + +void test56() +{ + auto inner() { + return dg56(); + } + + assert(inner() == 5); +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=4401 void test4401() { @@ -1542,7 +1555,7 @@ void test7428(){ } /*******************************************/ -// 4612 +// https://issues.dlang.org/show_bug.cgi?id=4612 struct S4612a(alias x) { @@ -1604,7 +1617,7 @@ void test7199() } /*******************************************/ -// 7965 +// https://issues.dlang.org/show_bug.cgi?id=7965 void test7965() { @@ -1662,7 +1675,7 @@ void test7965a() } /*******************************************/ -// 8188 +// https://issues.dlang.org/show_bug.cgi?id=8188 mixin template Print8188(b...) { @@ -1687,7 +1700,7 @@ void test8188() } /*******************************************/ -// 5082 +// https://issues.dlang.org/show_bug.cgi?id=5082 struct S5082 { float x; } @@ -1714,7 +1727,7 @@ void test5082() /*******************************************/ -// 8194 +// https://issues.dlang.org/show_bug.cgi?id=8194 void test8194() { @@ -1727,7 +1740,7 @@ void test8194() } /*******************************************/ -// 8339 +// https://issues.dlang.org/show_bug.cgi?id=8339 template map8339a(fun...) { @@ -1822,7 +1835,7 @@ void test8339c() } /*******************************************/ -// 8704 +// https://issues.dlang.org/show_bug.cgi?id=8704 void check8704(T, int num)() { @@ -1849,7 +1862,7 @@ void test8704() } /*******************************************/ -// 8923 +// https://issues.dlang.org/show_bug.cgi?id=8923 void test8923a() { @@ -2029,7 +2042,7 @@ void test8923c() } /*******************************************/ -// 9003 +// https://issues.dlang.org/show_bug.cgi?id=9003 void test9003() { @@ -2072,7 +2085,7 @@ void test9003() } /*******************************************/ -// 9006 +// https://issues.dlang.org/show_bug.cgi?id=9006 void test9006() { @@ -2101,7 +2114,7 @@ void test9006() } /*******************************************/ -// 9035 +// https://issues.dlang.org/show_bug.cgi?id=9035 void test9035() { @@ -2144,7 +2157,7 @@ void test9035a() } /*******************************************/ -// 9036 +// https://issues.dlang.org/show_bug.cgi?id=9036 void test9036() { @@ -2201,7 +2214,7 @@ void test8863() +/ /*******************************************/ -// 8774 +// https://issues.dlang.org/show_bug.cgi?id=8774 void popFront8774() { @@ -2274,7 +2287,7 @@ void test8832() } /*******************************************/ -// 9315 +// https://issues.dlang.org/show_bug.cgi?id=9315 auto test9315() { @@ -2287,7 +2300,7 @@ auto test9315() } /*******************************************/ -// 9244 +// https://issues.dlang.org/show_bug.cgi?id=9244 void test9244() { @@ -2298,7 +2311,7 @@ void test9244() } /*******************************************/ -// 10495 +// https://issues.dlang.org/show_bug.cgi?id=10495 struct X10495 { @@ -2321,7 +2334,7 @@ class C10495 } /*******************************************/ -// 11385 +// https://issues.dlang.org/show_bug.cgi?id=11385 auto map11385(alias fun, R)(R range) { @@ -2354,6 +2367,12 @@ enum foo11297 = function (int x) xmap!(y => x)(7); }; +enum goo11297 = delegate (int x) + { + //int bar(int y) { return x; } xmap!bar(7); + xmap!(y => x)(7); + }; + void xreduce(alias f)() { f(4); @@ -2362,10 +2381,11 @@ void xreduce(alias f)() void test11297() { xreduce!foo11297(); + xreduce!goo11297(); } /*******************************************/ -// 11886 +// https://issues.dlang.org/show_bug.cgi?id=11886 struct Lambda11886(alias fun) { @@ -2388,7 +2408,7 @@ void test11886() } /*******************************************/ -// 12234 +// https://issues.dlang.org/show_bug.cgi?id=12234 void test12234() { @@ -2407,7 +2427,7 @@ void test12234() } /*******************************************/ -// 12981 +// https://issues.dlang.org/show_bug.cgi?id=12981 template Mix12981(T) { @@ -2425,7 +2445,7 @@ class B12981 } /*******************************************/ -// 13861 +// https://issues.dlang.org/show_bug.cgi?id=13861 struct Foo13861(alias f) { @@ -2444,7 +2464,7 @@ void test13861() } /*******************************************/ -// 14398 +// https://issues.dlang.org/show_bug.cgi?id=14398 void test14398() { @@ -2479,7 +2499,7 @@ void test14398() } /*******************************************/ -// 14846 +// https://issues.dlang.org/show_bug.cgi?id=14846 void foo14846(Dg)(scope Dg code) { @@ -2509,14 +2529,14 @@ void test14846() } /*******************************************/ -// 15422 +// https://issues.dlang.org/show_bug.cgi?id=15422 class App15422(T) { this() {} auto test1(T val) - in {} body // necessary to reproduce the crash + in {} do // necessary to reproduce the crash { struct Foo { @@ -2544,7 +2564,7 @@ class App15422(T) } auto test2(T val) - //in {} body + //in {} do { int closVar; struct Foo @@ -2662,7 +2682,7 @@ void test15422b() } /***************************************************/ -// 15757 +// https://issues.dlang.org/show_bug.cgi?id=15757 template map15757(fun...) { @@ -2703,6 +2723,45 @@ void test15757() @safe /***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19384 + +struct Vec +{ + uint item; + + ref uint august() return + { + return item; + // commenting next line removes bug + foreach(ref val; range()) return val; + assert(false); + } + + uint* august2() return + { + return &item; + foreach(ref val; range()) return &val; + assert(false); + } +} + +struct range +{ + int opApply(scope int delegate(ref uint) dg) { return 0; } +} + +void test19384() +{ + Vec preds = Vec(0xDEAD); + void* ptr2 = &preds.august(); + void* ptr3 = preds.august2(); + assert(&preds == ptr2); + assert(&preds == ptr3); +} + + +/***************************************************/ + int main() { test1(); @@ -2760,6 +2819,7 @@ int main() test53(); test54(); test55(); + test56(); test4401(); test7428(); test4612(); @@ -2797,6 +2857,7 @@ int main() test15422a(); test15422b(); test15757(); + test19384(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/newdel.d b/gcc/testsuite/gdc.test/runnable/newdel.d index 21f7809c684..3729b2eb188 100644 --- a/gcc/testsuite/gdc.test/runnable/newdel.d +++ b/gcc/testsuite/gdc.test/runnable/newdel.d @@ -1,4 +1,10 @@ // PERMUTE_ARGS: +/* +TEST_OUTPUT: +--- +runnable/newdel.d(46): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import core.stdc.stdio; import core.stdc.stdlib; @@ -9,18 +15,6 @@ class Foo { static uint flags; - new(size_t sz, int x) - { void* p; - - printf("Foo.new(sz = %d, x = %d)\n", sz, x); - assert(sz == Foo.classinfo.initializer.length); - assert(x == 5); - - p = core.stdc.stdlib.malloc(sz); - flags |= 4; - return p; - } - this() { printf("this() %p\n", this); @@ -34,13 +28,6 @@ class Foo flags |= 1; } - delete(void* p) - { - printf("delete %p\n", p); - free(p); - flags |= 2; - } - int a = 3; int b = 4; int d = 56; @@ -50,61 +37,22 @@ void test1() { Foo f; - f = new(5) Foo; + f = new Foo(); assert(f.a == 36); assert(f.b == 4); assert(f.d == 56); - assert(Foo.flags == 4); - - delete f; - assert(Foo.flags == 7); -} - - -/*********************************************/ - -struct Foo2 -{ - static uint flags; - - new(size_t sz, int x) - { void* p; - - printf("Foo2.new(sz = %d, x = %d)\n", sz, x); - assert(sz == Foo2.sizeof); - assert(x == 5); - - p = core.stdc.stdlib.malloc(sz); - flags |= 4; - return p; - } - - delete(void *p) - { - printf("p = %p\n", p); - flags |= 2; - core.stdc.stdlib.free(p); - } -} + assert(Foo.flags == 0); -void test2() -{ - Foo2 *f = new(5) Foo2(); - - printf("f = %p\n", f); delete f; - assert(Foo2.flags == 6); + assert(Foo.flags == 1); } - /*********************************************/ int main() { test1(); - test2(); printf("Success\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/nogc.d b/gcc/testsuite/gdc.test/runnable/nogc.d index 8214e96e32a..c9a58b7e744 100644 --- a/gcc/testsuite/gdc.test/runnable/nogc.d +++ b/gcc/testsuite/gdc.test/runnable/nogc.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); @@ -9,7 +15,7 @@ extern(C) int printf(const char*, ...); } /***********************/ -// 3032 +// https://issues.dlang.org/show_bug.cgi?id=3032 void test3032() @nogc { @@ -23,7 +29,7 @@ void test3032() @nogc } /***********************/ -// 12642 +// https://issues.dlang.org/show_bug.cgi?id=12642 __gshared int[1] data12642; @@ -44,7 +50,7 @@ void test12642() @nogc } /***********************/ -// 12936 +// https://issues.dlang.org/show_bug.cgi?id=12936 void test12936() @nogc { diff --git a/gcc/testsuite/gdc.test/runnable/nulltype.d b/gcc/testsuite/gdc.test/runnable/nulltype.d index 7a1f1c333b4..87d79400505 100644 --- a/gcc/testsuite/gdc.test/runnable/nulltype.d +++ b/gcc/testsuite/gdc.test/runnable/nulltype.d @@ -58,7 +58,7 @@ void test2() } /**********************************************/ -// 5899 +// https://issues.dlang.org/show_bug.cgi?id=5899 auto f5899(bool b) { @@ -91,7 +91,7 @@ static assert(is(typeof(h5899) R == return) && is(R == int[])); pragma(msg, typeof(h5899)); /**********************************************/ -// 7278 +// https://issues.dlang.org/show_bug.cgi?id=7278 struct Foo7278(string s) { @@ -109,7 +109,7 @@ void test7278() } /**********************************************/ -// 8221 +// https://issues.dlang.org/show_bug.cgi?id=8221 class A8221 { @@ -130,7 +130,7 @@ void test8221() } /***************************************************/ -// 8589 +// https://issues.dlang.org/show_bug.cgi?id=8589 void test8589() { @@ -157,7 +157,7 @@ void test8589() } /**********************************************/ -// 9385 +// https://issues.dlang.org/show_bug.cgi?id=9385 void test9385() { @@ -167,7 +167,7 @@ void test9385() } /**********************************************/ -// 12203 +// https://issues.dlang.org/show_bug.cgi?id=12203 void test12203() { diff --git a/gcc/testsuite/gdc.test/runnable/opdisp.d b/gcc/testsuite/gdc.test/runnable/opdisp.d index f84a0ec794c..6aca559d7c4 100644 --- a/gcc/testsuite/gdc.test/runnable/opdisp.d +++ b/gcc/testsuite/gdc.test/runnable/opdisp.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern (C) int printf(const char* fmt, ...); int pass(int n){ return n; } @@ -265,7 +271,7 @@ void test6() } /**********************************************/ -// 7578 +// https://issues.dlang.org/show_bug.cgi?id=7578 struct Foo7578 { diff --git a/gcc/testsuite/gdc.test/runnable/opover.d b/gcc/testsuite/gdc.test/runnable/opover.d index 66270f4f0bd..633981e4cbb 100644 --- a/gcc/testsuite/gdc.test/runnable/opover.d +++ b/gcc/testsuite/gdc.test/runnable/opover.d @@ -1,5 +1,29 @@ +/* +RUN_OUTPUT: +--- +i = 1 +Writer.opShl(char[]) +BinaryWriter.opShl(int) +a + 1 = 2 +1 + a = 2 +a + b = 3 +b + a = 3 +i = 64 +12 +534 +A::opShl(int 4) +4A::opShl(char[]) + A::opShl(int 12) +12A::opShl(char[]) + +B::opShl_r(A) +Success +--- +*/ // Test operator overloading +// Ignore deprecation warnings for D1 style operator overloading +// TRANSFORM_OUTPUT: remove_lines("Deprecation: `op") import core.stdc.stdio; @@ -776,7 +800,7 @@ class A13 A13 opShl(string x) { printf("A::opShl(char[])\n"); - printf("%.*s", x.length, x.ptr); + printf("%.*s", cast(int)x.length, x.ptr); return this; } } @@ -821,7 +845,7 @@ void test14() /**************************************/ -// 3983 +// https://issues.dlang.org/show_bug.cgi?id=3983 struct Fug { @@ -849,7 +873,7 @@ void test15() } /**************************************/ -// 4953 +// https://issues.dlang.org/show_bug.cgi?id=4953 struct S4953a { @@ -907,7 +931,7 @@ void test4953d() } /**************************************/ -// 4993 +// https://issues.dlang.org/show_bug.cgi?id=4993 // reduced from the bug report struct Bar4993 @@ -924,7 +948,7 @@ void test4993() } /**************************************/ -// 8133 +// https://issues.dlang.org/show_bug.cgi?id=8133 void test8133() { @@ -942,7 +966,7 @@ void test8133() } /**************************************/ -// 8522 +// https://issues.dlang.org/show_bug.cgi?id=8522 struct Point8522 { @@ -961,7 +985,7 @@ void test8522() } /**************************************/ -// 12778 +// https://issues.dlang.org/show_bug.cgi?id=12778 struct Vec12778X { @@ -1009,7 +1033,7 @@ void test12778() } /**************************************/ -// 14343 +// https://issues.dlang.org/show_bug.cgi?id=14343 struct S14343a { @@ -1049,7 +1073,7 @@ void test14343() } /**************************************/ -// 14344 +// https://issues.dlang.org/show_bug.cgi?id=14344 struct S14344 { @@ -1080,7 +1104,41 @@ class C14344 } /**************************************/ +// https://issues.dlang.org/show_bug.cgi?id=1547 +struct A +{ + int b; + static A opCall(int k) + { + assert(0); + } + this(int) {} +} + +void fun(A k = 2) {} + +void test1547() +{ + fun(); +} +/**************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20475 +struct S20475 +{ + string[2] x; +} + +void test20475() +{ + auto s = S20475(["abc", "bcd"]); + auto t = S20475(["abc", ""]); + string u = "abcd"; + t.x[1] = u[1..$]; + assert(s == t); +} + +/**************************************/ int main() { test1(); @@ -1098,6 +1156,7 @@ int main() test13(); test14(); test15(); + test1547(); test4953a(); test4953b(); test4953c(); @@ -1105,6 +1164,7 @@ int main() test4993(); test8133(); test8522(); + test20475(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/opover2.d b/gcc/testsuite/gdc.test/runnable/opover2.d index 78fa04c4b23..dfc03528b2b 100644 --- a/gcc/testsuite/gdc.test/runnable/opover2.d +++ b/gcc/testsuite/gdc.test/runnable/opover2.d @@ -1,5 +1,5 @@ -// PERMUTE_ARGS: -inline -O -property -// REQUIRED_ARGS: -dip25 +// PERMUTE_ARGS: -inline -O +// REQUIRED_ARGS: -preview=fieldwise // Test operator overloading @@ -21,7 +21,7 @@ class A { string opUnary(string s)() { - printf("A.opUnary!(%.*s)\n", s.length, s.ptr); + printf("A.opUnary!(%.*s)\n", cast(int)s.length, s.ptr); return s; } } @@ -50,7 +50,7 @@ class A2 T opCast(T)() { auto s = T.stringof; - printf("A.opCast!(%.*s)\n", s.length, s.ptr); + printf("A.opCast!(%.*s)\n", cast(int)s.length, s.ptr); return T.init; } } @@ -73,20 +73,20 @@ struct A3 { int opBinary(string s)(int i) { - printf("A.opBinary!(%.*s)\n", s.length, s.ptr); + printf("A.opBinary!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } int opBinaryRight(string s)(int i) if (s == "/" || s == "*") { - printf("A.opBinaryRight!(%.*s)\n", s.length, s.ptr); + printf("A.opBinaryRight!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; - printf("A.opCast!(%.*s)\n", s.length, s.ptr); + printf("A.opCast!(%.*s)\n", cast(int)s.length, s.ptr); return T.init; } } @@ -108,14 +108,14 @@ struct A4 { int opUnary(string s)() { - printf("A.opUnary!(%.*s)\n", s.length, s.ptr); + printf("A.opUnary!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; - printf("A.opCast!(%.*s)\n", s.length, s.ptr); + printf("A.opCast!(%.*s)\n", cast(int)s.length, s.ptr); return T.init; } } @@ -145,14 +145,14 @@ class A5 int opUnary(string s)() { - printf("A.opUnary!(%.*s)\n", s.length, s.ptr); + printf("A.opUnary!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; - printf("A.opCast!(%.*s)\n", s.length, s.ptr); + printf("A.opCast!(%.*s)\n", cast(int)s.length, s.ptr); return T.init; } } @@ -296,31 +296,31 @@ struct A8 { int opUnary(string s)() { - printf("A.opUnary!(%.*s)\n", s.length, s.ptr); + printf("A.opUnary!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } int opIndexUnary(string s, T)(T i) { - printf("A.opIndexUnary!(%.*s)(%d)\n", s.length, s.ptr, i); + printf("A.opIndexUnary!(%.*s)(%d)\n", cast(int)s.length, s.ptr, i); return 0; } int opIndexUnary(string s, T)(T i, T j) { - printf("A.opIndexUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); + printf("A.opIndexUnary!(%.*s)(%d, %d)\n", cast(int)s.length, s.ptr, i, j); return 0; } int opSliceUnary(string s)() { - printf("A.opSliceUnary!(%.*s)()\n", s.length, s.ptr); + printf("A.opSliceUnary!(%.*s)()\n", cast(int)s.length, s.ptr); return 0; } int opSliceUnary(string s, T)(T i, T j) { - printf("A.opSliceUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); + printf("A.opSliceUnary!(%.*s)(%d, %d)\n", cast(int)s.length, s.ptr, i, j); return 0; } } @@ -344,31 +344,31 @@ struct A9 { int opOpAssign(string s)(int i) { - printf("A.opOpAssign!(%.*s)\n", s.length, s.ptr); + printf("A.opOpAssign!(%.*s)\n", cast(int)s.length, s.ptr); return 0; } int opIndexOpAssign(string s, T)(int v, T i) { - printf("A.opIndexOpAssign!(%.*s)(%d, %d)\n", s.length, s.ptr, v, i); + printf("A.opIndexOpAssign!(%.*s)(%d, %d)\n", cast(int)s.length, s.ptr, v, i); return 0; } int opIndexOpAssign(string s, T)(int v, T i, T j) { - printf("A.opIndexOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); + printf("A.opIndexOpAssign!(%.*s)(%d, %d, %d)\n", cast(int)s.length, s.ptr, v, i, j); return 0; } int opSliceOpAssign(string s)(int v) { - printf("A.opSliceOpAssign!(%.*s)(%d)\n", s.length, s.ptr, v); + printf("A.opSliceOpAssign!(%.*s)(%d)\n", cast(int)s.length, s.ptr, v); return 0; } int opSliceOpAssign(string s, T)(int v, T i, T j) { - printf("A.opSliceOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); + printf("A.opSliceOpAssign!(%.*s)(%d, %d, %d)\n", cast(int)s.length, s.ptr, v, i, j); return 0; } } @@ -468,7 +468,7 @@ int bug4913() static assert(bug4913() == 83); /**************************************/ -// 5551 +// https://issues.dlang.org/show_bug.cgi?id=5551 struct Foo11 { Foo11 opUnary(string op:"++")() { @@ -486,7 +486,7 @@ void test11() } /**************************************/ -// 4099 +// https://issues.dlang.org/show_bug.cgi?id=4099 struct X4099 { @@ -672,7 +672,7 @@ void test17() } /**************************************/ -// 3789 +// https://issues.dlang.org/show_bug.cgi?id=3789 bool test3789() { @@ -728,7 +728,7 @@ bool test3789() auto ua2 = UnionA([1,2,3]); assert(ua1.u.x is ua2.u.x); assert(ua1.u.x != ua2.u.x); - assert(ua1 == ua2); + assert(ua1 != ua2); ua1.u.x = 1.0; ua2.u.x = 1.0; assert(ua1.u.x is ua2.u.x); @@ -755,7 +755,7 @@ bool test3789() ub2.u.a = [1,2,3].dup; assert(ub1.u.a !is ub2.u.a); assert(ub1.u.a == ub2.u.a); - assert(ub1 != ub2); + assert(ub1 == ub2); ub2.u.a = ub1.u.a; assert(ub1.u.a is ub2.u.a); assert(ub1.u.a == ub2.u.a); @@ -789,44 +789,27 @@ bool test3789() } static assert(test3789()); -/**************************************/ -// 10037 - -struct S10037 -{ - bool opEquals(ref const S10037) { assert(0); } -} - -struct T10037 +struct S { - S10037 s; - // Compiler should not generate 'opEquals' here implicitly: + bool opEquals(ref const S) { return false; } } -struct Sub10037(TL...) +struct T { - TL data; + S s; int value; alias value this; } -void test10037() +void test11161() { - S10037 s; - T10037 t; - static assert( __traits(hasMember, S10037, "opEquals")); - static assert(!__traits(hasMember, T10037, "opEquals")); - assert(thrown!Error(s == s)); - assert(thrown!Error(t == t)); - - Sub10037!(S10037) lhs; - Sub10037!(S10037) rhs; - static assert(!__traits(hasMember, Sub10037!(S10037), "opEquals")); - assert(lhs == rhs); // lowered to: lhs.value == rhs.value + T t1, t2; + assert(t1.tupleof != t2.tupleof); + assert(t1 != t2); // fails } /**************************************/ -// 5810 +// https://issues.dlang.org/show_bug.cgi?id=5810 struct Bug5810 { @@ -840,7 +823,7 @@ struct Foo5810 } /**************************************/ -// 6798 +// https://issues.dlang.org/show_bug.cgi?id=6798 struct Tuple6798(T...) { @@ -1013,7 +996,7 @@ void test6798() } /**************************************/ -// 12382 +// https://issues.dlang.org/show_bug.cgi?id=12382 struct S12382 { @@ -1041,7 +1024,7 @@ void test12382() } /**************************************/ -// 12904 +// https://issues.dlang.org/show_bug.cgi?id=12904 struct S12904 { @@ -1080,7 +1063,7 @@ void test12904() } /**************************************/ -// 7641 +// https://issues.dlang.org/show_bug.cgi?id=7641 mixin template Proxy7641(alias a) { @@ -1110,7 +1093,7 @@ void test7641() } /**************************************/ -// 8434 +// https://issues.dlang.org/show_bug.cgi?id=8434 void test8434() { @@ -1338,7 +1321,7 @@ void test19() } /**************************************/ -// 9453 +// https://issues.dlang.org/show_bug.cgi?id=9453 struct Foo9453 { @@ -1360,7 +1343,7 @@ void test9453() } /**************************************/ -// 9496 +// https://issues.dlang.org/show_bug.cgi?id=9496 struct S9496 { @@ -1392,7 +1375,7 @@ void test9496() } /**************************************/ -// 9689 +// https://issues.dlang.org/show_bug.cgi?id=9689 struct B9689(T) { @@ -1418,7 +1401,7 @@ void test9689() } /**************************************/ -// 9694 +// https://issues.dlang.org/show_bug.cgi?id=9694 struct S9694 { @@ -1438,7 +1421,7 @@ void test9694() } /**************************************/ -// 10064 +// https://issues.dlang.org/show_bug.cgi?id=10064 void test10064() { @@ -1465,7 +1448,7 @@ void test10064() } /**************************************/ -// 12585 +// https://issues.dlang.org/show_bug.cgi?id=12585 void test12585() { @@ -1504,7 +1487,7 @@ void test12585() } /**************************************/ -// 10394 +// https://issues.dlang.org/show_bug.cgi?id=10394 void test10394() { @@ -1533,7 +1516,7 @@ void test10394() } /**************************************/ -// 10597 +// https://issues.dlang.org/show_bug.cgi?id=10597 struct R10597 { @@ -1577,7 +1560,7 @@ void test10597() } /**************************************/ -// 10567 +// https://issues.dlang.org/show_bug.cgi?id=10567 // doesn't require thunk struct S10567x1n { int value; int opCmp(ref const S10567x1n rhs) const { return 0; } } @@ -1662,13 +1645,6 @@ void test10567() S sy = S(2); assert(!(sx < sy) && !(sx > sy)); assert(sx.opCmp(sy) == 0); - - try - { - auto x = typeid(S).compare(&sx, &sy); - assert(0); - } - catch (Error e) { assert(e.msg[$-15 .. $] == "not implemented"); } } /+ foreach (S; Seq!(S10567d1, S10567d2)) @@ -1690,7 +1666,7 @@ void test10567() } /**************************************/ -// 11062 +// https://issues.dlang.org/show_bug.cgi?id=11062 struct S11062ia { @@ -1734,7 +1710,7 @@ void test11062() } /**************************************/ -// 11311 +// https://issues.dlang.org/show_bug.cgi?id=11311 void test11311() { @@ -1791,7 +1767,7 @@ void test11311() } /**************************************/ -// 12193 +// https://issues.dlang.org/show_bug.cgi?id=12193 void test12193() { @@ -1810,7 +1786,7 @@ void test12193() } /**************************************/ -// 14057 +// https://issues.dlang.org/show_bug.cgi?id=14057 struct W14057 { @@ -1936,7 +1912,7 @@ void test20d() } /**************************************/ -// 14624 +// https://issues.dlang.org/show_bug.cgi?id=14624 void test14624() { @@ -1981,7 +1957,7 @@ void test14624() } /**************************************/ -// 14625 +// https://issues.dlang.org/show_bug.cgi?id=14625 void test14625() { @@ -2033,7 +2009,7 @@ int main() test16(); test17(); test3789(); - test10037(); + test11161(); test6798(); test12904(); test7641(); @@ -2061,4 +2037,3 @@ int main() printf("Success\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/opover3.d b/gcc/testsuite/gdc.test/runnable/opover3.d index c6de5d757e2..71468262553 100644 --- a/gcc/testsuite/gdc.test/runnable/opover3.d +++ b/gcc/testsuite/gdc.test/runnable/opover3.d @@ -125,7 +125,7 @@ void test4() } /**************************************/ -// 12070 +// https://issues.dlang.org/show_bug.cgi?id=12070 void test12070() { @@ -160,7 +160,7 @@ void test12070() } /**************************************/ -// 12124 +// https://issues.dlang.org/show_bug.cgi?id=12124 struct S12124 { diff --git a/gcc/testsuite/gdc.test/runnable/overload.d b/gcc/testsuite/gdc.test/runnable/overload.d index f8fa7d5cdda..c413ade029a 100644 --- a/gcc/testsuite/gdc.test/runnable/overload.d +++ b/gcc/testsuite/gdc.test/runnable/overload.d @@ -1,5 +1,13 @@ -// EXTRA_SOURCES: imports/ovs1528a.d imports/ovs1528b.d -// EXTRA_SOURCES: imports/template_ovs1.d imports/template_ovs2.d imports/template_ovs3.d +/* +REQUIRED_ARGS: -preview=rvaluerefparam +EXTRA_SOURCES: imports/ovs1528a.d imports/ovs1528b.d +EXTRA_SOURCES: imports/template_ovs1.d imports/template_ovs2.d imports/template_ovs3.d +EXTRA_FILES: imports/m8668a.d imports/m8668b.d imports/m8668c.d +RUN_OUTPUT: +--- +Success +--- +*/ import imports.template_ovs1; import imports.template_ovs2; @@ -12,7 +20,7 @@ template Id( T){ alias T Id; } template Id(alias A){ alias A Id; } /***************************************************/ -// 1528 +// https://issues.dlang.org/show_bug.cgi?id=1528 int foo1528(long){ return 1; } int foo1528(int[]){ return 2; } @@ -313,7 +321,7 @@ void test1528d() } /***************************************************/ -// 1680 +// https://issues.dlang.org/show_bug.cgi?id=1680 struct S1680 { @@ -360,7 +368,7 @@ void test1680() } /***************************************************/ -// 7418 +// https://issues.dlang.org/show_bug.cgi?id=7418 int foo7418(uint a) { return 1; } int foo7418(char[] a) { return 2; } @@ -378,7 +386,7 @@ void test7418() } /***************************************************/ -// 7552 +// https://issues.dlang.org/show_bug.cgi?id=7552 struct S7552 { @@ -434,7 +442,7 @@ void test7552() } /***************************************************/ -// 8668 +// https://issues.dlang.org/show_bug.cgi?id=8668 import imports.m8668a; import imports.m8668c; //replace with m8668b to make it work @@ -446,7 +454,7 @@ void test8668() } /***************************************************/ -// 8943 +// https://issues.dlang.org/show_bug.cgi?id=8943 void test8943() { @@ -461,7 +469,7 @@ void test8943() } /***************************************************/ -// 9410 +// https://issues.dlang.org/show_bug.cgi?id=9410 struct S {} int foo(float f, ref S s) { return 1; } @@ -470,11 +478,17 @@ void test9410() { S s; assert(foo(1, s ) == 1); // works fine. Print: ref - assert(foo(1, S()) == 2); // Fails with: Error: S() is not an lvalue + + /* With the rvalue to ref param change, this calls the 'ref' version + * because both are the same match level, but the 'ref' version is + * considered "more specialized", as the non-ref version undergoes + * a "conversion" to call the ref version. + */ + assert(foo(1, S()) == 1); } /***************************************************/ -// 10171 +// https://issues.dlang.org/show_bug.cgi?id=10171 struct B10171(T) { static int x; } @@ -484,7 +498,8 @@ void test10171() } /***************************************************/ -// 1900 - template overload set +// https://issues.dlang.org/show_bug.cgi?id=1900 +// template overload set void test1900a() { @@ -623,7 +638,7 @@ void test1900e() } /***************************************************/ -// 1900 +// https://issues.dlang.org/show_bug.cgi?id=1900 void test1900() { @@ -669,7 +684,7 @@ mixin Foo1900!(char) B1900; alias Bar1900!(int) bar1900; // error /***************************************************/ -// 7780 +// https://issues.dlang.org/show_bug.cgi?id=7780 mixin template A7780() { @@ -710,7 +725,7 @@ void test7849() } /***************************************************/ -// 8352 +// https://issues.dlang.org/show_bug.cgi?id=8352 void test8352() { @@ -721,7 +736,7 @@ void test8352() } /***************************************************/ -// 8441 +// https://issues.dlang.org/show_bug.cgi?id=8441 mixin template T8441a(string i) { @@ -819,7 +834,7 @@ void test8441c() } /***************************************************/ -// 9235 +// https://issues.dlang.org/show_bug.cgi?id=9235 template FlowEvaluator9235() { @@ -893,7 +908,7 @@ void test9235b() } /***************************************************/ -// 10658 +// https://issues.dlang.org/show_bug.cgi?id=10658 alias Val10658 = imports.template_ovs1.Val10658; alias Val10658 = imports.template_ovs2.Val10658; @@ -1009,7 +1024,7 @@ void test11785() } /***************************************************/ -// 11915 +// https://issues.dlang.org/show_bug.cgi?id=11915 int f11915( int) { return 1; } int f11915(ref int) { return 2; } @@ -1025,7 +1040,7 @@ void test11915() } /***************************************************/ -// 11916 +// https://issues.dlang.org/show_bug.cgi?id=11916 auto f11916(T)( T) { return 1; } auto f11916(T)(out T) if (false) { return 2; } @@ -1054,12 +1069,12 @@ void test11916() } /***************************************************/ -// 13783 +// https://issues.dlang.org/show_bug.cgi?id=13783 enum E13783 { a = 5 } inout(int) f( inout(int) t) { return t * 2; } -ref inout(int) f(ref inout(int) t) { return t; } +ref inout(int) f(return ref inout(int) t) { return t; } void test13783() { @@ -1068,7 +1083,7 @@ void test13783() } /***************************************************/ -// 14858 +// https://issues.dlang.org/show_bug.cgi?id=14858 int foo14858()() { return 1; } int bar14858(int) { return 2; } @@ -1083,7 +1098,7 @@ void test14858() } /***************************************************/ -// 14989 +// https://issues.dlang.org/show_bug.cgi?id=14989 template Foo14989(T) if (is(T == int)) { enum Foo14989 = 1; } template Bar14989(T) if (is(T == double)) { enum Bar14989 = 2; } @@ -1136,7 +1151,7 @@ void test14989() } /***************************************************/ -// 14965 +// https://issues.dlang.org/show_bug.cgi?id=14965 auto f14965a1() { return f14965a1(123); } int f14965a1(int x) { return x; } @@ -1212,6 +1227,40 @@ void test14965() } /***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=21481 + +struct S21481 +{ + void funB2(char a) {} + alias funB = funB2; + // template as first symbol in overload set and overloading an alias + void funB()(float t) {} + void funB(int b) {} // function was lost -> OK now +} + +void test21481() +{ + static assert(__traits(getOverloads, S21481, "funB", true).length == 3); +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=21522 + +struct S21522 +{ + // alias to template as first symbol in overload set + void funA2()(int a) {} + void funA2(char a) {} // function was lost -> OK now + alias funA = funA2; + void funA(float b) {} +} + +void test21522() +{ + static assert(__traits(getOverloads, S21522, "funA", true).length == 3); +} + +/***************************************************/ int main() { @@ -1247,6 +1296,8 @@ int main() test13783(); test14858(); test14965(); + test21481(); + test21522(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/previewin.d b/gcc/testsuite/gdc.test/runnable/previewin.d new file mode 100644 index 00000000000..12a0551f7e5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/previewin.d @@ -0,0 +1,189 @@ +// REQUIRED_ARGS: -preview=dip1000 -preview=in + +void main () +{ + testWithAllAttributes(); + testForeach(); +} + +void testWithAllAttributes() @safe pure nothrow @nogc +{ + // Used to test dtors + bool isTestOver = false; + + // rvalues + testin1(42); + testin2((ulong[64]).init); + testin3(ValueT(42)); + testin3(RefT(42)); + testin4((ValueT[64]).init); + testin4([RefT(42), RefT(84), RefT(126), RefT(4)]); + testin5(NonCopyable(true)); + testin6(WithPostblit(true)); + testin7(WithCopyCtor(true)); + isTestOver = false; + testin8(WithDtor(&isTestOver), &isTestOver); + isTestOver = false; + + // lvalues + uint a1; + ulong[64] a2; + ValueT a3; + ValueT[64] a4; + RefT a5; + RefT[4] a6; + NonCopyable a7 = NonCopyable(true); + WithPostblit a8; + WithCopyCtor a9; + WithDtor a10 = WithDtor(&isTestOver); + + testin1(a1); + testin2(a2); + testin3(a3); + testin3(a5); + testin4(a4); + testin4(a6); + testin5(a7); + testin6(a8); + testin7(a9); + isTestOver = false; + testin8(a10, null); + + // Arguments are all values, no `ref` needed + testin9(int.init); + testin9(char.init, ubyte.init, short.init, int.init, size_t.init); + // Arguments are all refs + testin9(a2, a4, a5, a6, a7, a8, a9, a10); + testin9(NonCopyable(true), WithPostblit(true), WithCopyCtor(true)); + // Mixed values and ref + testin9(char.init, ubyte.init, a2, a4, a5, a6, a7, a8, a9, a10, size_t.init); + + // With dtor + isTestOver = false; + testin10(&isTestOver, NonCopyable(true), WithPostblit(true), + WithCopyCtor(true), WithDtor(&isTestOver)); + isTestOver = true; +} + +void testForeach() @safe pure +{ + int testCallNC (in NonCopyable k, in NonCopyable v) + { + assert(k == v); + return k.value - v.value; + } + + NonCopyable[NonCopyable] nc; + nc[NonCopyable(0)] = NonCopyable(0); + nc[NonCopyable(42)] = NonCopyable(42); + nc[NonCopyable(int.min)] = NonCopyable(int.min); + nc[NonCopyable(int.max)] = NonCopyable(int.max); + foreach (ref k, const ref v; nc) + { + assert(k.value == v.value); + assert(testCallNC(k, v) == 0); + } + assert(nc == nc); + assert(nc.length == 4); + + RefT[RefT] rt; + rt[RefT(42)] = RefT(42); + rt[RefT(4)] = RefT(4); + rt[RefT(242)] = RefT(242); + rt[RefT(24)] = RefT(24); + foreach (k, v; rt) + assert(k.value == v.value); + assert(rt == rt); + + static struct Msg + { + ubyte[3] value; + const(char)[] msg; + } + + static void testMsg (in Msg k_func, in Msg v_func) + { + assert(k_func.value == v_func.value); + assert(k_func.msg == v_func.msg); + assert(k_func == v_func); + } + + Msg[Msg] msg; + msg[Msg([1, 2, 3], "123")] = Msg([1, 2, 3], "123"); + msg[Msg([42, 4, 2], "4242")] = Msg([42, 4, 2], "4242"); + msg[Msg([242, 4, 0], "2424")] = Msg([242, 4, 0], "2424"); + foreach (ref k_loop, ref v_loop; msg) + testMsg(k_loop, v_loop); +} + +struct ValueT { int value; } +struct RefT { ulong[64] value; } + +struct NonCopyable +{ + @safe pure nothrow @nogc: + + int value; + this(int b) { this.value = b; } + + @disable this(this); + @disable this(ref NonCopyable); +} + +struct WithPostblit +{ + int value; + this(this) @safe pure nothrow @nogc { assert(0); } +} + +struct WithCopyCtor +{ + @safe pure nothrow @nogc: + + int value; + this(int b) { this.value = b; } + this(ref WithCopyCtor) { assert(0); } +} + +struct WithDtor +{ + bool* value; + ~this() scope @safe pure nothrow @nogc { assert(*value); } +} + +@safe pure nothrow @nogc: + +// By value +void testin1(in uint p) { static assert(!__traits(isRef, p)); } +// By ref because of size +void testin2(in ulong[64] p) { static assert(__traits(isRef, p)); } +// By value or ref depending on size +void testin3(in ValueT p) { static assert(!__traits(isRef, p)); } +void testin3(in RefT p) { static assert(__traits(isRef, p)); } +// By ref because of size +void testin4(in ValueT[64] p) { static assert(__traits(isRef, p)); } +void testin4(in RefT[4] p) { static assert(__traits(isRef, p)); } + +// By ref because of non-copyability +void testin5(in NonCopyable noncopy) { static assert(__traits(isRef, noncopy)); } +static assert(testin5.mangleof == "_D9previewin7testin5FNaNbNiNfIKSQBe11NonCopyableZv"); // incl. `ref` +// By ref because of postblit +void testin6(in WithPostblit withpostblit) { static assert(__traits(isRef, withpostblit)); } +// By ref because of copy ctor +void testin7(in WithCopyCtor withcopy) { static assert(__traits(isRef, withcopy)); } +// By ref because of dtor +void testin8(in WithDtor withdtor, scope bool* isTestOver) +{ + static assert(__traits(isRef, withdtor)); + if (isTestOver) + *isTestOver = true; +} + +// Allow to test various tuples (e.g. `(int, int)` and `(int, WithDtor)`) +// `ref` is only applied to the members which need it +void testin9(T...)(in T args) {} +void testin10(T...)(scope bool* isTestOver, in T args) +{ + if (isTestOver) + *isTestOver = true; +} diff --git a/gcc/testsuite/gdc.test/runnable/printargs.d b/gcc/testsuite/gdc.test/runnable/printargs.d index f4fc703163c..7d4d916f13d 100644 --- a/gcc/testsuite/gdc.test/runnable/printargs.d +++ b/gcc/testsuite/gdc.test/runnable/printargs.d @@ -3,12 +3,12 @@ extern(C) int printf(const char*, ...); -int main(char args[][]) +int main(char[][] args) { int i; for (i = 0; i < args.length; i++) - printf("args[%d] = '%.*s'\n", i, args[i].length, args[i].ptr); + printf("args[%d] = '%.*s'\n", i, cast(int)args[i].length, args[i].ptr); assert(args[1] == "A"); assert(args[2] == "B"); diff --git a/gcc/testsuite/gdc.test/runnable/property.d b/gcc/testsuite/gdc.test/runnable/property.d index 4fd3af4347b..661bd68565e 100644 --- a/gcc/testsuite/gdc.test/runnable/property.d +++ b/gcc/testsuite/gdc.test/runnable/property.d @@ -26,12 +26,12 @@ int test1() } /******************************************/ -// 6259 +// https://issues.dlang.org/show_bug.cgi?id=6259 struct S6259 { private int m_prop; - ref const(int) prop() { return m_prop; } + ref const(int) prop() return { return m_prop; } void prop(int v) { m_prop = v; } } diff --git a/gcc/testsuite/gdc.test/runnable/property2.d b/gcc/testsuite/gdc.test/runnable/property2.d index 1c5cf30aff0..275729f2a3e 100644 --- a/gcc/testsuite/gdc.test/runnable/property2.d +++ b/gcc/testsuite/gdc.test/runnable/property2.d @@ -1,4 +1,3 @@ -// PERMUTE_ARGS: -property /* TEST_OUTPUT: --- @@ -19,23 +18,13 @@ RUN_OUTPUT: Success --- */ - extern (C) int printf(const char* fmt, ...); -// Is -property option specified? -enum enforceProperty = !__traits(compiles, { - int prop(){ return 1; } - int n = prop; -}); - /*******************************************/ template select(alias v1, alias v2) { - static if (enforceProperty) - enum select = v1; - else - enum select = v2; + enum select = v2; } struct Test(int N) @@ -48,32 +37,28 @@ struct Test(int N) ref foo(){ getset = 1; return value; } enum result = select!(0, 1); - // -property test.d(xx): Error: not a property foo - // (no option) prints "getter" + // prints "getter" } static if (N == 1) { ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 2); - // -property test.d(xx): Error: not a property foo - // (no option) prints "setter" + // prints "setter" } static if (N == 2) { @property ref foo(){ getset = 1; return value; } enum result = select!(1, 1); - // -property prints "getter" - // (no option) prints "getter" + // prints "getter" } static if (N == 3) { @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(2, 2); - // -property prints "setter" - // (no option) prints "setter" + // prints "setter" } @@ -83,8 +68,7 @@ struct Test(int N) ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 2); - // -property test.d(xx): Error: not a property foo - // (no option) prints "setter" + // prints "setter" } static if (N == 5) { @@ -92,8 +76,7 @@ struct Test(int N) ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 0); - // -property test.d(xx): Error: cannot overload both property and non-property functions - // (no option) test.d(xx): Error: cannot overload both property and non-property functions + // test.d(xx): Error: cannot overload both property and non-property functions } static if (N == 6) { @@ -101,8 +84,7 @@ struct Test(int N) @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 0); - // -property test.d(xx): Error: cannot overload both property and non-property functions - // (no option) test.d(xx): Error: cannot overload both property and non-property functions + // test.d(xx): Error: cannot overload both property and non-property functions } static if (N == 7) { @@ -110,8 +92,7 @@ struct Test(int N) @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(2, 2); - // -property prints "setter" - // (no option) prints "setter" + // prints "setter" } } @@ -153,7 +134,7 @@ void test1() } /*******************************************/ -// 7722 +// https://issues.dlang.org/show_bug.cgi?id=7722 class Foo7722 {} void spam7722(Foo7722 f) {} @@ -161,10 +142,7 @@ void spam7722(Foo7722 f) {} void test7722() { auto f = new Foo7722; - static if (enforceProperty) - static assert(!__traits(compiles, f.spam7722)); - else - f.spam7722; + f.spam7722; } /*******************************************/ @@ -179,10 +157,7 @@ void test7722() assert(dg(0) == v); } - static if (enforceProperty) - checkImpl!(v1)(); - else - checkImpl!(v2)(); + checkImpl!(v2)(); } struct S {} @@ -292,7 +267,7 @@ void test7722b() } /*******************************************/ -// 7174 +// https://issues.dlang.org/show_bug.cgi?id=7174 void test7174() { @@ -301,7 +276,7 @@ void test7174() } /***************************************************/ -// 7274 +// https://issues.dlang.org/show_bug.cgi?id=7274 @property foo7274(){ return "test"; } @property bar7274(){ return "kernel32.lib"; } @@ -316,7 +291,7 @@ void test7274() } /***************************************************/ -// 7275 +// https://issues.dlang.org/show_bug.cgi?id=7275 void test7275() { @@ -333,7 +308,7 @@ void test7275() } /*****************************************/ -// 7538 +// https://issues.dlang.org/show_bug.cgi?id=7538 void test7538() { @@ -478,7 +453,7 @@ void test7538() } /*****************************************/ -// 8251 +// https://issues.dlang.org/show_bug.cgi?id=8251 struct S8251 { @@ -515,13 +490,13 @@ void test8251() } /*****************************************/ -// 9063 +// https://issues.dlang.org/show_bug.cgi?id=9063 @property bool foo9063(){ return true; } static assert(foo9063); /*****************************************/ -// 9234 +// https://issues.dlang.org/show_bug.cgi?id=9234 class Fizz9234 { @@ -533,7 +508,7 @@ struct Foo9234(alias F) {} struct Foo9234(string thunk) {} /*****************************************/ -// 10103 +// https://issues.dlang.org/show_bug.cgi?id=10103 mixin template Getter10103() { @@ -577,7 +552,7 @@ void test10103() } /*****************************************/ -// 10197 +// https://issues.dlang.org/show_bug.cgi?id=10197 template OriginalType10197(T) { diff --git a/gcc/testsuite/gdc.test/runnable/pubprivtmpl.d b/gcc/testsuite/gdc.test/runnable/pubprivtmpl.d new file mode 100644 index 00000000000..992f04fb74d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/pubprivtmpl.d @@ -0,0 +1,20 @@ +// EXTRA_SOURCES: imports/pubprivtmpla.d + +module pubprivtmpl; + +// Idiom: public alias to private template +// This idiom was discovered while refactoring access.d. The idiom was not being used in any DLang repository +// but was being used by a few projects in the D ecosystem. It is unkown at this time if this idiom is permitted +// by design or by accident. This test was added to DMD to prevent regressions in those projects that utilize this +// idiom. See also: +// https://issues.dlang.org/show_bug.cgi?id=4533 +// https://issues.dlang.org/show_bug.cgi?id=11173 + +import pubprivtmpla; + +void main() +{ + auto s = S(); + auto v = s.get(); + assert(v == 42); +} diff --git a/gcc/testsuite/gdc.test/runnable/s2ir.d b/gcc/testsuite/gdc.test/runnable/s2ir.d index 29cfc9669bb..840e6de9432 100644 --- a/gcc/testsuite/gdc.test/runnable/s2ir.d +++ b/gcc/testsuite/gdc.test/runnable/s2ir.d @@ -1,5 +1,14 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; +/* +RUN_OUTPUT: +--- +hello +world +foo +Success +--- +*/ + +import core.stdc.stdio; /***********************************/ @@ -17,6 +26,8 @@ void test1() } version(D_PIC) {} + else version (D_PIE) + {} else { asm @@ -43,7 +54,7 @@ int main() a[2] = "foo"; foreach (string s; a) - writefln(s); + printf("%.*s\n", cast(int)s.length, s.ptr); switch (1) { @@ -92,6 +103,6 @@ int main() default: assert(0); } - writefln("Success\n"); + printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/sctor.d b/gcc/testsuite/gdc.test/runnable/sctor.d index 7d640c09332..b587e6efe80 100644 --- a/gcc/testsuite/gdc.test/runnable/sctor.d +++ b/gcc/testsuite/gdc.test/runnable/sctor.d @@ -1,5 +1,11 @@ -// REQUIRED_ARGS: -// PERMUTE_ARGS: -w -d -de -dw +/* +REQUIRED_ARGS: -w -de +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); @@ -117,7 +123,7 @@ struct S4 } /***************************************************/ -// 8117 +// https://issues.dlang.org/show_bug.cgi?id=8117 struct S8117 { @@ -136,7 +142,7 @@ void test8117() } /***************************************************/ -// 9665 +// https://issues.dlang.org/show_bug.cgi?id=9665 struct X9665 { @@ -182,7 +188,7 @@ void test9665() } /***************************************************/ -// 11246 +// https://issues.dlang.org/show_bug.cgi?id=11246 struct Foo11246 { @@ -223,7 +229,7 @@ void test11246() } /***************************************************/ -// 13515 +// https://issues.dlang.org/show_bug.cgi?id=13515 Object[string][100] aa13515; @@ -253,7 +259,7 @@ void test13515() } /***************************************************/ -// 14409 +// https://issues.dlang.org/show_bug.cgi?id=14409 class B14409 { this(int) {} } class C14409 : B14409 @@ -268,7 +274,7 @@ class C14409 : B14409 } /***************************************************/ -// 14376 +// https://issues.dlang.org/show_bug.cgi?id=14376 auto map14376() { @@ -294,7 +300,7 @@ struct S14376 } /***************************************************/ -// 14351 +// https://issues.dlang.org/show_bug.cgi?id=14351 class B14351 { @@ -317,7 +323,7 @@ class D14351c : B14351 } /***************************************************/ -// 14450 +// https://issues.dlang.org/show_bug.cgi?id=14450 struct S14450a // non-template struct + non template ctors - OK { @@ -366,7 +372,7 @@ void test14450() } /***************************************************/ -// 14944 +// https://issues.dlang.org/show_bug.cgi?id=14944 static int[2] tbl14944; @@ -386,7 +392,8 @@ void test14944() } /***************************************************/ -// 15258 - a field initialization affects other overlapped fields +// https://issues.dlang.org/show_bug.cgi?id=15258 +// a field initialization affects other overlapped fields class C15258 { @@ -403,18 +410,62 @@ class C15258 } /***************************************************/ -// 15665 +// https://issues.dlang.org/show_bug.cgi?id=15869 -scope class C15665 (V) +struct Set { + @disable this(this); + int value = 0; +} + +Set clobber(ref Set a) { + Set ret; // <- This overwrites *a, i.e. &ret is the same as a + ret.value = a.value; // <- Now a.value is 0 + return ret; +} + +struct XX { + Set a = Set(1); + this(int n) { + a = clobber(a); // fix is to make this an assignment, not a construction + } +} +void test15869() { - this () {} + Set a = Set(1); + a = clobber(a); + assert(a.value == 1); + + XX xx = XX(0); + assert(xx.a.value == 1); } -void test15665() +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19389 + +struct Foo19389 { + int x; + + this(int dummy) { x = dummy; } +} + +struct Bar19389 { + Foo19389 a; + Foo19389 b; + + this(int dummy) { + a = (b = Foo19389(dummy)); + } +} + + +void test19389() { - scope foo = new C15665!int; + Bar19389 bar = Bar19389(7); + assert(bar.a.x == 7); + assert(bar.b.x == 7); // fails } + /***************************************************/ int main() @@ -425,7 +476,8 @@ int main() test13515(); test14450(); test14944(); - test15665(); + test15869(); + test19389(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/sctor2.d b/gcc/testsuite/gdc.test/runnable/sctor2.d new file mode 100644 index 00000000000..a2367cf7999 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/sctor2.d @@ -0,0 +1,20 @@ +// REQUIRED_ARGS: -w -de +// PERMUTE_ARGS: + +/***************************************************/ +// 15665 + +scope class C15665 (V) +{ + this () {} +} + +void test15665() +{ + scope foo = new C15665!int; +} + +void main() +{ + test15665(); +} diff --git a/gcc/testsuite/gdc.test/runnable/sdtor.d b/gcc/testsuite/gdc.test/runnable/sdtor.d index 3edf8cf85aa..56c5125cdaf 100644 --- a/gcc/testsuite/gdc.test/runnable/sdtor.d +++ b/gcc/testsuite/gdc.test/runnable/sdtor.d @@ -1,4 +1,5 @@ // PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g +// REQUIRED_ARGS: -preview=dtorfields /* TEST_OUTPUT: --- @@ -16,7 +17,7 @@ S7353 import core.vararg; -extern (C) int printf(const(char*) fmt, ...); +extern (C) int printf(const(char*) fmt, ...) nothrow; template TypeTuple(T...) { alias TypeTuple = T; } @@ -38,23 +39,6 @@ void test1() /**********************************/ -int sdtor2; - -struct S2 -{ - ~this() { printf("~S2()\n"); sdtor2++; } - delete(void* p) { assert(sdtor2 == 1); printf("S2.delete()\n"); sdtor2++; } -} - -void test2() -{ - S2* s = new S2(); - delete s; - assert(sdtor2 == 2); -} - -/**********************************/ - int sdtor3; struct S3 @@ -1185,7 +1169,7 @@ void test45() } /**********************************/ -// 3986 +// https://issues.dlang.org/show_bug.cgi?id=3986 struct SiberianHamster { @@ -1200,7 +1184,7 @@ void test46() } /**********************************/ -// 8741 +// https://issues.dlang.org/show_bug.cgi?id=8741 struct Vec8741 { @@ -1351,12 +1335,12 @@ void test52() A52 b = a.copy(); printf("a: %p, b: %p\n", &a, &b); } - printf("s = '%.*s'\n", s52.length, s52.ptr); + printf("s = '%.*s'\n", cast(int)s52.length, s52.ptr); assert(s52 == "cabb"); } /**********************************/ -// 4339 +// https://issues.dlang.org/show_bug.cgi?id=4339 struct A53 { invariant() { } @@ -1520,7 +1504,7 @@ void test56() } /**********************************/ -// 5859 +// https://issues.dlang.org/show_bug.cgi?id=5859 int dtor_cnt = 0; struct S57 @@ -1669,7 +1653,7 @@ void test57() } /**********************************/ -// 5574 +// https://issues.dlang.org/show_bug.cgi?id=5574 struct foo5574a { @@ -1690,7 +1674,7 @@ struct bar5574b } /**********************************/ -// 5777 +// https://issues.dlang.org/show_bug.cgi?id=5777 int sdtor58 = 0; S58* ps58; @@ -1716,7 +1700,7 @@ void test58() } /**********************************/ -// 6308 +// https://issues.dlang.org/show_bug.cgi?id=6308 struct C59 { @@ -1749,7 +1733,7 @@ void test59() } /**********************************/ -// 5737 +// https://issues.dlang.org/show_bug.cgi?id=5737 void test5737() { @@ -1785,7 +1769,7 @@ void test5737() } /**********************************/ -// 6119 +// https://issues.dlang.org/show_bug.cgi?id=6119 void test6119() { @@ -1817,7 +1801,7 @@ void test6119() } /**********************************/ -// 6364 +// https://issues.dlang.org/show_bug.cgi?id=6364 struct Foo6364 { @@ -1843,7 +1827,7 @@ void test6364() } /**********************************/ -// 6499 +// https://issues.dlang.org/show_bug.cgi?id=6499 struct S6499 { @@ -1852,18 +1836,18 @@ struct S6499 this(string s) { m = s; - printf("Constructor - %.*s\n", m.length, m.ptr); + printf("Constructor - %.*s\n", cast(int)m.length, m.ptr); if (m == "foo") { ++sdtor; assert(sdtor == 1); } if (m == "bar") { ++sdtor; assert(sdtor == 2); } } this(this) { - printf("Postblit - %.*s\n", m.length, m.ptr); + printf("Postblit - %.*s\n", cast(int)m.length, m.ptr); assert(0); } ~this() { - printf("Destructor - %.*s\n", m.length, m.ptr); + printf("Destructor - %.*s\n", cast(int)m.length, m.ptr); if (m == "bar") { assert(sdtor == 2); --sdtor; } if (m == "foo") { assert(sdtor == 1); --sdtor; } } @@ -1957,7 +1941,7 @@ void test60() } /**********************************/ -// 4316 +// https://issues.dlang.org/show_bug.cgi?id=4316 struct A4316 { @@ -1990,7 +1974,7 @@ void test6177() /**********************************/ -// 6470 +// https://issues.dlang.org/show_bug.cgi?id=6470 struct S6470 { @@ -2021,7 +2005,7 @@ void test6470() } /**********************************/ -// 6636 +// https://issues.dlang.org/show_bug.cgi?id=6636 struct S6636 { @@ -2043,7 +2027,7 @@ void test6636() } /**********************************/ -// 6637 +// https://issues.dlang.org/show_bug.cgi?id=6637 struct S6637 { @@ -2062,7 +2046,7 @@ void test6637() } /**********************************/ -// 7353 +// https://issues.dlang.org/show_bug.cgi?id=7353 struct S7353 { @@ -2101,7 +2085,7 @@ void test7353() } /**********************************/ -// 8036 +// https://issues.dlang.org/show_bug.cgi?id=8036 struct S8036a { @@ -2142,7 +2126,7 @@ void test61() } /**********************************/ -// 7506 +// https://issues.dlang.org/show_bug.cgi?id=7506 void test7506() { @@ -2172,7 +2156,7 @@ void test7506() } /**********************************/ -// 7516 +// https://issues.dlang.org/show_bug.cgi?id=7516 struct S7516 { @@ -2295,7 +2279,7 @@ void test7516e() } /**********************************/ -// 7530 +// https://issues.dlang.org/show_bug.cgi?id=7530 void test7530() { @@ -2352,7 +2336,7 @@ void test62() } /**********************************/ -// 7579 +// https://issues.dlang.org/show_bug.cgi?id=7579 void test7579a() { @@ -2425,7 +2409,7 @@ void test7579b() } /**********************************/ -// 8335 +// https://issues.dlang.org/show_bug.cgi?id=8335 struct S8335 { @@ -2471,7 +2455,7 @@ void test8335() } /**********************************/ -// 8356 +// https://issues.dlang.org/show_bug.cgi?id=8356 void test8356() { @@ -2493,7 +2477,7 @@ void test8356() } /**********************************/ -// 8475 +// https://issues.dlang.org/show_bug.cgi?id=8475 T func8475(T)(T x) @safe pure { @@ -2535,7 +2519,7 @@ Foo9320 test9320(Foo9320 a, Foo9320 b, Foo9320 c) { } /**********************************/ -// 9386 +// https://issues.dlang.org/show_bug.cgi?id=9386 struct Test9386 { @@ -2548,21 +2532,21 @@ struct Test9386 this(string name) { this.name = name; - printf("Created %.*s...\n", name.length, name.ptr); + printf("Created %.*s...\n", cast(int)name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'a'; } this(this) { - printf("Copied %.*s...\n", name.length, name.ptr); + printf("Copied %.*s...\n", cast(int)name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'b'; } ~this() { - printf("Deleted %.*s\n", name.length, name.ptr); + printf("Deleted %.*s\n", cast(int)name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'c'; } @@ -2592,7 +2576,7 @@ void test9386() printf("----\n"); foreach (Test9386 test; tests) { - printf("\tForeach %.*s\n", test.name.length, test.name.ptr); + printf("\tForeach %.*s\n", cast(int)test.name.length, test.name.ptr); Test9386.op[Test9386.i++] = 'x'; } @@ -2603,7 +2587,7 @@ void test9386() printf("----\n"); foreach (ref Test9386 test; tests) { - printf("\tForeach %.*s\n", test.name.length, test.name.ptr); + printf("\tForeach %.*s\n", cast(int)test.name.length, test.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "xxxx"); @@ -2625,8 +2609,8 @@ void test9386() printf("----\n"); foreach (Test9386 k, Test9386 v; tests) { - printf("\tForeach %.*s : %.*s\n", k.name.length, k.name.ptr, - v.name.length, v.name.ptr); + printf("\tForeach %.*s : %.*s\n", cast(int)k.name.length, k.name.ptr, + cast(int)v.name.length, v.name.ptr); Test9386.op[Test9386.i++] = 'x'; } @@ -2637,8 +2621,8 @@ void test9386() printf("----\n"); foreach (Test9386 k, ref Test9386 v; tests) { - printf("\tForeach %.*s : %.*s\n", k.name.length, k.name.ptr, - v.name.length, v.name.ptr); + printf("\tForeach %.*s : %.*s\n", cast(int)k.name.length, k.name.ptr, + cast(int)v.name.length, v.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "bxcbxcbxcbxc"); @@ -2648,7 +2632,7 @@ void test9386() } /**********************************/ -// 9441 +// https://issues.dlang.org/show_bug.cgi?id=9441 auto x9441 = X9441(0.123); @@ -2697,7 +2681,7 @@ struct Data ~this() { - printf("%d\n", _store._count); + printf("%zd\n", _store._count); --_store._count; } } @@ -2711,7 +2695,7 @@ void test9720() } /**********************************/ -// 9899 +// https://issues.dlang.org/show_bug.cgi?id=9899 struct S9899 { @@ -2729,7 +2713,7 @@ void test9899() @safe pure nothrow } /**********************************/ -// 9907 +// https://issues.dlang.org/show_bug.cgi?id=9907 void test9907() { @@ -2746,13 +2730,13 @@ void test9907() void opAssign(SX rhs) { - printf("%08X(%d) from Rvalue %08X(%d)\n", &this.i, this.i, &rhs.i, rhs.i); + printf("%08zX(%d) from Rvalue %08zX(%d)\n", cast(size_t)&this.i, this.i, cast(size_t)&rhs.i, rhs.i); ++assign; } void opAssign(ref SX rhs) { - printf("%08X(%d) from Lvalue %08X(%d)\n", &this.i, this.i, &rhs.i, rhs.i); + printf("%08zX(%d) from Lvalue %08zX(%d)\n", cast(size_t)&this.i, this.i, cast(size_t)&rhs.i, rhs.i); assert(0); } @@ -2760,7 +2744,7 @@ void test9907() { ~this() { - printf("destroying %08X(%d)\n", &this.i, this.i); + printf("destroying %08zX(%d)\n", cast(size_t)&this.i, this.i); ++dtor; } } @@ -2793,12 +2777,12 @@ void test9907() } /**********************************/ -// 9985 +// https://issues.dlang.org/show_bug.cgi?id=9985 struct S9985 { ubyte* b; - ubyte buf[128]; + ubyte[128] buf; this(this) { assert(0); } static void* ptr; @@ -2864,7 +2848,7 @@ void test17457() } /**********************************/ -// 9994 +// https://issues.dlang.org/show_bug.cgi?id=9994 void test9994() { @@ -2884,7 +2868,7 @@ void test9994() } /**********************************/ -// 10053 +// https://issues.dlang.org/show_bug.cgi?id=10053 struct S10053A { @@ -2898,7 +2882,7 @@ struct S10053B } /**********************************/ -// 10055 +// https://issues.dlang.org/show_bug.cgi?id=10055 void test10055a() { @@ -2999,7 +2983,7 @@ void test10055b() } /**********************************/ -// 10160 +// https://issues.dlang.org/show_bug.cgi?id=10160 struct S10160 { this(this) {} } @@ -3013,7 +2997,7 @@ void test10160() } /**********************************/ -// 10094 +// https://issues.dlang.org/show_bug.cgi?id=10094 void test10094() { @@ -3035,7 +3019,7 @@ void test10094() } /**********************************/ -// 10079 +// https://issues.dlang.org/show_bug.cgi?id=10079 // dtor || postblit struct S10079a @@ -3082,7 +3066,7 @@ static assert(__traits(compiles, &check10079!S10079e)); static assert(__traits(compiles, &check10079!S10079f)); /**********************************/ -// 10244 +// https://issues.dlang.org/show_bug.cgi?id=10244 void test10244() { @@ -3110,7 +3094,7 @@ void test10244() } /**********************************/ -// 10694 +// https://issues.dlang.org/show_bug.cgi?id=10694 struct Foo10694 { ~this() { } } @@ -3126,7 +3110,7 @@ void test10694() pure } /**********************************/ -// 10787 +// https://issues.dlang.org/show_bug.cgi?id=10787 int global10787; @@ -3145,7 +3129,7 @@ shared static ~this() nothrow pure @safe } /**********************************/ -// 10789 +// https://issues.dlang.org/show_bug.cgi?id=10789 struct S10789 { @@ -3212,7 +3196,7 @@ void test10789() } /**********************************/ -// 10972 +// https://issues.dlang.org/show_bug.cgi?id=10972 int test10972() { @@ -3276,7 +3260,7 @@ int test10972() static assert(test10972()); // CTFE /**********************************/ -// 11134 +// https://issues.dlang.org/show_bug.cgi?id=11134 void test11134() { @@ -3312,7 +3296,7 @@ void test11134() } /**********************************/ -// 11197 +// https://issues.dlang.org/show_bug.cgi?id=11197 struct S11197a { @@ -3346,7 +3330,7 @@ void fun7474(T...)() { T x; } void test7474() { fun7474!S7474(); } /**********************************/ -// 11286 +// https://issues.dlang.org/show_bug.cgi?id=11286 struct A11286 { @@ -3364,7 +3348,7 @@ void test11286() } /**********************************/ -// 11505 +// https://issues.dlang.org/show_bug.cgi?id=11505 struct Foo11505 { @@ -3384,7 +3368,7 @@ void test11505() } /**********************************/ -// 12045 +// https://issues.dlang.org/show_bug.cgi?id=12045 bool test12045() { @@ -3435,7 +3419,7 @@ bool test12045() static assert(test12045()); /**********************************/ -// 12591 +// https://issues.dlang.org/show_bug.cgi?id=12591 struct S12591(T) { @@ -3458,7 +3442,7 @@ void test12591() } /**********************************/ -// 12660 +// https://issues.dlang.org/show_bug.cgi?id=12660 struct X12660 { @@ -3499,7 +3483,7 @@ void test12660() @nogc } /**********************************/ -// 12686 +// https://issues.dlang.org/show_bug.cgi?id=12686 struct Foo12686 { @@ -3527,7 +3511,7 @@ void test12686() } /**********************************/ -// 13089 +// https://issues.dlang.org/show_bug.cgi?id=13089 struct S13089 { @@ -3687,7 +3671,7 @@ void test13586() } /**********************************/ -// 14443 +// https://issues.dlang.org/show_bug.cgi?id=14443 T enforce14443(E : Throwable = Exception, T)(T value) { @@ -3831,7 +3815,10 @@ void test14443() } /**********************************/ -// 13661, 14022, 14023 - postblit/dtor call on static array assignment +// postblit/dtor call on static array assignment +// https://issues.dlang.org/show_bug.cgi?id=13661 +// https://issues.dlang.org/show_bug.cgi?id=14022 +// https://issues.dlang.org/show_bug.cgi?id=14023 bool test13661() { @@ -4039,7 +4026,7 @@ bool test14023() static assert(test14023()); /************************************************/ -// 13669 - dtor call on static array variable +// https://issues.dlang.org/show_bug.cgi?id=13669 - dtor call on static array variable bool test13669() { @@ -4084,7 +4071,7 @@ void test13095() } /**********************************/ -// 14264 +// https://issues.dlang.org/show_bug.cgi?id=14264 void test14264() { @@ -4116,7 +4103,7 @@ void test14264() } /**********************************/ -// 14686 +// https://issues.dlang.org/show_bug.cgi?id=14686 int test14686() { @@ -4160,7 +4147,7 @@ int test14686() static assert(test14686()); /**********************************/ -// 14815 +// https://issues.dlang.org/show_bug.cgi?id=14815 int test14815() { @@ -4222,7 +4209,7 @@ void test16197() { } /**********************************/ -// 14860 +// https://issues.dlang.org/show_bug.cgi?id=14860 int test14860() { @@ -4245,7 +4232,39 @@ int test14860() static assert(test14860()); /**********************************/ -// 14696 +// https://issues.dlang.org/show_bug.cgi?id=14246 + +struct A14246 { + int a = 3; + static string s; + this( int var ) { printf("A()\n"); a += var; s ~= "a"; } + + ~this() { printf("~A()\n"); s ~= "b"; } +} + +struct B14246 { + int i; + A14246 a; + + this( int var ) { + A14246.s ~= "c"; + a = A14246(var+1); + throw new Exception("An exception"); + } +} + +void test14246() { + try { + auto b = B14246(2); + } catch( Exception ex ) { + printf("Caught ex\n"); + A14246.s ~= "d"; + } + assert(A14246.s == "cabd"); +} + +/**********************************/ +// https://issues.dlang.org/show_bug.cgi?id=14696 void test14696(int len = 2) { @@ -4351,10 +4370,12 @@ void test14696(int len = 2) check({ foo(len == 2 ? makeS(1).get(len != 2 ? makeS(2).get() : null) : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len != 2 ? makeS(1).get(len == 2 ? makeS(2).get() : null) : null); }, "foo."); check({ foo(len != 2 ? makeS(1).get(len != 2 ? makeS(2).get() : null) : null); }, "foo."); + check({ foo(len == 2 ? makeS(makeS(2).n - 1).get() : null); }, "makeS(2).makeS(1).get(1).foo.dtor(1).dtor(2)."); + check({ foo(len != 2 ? makeS(makeS(2).n - 1).get() : null); }, "foo."); } /**********************************/ -// 14838 +// https://issues.dlang.org/show_bug.cgi?id=14838 int test14838() pure nothrow @safe { @@ -4408,6 +4429,21 @@ static assert(test14838()); /**********************************/ +// https://issues.dlang.org/show_bug.cgi?id=14639 + +struct Biggy { + ulong[50000] a; + @disable this(this); +} + +__gshared Biggy biggy; + +void test14639() { + biggy = Biggy.init; +} + +/**********************************/ + struct S63 { private long p = 87; @@ -4501,7 +4537,7 @@ void test65() } /**********************************/ -// 15661 +// https://issues.dlang.org/show_bug.cgi?id=15661 struct X15661 { @@ -4542,10 +4578,253 @@ void test15661() /**********************************/ -int main() +// https://issues.dlang.org/show_bug.cgi?id=18045 + +struct A18045 +{ + nothrow: + __gshared int r; + int state; + this(this) { printf("postblit: A(%d)\n", state); r += 1; } + ~this() { printf("dtor: A(%d)\n", state); r *= 3; } +} + +A18045 fun18045() nothrow +{ + __gshared a = A18045(42); + return a; +} + +void test18045() nothrow +{ + alias A = A18045; + + __gshared a = A(-42); + if (fun18045() == a) + assert(0); + else + assert(A.r == 3); + + A.r = 0; + if (a == fun18045()) + assert(0); + else + assert(A.r == 3); +} + +/**********************************/ + +struct S66 +{ + ~this() { } +} + +nothrow void notthrow() { } + +class C66 { + S66 s; + + this() nothrow { notthrow(); } +} + +/**********************************/ +// https://issues.dlang.org/show_bug.cgi?id=16652 + +struct Vector +{ + this(ubyte a) + { + pragma(inline, false); + buf = a; + } + + ~this() + { + pragma(inline, false); + buf = 0; + } + + ubyte buf; +} + +int bar16652(ubyte* v) +{ + pragma(inline, true); + assert(*v == 1); + return 0; +} + +void test16652() +{ + bar16652(&Vector(1).buf); +} + + +/**********************************/ +// https://issues.dlang.org/show_bug.cgi?id=19676 + +void test19676() +{ + static struct S + { + __gshared int count; + ~this() { ++count; } + } + + static S foo() { return S(); } + + static void test1() + { + cast(void)foo(); + } + + static void test2() + { + foo(); + } + test1(); + assert(S.count == 1); test2(); + assert(S.count == 2); +} + +/**********************************/ + +// https://issues.dlang.org/show_bug.cgi?id=14708 + +__gshared bool dtor14078 = false; + +struct S14078 +{ + int n; + + void* get(void* p = null) + { + return null; + } + + ~this() + { + //printf("dtor\n"); + dtor14078 = true; + } +} + +S14078 makeS14078(int n) +{ + return S14078(n); +} + +void foo14078(void* x) +{ + throw new Exception("fail!"); +} + +void test(int len = 2) +{ + foo14078(makeS14078(1).get()); + // A temporary is allocated on stack for the + // return value from makeS14078(1). + // When foo14078 throws exception, it's dtor should be called + // during unwinding stack, but it does not happen in Win64. +} + +void test14078() +{ + try + { + test(); + } catch (Exception e) {} + assert(dtor14078); // fails! +} + +/**********************************/ + +void test67() +{ + char[] deleted; + + struct S + { + char* p; + + ~this() { deleted ~= *p; } + + void opAssign(S rhs) + { + // swap + char* tmp = p; + this.p = rhs.p; + rhs.p = tmp; + } + } + + char a = 'a', b = 'b'; + { + S s = S(&a); + s = S(&b); + } + assert(deleted == "ab", deleted); +} + +/**********************************/ + +void test68() +{ + static struct S + { + int i; + bool opEquals(S) { return false; } + ~this() {} + } + + assert(S(0) != S(1)); +} + +/**********************************/ + +// https://github.com/dlang/dmd/pull/12012 + +extern (C++) +{ +struct S12012 +{ + int* ctr; + ~this() { } +} + +void bar12012(int value, S12012 s) +{ +} + +S12012 abc12012(ref S12012 s) +{ + s.ctr = null; + return s; +} + +int def12012(ref S12012 s) +{ + return *s.ctr; // seg fault is here +} + +void testPR12012() +{ + int i; + S12012 s = S12012(&i); + // def must be executed before abc else seg fault + bar12012(def12012(s), abc12012(s)); +} +} + +/**********************************/ + +int main() +{ + test1(); + test3(); test4(); test5(); @@ -4666,12 +4945,21 @@ int main() test14815(); test16197(); test14860(); + test14246(); test14696(); test14838(); + test14639(); test63(); test64(); test65(); test15661(); + test18045(); + test16652(); + test19676(); + test14078(); + test67(); + test68(); + testPR12012(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/statictor.d b/gcc/testsuite/gdc.test/runnable/statictor.d index 7e34bd123c2..b00277b789e 100644 --- a/gcc/testsuite/gdc.test/runnable/statictor.d +++ b/gcc/testsuite/gdc.test/runnable/statictor.d @@ -1,7 +1,19 @@ -// PERMUTE_ARGS: -// POST_SCRIPT: runnable/extra-files/statictor-postscript.sh +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +shared static this() +Foo static ctor +static ctor +Bar static ctor +Bar static dtor +static dtor +Foo static dtor +shared static this() +--- +*/ -private import std.stdio; +private import core.stdc.stdio; class Foo { @@ -29,7 +41,7 @@ class Bar } /***********************************************/ -// 6677 +// https://issues.dlang.org/show_bug.cgi?id=6677 int global6677; @@ -50,7 +62,7 @@ shared static this() nothrow pure @safe } /***********************************************/ -// 7533 +// https://issues.dlang.org/show_bug.cgi?id=7533 struct Foo7533(int n) { pure static this() { } @@ -64,4 +76,3 @@ int main() { return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/stress.d b/gcc/testsuite/gdc.test/runnable/stress.d index a8c6c91008c..66373c4270d 100644 --- a/gcc/testsuite/gdc.test/runnable/stress.d +++ b/gcc/testsuite/gdc.test/runnable/stress.d @@ -83,10 +83,10 @@ void MDCHAR() str[idx] = str[idx] ~ "TEST LINE\n"; } - if(str.length != ITERS) printf("Length Error: %d\n",str.length); - if(str[0].length != 10) printf("Length Error: %d\n",str[0].length); - if(str[ITERS-1].sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str[ITERS-1].sizeof); - if(str[ITERS-1][0].sizeof != (typ).sizeof) printf("Size Error: %d\n",str[ITERS-1][0].sizeof); + if(str.length != ITERS) printf("Length Error: %zd\n",str.length); + if(str[0].length != 10) printf("Length Error: %zd\n",str[0].length); + if(str[ITERS-1].sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",str[ITERS-1].sizeof); + if(str[ITERS-1][0].sizeof != (typ).sizeof) printf("Size Error: %zd\n",str[ITERS-1][0].sizeof); foreach(s; str) { size_t lstart; @@ -131,8 +131,8 @@ void CHAR() str = str ~ "TEST LINE\n"; } - if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); - if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); + if(str.length != (ITERS * 10)) printf("Length Error: %zd\n",str.length); + if(str.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",str.sizeof); size_t lstart; foreach(size_t idx, char c; str) { @@ -156,8 +156,8 @@ void WCHAR() str = str ~ toUTF16(cast(char[])"TEST LINE\n"); } - if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); - if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); + if(str.length != (ITERS * 10)) printf("Length Error: %zd\n",str.length); + if(str.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",str.sizeof); size_t lstart; foreach(size_t idx, char c; str) { @@ -181,8 +181,8 @@ void DCHAR() str = str ~ toUTF32(cast(char[])"TEST LINE\n"); } - if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); - if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); + if(str.length != (ITERS * 10)) printf("Length Error: %zd\n",str.length); + if(str.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",str.sizeof); size_t lstart; foreach(size_t idx, char c; str) { @@ -206,8 +206,8 @@ void BYTE() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -218,8 +218,8 @@ void BYTE() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -230,8 +230,8 @@ void BYTE() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -250,8 +250,8 @@ void UBYTE() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -262,8 +262,8 @@ void UBYTE() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -275,8 +275,8 @@ void UBYTE() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -295,8 +295,8 @@ void SHORT() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -306,8 +306,8 @@ void SHORT() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -319,8 +319,8 @@ void SHORT() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -339,8 +339,8 @@ void USHORT() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -350,8 +350,8 @@ void USHORT() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -363,8 +363,8 @@ void USHORT() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -383,8 +383,8 @@ void INT() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -395,8 +395,8 @@ void INT() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -408,8 +408,8 @@ void INT() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -428,8 +428,8 @@ void UINT() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); @@ -440,8 +440,8 @@ void UINT() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); @@ -453,8 +453,8 @@ void UINT() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); @@ -473,22 +473,22 @@ void LONG() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { - printf("a Data Error: %d\n",a[idx]); + printf("a Data Error: %lld\n",a[idx]); break; } } typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { - printf("b Data Error: %d\n",b[idx]); + printf("b Data Error: %lld\n",b[idx]); break; } } @@ -497,11 +497,11 @@ void LONG() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { - printf("c Data Error: %d\n",c[idx]); + printf("c Data Error: %lld\n",c[idx]); break; } } @@ -517,22 +517,22 @@ void ULONG() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { - printf("a Data Error: %d\n",a[idx]); + printf("a Data Error: %lld\n",a[idx]); break; } } typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { - printf("b Data Error: %d\n",b[idx]); + printf("b Data Error: %lld\n",b[idx]); break; } } @@ -541,11 +541,11 @@ void ULONG() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { - printf("c Data Error: %d\n",c[idx]); + printf("c Data Error: %lld\n",c[idx]); break; } } @@ -561,22 +561,22 @@ void FLOAT() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { - printf("a Data Error: %d\n",a[idx]); + printf("a Data Error: %g\n",a[idx]); break; } } typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { - printf("b Data Error: %d\n",b[idx]); + printf("b Data Error: %g\n",b[idx]); break; } } @@ -585,11 +585,11 @@ void FLOAT() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { - printf("c Data Error: %d\n",c[idx]); + printf("c Data Error: %g\n",c[idx]); break; } } @@ -605,22 +605,22 @@ void DOUBLE() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { - printf("a Data Error: %d\n",a[idx]); + printf("a Data Error: %g\n",a[idx]); break; } } typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { - printf("b Data Error: %d\n",b[idx]); + printf("b Data Error: %g\n",b[idx]); break; } } @@ -629,11 +629,11 @@ void DOUBLE() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { - printf("c Data Error: %d\n",c[idx]); + printf("c Data Error: %g\n",c[idx]); break; } } @@ -649,22 +649,22 @@ void REAL() a ~= idx; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { - printf("a Data Error: %d\n",a[idx]); + printf("a Data Error: %Lg\n",a[idx]); break; } } typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { - printf("b Data Error: %d\n",b[idx]); + printf("b Data Error: %Lg\n",b[idx]); break; } } @@ -673,11 +673,11 @@ void REAL() c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { - printf("c Data Error: %d\n",c[idx]); + printf("c Data Error: %Lg\n",c[idx]); break; } } @@ -694,8 +694,8 @@ void CLASS() a ~= tc; } - if(a.length != ITERS) printf("Length Error: %d\n",a.length); - if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); + if(a.length != ITERS) printf("Length Error: %zd\n",a.length); + if(a.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx].i != idx) { printf("a Data Error: %d\n",a[idx].i); @@ -705,8 +705,8 @@ void CLASS() typ[] b = a[]; - if(b.length != ITERS) printf("Length Error: %d\n",b.length); - if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); + if(b.length != ITERS) printf("Length Error: %zd\n",b.length); + if(b.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx].i != idx) { printf("b Data Error: %d\n",b[idx].i); @@ -717,8 +717,8 @@ void CLASS() typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; - if(c.length != ITERS) printf("Length Error: %d\n",c.length); - if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); + if(c.length != ITERS) printf("Length Error: %zd\n",c.length); + if(c.sizeof != (typ[]).sizeof) printf("Size Error: %zd\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx].i != idx) { printf("c Data Error: %d\n",c[idx].i); diff --git a/gcc/testsuite/gdc.test/runnable/structlit.d b/gcc/testsuite/gdc.test/runnable/structlit.d index 38af612e351..d4a6bd6061b 100644 --- a/gcc/testsuite/gdc.test/runnable/structlit.d +++ b/gcc/testsuite/gdc.test/runnable/structlit.d @@ -1,4 +1,12 @@ -import std.stdio; +/* +REQUIRED_ARGS: -preview=rvaluerefparam +RUN_OUTPUT: +--- +Success +--- +*/ + +import core.stdc.stdio; struct S { @@ -318,13 +326,13 @@ int waz14(S)(ref S s) { return 2; } void test14() { - // can not bind rvalue-sl with ref - static assert(!__traits(compiles, foo14(S14a(0)))); - static assert(!__traits(compiles, foo14(S14b(0)))); - static assert(!__traits(compiles, hoo14(S14a(0)))); - static assert(!__traits(compiles, hoo14(S14b(0)))); - static assert(!__traits(compiles, poo14(S14a(0)))); - static assert(!__traits(compiles, poo14(S14b(0)))); + // can bind rvalue-sl with ref + foo14(S14a(0)); + foo14(S14b(0)); + hoo14(S14a(0)); + hoo14(S14b(0)); + poo14(S14a(0)); + poo14(S14b(0)); // still can bind rvalue-sl with non-ref bar14(S14a(0)); @@ -491,7 +499,7 @@ void test15c() auto c2 = new immutable C(1); } -void test15d() // Bugzilla 9974 +void test15d() // https://issues.dlang.org/show_bug.cgi?id=9974 { class CM { this() {} } auto cm = new CM(); @@ -525,7 +533,7 @@ void test15d() // Bugzilla 9974 shared const ssc = new shared const SSC(1); } -void test15e() // Bugzilla 10005 +void test15e() // https://issues.dlang.org/show_bug.cgi?id=10005 { // struct literal static struct S @@ -642,7 +650,7 @@ void test9993b() } /********************************************/ -// 1914 +// https://issues.dlang.org/show_bug.cgi?id=1914 struct Bug1914a { @@ -703,7 +711,7 @@ void test3198and1914() } /********************************************/ -// 14996 +// https://issues.dlang.org/show_bug.cgi?id=14996 enum E14996a : string { confirm = "confirm" } enum E14996b : long[] { confirm = [1,2,3,4] } @@ -715,7 +723,7 @@ struct S14996 } /********************************************/ -// 2427 +// https://issues.dlang.org/show_bug.cgi?id=2427 void test2427() { @@ -755,7 +763,7 @@ void test5885() } /********************************************/ -// 5889 +// https://issues.dlang.org/show_bug.cgi?id=5889 struct S5889a { int n; } struct S5889b { this(int n){} } @@ -812,7 +820,7 @@ void test5889() } /********************************************/ -// 4147 +// https://issues.dlang.org/show_bug.cgi?id=4147 struct S4247 { @@ -829,7 +837,7 @@ void test4247() } /********************************************/ -// 6937 +// https://issues.dlang.org/show_bug.cgi?id=6937 void test6937() { @@ -885,7 +893,7 @@ void test6937() } /********************************************/ -// 12681 +// https://issues.dlang.org/show_bug.cgi?id=12681 struct HasUnion12774 { @@ -930,7 +938,7 @@ bool test12681() static assert(test12681()); /********************************************/ -// 3991 +// https://issues.dlang.org/show_bug.cgi?id=3991 union X3991 { @@ -940,8 +948,8 @@ union X3991 union Y3991 { - int a = void; dchar b = 'a'; + int a = void; } union Z3991 @@ -962,7 +970,7 @@ void test3991() } /********************************************/ -// 7727 +// https://issues.dlang.org/show_bug.cgi?id=7727 union U7727A1 { int i; double d; } union U7727A2 { int i = 123; double d; } @@ -990,7 +998,7 @@ void test7727() { U7727A2 u = { i: 1024, d: 1.225 }; } )); -// Blocked by issue 1432 +// Blocked by https://issues.dlang.org/show_bug.cgi?id=1432 // { U7727A3 u; assert(u.d == 2.5); } // { U7727A3 u = { i: 1024 }; assert(u.i == 1024); } // { U7727A3 u = { d: 1.225 }; assert(u.d == 1.225); } @@ -1012,7 +1020,7 @@ void test7727() { U7727B2 u = { i: 1024, d: 1.225 }; } )); -// Blocked by issue 1432 +// Blocked by https://issues.dlang.org/show_bug.cgi?id=1432 // { U7727B3 u; assert(u.i == 123); } // { U7727B3 u = { i: 1024 }; assert(u.i == 1024); } // { U7727B3 u = { d: 1.225 }; assert(u.d == 1.225); } @@ -1058,7 +1066,7 @@ void test7727b() } /********************************************/ -// 7929 +// https://issues.dlang.org/show_bug.cgi?id=7929 void test7929() { @@ -1076,7 +1084,7 @@ void test7929() } /********************************************/ -// 7021 +// https://issues.dlang.org/show_bug.cgi?id=7021 struct S7021 { @@ -1091,7 +1099,7 @@ void test7021() } /********************************************/ -// 8738 +// https://issues.dlang.org/show_bug.cgi?id=8738 void test8738() { @@ -1108,7 +1116,7 @@ void test8738() } /********************************************/ -// 8763 +// https://issues.dlang.org/show_bug.cgi?id=8763 void test8763() { @@ -1128,7 +1136,7 @@ void test8763() } /********************************************/ -// 8902 +// https://issues.dlang.org/show_bug.cgi?id=8902 union U8902 { int a, b; } @@ -1146,7 +1154,7 @@ void test8902() } /********************************************/ -// 9116 +// https://issues.dlang.org/show_bug.cgi?id=9116 void test9116() { @@ -1167,7 +1175,7 @@ void test9116() } /********************************************/ -// 9293 +// https://issues.dlang.org/show_bug.cgi?id=9293 void test9293() { @@ -1192,7 +1200,7 @@ void test9293() } /********************************************/ -// 9566 +// https://issues.dlang.org/show_bug.cgi?id=9566 void test9566() { @@ -1205,7 +1213,7 @@ void test9566() } /********************************************/ -// 9775 +// https://issues.dlang.org/show_bug.cgi?id=9775 enum Month9775 : ubyte { jan = 1, } struct Date9775 @@ -1227,7 +1235,7 @@ enum Date9775 date9775e1 = Date9775(2012, 12, 21); enum date9775e2 = Date9775(2012, 12, 21); /********************************************/ -// 11105 +// https://issues.dlang.org/show_bug.cgi?id=11105 struct S11105 { @@ -1240,7 +1248,7 @@ void test11105() } /********************************************/ -// 11147 +// https://issues.dlang.org/show_bug.cgi?id=11147 struct V11147 { @@ -1273,7 +1281,7 @@ void test11147() } /********************************************/ -// 11256 +// https://issues.dlang.org/show_bug.cgi?id=11256 struct S11256 { @disable this(); } @@ -1311,7 +1319,7 @@ void test11256() } /********************************************/ -// 11269 +// https://issues.dlang.org/show_bug.cgi?id=11269 struct Atom { @@ -1336,7 +1344,7 @@ void test11269() } /********************************************/ -// 11427 +// https://issues.dlang.org/show_bug.cgi?id=11427 struct S11427 { @@ -1356,7 +1364,7 @@ int foo11427() @safe } /********************************************/ -// 12011 +// https://issues.dlang.org/show_bug.cgi?id=12011 struct S12011a { @@ -1379,7 +1387,7 @@ void test12011() } /********************************************/ -// 13021 +// https://issues.dlang.org/show_bug.cgi?id=13021 void test13021() { @@ -1417,7 +1425,7 @@ void test13021() } /********************************************/ -// 14556 +// https://issues.dlang.org/show_bug.cgi?id=14556 enum E14556 { a = 1 } diff --git a/gcc/testsuite/gdc.test/runnable/template1.d b/gcc/testsuite/gdc.test/runnable/template1.d index 51f96bf2acf..dde9213deb5 100644 --- a/gcc/testsuite/gdc.test/runnable/template1.d +++ b/gcc/testsuite/gdc.test/runnable/template1.d @@ -715,7 +715,7 @@ public template TRange29(T) { recursing = false; } } - } body { + } do { return contains(other.lower()) || contains(other.upper()) || other.includes(this); } public bool includes(Range other) @@ -723,7 +723,7 @@ public template TRange29(T) { assert(other !is null); } out (result) { assert(result == (contains(other.lower()) && contains(other.upper()))); - } body { + } do { return contains(other.lower()) && contains(other.upper()); } } @@ -771,22 +771,22 @@ void test30() assert(i == 3); copystr.copy(s, "Here it comes"); - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(s == "Here it comes"); } /******************************************/ -import std.string; +import core.demangle; template Foo31(alias X) { - alias X.toStringz y; + alias X.demangle y; } void test31() { - alias Foo31!(std.string) bar; + alias Foo31!(core.demangle) bar; } @@ -1367,7 +1367,7 @@ void test56() { alias CT56!(int) Ct; Ct.C c= new Ct.C(); - printf("%.*s\n", c.arrArr[0].length, c.arrArr[0].ptr); + printf("%.*s\n", cast(int)c.arrArr[0].length, c.arrArr[0].ptr); assert(c.arrArr[0] == "foo"); } @@ -1449,15 +1449,15 @@ void test60() B60!(int, long).Thing thing1; B60!(int).Thing thing2; - printf("thing1.sizeof: %u\n", thing1.sizeof); - printf("thing2.sizeof: %u\n", thing2.sizeof); + printf("thing1.sizeof: %zu\n", thing1.sizeof); + printf("thing2.sizeof: %zu\n", thing2.sizeof); assert(thing1.sizeof == long.alignof + long.sizeof); assert(thing2.sizeof == 8); C60!(int /*,A60*/ ) container1; - printf("container1.sizeof: %u\n", container1.sizeof); + printf("container1.sizeof: %zu\n", container1.sizeof); assert(container1.sizeof == (void*).sizeof); } @@ -1604,7 +1604,7 @@ template Foo67(alias T) { void Foo67() { - printf("T = '%.*s'\n", T.length, T.ptr); + printf("T = '%.*s'\n", cast(int)T.length, T.ptr); assert(T == "hello"); } } @@ -1620,7 +1620,7 @@ void test67() /******************************************/ template T68(int a) { - int vec[a]; + int[a] vec; } void test68() @@ -1637,7 +1637,7 @@ void test68() size_t printx(string s) { - printf("s = '%.*s'\n", s.length, s.ptr); + printf("s = '%.*s'\n", cast(int)s.length, s.ptr); return s.length; } @@ -1735,8 +1735,8 @@ void test72() static ulong[5] a = [0,1,2,3,4]; static uint[5] b = [0,1,2,3,4]; char[] r; - r = foo72!(ulong[5])(a); printf("%.*s\n", r.length, r.ptr); - r = foo72!(uint[5])(b); printf("%.*s\n", r.length, r.ptr); + r = foo72!(ulong[5])(a); printf("%.*s\n", cast(int)r.length, r.ptr); + r = foo72!(uint[5])(b); printf("%.*s\n", cast(int)r.length, r.ptr); } diff --git a/gcc/testsuite/gdc.test/runnable/template13478.d b/gcc/testsuite/gdc.test/runnable/template13478.d index 7fa7a18aa27..b7b9709a32b 100644 --- a/gcc/testsuite/gdc.test/runnable/template13478.d +++ b/gcc/testsuite/gdc.test/runnable/template13478.d @@ -1,3 +1,5 @@ +// EXTRA_FILES: imports/template13478a.d imports/template13478b.d + /// Tests emission of templates also referenced in speculative contexts. /// Failure triggered with -inline. module template13478; diff --git a/gcc/testsuite/gdc.test/runnable/template2.d b/gcc/testsuite/gdc.test/runnable/template2.d index 3adaeae61ae..fe08a6c0738 100644 --- a/gcc/testsuite/gdc.test/runnable/template2.d +++ b/gcc/testsuite/gdc.test/runnable/template2.d @@ -1,17 +1,16 @@ -// RUNNABLE_PHOBOS_TEST // original post to the D newsgroup: // http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=D&artnum=10554&header // Test to manipulate 3D vectors, in D! // by Sean L Palmer (seanpalmer@directvinternet.com) // This code is released without any warranty. Use at your own risk. import core.stdc.stdio; -import std.math : sqrt; +import core.math : sqrt; template VecTemplate(tfloat, int dim:3) { struct Vector { - tfloat d[dim]; + tfloat[dim] d; version(none) { @@ -21,24 +20,24 @@ template VecTemplate(tfloat, int dim:3) bool opEquals(Vector b) { for (int i=0; i<dim; ++i) if (d[i] != b.d[i]) return false; return true; } // negate (-a) - Vector opNeg() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return + Vector opUnary(string op : "-")() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return r; } // complement (~a) - Vector opCom() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim]; + Vector opUnary(string op : "~")() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim]; d[0] = -d[0]; return r; } // add (a + b) - Vector opAdd(Vector b) { Vector r; r.d[] = d[] + b.d[]; return r; } + Vector opBinary(string op : "+")(Vector b) { Vector r; r.d[] = d[] + b.d[]; return r; } // addto (a += b) - Vector opAddAssign(Vector b) { d[] += b.d[]; return r; } + Vector opOpAssign(string op : "+")(Vector b) { d[] += b.d[]; return r; } // subtract (a - b) - Vector opSub(Vector b) { Vector r; r.d[] = d[] - b.d[]; return r; } + Vector opBinary(string op : "-")(Vector b) { Vector r; r.d[] = d[] - b.d[]; return r; } // multiply by scalar (a * 2.0) - Vector opMul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] + Vector opBinary(string op : "*")(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] * b; return r; } // divide by scalar (a / b) - Vector opDiv(tfloat b) { return *this * (1/b); } + Vector opBinary(string op : "/")(tfloat b) { return *this * (1/b); } // dot product (a * b) - tfloat opMul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i]; + tfloat opBinary(string op : "*")(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i]; return r; } // outer product (a ^ b) //Vector opXor(Vector b) { Vector r; for (int i=0; i<dim; ++i) r += d[i]; return r; } @@ -49,27 +48,27 @@ return r; } const bool opEquals(ref const Vector b) { for (int i=0; i<dim; ++i) if (d[i] != b.d[i]) return false; return true; } // negate (-a) - Vector opNeg() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return + Vector opUnary(string op : "-")() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return r; } // complement (~a) - Vector opCom() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim]; + Vector opUnary(string op : "~")() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim]; d[0] = -d[0]; return r; } // add (a + b) - Vector opAdd(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] + + Vector opBinary(string op : "+")(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] + b.d[i]; return r; } // addto (a += b) - Vector opAddAssign(Vector b) { for (int i=0; i<dim; ++i) d[i] += b.d[i]; return + Vector opOpAssign(string op : "+")(Vector b) { for (int i=0; i<dim; ++i) d[i] += b.d[i]; return this; } // subtract (a - b) - Vector opSub(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] - + Vector opBinary(string op : "-")(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] - b.d[i]; return r; } // multiply by scalar (a * 2.0) - Vector opMul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] * + Vector opBinary(string op : "*")(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] * b; return r; } // divide by scalar (a / b) - Vector opDiv(tfloat b) { return this * (1/b); } + Vector opBinary(string op : "/")(tfloat b) { return this * (1/b); } // dot product (a * b) - tfloat opMul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i]; + tfloat opBinary(string op : "*")(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i]; return r; } // outer product (a ^ b) //Vector opXor(Vector b) { Vector r; for (int i=0; i<dim; ++i) r += d[i]; return r; } @@ -110,6 +109,3 @@ int main(char[][] args) printf("closing\n"); return 0; } - - - diff --git a/gcc/testsuite/gdc.test/runnable/template4.d b/gcc/testsuite/gdc.test/runnable/template4.d index 0381d890ceb..ae02c182814 100644 --- a/gcc/testsuite/gdc.test/runnable/template4.d +++ b/gcc/testsuite/gdc.test/runnable/template4.d @@ -1,4 +1,4 @@ -/* RUNNABLE_PHOBOS_TEST +/* TEST_OUTPUT: --- This actually gets evaluated! @@ -10,7 +10,6 @@ Alias Test instantiated Alias Test instantiated --- */ -import std.stdio; import core.stdc.stdio; /*********************************************************/ @@ -246,31 +245,6 @@ void test6() /*********************************************************/ -template factorial7(float n, cdouble c, string sss, string ttt) -{ - static if (n == 1) - const float factorial7 = 1; - else - const float factorial7 = n * 2; -} - -template bar7(wstring abc, dstring def) -{ - const int x = 3; -} - -void test7() -{ - float f = factorial7!(4.25, 6.8+3i, "hello", null); - printf("%g\n", f); - assert(f == 8.5); - int i = bar7!("abc"w, "def"d).x; - printf("%d\n", i); - assert(i == 3); -} - -/*********************************************************/ - template whale(string walrus) { const char [] whale = walrus; @@ -449,20 +423,15 @@ template horse(string w) void test14() { bool lion = zebra!("a"); - writeln(lion); assert(!lion); lion = zebra!("aqb"); - writeln(lion); assert(lion); lion = horse!("a"); - writeln(lion); assert(lion); lion = horse!("aqb"); - writeln(lion); assert(lion); lion = horse!("ab"); - writeln(lion); assert(!lion); } @@ -529,7 +498,7 @@ void test16() { for (int i=0; i<smallfactorials.length; ++i) { - writefln("%d %d", i, smallfactorials[i]); + printf("%d %d\n", i, smallfactorials[i]); assert(smallfactorials[i] == testtable[i]); } } @@ -621,7 +590,7 @@ template sqrt(real x, real root = x/2, int ntries = 0) void test20() { real x = sqrt!(2); - writefln("%.20g", x); // 1.4142135623730950487 + printf("%.20Lg\n", x); // 1.4142135623730950487 } /*********************************************************/ @@ -642,7 +611,7 @@ uint foo21() void test21() { auto i = foo21(); - writeln(i); + printf("%d\n", i); assert(i == 1871483972); } @@ -826,10 +795,14 @@ void test31() i2s[1] = "Hello"; i2s[5] = "There"; - writeln( i2s.get31(1, "yeh") ); - writeln( i2s.get31(2, "default") ); - writeln( i2s.get31(1) ); - writeln( i2s.get31(2) ); + auto result = i2s.get31(1, "yeh"); + printf("%.*s\n", cast(int)result.length, result.ptr); + result = i2s.get31(2, "default"); + printf("%.*s\n", cast(int)result.length, result.ptr); + result = i2s.get31(1); + printf("%.*s\n", cast(int)result.length, result.ptr); + result = i2s.get31(2); + printf("%.*s\n", cast(int)result.length, result.ptr); } /*********************************************************/ @@ -860,7 +833,7 @@ struct Composer(T) { } return result; } - public void opAddAssign(Fun f) { + public void opOpAssign(string op)(Fun f) if (op == "+") { funs ~= f; } } @@ -904,14 +877,14 @@ void test33() { comp += delegate double (double x) { return x/3.0;}; comp += delegate double (double x) { return x*x;}; comp += (double x) => x + 1.0; - writefln("%f", comp(2.0)); + printf("%f\n", comp(2.0)); // Try function objects Composer!(double) comp2; comp2 += tofp!(div3!(double))(); comp2 += tofp!(square!(double))(); comp2 += tofp!(plus1!(double))(); - writefln("%f", comp2( 2.0)); + printf("%f\n", comp2( 2.0)); } /*********************************************************/ @@ -1035,7 +1008,7 @@ void instantiate4652() } /*********************************************************/ -// 7589 +// https://issues.dlang.org/show_bug.cgi?id=7589 struct T7589(T) { @@ -1062,7 +1035,7 @@ void test39() } /*********************************************************/ -// 6701 +// https://issues.dlang.org/show_bug.cgi?id=6701 uint foo_6701(uint v:0)() { return 1; } uint foo_6701(uint v)() { return 0; } @@ -1076,7 +1049,7 @@ void test6701() } /******************************************/ -// 7469 +// https://issues.dlang.org/show_bug.cgi?id=7469 struct Foo7469a(int x) { } struct Foo7469b(int x) { } @@ -1142,7 +1115,6 @@ int main() test4(); test5(); test6(); - test7(); test8(); test9(); test10(); diff --git a/gcc/testsuite/gdc.test/runnable/template9.d b/gcc/testsuite/gdc.test/runnable/template9.d index 486eb67ab09..63620dd9254 100644 --- a/gcc/testsuite/gdc.test/runnable/template9.d +++ b/gcc/testsuite/gdc.test/runnable/template9.d @@ -1,4 +1,5 @@ -/* RUNNABLE_PHOBOS_TEST +/* +REQUIRED_ARGS: -preview=rvaluerefparam PERMUTE_ARGS: EXTRA_FILES: imports/testmangle.d TEST_OUTPUT: @@ -123,19 +124,23 @@ void test4() /**********************************/ -import std.stdio:writefln; - template foo5(T,S) { void foo5(T t, S s) { - writefln("typeof(T)=",typeid(T)," typeof(S)=",typeid(S)); + const tstr = typeid(T).toString(); + const sstr = typeid(S).toString(); + printf("typeof(T)=%.*s typeof(S)=%.*s\n", + cast(int)tstr.length, tstr.ptr, cast(int)sstr.length, sstr.ptr); } } template bar5(T,S) { void bar5(S s) { - writefln("typeof(T)=",typeid(T),"typeof(S)=",typeid(S)); + const tstr = typeid(T).toString(); + const sstr = typeid(S).toString(); + printf("typeof(T)=%.*s typeof(S)=%.*s\n", + cast(int)tstr.length, tstr.ptr, cast(int)sstr.length, sstr.ptr); } } @@ -200,7 +205,7 @@ void test7() } /**********************************/ -// 5946 +// https://issues.dlang.org/show_bug.cgi?id=5946 template TTest8() { @@ -217,7 +222,7 @@ void test8() } /**********************************/ -// 693 +// https://issues.dlang.org/show_bug.cgi?id=693 template TTest9(alias sym) { @@ -236,7 +241,7 @@ void test9() } /**********************************/ -// 1780 +// https://issues.dlang.org/show_bug.cgi?id=1780 template Tuple1780(Ts ...) { alias Ts Tuple1780; } @@ -253,7 +258,7 @@ void test1780() } /**********************************/ -// 1659 +// https://issues.dlang.org/show_bug.cgi?id=1659 class Foo1659 { } class Bar1659 : Foo1659 { } @@ -267,7 +272,7 @@ void test1659() } /**********************************/ -// 2025 +// https://issues.dlang.org/show_bug.cgi?id=2025 struct S2025 {} void f2025() {} @@ -294,7 +299,7 @@ static assert(Baz2025!S2025 == 1); // 2 -> 1 static assert(Baz2025!f2025 == 2); /**********************************/ -// 3608 +// https://issues.dlang.org/show_bug.cgi?id=3608 template foo3608(T, U){} @@ -318,7 +323,7 @@ void test3608() } /**********************************/ -// 5015 +// https://issues.dlang.org/show_bug.cgi?id=5015 import breaker; @@ -333,7 +338,7 @@ template _ElemType(T) { } /**********************************/ -// 5185 +// https://issues.dlang.org/show_bug.cgi?id=5185 class C5185(V) { @@ -349,7 +354,7 @@ void test5185() } /**********************************/ -// 5893 +// https://issues.dlang.org/show_bug.cgi?id=5893 class C5893 { @@ -372,7 +377,7 @@ void test5893() } /**********************************/ -// 5988 +// https://issues.dlang.org/show_bug.cgi?id=5988 template Templ5988(alias T) { @@ -388,7 +393,7 @@ Templ5988!C5988b foo5988b; // Uncomment version void test5988b() { C5988b!int a; } // Works /**********************************/ -// 6404 +// https://issues.dlang.org/show_bug.cgi?id=6404 // receive only rvalue void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {} @@ -416,7 +421,7 @@ void test6404() } /**********************************/ -// 2246 +// https://issues.dlang.org/show_bug.cgi?id=2246 class A2246(T,d){ T p; @@ -452,7 +457,7 @@ void test2246(){ } /**********************************/ -// 2296 +// https://issues.dlang.org/show_bug.cgi?id=2296 void foo2296(size_t D)(int[D] i...){} void test2296() @@ -461,7 +466,7 @@ void test2296() } /**********************************/ -// 1684 +// https://issues.dlang.org/show_bug.cgi?id=1684 template Test1684( uint memberOffset ){} @@ -494,7 +499,7 @@ void bug4984() { } /***************************************/ -// 2579 +// https://issues.dlang.org/show_bug.cgi?id=2579 void foo2579(T)(T delegate(in Object) dlg) { @@ -506,7 +511,7 @@ void test2579() } /**********************************/ -// 2803 +// https://issues.dlang.org/show_bug.cgi?id=2803 auto foo2803(T)(T t = 0) { return t; } @@ -576,7 +581,7 @@ void test2803() } /**********************************/ -// 6613 +// https://issues.dlang.org/show_bug.cgi?id=6613 alias Tuple6613(T...) = T; @@ -592,13 +597,14 @@ void test6613() } /**********************************/ -// 4953 +// https://issues.dlang.org/show_bug.cgi?id=4953 void bug4953(T = void)(short x) {} static assert(is(typeof(bug4953(3)))); /**********************************/ -// 5886 & 5393 +// https://issues.dlang.org/show_bug.cgi?id=5886 +// https://issues.dlang.org/show_bug.cgi?id=5393 mixin template Foo5886(T) { @@ -666,7 +672,7 @@ void test5393() } /**********************************/ -// 5896 +// https://issues.dlang.org/show_bug.cgi?id=5896 struct X5896 { @@ -691,7 +697,7 @@ void test5896() } /**********************************/ -// 6312 +// https://issues.dlang.org/show_bug.cgi?id=6312 void h6312() {} @@ -715,7 +721,7 @@ void test6312() } /**********************************/ -// 6825 +// https://issues.dlang.org/show_bug.cgi?id=6825 void test6825() { @@ -731,7 +737,7 @@ void test6825() } /**********************************/ -// 6789 +// https://issues.dlang.org/show_bug.cgi?id=6789 template isStaticArray6789(T) { @@ -751,7 +757,7 @@ void test6789() } /**********************************/ -// 2778 +// https://issues.dlang.org/show_bug.cgi?id=2778 struct ArrayWrapper2778(T) { @@ -806,7 +812,7 @@ void test2778get() static struct S { ubyte[] val = [1,2,3]; - @property ref ubyte[] get(){ return val; } + @property ref ubyte[] get() return { return val; } alias get this; } S s; @@ -814,7 +820,7 @@ void test2778get() } /**********************************/ -// 6208 +// https://issues.dlang.org/show_bug.cgi?id=6208 int getRefNonref(T)(ref T s){ return 1; } int getRefNonref(T)( T s){ return 2; } @@ -929,7 +935,7 @@ void test6208c() } /**********************************/ -// 6805 +// https://issues.dlang.org/show_bug.cgi?id=6805 struct T6805 { @@ -941,7 +947,7 @@ struct T6805 static assert(is(T6805.xxx.Type == int)); /**********************************/ -// 6738 +// https://issues.dlang.org/show_bug.cgi?id=6738 struct Foo6738 { @@ -960,7 +966,7 @@ void test6738() } /**********************************/ -// 7498 +// https://issues.dlang.org/show_bug.cgi?id=7498 template IndexMixin(){ void insert(T)(T value){ } @@ -976,7 +982,7 @@ class MultiIndexContainer{ } /**********************************/ -// 6780 +// https://issues.dlang.org/show_bug.cgi?id=6780 @property int foo6780()(){ return 10; } @@ -993,7 +999,7 @@ void test6780() } /**********************************/ -// 6810 +// https://issues.dlang.org/show_bug.cgi?id=6810 int f6810(int n)(int) { return 1;} int f6810(U...)(U) { assert(0); } @@ -1007,7 +1013,7 @@ void test6810() } /**********************************/ -// 6891 +// https://issues.dlang.org/show_bug.cgi?id=6891 struct S6891(int N, T) { @@ -1021,7 +1027,7 @@ void test6891() } /**********************************/ -// 6994 +// https://issues.dlang.org/show_bug.cgi?id=6994 struct Foo6994 { @@ -1044,7 +1050,7 @@ void test6994() } /**********************************/ -// 6764 +// https://issues.dlang.org/show_bug.cgi?id=6764 enum N6764 = 1; //use const for D1 @@ -1064,7 +1070,8 @@ void test6764() } /**********************************/ -// 3467 & 6806 +// https://issues.dlang.org/show_bug.cgi?id=3467 +// https://issues.dlang.org/show_bug.cgi?id=6806 struct Foo3467( uint n ) { @@ -1087,11 +1094,11 @@ void test3467() a1 ~ a2; // line 7, Error } -struct TS6806(size_t n) { pragma(msg, typeof(n)); } +struct TS6806(uint n) { pragma(msg, typeof(n)); } static assert(is(TS6806!(1u) == TS6806!(1))); /**********************************/ -// 4413 +// https://issues.dlang.org/show_bug.cgi?id=4413 struct Foo4413 { @@ -1112,7 +1119,7 @@ void test4413() } /**********************************/ -// 4675 +// https://issues.dlang.org/show_bug.cgi?id=4675 template isNumeric(T) { @@ -1130,7 +1137,7 @@ void test4675() } /**********************************/ -// 5525 +// https://issues.dlang.org/show_bug.cgi?id=5525 template foo5525(T) { @@ -1146,7 +1153,7 @@ void test5525() } /**********************************/ -// 5801 +// https://issues.dlang.org/show_bug.cgi?id=5801 int a5801; void bar5801(T = double)(typeof(a5801) i) {} @@ -1158,7 +1165,7 @@ void test5801() } /**********************************/ -// 5832 +// https://issues.dlang.org/show_bug.cgi?id=5832 struct Bar5832(alias v) {} @@ -1188,7 +1195,7 @@ static assert( isBar5832b!(Bar5832!1234)); static assert(!isBar5832c!(Bar5832!1234)); /**********************************/ -// 2550 +// https://issues.dlang.org/show_bug.cgi?id=2550 template pow10_2550(long n) { @@ -1246,7 +1253,7 @@ void test10() } /**********************************/ -// 3092 +// https://issues.dlang.org/show_bug.cgi?id=3092 template Foo3092(A...) { @@ -1255,7 +1262,7 @@ template Foo3092(A...) static assert(is(Foo3092!(int, "foo") == int)); /**********************************/ -// 7037 +// https://issues.dlang.org/show_bug.cgi?id=7037 struct Foo7037 {} struct Bar7037 { Foo7037 f; alias f this; } @@ -1270,7 +1277,7 @@ void test7037() } /**********************************/ -// 7110 +// https://issues.dlang.org/show_bug.cgi?id=7110 struct S7110 { @@ -1304,7 +1311,7 @@ alias T7110!( (e7110[0]) ) D1; // passes alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110 /**********************************/ -// 7124 +// https://issues.dlang.org/show_bug.cgi?id=7124 template StaticArrayOf(T : E[dim], E, size_t dim) { @@ -1336,7 +1343,7 @@ void test7124() } /**********************************/ -// 7359 +// https://issues.dlang.org/show_bug.cgi?id=7359 bool foo7359(T)(T[] a ...) { @@ -1350,7 +1357,7 @@ void test7359() } /**********************************/ -// 7363 +// https://issues.dlang.org/show_bug.cgi?id=7363 template t7363() { @@ -1382,7 +1389,7 @@ alias S4371!("hi!") t; static if (is(t U == S4371!(U))) { } /**********************************/ -// 7416 +// https://issues.dlang.org/show_bug.cgi?id=7416 void t7416(alias a)() if(is(typeof(a()))) {} @@ -1393,7 +1400,7 @@ void test7416() { } /**********************************/ -// 7563 +// https://issues.dlang.org/show_bug.cgi?id=7563 class Test7563 { @@ -1411,7 +1418,7 @@ void test7563() } /**********************************/ -// 7572 +// https://issues.dlang.org/show_bug.cgi?id=7572 class F7572 { @@ -1430,7 +1437,7 @@ void test7572() } /**********************************/ -// 7580 +// https://issues.dlang.org/show_bug.cgi?id=7580 struct S7580(T) { @@ -1462,7 +1469,7 @@ void test7580() } /**********************************/ -// 7585 +// https://issues.dlang.org/show_bug.cgi?id=7585 extern(C) alias void function() Callback; @@ -1499,7 +1506,7 @@ void test7585() } /**********************************/ -// 7643 +// https://issues.dlang.org/show_bug.cgi?id=7643 template T7643(A...){ alias A T7643; } @@ -1508,7 +1515,7 @@ alias T7643!(long, "x", string, "y") Specs7643; alias T7643!( Specs7643[] ) U7643; // Error: tuple A is used as a type /**********************************/ -// 7671 +// https://issues.dlang.org/show_bug.cgi?id=7671 inout(int)[3] id7671n1 ( inout(int)[3] ); inout( U )[n] id7671x1(U, size_t n)( inout( U )[n] ); @@ -1526,7 +1533,7 @@ void test7671() } /************************************/ -// 7672 +// https://issues.dlang.org/show_bug.cgi?id=7672 T foo7672(T)(T a){ return a; } @@ -1540,7 +1547,7 @@ void test7672(inout(int[]) a = null, inout(int*) p = null) } /**********************************/ -// 7684 +// https://issues.dlang.org/show_bug.cgi?id=7684 U[] id7684(U)( U[] ); shared(U[]) id7684(U)( shared(U[]) ); @@ -1552,7 +1559,7 @@ void test7684() } /**********************************/ -// 7694 +// https://issues.dlang.org/show_bug.cgi?id=7694 void match7694(alias m)() { @@ -1573,7 +1580,7 @@ struct T7694 } /**********************************/ -// 7755 +// https://issues.dlang.org/show_bug.cgi?id=7755 template to7755(T) { @@ -1628,7 +1635,7 @@ void test11b() } /**********************************/ -// 7769 +// https://issues.dlang.org/show_bug.cgi?id=7769 void f7769(K)(inout(K) value){} void test7769() @@ -1637,7 +1644,7 @@ void test7769() } /**********************************/ -// 7812 +// https://issues.dlang.org/show_bug.cgi?id=7812 template A7812(T...) {} @@ -1651,7 +1658,7 @@ template D7812() static assert(!__traits(compiles, D7812!())); /**********************************/ -// 7873 +// https://issues.dlang.org/show_bug.cgi?id=7873 inout(T)* foo(T)(inout(T)* t) { @@ -1671,7 +1678,7 @@ void test7873() } /**********************************/ -// 7933 +// https://issues.dlang.org/show_bug.cgi?id=7933 struct Boo7933(size_t dim){int a;} struct Baa7933(size_t dim) @@ -1690,7 +1697,7 @@ void test7933() } /**********************************/ -// 8094 +// https://issues.dlang.org/show_bug.cgi?id=8094 struct Tuple8094(T...) {} @@ -1728,14 +1735,14 @@ void test12() } /**********************************/ -// 14290 +// https://issues.dlang.org/show_bug.cgi?id=14290 struct Foo14290(int i) {} alias Foo14290a = Foo14290!1; static assert(!is(Foo14290!2 == Foo14290a!T, T...)); /**********************************/ -// 8125 +// https://issues.dlang.org/show_bug.cgi?id=8125 void foo8125(){} @@ -1823,7 +1830,7 @@ void test15() } /**********************************/ -// 8129 +// https://issues.dlang.org/show_bug.cgi?id=8129 class X8129 {} class A8129 {} @@ -1857,7 +1864,7 @@ void test8129() } /**********************************/ -// 8238 +// https://issues.dlang.org/show_bug.cgi?id=8238 void test8238() { @@ -1873,7 +1880,7 @@ void test8238() } /**********************************/ -// 8669 +// https://issues.dlang.org/show_bug.cgi?id=8669 struct X8669 { @@ -1939,7 +1946,7 @@ void test8669() } /**********************************/ -// 8833 +// https://issues.dlang.org/show_bug.cgi?id=8833 template TypeTuple8833(T...) { alias TypeTuple = T; } @@ -1956,7 +1963,7 @@ void test8833() } /**********************************/ -// 8976 +// https://issues.dlang.org/show_bug.cgi?id=8976 void f8976(ref int) { } @@ -1971,17 +1978,17 @@ void h8976()() g8976!()(); } -static assert(! __traits(compiles, h8976!()() ) ); // causes error -static assert(!is(typeof( h8976!()() ))); +static assert( __traits(compiles, h8976!()() ) ); // causes error +static assert(is(typeof( h8976!()() ))); void test8976() { - static assert(! __traits(compiles, h8976!()() ) ); - static assert(!is(typeof( h8976!()() ))); + static assert( __traits(compiles, h8976!()() ) ); + static assert(is(typeof( h8976!()() ))); } /****************************************/ -// 8940 +// https://issues.dlang.org/show_bug.cgi?id=8940 const int n8940; // or `immutable` static this() { n8940 = 3; } @@ -2002,7 +2009,8 @@ void test8940() } /**********************************/ -// 6969 + 8990 +// https://issues.dlang.org/show_bug.cgi?id=6969 +// https://issues.dlang.org/show_bug.cgi?id=8990 class A6969() { alias C6969!() C1; } class B6969 { alias A6969!() A1; } @@ -2013,7 +2021,7 @@ struct B8990(T) { A8990!T* a; } struct C8990 { B8990!C8990* b; } /**********************************/ -// 9018 +// https://issues.dlang.org/show_bug.cgi?id=9018 template Inst9018(alias Template, T) { @@ -2029,7 +2037,7 @@ static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert pass static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert fails /**********************************/ -// 9022 +// https://issues.dlang.org/show_bug.cgi?id=9022 class C9022 { @@ -2074,7 +2082,7 @@ void test9022() } /**********************************/ -// 9026 +// https://issues.dlang.org/show_bug.cgi?id=9026 mixin template node9026() { @@ -2107,7 +2115,7 @@ void test9026() } /**********************************/ -// 9038 +// https://issues.dlang.org/show_bug.cgi?id=9038 mixin template Foo9038() { @@ -2142,7 +2150,7 @@ void test9038() } /**********************************/ -// 9050 +// https://issues.dlang.org/show_bug.cgi?id=9050 struct A9050(T) {} @@ -2159,7 +2167,7 @@ auto foo9050()(A9050!int base) pure auto s9050 = foo9050(A9050!int()); /**********************************/ -// 10936 (dup of 9050) +// https://issues.dlang.org/show_bug.cgi?id=10936 (dup of 9050) struct Vec10936(string s) { @@ -2178,7 +2186,7 @@ struct Vec10936(string s) Vec10936!"" v; /**********************************/ -// 9076 +// https://issues.dlang.org/show_bug.cgi?id=9076 template forward9076(args...) { @@ -2193,7 +2201,7 @@ void test9076() } /**********************************/ -// 9083 +// https://issues.dlang.org/show_bug.cgi?id=9083 template isFunction9083(X...) if (X.length == 1) { @@ -2231,7 +2239,7 @@ class C9083 } /**********************************/ -// 9100 +// https://issues.dlang.org/show_bug.cgi?id=9100 template Id(alias A) { alias Id = A; } template ErrId(alias A) { static assert(0); } @@ -2287,7 +2295,7 @@ void test9100() } /**********************************/ -// 9101 +// https://issues.dlang.org/show_bug.cgi?id=9101 class Node9101 { @@ -2300,7 +2308,7 @@ class Node9101 enum x9101 = __traits(compiles, Node9101.ForwardCtorNoId!()); /**********************************/ -// 9124 +// https://issues.dlang.org/show_bug.cgi?id=9124 struct Foo9124a(N...) { @@ -2353,7 +2361,7 @@ void test9124b() } /**********************************/ -// 9143 +// https://issues.dlang.org/show_bug.cgi?id=9143 struct Foo9143a(bool S, bool L) { @@ -2392,7 +2400,7 @@ void test9143() } /**********************************/ -// 9266 +// https://issues.dlang.org/show_bug.cgi?id=9266 template Foo9266(T...) { @@ -2408,7 +2416,7 @@ void test9266() } /**********************************/ -// 9361 +// https://issues.dlang.org/show_bug.cgi?id=9361 struct Unit9361(A) { @@ -2429,7 +2437,7 @@ void test9361() } /**********************************/ -// 9536 +// https://issues.dlang.org/show_bug.cgi?id=9536 struct S9536 { @@ -2450,7 +2458,7 @@ void test9536() } /**********************************/ -// 9578 +// https://issues.dlang.org/show_bug.cgi?id=9578 template t9578(alias f) { void tf()() { f(); } } @@ -2467,7 +2475,7 @@ void test9578() } /**********************************/ -// 9596 +// https://issues.dlang.org/show_bug.cgi?id=9596 int foo9596a(K, V)(inout( V [K])) { return 1; } int foo9596a(K, V)(inout(shared(V) [K])) { return 2; } @@ -2499,7 +2507,7 @@ void test9596() } /******************************************/ -// 9806 +// https://issues.dlang.org/show_bug.cgi?id=9806 struct S9806a(alias x) { @@ -2535,7 +2543,7 @@ alias S9806c!1 One9806c; alias S9806c!0.Next!() OneAgain9806c; /******************************************/ -// 9837 +// https://issues.dlang.org/show_bug.cgi?id=9837 void test9837() { @@ -2576,7 +2584,7 @@ void test9837() } /******************************************/ -// 9874 +// https://issues.dlang.org/show_bug.cgi?id=9874 bool foo9874() { return true; } void bar9874(T)(T) if (foo9874()) {} // OK @@ -2667,7 +2675,7 @@ void test9885() } /******************************************/ -// 9971 +// https://issues.dlang.org/show_bug.cgi?id=9971 void goo9971()() { @@ -2691,7 +2699,7 @@ void test9971() } /******************************************/ -// 9977 +// https://issues.dlang.org/show_bug.cgi?id=9977 void test9977() { @@ -2730,7 +2738,7 @@ static assert(T8848b!([1:2,3:4]) == [1:2,3:4]); static assert(T8848c!(null) == null); /******************************************/ -// 9990 +// https://issues.dlang.org/show_bug.cgi?id=9990 auto initS9990() { return "hi"; } @@ -2739,7 +2747,7 @@ class C9990(alias init) {} alias SC9990 = C9990!(initS9990); /******************************************/ -// 10067 +// https://issues.dlang.org/show_bug.cgi?id=10067 struct assumeSize10067(alias F) {} @@ -2753,7 +2761,7 @@ template useItemAt10067(size_t idx, T) useItemAt10067!(0, char) mapS10067; /******************************************/ -// 4072 +// https://issues.dlang.org/show_bug.cgi?id=4072 void bug4072(T)(T x) if (is(typeof(bug4072(x)))) @@ -2762,7 +2770,7 @@ void bug4072(T)(T x) static assert(!is(typeof(bug4072(7)))); /******************************************/ -// 10074 +// https://issues.dlang.org/show_bug.cgi?id=10074 template foo10074(F) { @@ -2777,7 +2785,7 @@ bool foo10074(F)(F f) static assert(!is(typeof(foo10074(1)))); /******************************************/ -// 10083 +// https://issues.dlang.org/show_bug.cgi?id=10083 // [a-c] IFTI can find syntactic eponymous member template foo10083a(T) @@ -2867,7 +2875,7 @@ void test10083() } /******************************************/ -// 10134 +// https://issues.dlang.org/show_bug.cgi?id=10134 template ReturnType10134(alias func) { @@ -2914,7 +2922,7 @@ template b10134() pragma(msg, getResultType10134!(a10134!())); /******************************************/ -// 10313 +// https://issues.dlang.org/show_bug.cgi?id=10313 void test10313() { @@ -2933,7 +2941,7 @@ void test10313() } /******************************************/ -// 10498 +// https://issues.dlang.org/show_bug.cgi?id=10498 template triggerIssue10498a() { @@ -2985,7 +2993,7 @@ void test10498b() } /******************************************/ -// 10537 +// https://issues.dlang.org/show_bug.cgi?id=10537 struct Iota10537 { @@ -3010,7 +3018,7 @@ dstring rewriteCode10537(dstring code) } /******************************************/ -// 10558 +// https://issues.dlang.org/show_bug.cgi?id=10558 template Template10558() {} @@ -3029,7 +3037,7 @@ template foo10558(alias T) } /******************************************/ -// 10592 +// https://issues.dlang.org/show_bug.cgi?id=10592 void test10592() { @@ -3058,7 +3066,7 @@ void test10592() } /******************************************/ -// 11242 +// https://issues.dlang.org/show_bug.cgi?id=11242 inout(T[]) fromString11242(T)(inout(char[]) s, T[] dst) { @@ -3072,7 +3080,7 @@ void test11242() } /******************************************/ -// 10811 +// https://issues.dlang.org/show_bug.cgi?id=10811 void foo10811a(R1, R2)(R1, R2) {} template foo10811a(alias pred) { void foo10811a(R1, R2)(R1, R2) {} } @@ -3090,7 +3098,7 @@ void test10811() } /******************************************/ -// 10969 +// https://issues.dlang.org/show_bug.cgi?id=10969 template A10969(T, U...) { alias A10969 = T; } void foo10969(T, U...)(A10969!(T, U) a) {} @@ -3105,7 +3113,7 @@ void test10969() } /******************************************/ -// 11271 +// https://issues.dlang.org/show_bug.cgi?id=11271 struct SmartPtr11271(T) { @@ -3120,7 +3128,7 @@ void test11271() } /******************************************/ -// 11533 +// https://issues.dlang.org/show_bug.cgi?id=11533 version (none) { @@ -3171,7 +3179,7 @@ void test11533() } /******************************************/ -// 11553 +// https://issues.dlang.org/show_bug.cgi?id=11553 struct Pack11553(T ...) { @@ -3226,7 +3234,7 @@ static if ( hl11553!(Pack11553!(5))) { pragma(msg, "All good 2"); } static if (!hl11553!(Pack11553!( ))) { pragma(msg, "All good 3"); } /******************************************/ -// 11818 +// https://issues.dlang.org/show_bug.cgi?id=11818 enum E11818 { e0, e1 } @@ -3244,13 +3252,13 @@ void test11818() } /******************************************/ -// 11843 +// https://issues.dlang.org/show_bug.cgi?id=11843 void test11843() { struct Foo { - int x[string]; + int[string] x; } struct Bar(alias foo) {} @@ -3268,7 +3276,7 @@ void test11843() } /******************************************/ -// 11872 +// https://issues.dlang.org/show_bug.cgi?id=11872 class Foo11872 { @@ -3299,7 +3307,7 @@ void test11872() } /******************************************/ -// 12042 +// https://issues.dlang.org/show_bug.cgi?id=12042 struct S12042 { @@ -3324,7 +3332,7 @@ int test12042() static assert(test12042()); /******************************************/ -// 12077 +// https://issues.dlang.org/show_bug.cgi?id=12077 struct S12077(A) {} @@ -3336,7 +3344,7 @@ alias U12077( T : Base!Args, alias Base, Args...) = Base; static assert(__traits(isSame, U12077!(S12077!int), S12077)); /******************************************/ -// 12262 +// https://issues.dlang.org/show_bug.cgi?id=12262 template Inst12262(T) { int x; } @@ -3347,7 +3355,7 @@ static assert(fqnSym12262!(Inst12262!(Object)) == 2); static assert(fqnSym12262!(Inst12262!(Object).x) == 1); /******************************************/ -// 12264 +// https://issues.dlang.org/show_bug.cgi?id=12264 struct S12264(A) {} @@ -3372,7 +3380,7 @@ static assert(TY12264!(S12264!int) == 2); static assert(TZ12264!(S12264!int) == 2); /******************************************/ -// 12122 +// https://issues.dlang.org/show_bug.cgi?id=12122 enum N12122 = 1; @@ -3385,7 +3393,7 @@ void test12122() } /******************************************/ -// 12186 +// https://issues.dlang.org/show_bug.cgi?id=12186 template map_front12186(fun...) { @@ -3406,7 +3414,7 @@ void test12186() } /******************************************/ -// 12207 +// https://issues.dlang.org/show_bug.cgi?id=12207 void test12207() { @@ -3421,7 +3429,7 @@ void test12207() } /******************************************/ -// 12263 +// https://issues.dlang.org/show_bug.cgi?id=12263 template A12263(alias a) { int x; } template B12263(alias a) { int x; } @@ -3435,7 +3443,7 @@ static assert(fqnSym12263!(A12263!(Object))); static assert(fqnSym12263!(B12263!(Object))); /******************************************/ -// 12290 +// https://issues.dlang.org/show_bug.cgi?id=12290 void test12290() { @@ -3520,7 +3528,7 @@ void test12290() } /******************************************/ -// 12292 +// https://issues.dlang.org/show_bug.cgi?id=12292 void test12292() { @@ -3532,7 +3540,7 @@ void test12292() } /******************************************/ -// 12376 +// https://issues.dlang.org/show_bug.cgi?id=12376 static auto encode12376(size_t sz)(dchar ch) if (sz > 1) { @@ -3545,7 +3553,7 @@ void test12376() } /******************************************/ -// 12447 +// https://issues.dlang.org/show_bug.cgi?id=12447 enum test12447(string str) = str; // [1] string test12447(T...)(T args) if (T.length) { return args[0]; } // [2] @@ -3560,7 +3568,7 @@ static assert(test12447("foo") == "foo"); static assert(test12447!("bar") == "bar"); /******************************************/ -// 12651 +// https://issues.dlang.org/show_bug.cgi?id=12651 alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args; @@ -3569,7 +3577,7 @@ struct S12651(T) { } static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float))); /******************************************/ -// 12719 +// https://issues.dlang.org/show_bug.cgi?id=12719 struct A12719 { @@ -3598,7 +3606,7 @@ struct W12719(R) W12719!int a12719; /******************************************/ -// 12746 +// https://issues.dlang.org/show_bug.cgi?id=12746 template foo12746() { @@ -3620,7 +3628,7 @@ void test12746() } /******************************************/ -// 12748 +// https://issues.dlang.org/show_bug.cgi?id=12748 void foo12748(S, C : typeof(S.init[0]))(S s, C c) { @@ -3632,7 +3640,7 @@ void test12748() } /******************************************/ -// 9708 +// https://issues.dlang.org/show_bug.cgi?id=9708 struct S9708 { @@ -3646,13 +3654,13 @@ void test9708() } /******************************************/ -// 12880 +// https://issues.dlang.org/show_bug.cgi?id=12880 void f12880(T)(in T value) { static assert(is(T == string)); } void test12880() { f12880(string.init); } /******************************************/ -// 13087 +// https://issues.dlang.org/show_bug.cgi?id=13087 struct Vec13087 { @@ -3674,7 +3682,7 @@ template component13087(alias vec, char c) } /******************************************/ -// 13127 +// https://issues.dlang.org/show_bug.cgi?id=13127 /+void test13127(inout int = 0) { @@ -3895,7 +3903,7 @@ void test13127a() } /******************************************/ -// 13159 +// https://issues.dlang.org/show_bug.cgi?id=13159 template maxSize13159(T...) { @@ -3924,7 +3932,7 @@ struct Node13159 } /******************************************/ -// 13180 +// https://issues.dlang.org/show_bug.cgi?id=13180 void test13180() { @@ -3962,7 +3970,7 @@ void test13180() } /******************************************/ -// 13204 +// https://issues.dlang.org/show_bug.cgi?id=13204 struct A13204(uint v) { @@ -3994,7 +4002,7 @@ void test13204() } /******************************************/ -// 8462 (dup of 13204) +// https://issues.dlang.org/show_bug.cgi?id=8462 (dup of 13204) alias FP8462 = void function(C8462.Type arg); @@ -4005,7 +4013,7 @@ class C8462 } /******************************************/ -// 13218 +// https://issues.dlang.org/show_bug.cgi?id=13218 template isCallable13218(T...) if (T.length == 1) @@ -4039,7 +4047,7 @@ struct R13218 } /******************************************/ -// 13219 +// https://issues.dlang.org/show_bug.cgi?id=13219 struct Map13219(V) {} @@ -4059,7 +4067,7 @@ void test13219() } /******************************************/ -// 13223 +// https://issues.dlang.org/show_bug.cgi?id=13223 void test13223() { @@ -4125,7 +4133,7 @@ void test13223a() } /******************************************/ -// 13235 +// https://issues.dlang.org/show_bug.cgi?id=13235 struct Tuple13235(T...) { @@ -4171,7 +4179,7 @@ void test13235() } /******************************************/ -// 13252 +// https://issues.dlang.org/show_bug.cgi?id=13252 alias TypeTuple13252(T...) = T; @@ -4181,9 +4189,6 @@ static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long)); static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float )); static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double)); -static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat )); -static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble)); - static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string )); static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG @@ -4198,7 +4203,7 @@ static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13 static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG /******************************************/ -// 13294 +// https://issues.dlang.org/show_bug.cgi?id=13294 void test13294() { @@ -4218,7 +4223,7 @@ void test13294() f(src, dst); } - // 13351 + // https://issues.dlang.org/show_bug.cgi?id=13351 T add(T)(in T x, in T y) { T z; @@ -4232,7 +4237,7 @@ void test13294() } /******************************************/ -// 13299 +// https://issues.dlang.org/show_bug.cgi?id=13299 struct Foo13299 { @@ -4263,7 +4268,7 @@ void test13299() } /******************************************/ -// 13333 +// https://issues.dlang.org/show_bug.cgi?id=13333 template AliasThisTypeOf13333(T) { @@ -4315,7 +4320,7 @@ void test13333() } /******************************************/ -// 13374 +// https://issues.dlang.org/show_bug.cgi?id=13374 int f13374(alias a)() { return 1; } int f13374(string s)() { return 2; } @@ -4328,7 +4333,7 @@ void test13374() } /******************************************/ -// 14109 +// https://issues.dlang.org/show_bug.cgi?id=14109 string f14109() { return "a"; } string g14109()() { return "a"; } @@ -4340,7 +4345,7 @@ alias Y14109 = S14109!(g14109!()); static assert(is(X14109 == Y14109)); /******************************************/ -// 13378 +// https://issues.dlang.org/show_bug.cgi?id=13378 struct Vec13378(size_t n, T, string as) { @@ -4356,7 +4361,7 @@ void test13378() } /******************************************/ -// 13379 +// https://issues.dlang.org/show_bug.cgi?id=13379 void test13379() { @@ -4395,7 +4400,7 @@ MinType13379!T min13379(T...)(T args) // #4 MinType!uint (speculative && thist } /******************************************/ -// 13417 +// https://issues.dlang.org/show_bug.cgi?id=13417 struct V13417(size_t N, E, alias string AS) { @@ -4412,7 +4417,7 @@ void test13417() } /******************************************/ -// 13484 +// https://issues.dlang.org/show_bug.cgi?id=13484 int foo13484()(void delegate() hi) { return 1; } int foo13484(T)(void delegate(T) hi) { return 2; } @@ -4424,7 +4429,7 @@ void test13484() } /******************************************/ -// 13675 +// https://issues.dlang.org/show_bug.cgi?id=13675 enum E13675; @@ -4440,7 +4445,7 @@ void test13675() } /******************************************/ -// 13694 +// https://issues.dlang.org/show_bug.cgi?id=13694 auto foo13694(T)(string A, T[] G ...) { return 1; } auto foo13694(T)(string A, long E, T[] G ...) { return 2; } @@ -4456,7 +4461,7 @@ void test13694() } /******************************************/ -// 13760 +// https://issues.dlang.org/show_bug.cgi?id=13760 void test13760() { @@ -4468,7 +4473,7 @@ void test13760() } /******************************************/ -// 13714 +// https://issues.dlang.org/show_bug.cgi?id=13714 struct JSONValue13714 { @@ -4497,7 +4502,7 @@ void test13714() } /******************************************/ -// 13807 +// https://issues.dlang.org/show_bug.cgi?id=13807 T f13807(T)(inout(T)[] arr) { @@ -4512,7 +4517,7 @@ void test13807() } /******************************************/ -// 14174 +// https://issues.dlang.org/show_bug.cgi?id=14174 import imports.testmangle; struct Config14174(a, b) {} @@ -4521,6 +4526,7 @@ struct N14174 {} alias defConfig14174 = Config14174!(N14174, N14174); +@safe @nogc pure nothrow void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)() { static assert(equalDemangle(accepter14174a.mangleof, @@ -4528,9 +4534,10 @@ void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)() "accepter14174a"~ "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ "accepter14174a"~ - "FZv")); + "FNaNbNiNfZv")); } +@safe @nogc pure nothrow void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)() { static assert(equalDemangle(accepter14174b.mangleof, @@ -4538,17 +4545,18 @@ void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)() "accepter14174b"~ "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ "accepter14174b"~ - "FZv")); + "FNaNbNiNfZv")); } void test14174() { - accepter14174a!()(); // ok - accepter14174b(); // error + accepter14174a!()(); + + accepter14174b!()(); } /******************************************/ -// 14836 +// https://issues.dlang.org/show_bug.cgi?id=14836 template a14836x(alias B, C...) { @@ -4571,7 +4579,7 @@ void test14836() } /******************************************/ -// 14357 +// https://issues.dlang.org/show_bug.cgi?id=14357 template Qux14357(T : U*, U : V*, V) { @@ -4583,7 +4591,7 @@ template Qux14357(T : U*, U : V*, V) static assert(!__traits(compiles, Qux14357!(float**, int*))); /******************************************/ -// 14481 +// https://issues.dlang.org/show_bug.cgi?id=14481 template someT14481(alias e) { @@ -4602,7 +4610,7 @@ struct Hoge14481 } /******************************************/ -// 14520 +// https://issues.dlang.org/show_bug.cgi?id=14520 template M14520(alias a) { enum M14520 = 1; } template M14520(string s) { enum M14520 = 2; } @@ -4616,7 +4624,7 @@ static assert(M14520!f14520b == 1); static assert(M14520!f14520c == 1); /******************************************/ -// 14568 +// https://issues.dlang.org/show_bug.cgi?id=14568 struct Interval14568() { @@ -4659,7 +4667,8 @@ template SubOps14568(Args...) struct Nat14568 { mixin SubOps14568!(null); } /******************************************/ -// 14603, 14604 +// https://issues.dlang.org/show_bug.cgi?id=14603 +// https://issues.dlang.org/show_bug.cgi?id=14604 struct S14603 { @@ -4683,7 +4692,7 @@ alias c14604 = Id14604!(S14604.opDispatch!"go"); // ok alias d14604 = Id14604!(S14604.go); // issue 14604, 'Error: template instance opDispatch!"go" cannot resolve forward reference' /******************************************/ -// 14735 +// https://issues.dlang.org/show_bug.cgi?id=14735 enum CS14735 { yes, no } @@ -4707,7 +4716,7 @@ void test14735() } /******************************************/ -// 14743 +// https://issues.dlang.org/show_bug.cgi?id=14743 class A14743 { @@ -4716,7 +4725,7 @@ class A14743 } /******************************************/ -// 14802 +// https://issues.dlang.org/show_bug.cgi?id=14802 void test14802() { @@ -4756,7 +4765,7 @@ void test14802() } /******************************************/ -// 14886 +// https://issues.dlang.org/show_bug.cgi?id=14886 void test14886() { @@ -4778,9 +4787,9 @@ void test14886() } /******************************************/ -// 15156 +// https://issues.dlang.org/show_bug.cgi?id=15156 -// 15156 +// https://issues.dlang.org/show_bug.cgi?id=15156 auto f15116a(T)(string s, string arg2) { return 1; } auto f15116b(T)(int i, string arg2) { return 2; } @@ -4798,7 +4807,7 @@ void test15116() } /******************************************/ -// 15152 +// https://issues.dlang.org/show_bug.cgi?id=15152 void test15152() { @@ -4814,7 +4823,7 @@ void test15152() } /******************************************/ -// 15352 +// https://issues.dlang.org/show_bug.cgi?id=15352 struct S15352(T, T delegate(uint idx) supplier) { @@ -4844,7 +4853,7 @@ void test15352() } /******************************************/ -// 15623 +// https://issues.dlang.org/show_bug.cgi?id=15623 struct WithFoo15623a { void foo() {} } struct WithFoo15623b { void foo() {} } @@ -4875,7 +4884,7 @@ static assert( __traits(compiles, { alias Baz = CallsFoo15623!WithFoo15623d; ret static assert(!__traits(compiles, { alias Baz = CallsFoo15623!WithoutFoo15623d; return Baz.init; }())); /******************************************/ -// 15781 +// https://issues.dlang.org/show_bug.cgi?id=15781 void test15781() { @@ -4898,6 +4907,133 @@ void test15781() } /******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=16042 + +struct Foo16042 {} + +auto map16042(alias func, T)(T t) +{ + return func(t); +} + +auto toChars16042(R)(R r) if (is(R == int[])) +{ + Foo16042 f; + assert(toChars16042(f) == 1); // OK + assert(map16042!(toChars16042)(f) == 1); // OK <- NG + assert(map16042!((toChars16042))(f) == 1); // OK +} + +auto toChars16042(Foo16042 f) +{ + return 1; +} + +void test16042() +{ + [1].toChars16042(); +} + +// --- + +auto fn16042(R)(R r) if (is(R == int[])) {} +auto fn16042(Foo16042 f) { return 1; } + +struct Namespace16042 +{ + alias fn = fn16042!(int[]); +} + +void test16042b() +{ + Foo16042 f; + + with (Namespace16042) + { + static assert(!__traits(compiles, fn(f))); // NG + static assert(!__traits(compiles, map16042!(fn)(f))); // should be NG -> actually NG + static assert(!__traits(compiles, map16042!((fn))(f))); // NG + } +} + +/******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15243 + +struct S15243(Types...) +{ + void apply1(U)(U delegate(Types[0]) f0) {} + + void apply2(U)(U delegate(Types) f0) {} + + void apply3(U)(U delegate(Types[1..$]) f0) {} +} + +void test15243() +{ + int f1(int) { return 0; } + int f2(int, long) { return 0; } + int f3(long, string) { return 0; } + + S15243!(int) s1; + s1.apply1(&f1); + s1.apply2(&f1); + + S15243!(int, long) s2; + s2.apply2(&f2); + + S15243!(int, long, string) s3; + s3.apply3(&f3); +} + +/******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15653 + +alias TypeTuple15653(T...) = T; + +void test15653() +{ + void foo(U, T)(const T x) { static assert(is(T == U)); } + void bar(U, T)(immutable T x) { static assert(is(T == U)); } + + struct X { int a; long[2] b; } + struct Y { int* a; long[] b; } + + foreach (U; TypeTuple15653!( byte, short, int, long, + ubyte, ushort, uint, ulong, + float, double, real, + void delegate(), + int[2], X, X[2])) + { + foo!U(U.init); // OK + bar!U(U.init); // Was error, now OK + + U u; + foo!U(u); // OK + bar!U(u); // Was error, now OK + } + + foreach (U; TypeTuple15653!(void*, int**, long[], double*[2])) + { + foo!U(U.init); // OK + bar!U(U.init); // Was error, now OK + + U u; + foo!U(u); + static assert(!__traits(compiles, bar!U(u)), U.stringof); + } + + foreach (U; TypeTuple15653!(Object, Y, Y[2], int[int])) + { + foo!U(U.init); // OK + static assert(!__traits(compiles, bar!U(U.init)), U.stringof); + + U u; + foo!U(u); // OK + static assert(!__traits(compiles, bar!U(u)), U.stringof); + } +} + +/******************************************/ int main() { @@ -5011,6 +5147,10 @@ int main() test14735(); test14802(); test15116(); + test16042(); + test16042b(); + test15243(); + test15653(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test10.d b/gcc/testsuite/gdc.test/runnable/test10.d index 671a61a661e..b9f8885696a 100644 --- a/gcc/testsuite/gdc.test/runnable/test10.d +++ b/gcc/testsuite/gdc.test/runnable/test10.d @@ -1,4 +1,10 @@ -// EXTRA_SOURCES: imports/test10a.d +/* +EXTRA_SOURCES: imports/test10a.d +RUN_OUTPUT: +--- +it is 32 +--- +*/ import imports.test10a; diff --git a/gcc/testsuite/gdc.test/runnable/test10378.d b/gcc/testsuite/gdc.test/runnable/test10378.d index f83ece18bbf..8ad457a5b5e 100644 --- a/gcc/testsuite/gdc.test/runnable/test10378.d +++ b/gcc/testsuite/gdc.test/runnable/test10378.d @@ -1,4 +1,4 @@ - +// EXTRA_FILES: imports/bar10378.d int writeln() { return 3; } struct S { diff --git a/gcc/testsuite/gdc.test/runnable/test10619.d b/gcc/testsuite/gdc.test/runnable/test10619.d new file mode 100644 index 00000000000..4156289fdd7 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test10619.d @@ -0,0 +1,38 @@ +/* +https://issues.dlang.org/show_bug.cgi?id=10619 + +PERMUTE_ARGS: +RUN_OUTPUT: +--- +1 +2 +3 +4 +--- +*/ + +void main() +{ + { + int x = 1; + print!x(); + } + { + int x = 2; + print!x(); + } + { + static int y = 3; + print!y(); + } + { + static int y = 4; + print!y(); + } +} + +void print(alias symbol)() +{ + import core.stdc.stdio : printf; + printf("%d\n", symbol); +} diff --git a/gcc/testsuite/gdc.test/runnable/test10736.d b/gcc/testsuite/gdc.test/runnable/test10736.d index 55b6f539887..0b70606faff 100644 --- a/gcc/testsuite/gdc.test/runnable/test10736.d +++ b/gcc/testsuite/gdc.test/runnable/test10736.d @@ -1,5 +1,12 @@ -// EXTRA_SOURCES: imports/test10736a.d -// EXTRA_SOURCES: imports/test10736b.d +/* +EXTRA_SOURCES: imports/test10736a.d +EXTRA_SOURCES: imports/test10736b.d +EXTRA_FILES: imports/test10736c.d +RUN_OUTPUT: +--- +success +--- +*/ import imports.test10736a; import imports.test10736b; diff --git a/gcc/testsuite/gdc.test/runnable/test10942.d b/gcc/testsuite/gdc.test/runnable/test10942.d index 0d48946383d..8c45c203dbb 100644 --- a/gcc/testsuite/gdc.test/runnable/test10942.d +++ b/gcc/testsuite/gdc.test/runnable/test10942.d @@ -1,16 +1,22 @@ -// RUNNABLE_PHOBOS_TEST // REQUIRED_ARGS: -g -import std.string; - string getEnum(size_t count) { string en; en ~= "enum KeyCode\n { \n"; - foreach (i; 0 .. count) + foreach (i; 1 .. count + 1) { - en ~= format(" memb_%s = %s,\n", i+1, i+1); + char[4] buffer; + int start = buffer.length; + + while (i > 0) + { + buffer[--start] = cast(char) ('0' + (i % 10)); + i /= 10; + } + char[] id = buffer[start .. $]; + en ~= "memb_" ~ id ~ " = " ~ id ~ ",\n"; } en ~= "} "; diff --git a/gcc/testsuite/gdc.test/runnable/test11.d b/gcc/testsuite/gdc.test/runnable/test11.d index 0d916c1af6c..abaae37a15f 100644 --- a/gcc/testsuite/gdc.test/runnable/test11.d +++ b/gcc/testsuite/gdc.test/runnable/test11.d @@ -1,5 +1,5 @@ -// RUNNABLE_PHOBOS_TEST // REQUIRED_ARGS: +// EXTRA_SOURCES: imports/std11file.d extern(C) int printf(const char*, ...); extern(C) size_t strlen(const char*); @@ -531,14 +531,14 @@ struct NODE27 { shared(NODE27) *next; } -static shared NODE27 nodetbl[3] = +static shared NODE27[3] nodetbl = [ { 0,cast(shared(NODE27)*)nodetbl + 1}, { 0,cast(shared(NODE27)*)nodetbl + 2}, { 0,null} ]; -static shared NODE27 nodetbl2[3] = [ +static shared NODE27[3] nodetbl2 = [ { 0,&nodetbl2[1]}, { 0,&nodetbl2[2]}, { 0,null} @@ -682,7 +682,7 @@ void test35() try { alias Foo35!( Bar35 ) filter; } catch (Exception e) { - printf( "Exception %.*s", e.msg.length, e.msg.ptr ); + printf( "Exception %.*s", cast(int)e.msg.length, e.msg.ptr ); } finally { printf( "Done0." ); } @@ -886,7 +886,7 @@ void test45() char[5] foo; foo[] = "hello"; - printf("'%.*s'\n", foo.length, foo.ptr); + printf("'%.*s'\n", cast(int)foo.length, foo.ptr); func45(cast(string)foo); } @@ -1182,15 +1182,15 @@ void test62() class A63 { - private import std.file; - alias std.file.getcwd getcwd; + private import imports.std11file; + alias imports.std11file.getcwd getcwd; } void test63() { A63 f = new A63(); auto s = f.getcwd(); - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); } @@ -1229,7 +1229,7 @@ void test65() } /**************************************/ -// 8809 +// https://issues.dlang.org/show_bug.cgi?id=8809 void test8809() { @@ -1298,7 +1298,7 @@ void test8809() } /**************************************/ -// 9734 +// https://issues.dlang.org/show_bug.cgi?id=9734 void test9734() { diff --git a/gcc/testsuite/gdc.test/runnable/test11447c.d b/gcc/testsuite/gdc.test/runnable/test11447c.d index d09e3d2098f..ecec3e5c2c9 100644 --- a/gcc/testsuite/gdc.test/runnable/test11447c.d +++ b/gcc/testsuite/gdc.test/runnable/test11447c.d @@ -1,6 +1,7 @@ // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/c11447.d -// PERMUTE_ARGS: -allinst -w -debug -g +// REQUIRED_ARGS: -w +// PERMUTE_ARGS: -allinst -debug -g import imports.c11447; diff --git a/gcc/testsuite/gdc.test/runnable/test11863.d b/gcc/testsuite/gdc.test/runnable/test11863.d index c1285b3bef7..f6446aae725 100644 --- a/gcc/testsuite/gdc.test/runnable/test11863.d +++ b/gcc/testsuite/gdc.test/runnable/test11863.d @@ -1,6 +1,6 @@ // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/std11863conv.d -// EXTRA_FILES: imports/std11863format.d +// EXTRA_FILES: imports/std11863bitmanip.d imports/std11863format.d import imports.std11863conv; diff --git a/gcc/testsuite/gdc.test/runnable/test11934.d b/gcc/testsuite/gdc.test/runnable/test11934.d new file mode 100644 index 00000000000..4ab65d23eb2 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test11934.d @@ -0,0 +1,22 @@ +void main() +{ + struct Struct11934 + { + this(int i) { instances++; } + this(this) { instances++; } + ~this() { instances--; } + static size_t instances = 0; + } + + struct Range11934 + { + void popFront() { cnt++; } + @property front() { return Struct11934(0); } + @property empty() { return cnt >= 10; } + size_t cnt; + } + + foreach(ref i; Range11934()) { } + + assert(Struct11934.instances == 0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test12.d b/gcc/testsuite/gdc.test/runnable/test12.d index eb7e422c28b..dac4ed647b0 100644 --- a/gcc/testsuite/gdc.test/runnable/test12.d +++ b/gcc/testsuite/gdc.test/runnable/test12.d @@ -1,4 +1,3 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g extern(C) int printf(const char*, ...); @@ -156,7 +155,7 @@ int[] fun(int i) { assert(result[0] == 2); } - body + do { char result; int[] res = new int[10]; @@ -312,15 +311,15 @@ void test12() class A13 { - int opShl(char* v) { return 1; } - int opShl(string v) { return 2; } + int opBinary(string op : "<<")(char* v) { return 1; } + int opBinary(string op : "<<")(string v) { return 2; } } void test13() { A13 a = new A13(); int i; - i = a.opShl(cast(string)""); + i = a << cast(string) ""; assert(i == 2); i = a << cast(string)""; assert(i == 2); @@ -366,32 +365,32 @@ union U6 void test14() { - printf("%d %d %d\n", U1.a.offsetof, U1.b.offsetof, U1.sizeof); + printf("%zd %zd %zd\n", U1.a.offsetof, U1.b.offsetof, U1.sizeof); assert(U1.a.offsetof == 0); assert(U1.b.offsetof == 0); assert(U1.sizeof == 4); - printf("%d %d %d\n", U2.a.offsetof, U2.b.offsetof, U2.sizeof); + printf("%zd %zd %zd\n", U2.a.offsetof, U2.b.offsetof, U2.sizeof); assert(U2.a.offsetof == 0); assert(U2.b.offsetof == 0); assert(U2.sizeof == 8); - printf("%d %d %d\n", U3.a.offsetof, U3.b.offsetof, U3.sizeof); + printf("%zd %zd %zd\n", U3.a.offsetof, U3.b.offsetof, U3.sizeof); assert(U3.a.offsetof == 0); assert(U3.b.offsetof == 0); assert(U3.sizeof == 8); - printf("%d %d %d\n", U4.a.offsetof, U4.b.offsetof, U4.sizeof); + printf("%zd %zd %zd\n", U4.a.offsetof, U4.b.offsetof, U4.sizeof); assert(U4.a.offsetof == 0); assert(U4.b.offsetof == 0); assert(U4.sizeof == 4); - printf("%d %d %d\n", U5.a.offsetof, U5.b.offsetof, U5.sizeof); + printf("%zd %zd %zd\n", U5.a.offsetof, U5.b.offsetof, U5.sizeof); assert(U5.a.offsetof == 0); assert(U5.b.offsetof == 0); assert(U5.sizeof == 8); - printf("%d %d %d\n", U6.a.offsetof, U6.b.offsetof, U6.sizeof); + printf("%zd %zd %zd\n", U6.a.offsetof, U6.b.offsetof, U6.sizeof); assert(U6.a.offsetof == 0); assert(U6.b.offsetof == 0); assert(U6.sizeof == 8); @@ -434,7 +433,7 @@ class Cout17 printf("%d",x); return this; } - alias set opShl; + alias opBinary(string op : "<<") = set; } void test17() @@ -671,9 +670,9 @@ void test31() printf("%s\n", foo.ptr); auto s = typeid(typeof(foo.ptr)).toString(); - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); s = typeid(char*).toString(); - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(typeid(typeof(foo.ptr)) == typeid(immutable(char)*)); } @@ -689,7 +688,7 @@ class Qwert32 void foo() { - printf("yuiop = %d, asdfg = %d\n", Qwert32.yuiop.offsetof, Qwert32.asdfg.offsetof); + printf("yuiop = %zd, asdfg = %zd\n", Qwert32.yuiop.offsetof, Qwert32.asdfg.offsetof); version(D_LP64) { assert(Qwert32.yuiop.offsetof == 16); @@ -778,7 +777,7 @@ void test36() { A36 a = new A36; - printf("A36.sizeof = %d\n", a.classinfo.initializer.length); + printf("A36.sizeof = %zd\n", a.classinfo.initializer.length); printf("%d\n", a.s); printf("%d\n", a.a); printf("%d\n", a.b); @@ -819,7 +818,7 @@ class Foo38 { static void display_name() { - printf("%.*s\n", Object.classinfo.name.length, Object.classinfo.name.ptr); + printf("%.*s\n", cast(int)Object.classinfo.name.length, Object.classinfo.name.ptr); assert(Object.classinfo.name == "object.Object"); assert(super.classinfo.name == "object.Object"); assert(this.classinfo.name == "test12.Foo38"); @@ -951,31 +950,28 @@ struct Shell const int opCmp(ref const Shell s) { - import std.algorithm; - return std.algorithm.cmp(this.str, s.str); + // Obviously not Unicode-aware... + foreach (const i, const a; this.str) + { + const b = s.str[i]; + if (a < b) return -1; + if (a > b) return 1; + } + + if (this.str.length < s.str.length) return -1; + if (this.str.length > s.str.length) return 1; + return 0; } } void test45() { - import std.algorithm; - - Shell[3] a; - - a[0].str = "hello"; - a[1].str = "betty"; - a[2].str = "fred"; - - a[].sort; - - foreach (Shell s; a) - { - printf("%.*s\n", s.str.length, s.str.ptr); - } + Shell a = Shell("hello"); + Shell b = Shell("betty"); + Shell c = Shell("fred"); - assert(a[0].str == "betty"); - assert(a[1].str == "fred"); - assert(a[2].str == "hello"); + assert(a > b); + assert(b < c); } /**************************************/ @@ -1153,7 +1149,7 @@ void test55() void writefln(string s) { - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); } void test58() diff --git a/gcc/testsuite/gdc.test/runnable/test12486.d b/gcc/testsuite/gdc.test/runnable/test12486.d new file mode 100644 index 00000000000..a0a6e2c4152 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test12486.d @@ -0,0 +1,18 @@ +module test12486; + +struct S { enum a = 1; } // or `const` but not for all types + +S f(ref int i) +{ + ++i; + return S(); +} + +void main() +{ + int i = 2; + assert(f(i).a == 1); + // ensure that f(i) was actually called, even though + // a is a statically known property of the returned type + assert(i == 3); +} diff --git a/gcc/testsuite/gdc.test/runnable/test14874.d b/gcc/testsuite/gdc.test/runnable/test14874.d index 470a93c60ff..fa69211e18f 100644 --- a/gcc/testsuite/gdc.test/runnable/test14874.d +++ b/gcc/testsuite/gdc.test/runnable/test14874.d @@ -1,38 +1,38 @@ -// REQUIRED_ARGS: -dip25
-
-template indexOfReturn(T...)
-{
- static if (T.length == 0)
- {
- enum indexOfReturn = -1;
- }
- else static if (T[$ - 1] == "return")
- {
- enum indexOfReturn = T.length - 1;
- }
- else
- {
- enum indexOfReturn = indexOfReturn!(T[0..$-1]);
- }
-}
-
-struct Test
-{
- int n;
-
- ref int getN() return
- {
- return n;
- }
-
- int getNNonReturn()
- {
- return n;
- }
-}
-
-void main()
-{
- assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getN)) != -1);
- assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getNNonReturn)) == -1);
-}
+// REQUIRED_ARGS: + +template indexOfReturn(T...) +{ + static if (T.length == 0) + { + enum indexOfReturn = -1; + } + else static if (T[$ - 1] == "return") + { + enum indexOfReturn = T.length - 1; + } + else + { + enum indexOfReturn = indexOfReturn!(T[0..$-1]); + } +} + +struct Test +{ + int n; + + ref int getN() return + { + return n; + } + + int getNNonReturn() + { + return n; + } +} + +void main() +{ + assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getN)) != -1); + assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getNNonReturn)) == -1); +} diff --git a/gcc/testsuite/gdc.test/runnable/test15.d b/gcc/testsuite/gdc.test/runnable/test15.d index 405171e44ae..222742c4080 100644 --- a/gcc/testsuite/gdc.test/runnable/test15.d +++ b/gcc/testsuite/gdc.test/runnable/test15.d @@ -1,13 +1,10 @@ -// RUNNABLE_PHOBOS_TEST -// REQUIRED_ARGS: -// EXTRA_FILES: extra-files/test15.txt +/* +REQUIRED_ARGS: -Jrunnable/extra-files +EXTRA_FILES: extra-files/test15.txt +*/ -import std.array; -import core.stdc.math : cos, fabs, sin, sqrt; +import core.math; import core.vararg; -import std.math: rndtol, rint; -import std.string; -import std.stdio : File; extern (C) { @@ -46,9 +43,9 @@ void test6() void test7() { string s = `hello"there'you`; - printf("s = '%.*s'\n", s.length, s.ptr); + printf("s = '%.*s'\n", cast(int)s.length, s.ptr); assert(s == "hello\"there'you"); - ubyte[] b = cast(ubyte[])x"8B 7D f4 0d"; + ubyte[] b = cast(ubyte[])"\x8B\x7D\xf4\x0d"; for (int i = 0; i < b.length; i++) printf("b[%d] = x%02x\n", i, b[i]); assert(b.length == 4); @@ -95,7 +92,7 @@ struct Pair return this; } - Pair opDiv(Pair other) + Pair opBinary(string op)(Pair other) if (op == "/") { Pair result; @@ -206,8 +203,8 @@ class A15 List2.rehash; } private: - int delegate(in int arg1) List1[char[]]; - int List2[char []]; + int delegate(in int arg1)[char[]] List1; + int[char []] List2; } void test15() @@ -223,7 +220,7 @@ void test16() uint c = 200000; while (c--) a ~= 'x'; - //printf("a = '%.*s'\n", a.length, a.ptr); + //printf("a = '%.*s'\n", cast(int)a.length, a.ptr); } @@ -266,7 +263,7 @@ void test19() int foo20(string s,char d) { return 1; } int foo20(string s,double d) { return 2; } -int foo20(string s,cdouble d) { return 3; } +int foo20(string s,long d) { return 3; } void test20() { @@ -280,10 +277,47 @@ void test20() void test21() { + // Minimalistic byLine implementation + static struct Lines + { + private string text, line; + this(string text) + { + this.text = text; + popFront(); + } + + bool empty() const { return text == ""; } + + string front() const + { + assert(!empty); + return line; + } + + void popFront() + { + assert(!empty); + foreach (const idx; 0 .. text.length) + { + if (text[idx] == '\n') + { + line = text[0..idx]; + text = text[idx + 1..$]; + return; + } + } + + line = text; + text = null; + } + } + + static immutable string file = import(`test15.txt`); + int[string] esdom; - auto f = File("runnable/extra-files/test15.txt", "r"); - foreach(it; f.byLine()) + foreach(it; Lines(file)) esdom[it.idup] = 0; esdom.rehash; @@ -362,16 +396,16 @@ void test25() void test26() { - string[] instructions = std.array.split("a;b;c", ";"); + string[] instructions =[ "a", "b", "c" ]; foreach(ref string instr; instructions) { - std.string.strip(instr); + instr = instr[]; } foreach(string instr; instructions) { - printf("%.*s\n", instr.length, instr.ptr); + printf("%.*s\n", cast(int)instr.length, instr.ptr); } } @@ -402,7 +436,7 @@ void test27() void foo28(ClassInfo ci) { - printf("%.*s\n", ci.name.length, ci.name.ptr); + printf("%.*s\n", cast(int)ci.name.length, ci.name.ptr); static int i; switch (i++) @@ -786,7 +820,7 @@ class C44 void test44() { C44 c= new C44(); - printf("%.*s\n", c.arrArr[0].length, c.arrArr[0].ptr); + printf("%.*s\n", cast(int)c.arrArr[0].length, c.arrArr[0].ptr); assert(c.arrArr[0] == "foo"); } @@ -815,11 +849,11 @@ union A46 void test46() { A46 a; - printf("%d\n", cast(byte*)&a.c - cast(byte*)&a); - printf("%d\n", cast(byte*)&a.s - cast(byte*)&a); - printf("%d\n", cast(byte*)&a.l - cast(byte*)&a); - printf("%d\n", cast(byte*)&a.a - cast(byte*)&a); - printf("%d\n", cast(byte*)&a.f - cast(byte*)&a); + printf("%td\n", cast(byte*)&a.c - cast(byte*)&a); + printf("%td\n", cast(byte*)&a.s - cast(byte*)&a); + printf("%td\n", cast(byte*)&a.l - cast(byte*)&a); + printf("%td\n", cast(byte*)&a.a - cast(byte*)&a); + printf("%td\n", cast(byte*)&a.f - cast(byte*)&a); assert(cast(byte*)&a.c == cast(byte*)&a); assert(cast(byte*)&a.s == cast(byte*)&a); @@ -1044,9 +1078,9 @@ void test56() /************************************/ -void det(float mat[][]) +void det(float[][] mat) { - float newmat[][]; + float[][] newmat; size_t i = newmat[0 .. (mat.length - 1)].length; } @@ -1099,7 +1133,6 @@ void test59() class Foo60 { int x; -static: this() { x = 3; } ~this() { } } @@ -1117,16 +1150,13 @@ void test60() class StdString { - alias std.string.format toString; + alias nearest = core.math.rint; } void test61() { - int i = 123; StdString g = new StdString(); - string s = g.toString("%s", i); - printf("%.*s\n", s.length, s.ptr); - assert(s == "123"); + assert(g.nearest(123.1) == 123); } @@ -1366,6 +1396,38 @@ void test72() assert(foos.length == 1); } +/************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19758 + +void test19758() +{ + byte[1] a = [1]; + int b = 0; + + // If delete this 4 lines, the result is correct. + if (a[b] == 0) + { + a[b] = 0; + if (1 << b) { } + } + + if ((a[b] & 0xFF) == 0) + { + assert((a[b] & 0xFF) == 0); + } +} + +/************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19968 + +@safe void test19968() +{ + int[2] array = [16, 678]; + union U { int i; bool b; } + U u; + u.i = 0xDEADBEEF; + assert(array[u.b] == 678); +} /************************************/ @@ -1436,6 +1498,8 @@ int main() test70(); test71(); test72(); + test19758(); + test19968(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test15079.d b/gcc/testsuite/gdc.test/runnable/test15079.d index 5316d73e2ca..e0fea972ea4 100644 --- a/gcc/testsuite/gdc.test/runnable/test15079.d +++ b/gcc/testsuite/gdc.test/runnable/test15079.d @@ -1,3 +1,4 @@ +// EXTRA_FILES: imports/a15079.d module test15079; import imports.a15079; diff --git a/gcc/testsuite/gdc.test/runnable/test15373.d b/gcc/testsuite/gdc.test/runnable/test15373.d new file mode 100644 index 00000000000..13144b75e45 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test15373.d @@ -0,0 +1,15 @@ +// https://issues.dlang.org/show_bug.cgi?id=15373 + +// Using `typeid` on an `extern(C++) class` type is fine as it is evaluated at compile-time + +// Using `typeid` on an `extern(C++) class` instance is not ok because `extern(C++) class` +// instances are not rooted in `Object`. See test/fail_compilation/test15373.d + +extern(C++) class C +{ } + +void main() +{ + auto Cti = typeid(C); + assert(Cti.name == "test15373.C"); +} diff --git a/gcc/testsuite/gdc.test/runnable/test15568.d b/gcc/testsuite/gdc.test/runnable/test15568.d new file mode 100644 index 00000000000..d21ede26d09 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test15568.d @@ -0,0 +1,58 @@ +// REQUIRED_ARGS: -unittest -main -O +// https://issues.dlang.org/show_bug.cgi?id=15568 + +auto filter(alias pred)(D[]) +{ + struct FilterResult + { + void popFront() + { + pred(null); + } + + D[] array() + { + return null; + } + } + return FilterResult(); +} + +class A +{ + B foo(C c, D[] ds, bool f) + in + { + assert(c !is null); + } + do + { + D[] ds2 = ds.filter!(a => c).array; + + return new B(ds2, f); + } +} + +class B +{ + this(D[], bool) + { + } +} + +class C +{ +} + +struct D +{ +} + +unittest +{ + auto a = new A; + C c = new C; + + a.foo(c, null, false); +} + diff --git a/gcc/testsuite/gdc.test/runnable/test15624.d b/gcc/testsuite/gdc.test/runnable/test15624.d new file mode 100644 index 00000000000..792757932e4 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test15624.d @@ -0,0 +1,51 @@ +/* PERMUTE_ARGS: + */ + +// https://issues.dlang.org/show_bug.cgi?id=15624 + +struct Foo { + int x; + int opApply(int delegate(int, string, string) @safe dg) @safe { + x = 1; + return 0; + } + int opApply(int delegate(int, string, string) @system dg) @system { + x = 2; + return 0; + } +} + +void testSafe() @safe { + Foo foo; + foreach (i, k, v; foo) { + } + assert(foo.x == 1); +} + +void testSystem() @system { + Foo foo; + foreach (i, k, v; foo) { + } + assert(foo.x == 2); +} + +void test() @system +{ + Foo f; + + int dgsafe (int x, string s, string t) @safe { return 1; } + int dgsystem(int x, string s, string t) @system { return 1; } + + f.opApply(&dgsafe); + assert(f.x == 1); + f.opApply(&dgsystem); + assert(f.x == 2); +} + +int main() +{ + testSafe(); + testSystem(); + test(); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test16047.d b/gcc/testsuite/gdc.test/runnable/test16047.d new file mode 100644 index 00000000000..eff2db3c7c4 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test16047.d @@ -0,0 +1,17 @@ +// https://issues.dlang.org/show_bug.cgi?id=16047 +module test16047; + +void main() +{ + Reassignable[int][int] aa; + + aa[0][0] = Reassignable.init; + aa[s()][0] = Reassignable.init; // range violation +} + +struct Reassignable +{ + void opAssign(Reassignable) {} +} + +int s() { return 1; } diff --git a/gcc/testsuite/gdc.test/runnable/test16115.d b/gcc/testsuite/gdc.test/runnable/test16115.d index c8ad4649f2c..8cd9c6ad482 100644 --- a/gcc/testsuite/gdc.test/runnable/test16115.d +++ b/gcc/testsuite/gdc.test/runnable/test16115.d @@ -25,7 +25,7 @@ auto call() else // assert error { //return n = tagx, null; - return n = Test.tag, null; + return n = Test.tag; //return n = Test.tag; } } diff --git a/gcc/testsuite/gdc.test/runnable/test16140.d b/gcc/testsuite/gdc.test/runnable/test16140.d new file mode 100644 index 00000000000..3004945c070 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test16140.d @@ -0,0 +1,32 @@ +// https://issues.dlang.org/show_bug.cgi?id=16140 + +int fun() +{ + static int count = 0; + if (count == 3) + { + count = 0; + return 0; + } + ++count; + return count; +} + +void main() +{ + uint[] res; + while(auto value = fun()) + res ~= value; + assert(res == [1, 2, 3]); + + res.length = 0; + while(uint value = fun()) + res ~= value; + assert(res == [1, 2, 3]); + + res.length = 0; + while(const value = fun()) + res ~= value; + assert(res == [1, 2, 3]); +} + diff --git a/gcc/testsuite/gdc.test/runnable/test16555.d b/gcc/testsuite/gdc.test/runnable/test16555.d new file mode 100644 index 00000000000..78db1f74e6b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test16555.d @@ -0,0 +1,20 @@ +// https://issues.dlang.org/show_bug.cgi?id=16555 + +void outer( + double x, + double a, double b, double c, double d, + double e, double f, double g, double h) +{ + assert(x == 999.0 && a == 1 && b == 2 && c == 3 && d == 4 + && e == 5 && f == 6 && g == 7 && h == 8); +} + +void main() +{ + void inner(double x) + { + outer(x, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); + } + + inner(999.0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test17.d b/gcc/testsuite/gdc.test/runnable/test17.d index 58873a095e6..4b17ede464b 100644 --- a/gcc/testsuite/gdc.test/runnable/test17.d +++ b/gcc/testsuite/gdc.test/runnable/test17.d @@ -5,15 +5,15 @@ extern(C) int printf(const char*, ...); void ulog(string s) { - printf("%.*s\n",s.length, s.ptr); + printf("%.*s\n",cast(int)s.length, s.ptr); fflush(stdout); } int open() { char *s; - char abs[2000]; - char qu[100]; + char[2000] abs; + char[100] qu; int a; ulog("reaches this only 9 times of 10!\n"); return 0; @@ -22,7 +22,7 @@ int open() int yhenda() { - char MEM[2200]; + char[2200] MEM; int a; ulog("point(2.1) \n"); open(); diff --git a/gcc/testsuite/gdc.test/runnable/test17072.d b/gcc/testsuite/gdc.test/runnable/test17072.d index 0ad04109f0a..2c5977fe998 100644 --- a/gcc/testsuite/gdc.test/runnable/test17072.d +++ b/gcc/testsuite/gdc.test/runnable/test17072.d @@ -1,6 +1,6 @@ /* REQUIRED_ARGS: -inline -PERMUTE_ARGS: -release -O -dip25 +PERMUTE_ARGS: -release -O */ // https://issues.dlang.org/show_bug.cgi?id=17072 diff --git a/gcc/testsuite/gdc.test/runnable/test17073.d b/gcc/testsuite/gdc.test/runnable/test17073.d deleted file mode 100644 index 82df219254d..00000000000 --- a/gcc/testsuite/gdc.test/runnable/test17073.d +++ /dev/null @@ -1,13 +0,0 @@ -struct S0 -{ - int x = void; -} -struct S1 -{ - S0 x = S0(42); -} -void main() -{ - S1 x; - assert(x.x.x == 42); -} diff --git a/gcc/testsuite/gdc.test/runnable/test17181.d b/gcc/testsuite/gdc.test/runnable/test17181.d new file mode 100644 index 00000000000..59ee8957dc0 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17181.d @@ -0,0 +1,12 @@ +// EXTRA_SOURCES: imports/test17181a.d imports/test17181b.d + +module test17181; +import imports.test17181a; + +int foo() +{ + return imports.test17181a.abc(1); +} + +static this() { assert(a == 2); } +void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/test17181b.d b/gcc/testsuite/gdc.test/runnable/test17181b.d new file mode 100644 index 00000000000..5e4a4be98ae --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17181b.d @@ -0,0 +1,16 @@ +// EXTRA_SOURCES: imports/test17181a.d +// EXTRA_FILES: imports/test17181c.d +module test17181b; + +import imports.test17181c; // only imported, not compiled + // => must not be in ModuleInfo.importedModules + +static this() +{ + // By instantiating the getA template, its local imports.test17181a + // import is added to this module (not to imports.test17181c), and its + // module ctor must have run already. + assert(imports.test17181c.getA!() == 1); +} + +void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/test17246.d b/gcc/testsuite/gdc.test/runnable/test17246.d new file mode 100644 index 00000000000..2d517205896 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17246.d @@ -0,0 +1,50 @@ +/* REQUIRED_ARGS: + * OPTIONAL_ARGS: + */ + +// https://issues.dlang.org/show_bug.cgi?id=17246 + +struct Foo +{ + int* rc; + this(int val) + { + rc = new int; + (*rc) = 1; + } + this(this) + { + (*rc)++; + } + ~this() + { + if (rc) + { + assert(*rc > 0); + (*rc)--; + } + } +} + +struct Bar +{ + Foo foo; + this(Foo foo, bool) + { + this.foo = foo; + } +} + +bool fun(bool val) { return !val; } + +auto genBar(bool flag) +{ + return flag ? Bar() : Bar(Foo(10), fun(!flag)); +} + +int main(string[] args) +{ + auto bar = genBar(args.length == 0); + return 0; +} + diff --git a/gcc/testsuite/gdc.test/runnable/test17258.d b/gcc/testsuite/gdc.test/runnable/test17258.d new file mode 100644 index 00000000000..1e86c95c4f0 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17258.d @@ -0,0 +1,33 @@ +class ByNameC(alias Var) +{ + alias var = Var; +} + +struct ByNameS(alias Var) +{ + alias var = Var; + ubyte value = 1; +} + +void main() +{ + ulong x; + ByNameS!x v; + ubyte w = 2; + + v.var = 0xAA_BB; /* stomps over v.value and w */ + + assert(w == 2); + assert(v.value == 1); + //printf("%x\n", w); /* prints "aa", should be 2 */ + //printf("%x\n", v.value); /* prints "bb", should be 1 */ + + auto c = new ByNameC!x; + c.var = 0xAA_BB; /* stomps over c.__vptr */ + + assert(*cast(ulong*)c != 0xAA_BB); + //printf("%x\n", *cast(ulong*)c); /* prints "aabb", should be pointer value */ + + assert(x == 0xAA_BB); + //printf("%lx\n", x); /* prints 0, should be "aabb" */ +} diff --git a/gcc/testsuite/gdc.test/runnable/test17337.d b/gcc/testsuite/gdc.test/runnable/test17337.d new file mode 100644 index 00000000000..f817eb7d2e8 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17337.d @@ -0,0 +1,23 @@ +// REQUIRED_ARGS: -mcpu=native + +static if (__traits(compiles, __vector(ubyte[16]))) +{ + alias ubyte16 = __vector(ubyte[16]); + + ubyte16 bug(ubyte val) + { + immutable ubyte16 a = 0, b = val; + return b; + } + + void main() + { + bug(0); + } +} +else +{ + void main() + { + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test17338.d b/gcc/testsuite/gdc.test/runnable/test17338.d index 5c5012fecdd..1c937be77e6 100644 --- a/gcc/testsuite/gdc.test/runnable/test17338.d +++ b/gcc/testsuite/gdc.test/runnable/test17338.d @@ -1,25 +1,23 @@ // PERMUTE_ARGS: + +// COMDAT folding increases runtime by > 80x +// REQUIRED_ARGS(windows): -L/OPT:NOICF + +// Apparently omf or optlink does not support more than 32767 symbols. +// DISABLED: win32 + // Generate \sum_{i=0}^{14} 2^i = 32767 template instantiations // (each with 3 sections) to use more than 64Ki sections in total. -version (Win32) + +size_t foo(size_t i, size_t mask)() { - // Apparently omf or optlink does not support more than 32767 symbols. - void main() - { - } + static if (i == 14) + return mask; + else + return foo!(i + 1, mask) + foo!(i + 1, mask | (1UL << i)); } -else -{ - size_t foo(size_t i, size_t mask)() - { - static if (i == 14) - return mask; - else - return foo!(i + 1, mask) + foo!(i + 1, mask | (1UL << i)); - } - void main() - { - assert(foo!(0, 0) != 0); - } +void main() +{ + assert(foo!(0, 0) != 0); } diff --git a/gcc/testsuite/gdc.test/runnable/test17373.d b/gcc/testsuite/gdc.test/runnable/test17373.d deleted file mode 100644 index 93753baf27b..00000000000 --- a/gcc/testsuite/gdc.test/runnable/test17373.d +++ /dev/null @@ -1,20 +0,0 @@ -interface Foo { void visit (int); } -interface Bar { void visit(double); } -interface FooBar : Foo, Bar {} -static assert(__traits(getOverloads, FooBar, "visit").length == 2); - -interface Fbar { void visit(char); void visit(double); } -interface Triple : Foo, Bar, Fbar {} -static assert(__traits(getOverloads, Triple, "visit").length == 3); - -interface InheritanceMadness : FooBar, Triple {} -static assert(__traits(getOverloads, Triple, "visit").length == 3); - -interface Simple -{ - int square(int); - real square(real); -} -static assert(__traits(getOverloads, Simple, "square").length == 2); - -void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/test17559.d b/gcc/testsuite/gdc.test/runnable/test17559.d new file mode 100644 index 00000000000..a759f1564c6 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17559.d @@ -0,0 +1,84 @@ +// REQUIRED_ARGS: -g +// REQUIRED_ARGS(linux freebsd dragonflybsd): -L-export-dynamic +// PERMUTE_ARGS: +// DISABLED: osx + +import core.stdc.stdio; + +void main() +{ + fun(1); + fun(2); + fun(3); +#line 30 + fun(4); + + foo(1, 10); + foo(2, 10); + foo(3, 10); +#line 40 + foo(4, 10); +} + +void fun(int n, int defParam = 10) +{ + try + { + if (n == 4) + throw new Exception("fun"); + } + catch(Exception e) + { + string s = e.toString(); + printf("%.*s\n", cast(int)s.length, s.ptr); + int line = lineInMain(e.toString()); + assert(line >= 30 && line <= 32); // return address might be next statement + } +} + +void foo(int n, int m) +{ + try + { + if (n == 4) + throw new Exception("foo"); + } + catch(Exception e) + { + string s = e.toString(); + printf("%.*s\n", cast(int)s.length, s.ptr); + int line = lineInMain(e.toString()); + assert(line >= 40 && line <= 41); // return address might be next statement + } +} + +int lineInMain(string msg) +{ + // find line number of _Dmain in stack trace + // on linux: file.d:line _Dmain [addr] + // on windows: addr in _Dmain at file.d(line) + int line = 0; + bool mainFound = false; + for (size_t pos = 0; pos + 6 < msg.length; pos++) + { + if (msg[pos] == '\n') + { + line = 0; + mainFound = false; + } + else if ((msg[pos] == ':' || msg[pos] == '(') && line == 0) + { + for (pos++; pos < msg.length && msg[pos] >= '0' && msg[pos] <= '9'; pos++) + line = line * 10 + msg[pos] - '0'; + if (line > 0 && mainFound) + return line; + } + else if (msg[pos .. pos + 6] == "_Dmain" || msg[pos .. pos + 6] == "D main") + { + mainFound = true; + if (line > 0 && mainFound) + return line; + } + } + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test17684.d b/gcc/testsuite/gdc.test/runnable/test17684.d index 4734d962810..d42baac0e16 100644 --- a/gcc/testsuite/gdc.test/runnable/test17684.d +++ b/gcc/testsuite/gdc.test/runnable/test17684.d @@ -74,6 +74,20 @@ bool boolTest(T)() assert(t == boolValue); assert(boolValue == t); + t = true; // tests inferType + auto inferredValue = t; + assert(inferredValue == true); + + t = true; // tests function argument + bool functionCall(bool test) + { + return test; + } + assert(t == functionCall(t)); + + t = true; // tests CastExp + assert(t == cast(bool)t); + t = true; return t; // tests ReturnStatement } @@ -97,6 +111,9 @@ int intTest(T)() assert(t <= 42); assert(42 >= t); + t = 42; // tests CastExp + assert(42 == cast(int)t); + // These currently don't work for properties due to https://issues.dlang.org/show_bug.cgi?id=8006 static if (!(typeid(T) is typeid(StructProperty!int)) && !(typeid(T) is typeid(ClassProperty!int))) { diff --git a/gcc/testsuite/gdc.test/runnable/test17868.d b/gcc/testsuite/gdc.test/runnable/test17868.d new file mode 100644 index 00000000000..4609440c702 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17868.d @@ -0,0 +1,45 @@ +/* +REQUIRED_ARGS: -betterC +RUN_OUTPUT: +--- +init +init +main +fini +fini +--- +*/ + +import core.stdc.stdio; + +extern(C): + +pragma(crt_constructor) +void init() +{ + puts("init"); +} + +pragma(crt_destructor) +void fini2() +{ + puts("fini"); +} + +pragma(crt_constructor) +void foo() +{ + puts("init"); +} + +pragma(crt_destructor) +void bar() +{ + puts("fini"); +} + +int main() +{ + puts("main"); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test17868b.d b/gcc/testsuite/gdc.test/runnable/test17868b.d new file mode 100644 index 00000000000..d28cae29edc --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17868b.d @@ -0,0 +1,52 @@ +/* +REQUIRED_ARGS: -betterC +RUN_OUTPUT: +--- +init +init +main +fini +fini +--- +*/ + +import core.stdc.stdio; + +extern(C): + +pragma(crt_constructor) +pragma(crt_destructor) +void ctor_dtor_1() +{ + __gshared bool initialized; + puts(initialized ? "fini" : "init"); + initialized = true; +} + +pragma(crt_constructor) +__gshared int var; // ignored for anything but functions + +pragma(crt_constructor) +{ + version (all) void init() + { + puts("init"); + } +} + +template fini() +{ + pragma(crt_destructor) + void fini() + { + puts("fini"); + } +} + +alias instantiate = fini!(); + +int main() +{ + puts("main"); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test17885.d b/gcc/testsuite/gdc.test/runnable/test17885.d new file mode 100644 index 00000000000..a6e521b03a3 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17885.d @@ -0,0 +1,11 @@ +module test17885; + +struct T { ulong a, b; } +T f() { return T(); } + +void main() +{ + int[T] set = [f(): 0]; + set.remove(f()); + assert(f() !in set); +} diff --git a/gcc/testsuite/gdc.test/runnable/test17940.d b/gcc/testsuite/gdc.test/runnable/test17940.d new file mode 100644 index 00000000000..1ea43dbfacc --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17940.d @@ -0,0 +1,46 @@ +// PERMUTE_ARGS: -O + +// https://issues.dlang.org/show_bug.cgi?id=17940 + +struct Array +{ + long length; + long ptr; +} + +struct Struct +{ + bool b = true; +} + +void fun1(int) +{ +} + +void fun2(Array arr, int, int) +{ + assert(!arr.length); +} + +void fn(Struct* str) +{ + Array arr; + if (!str) + { + return; + } + if (str) + { + fun1(str.b); + } + if (str.b) + { + fun2(arr, str.b, 0); + } +} + +void main() +{ + Struct s; + fn(&s); +} diff --git a/gcc/testsuite/gdc.test/runnable/test17943.d b/gcc/testsuite/gdc.test/runnable/test17943.d new file mode 100644 index 00000000000..7ec2665845d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17943.d @@ -0,0 +1,9 @@ +// REQUIRED_ARGS: -O + +void main() +{ + int[32] data; + auto p1 = data.ptr + 0; + auto p2 = data.ptr + 3; + assert(p2 - p1 == 3); +} diff --git a/gcc/testsuite/gdc.test/runnable/test17965.d b/gcc/testsuite/gdc.test/runnable/test17965.d new file mode 100644 index 00000000000..2937d6d8844 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test17965.d @@ -0,0 +1,29 @@ +/***************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17965 + +import core.stdc.math; + +struct Point{double x,y;} + +Point foo10() +{ + Point result = Point(1.0, 2.0); + return result; +} + +Point foo20() +{ + Point result; + return result; +} + +void main() +{ + auto p = foo10(); + assert(p.x == 1.0); + assert(p.y == 2.0); + + auto q = foo20(); + assert(isnan(q.x)); + assert(isnan(q.y)); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18296.d b/gcc/testsuite/gdc.test/runnable/test18296.d new file mode 100644 index 00000000000..0f7ac7e0db1 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18296.d @@ -0,0 +1,24 @@ +// REQUIRED_ARGS: -cov +// PERMUTE_ARGS: -fPIC +alias AliasSeq(Args...) = Args; + +struct Duration +{ + this(long hnsecs) + { + _hnsecs = hnsecs; + } + + + long _hnsecs; +} + +void main() +{ + foreach(U; AliasSeq!(Duration, const Duration)) + { + const Duration t = 42; + U u = t; + assert(t._hnsecs == u._hnsecs); + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test18534.d b/gcc/testsuite/gdc.test/runnable/test18534.d new file mode 100644 index 00000000000..8d4653dec9d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18534.d @@ -0,0 +1,18 @@ +/* REQUIRED_ARGS: -O + * PERMUTE_ARGS: + */ + +// https://issues.dlang.org/show_bug.cgi?id=18534 + +auto blah(char ch) { return ch; } + +auto foo(int i) +{ + return blah(i ? 'A' : 'A'); +} + +void main() +{ + auto c = foo(0); + assert(c == 'A'); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18545.d b/gcc/testsuite/gdc.test/runnable/test18545.d new file mode 100644 index 00000000000..fc3d24acc99 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18545.d @@ -0,0 +1,63 @@ +module test18545; + +enum Constness +{ + Mutable, + Const, + Immutable, +} + +enum Cases = [Constness.Mutable, Constness.Const, Constness.Immutable]; + +void main() +{ + static foreach (from; Cases) + { + static foreach (to; Cases) + { + test!(from, to)(); + } + } +} + +void test(Constness from, Constness to)() +{ + struct S { + int i; + + @property int get() const { return 0; } + + alias get this; + } + + static if (from == Constness.Mutable) + { + alias ConstS = S; + } + else static if (from == Constness.Const) + { + alias ConstS = const(S); + } + else + { + alias ConstS = immutable(S); + } + + ConstS s1 = S(42); + + // this should reinterpret-cast, NOT call the implicit constructor with .get! + static if (to == Constness.Mutable) + { + auto s2 = cast() s1; + } + else static if (to == Constness.Const) + { + const s2 = cast(const) s1; + } + else static if (to == Constness.Immutable) + { + immutable s2 = cast(immutable) s1; + } + + assert(s2.i == s1.i, "Bug 18545 occurred casting from "~from.stringof~" to "~to.stringof); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18746.d b/gcc/testsuite/gdc.test/runnable/test18746.d new file mode 100644 index 00000000000..a2cf38b20df --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18746.d @@ -0,0 +1,16 @@ +// https://issues.dlang.org/show_bug.cgi?id=18746 + +struct S {} + +S f(ref int i) +{ + ++i; + return S(); +} + +void main() +{ + int i = 2; + assert(f(i) == S()); + assert(i == 3); /* failed before patch, i = 2; should pass */ +} diff --git a/gcc/testsuite/gdc.test/runnable/test18868.d b/gcc/testsuite/gdc.test/runnable/test18868.d new file mode 100644 index 00000000000..b0085c030e0 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18868.d @@ -0,0 +1,9 @@ +/* +COMPILE_SEPARATELY +EXTRA_SOURCES: imports/test18868_a.d imports/test18868_fls.d +PERMUTE_ARGS: +*/ + +import imports.test18868_fls; +alias floop = FLS!(int); +void main() {} diff --git a/gcc/testsuite/gdc.test/runnable/test18868_2.d b/gcc/testsuite/gdc.test/runnable/test18868_2.d new file mode 100644 index 00000000000..a90ec1f3318 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18868_2.d @@ -0,0 +1,13 @@ +mixin(genCtor("666")); mixin(genCtor("777")); + +int i; + +string genCtor(string a) +{ + return "static this() { i += " ~ a ~ "; }"; +} + +void main() +{ + assert(i == 0 + 666 + 777); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18868_3.d b/gcc/testsuite/gdc.test/runnable/test18868_3.d new file mode 100644 index 00000000000..ed6f1724322 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18868_3.d @@ -0,0 +1,16 @@ +static foreach(s; ["666", "777", "888"]) +{ + mixin(genCtor(s)); +} + +int i; + +string genCtor(string a) +{ + return "static this() { i += " ~ a ~ "; }"; +} + +void main() +{ + assert(i == 0 + 666 + 777 + 888); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18880.d b/gcc/testsuite/gdc.test/runnable/test18880.d new file mode 100644 index 00000000000..c275ef22827 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18880.d @@ -0,0 +1,20 @@ +/* REQUIRED_ARGS: -unittest + PERMUTE_ARGS: + */ + +static foreach(s; ["666", "777", "888"]) +{ + mixin(genTest(s)); +} + +int i; + +string genTest(string a) +{ + return "unittest { i += " ~ a ~ "; }"; +} + +void main() +{ + assert(i == 0 + 666 + 777 + 888); +} diff --git a/gcc/testsuite/gdc.test/runnable/test18916.d b/gcc/testsuite/gdc.test/runnable/test18916.d new file mode 100644 index 00000000000..0e844ada15a --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test18916.d @@ -0,0 +1,22 @@ +struct Line +{ + int line; + alias line this; + + this(int line) + { + this.line = line; + } +} + +void foo(Line line1 = __LINE__, int line2 = __LINE__, int line3 = int(__LINE__)) +{ + assert(line1 == 12); + assert(line2 == 21); + assert(line3 == 12); +} + +void main() +{ + foo(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19.d b/gcc/testsuite/gdc.test/runnable/test19.d index b9360eeeabb..372d32f71e3 100644 --- a/gcc/testsuite/gdc.test/runnable/test19.d +++ b/gcc/testsuite/gdc.test/runnable/test19.d @@ -128,8 +128,8 @@ int[] test6_1(int[] a) void test6() { printf("test6()\n"); - int b[3]; - int a[]; + int[3] b; + int[] a; b[0] = 0; b[1] = 1; @@ -144,7 +144,7 @@ void test6() class OutBuffer7 { - char data[]; + char[] data; uint offset; void write(const(char) *p, uint nbytes) @@ -161,7 +161,7 @@ void test7() OutBuffer7 ob = new OutBuffer7; ob.data = new char[10]; - printf("ob.data.length = %d\n", ob.data.length); + printf("ob.data.length = %zd\n", ob.data.length); assert(ob.data.length == 10); for (i = 0; i < 10; i++) assert(ob.data[i] == char.init); @@ -169,14 +169,14 @@ void test7() printf("test7.1()\n"); ob.data[] = '-'; printf("test7.2()\n"); - printf("ob.data[] = '%.*s'\n", ob.data.length, ob.data.ptr); + printf("ob.data[] = '%.*s'\n", cast(int)ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) assert(ob.data[i] == '-'); ob.offset = 3; ob.write("foo", 3); - printf("ob.data.length = %d\n", ob.data.length); - printf("ob.data[] = '%.*s'\n", ob.data.length, ob.data.ptr); + printf("ob.data.length = %zd\n", ob.data.length); + printf("ob.data[] = '%.*s'\n", cast(int)ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) { if (i < 3 || i >= 6) @@ -404,7 +404,7 @@ void test20() } /* ================================ */ -// 7848 +// https://issues.dlang.org/show_bug.cgi?id=7848 @safe pure nothrow void func7848() {} @@ -414,7 +414,7 @@ void test20() } /* ================================ */ -// 8128 +// https://issues.dlang.org/show_bug.cgi?id=8128 int flag8128 = 0; diff --git a/gcc/testsuite/gdc.test/runnable/test19086.d b/gcc/testsuite/gdc.test/runnable/test19086.d new file mode 100644 index 00000000000..026aee436c8 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19086.d @@ -0,0 +1,64 @@ +// REQUIRED_ARGS: -g
+// REQUIRED_ARGS(linux freebsd dragonflybsd): -L-export-dynamic
+// PERMUTE_ARGS:
+// DISABLED: osx
+
+void run19086()
+{
+ long x = 1;
+ int y = 0;
+#line 20
+ throw newException();
+}
+
+// moved here to keep run19086 short
+Exception newException() { return new Exception("hi"); }
+
+void test19086()
+{
+ try
+ {
+ run19086();
+ }
+ catch(Exception e)
+ {
+ int line = findLineStackTrace(e.toString(), "run19086");
+ assert(line >= 20 && line <= 21);
+ }
+}
+
+int findLineStackTrace(string msg, string func)
+{
+ // find line number of _Dmain in stack trace
+ // on linux: file.d:line _Dmain [addr]
+ // on windows: addr in _Dmain at file.d(line)
+ int line = 0;
+ bool found = false;
+ for (size_t pos = 0; pos + func.length < msg.length; pos++)
+ {
+ if (msg[pos] == '\n')
+ {
+ line = 0;
+ found = false;
+ }
+ else if ((msg[pos] == ':' || msg[pos] == '(') && line == 0)
+ {
+ for (pos++; pos < msg.length && msg[pos] >= '0' && msg[pos] <= '9'; pos++)
+ line = line * 10 + msg[pos] - '0';
+ if (line > 0 && found)
+ return line;
+ }
+ else if (msg[pos .. pos + func.length] == func)
+ {
+ found = true;
+ if (line > 0 && found)
+ return line;
+ }
+ }
+ return 0;
+}
+
+void main()
+{
+ test19086();
+}
diff --git a/gcc/testsuite/gdc.test/runnable/test19122.d b/gcc/testsuite/gdc.test/runnable/test19122.d new file mode 100644 index 00000000000..369f5dd5cfc --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19122.d @@ -0,0 +1,46 @@ +// https://issues.dlang.org/show_bug.cgi?id=19122 +struct HasDestructor +{ + ~this() + { + assert(0); + } + this(this) + { + assert(0); + } +} + +struct S +{ + union + { + int i; + HasDestructor h; + } +} + +struct S2 +{ + union + { + align(1) + { + int i; + HasDestructor h; + } + } +} + +void main() +{ + { + S s; + s = s; + } + + { + S2 s2; + s2 = s2; + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test19185.d b/gcc/testsuite/gdc.test/runnable/test19185.d new file mode 100644 index 00000000000..d5a1e5ec7c5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19185.d @@ -0,0 +1,22 @@ +// https://issues.dlang.org/show_bug.cgi?id=19185 + +int fun() +{ + int x = 2; + struct A + { + int a; + this(int a) + { + this.a = a + x; // segault here + } + } + + A a = 5; + return a.a; +} + +void main() +{ + assert(fun() == 7); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19192.d b/gcc/testsuite/gdc.test/runnable/test19192.d new file mode 100644 index 00000000000..24f245089e1 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19192.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=19192 +interface Foo +{ + Foo covariant(); +} + +abstract class Frop : Foo {} + +class Bar : Frop +{ + Bar covariant() { return this; } +} + +void main() +{ + Foo foo = new Bar; + assert(foo is foo.covariant()); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19223.d b/gcc/testsuite/gdc.test/runnable/test19223.d new file mode 100644 index 00000000000..6faa59bbedf --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19223.d @@ -0,0 +1,38 @@ + +static if (__traits(compiles, __vector(int[4]))) +{ + alias int4 = __vector(int[4]); + + int fn(const int[4] x) + { + int sum = 0; + foreach (i; x) sum += i; + return sum; + } + + // https://issues.dlang.org/show_bug.cgi?id=19223 + void test19223() + { + int4 v1 = int4.init; + assert(fn(v1.array) == 0); + assert(fn(int4.init.array) == 0); + } + + // https://issues.dlang.org/show_bug.cgi?id=19607 + void test19607() + { + int4 v1 = 1; + assert(fn(v1.array) == 4); + assert(fn(int4(2).array) == 8); + } + + void main () + { + test19223(); + test19607(); + } +} +else +{ + void main() { } +} diff --git a/gcc/testsuite/gdc.test/runnable/test19251.d b/gcc/testsuite/gdc.test/runnable/test19251.d new file mode 100644 index 00000000000..9e0b9d4f083 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19251.d @@ -0,0 +1,20 @@ +string result; + +struct A +{ + int[] a; + immutable(A) fun() + { + result ~= "Yo"; + return immutable A([7]); + } + + alias fun this; +} + +void main() +{ + A a; + immutable A b = a; // error: cannot implicitly convert expression a of type A to immutable(A) + assert(result == "Yo"); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19317.d b/gcc/testsuite/gdc.test/runnable/test19317.d new file mode 100644 index 00000000000..a5633b8c13b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19317.d @@ -0,0 +1,32 @@ +// REQUIRED_ARGS: -preview=dip1008 +// https://issues.dlang.org/show_bug.cgi?id=19317 + +class MyException: Exception { + static int numInstances; + this(string msg) { + super(msg); + ++numInstances; + } + + ~this() { + --numInstances; + } +} + +void main() { + assert(MyException.numInstances == 0); + + try + throw new MyException("oops"); + catch(MyException _) + assert(MyException.numInstances == 1); + + assert(MyException.numInstances == 0); + + try + throw new MyException("oops I did it again"); + catch(MyException) + assert(MyException.numInstances == 1); + + assert(MyException.numInstances == 0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19386.d b/gcc/testsuite/gdc.test/runnable/test19386.d new file mode 100644 index 00000000000..3e3157a8a2b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19386.d @@ -0,0 +1,36 @@ +struct Thing +{ + this(int* i) + { + ptr = i; + (*ptr)++; + } + + ~this() + { + (*ptr)--; + } + + T opCast(T : bool)() + { + return false; + } + + int* ptr; +} + +Thing makeThing(int* p) +{ + return Thing(p); +} + +void main() +{ + int i; + { + if (auto t = makeThing(&i)) // destructor not called + { + } + } + assert(i == 0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19393.d b/gcc/testsuite/gdc.test/runnable/test19393.d new file mode 100644 index 00000000000..4226bbd402c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19393.d @@ -0,0 +1,37 @@ +string result; + +struct S +{ + this(this) + { + result ~= "A"; + } + + ~this() + { + result ~= "B"; + } +} + +void foo(const(S)[] ar...) +{ + /* postblit gets called on this initialization, + * then when the function returns, the destructor + * gets called => result = "AB"; + */ + auto d = ar[0]; +} + +void bar() +{ + /* S(null) needs to be destroyed after the function call, + * that means that another `B` is appended => result = "ABB" + */ + foo(S()); +} + +void main() +{ + bar(); + assert(result == "ABB"); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19441.d b/gcc/testsuite/gdc.test/runnable/test19441.d new file mode 100644 index 00000000000..5dcb573600a --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19441.d @@ -0,0 +1,24 @@ +// https://issues.dlang.org/show_bug.cgi?id=19441 +struct S1 +{ + int a; + long b; + alias a this; +} + +struct S2 +{ + S1 v; + alias v this; +} + +void main() +{ + auto x = S2(S1(1, 12345678)); + assert(x.a == 1 && x.b == 12345678); // prints: 1 12345678 + S1 y; + y = x; + assert(y.a == 1 && y.b == 12345678); + y = x.v; + assert(y.a == 1 && y.b == 12345678); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19476.d b/gcc/testsuite/gdc.test/runnable/test19476.d new file mode 100644 index 00000000000..3143c20817f --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19476.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=19476 + +mixin template operators() { + int foo(int op = 1, T)(T rhs) { + return 1; + } +} + +struct S { + mixin operators ops; + int foo(int op = 1, T)(T a) { + return ops.foo!1(a); + } +} + +void main() { + S.init.foo(S.init); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19639.d b/gcc/testsuite/gdc.test/runnable/test19639.d new file mode 100644 index 00000000000..36b763046e5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19639.d @@ -0,0 +1,22 @@ +enum EMPTY_STRING = ""[0..0]; +enum SMALL_STRING = "a"[0..1]; + +void main() +{ + { + char[64] buf = EMPTY_STRING; + foreach (c; buf) assert(c == 0); + buf[$-1] = 'e'; + buf = EMPTY_STRING; + assert(buf[$-1] == 0); + } + + { + char[64] buf = SMALL_STRING; + assert(buf[0] == 'a'); + foreach (c; buf[1..$]) assert(c == 0); + buf[$-1] = 'e'; + buf = SMALL_STRING; + assert(buf[$-1] == 0); + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test19655a.d b/gcc/testsuite/gdc.test/runnable/test19655a.d new file mode 100644 index 00000000000..fc636396b3f --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19655a.d @@ -0,0 +1,10 @@ +/* +REQUIRED_ARGS: -Irunnable/imports +PERMUTE_ARGS: +COMPILE_SEPARATELY: +EXTRA_SOURCES: imports/test19655b.d imports/test19655c.d imports/test19655d.d imports/test19655e.d imports/test19655f.d imports/test19655g.d +*/ + +import test19655g; +class Corge +{ } diff --git a/gcc/testsuite/gdc.test/runnable/test19672.d b/gcc/testsuite/gdc.test/runnable/test19672.d new file mode 100644 index 00000000000..8f5f50bdf97 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19672.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=19672 + +struct S +{ + ulong c; + bool b; // removing this prevents bug +} + +// increase the struct size at least to 17 bytes also prevents the bug. + +void main() +{ + S[1] a = [S(42)]; + assert(a[0].c == 42); /* Passes. */ + f(a); +} + +void f(S[1] a) +{ + assert(a[0].c == 42); /* Fails. */ +} diff --git a/gcc/testsuite/gdc.test/runnable/test19679.d b/gcc/testsuite/gdc.test/runnable/test19679.d new file mode 100644 index 00000000000..18b050c91fd --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19679.d @@ -0,0 +1,21 @@ +void delegate() foo() +{ + size_t value = 0; + + void check() + { + assert(value == 0); + } + + void nest1() + { + void nest2() { check(); } + nest2(); + } + return &nest1; +} + +void main() +{ + foo()(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19688.d b/gcc/testsuite/gdc.test/runnable/test19688.d new file mode 100644 index 00000000000..9cc4dd7298d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19688.d @@ -0,0 +1,13 @@ +/* TEST_OUTUT: +--- +--- +*/ +void test(string s = __FUNCTION__ ~ __MODULE__ ~ __FUNCTION__) +{ + assert(s == "test19688.maintest19688test19688.main"); +} + +void main() +{ + test(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19729.d b/gcc/testsuite/gdc.test/runnable/test19729.d new file mode 100644 index 00000000000..b959c71c62e --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19729.d @@ -0,0 +1,61 @@ +//https://issues.dlang.org/show_bug.cgi?id=19729 +// PERMUTE_ARGS: +module test19729; + +mixin template Templ(T) +{ + this(T t) + { + } +} + +class C // original TC +{ + mixin Templ!int; + mixin Templ!string; +} + +class D // named +{ + mixin Templ!int ti; + mixin Templ!string ts; +} + +class E // top level ctor wins +{ + bool topLevelWins; + mixin Templ!int; + this(int){topLevelWins = true;} +} + +class F // top level ctor wins even if not exact match +{ + bool topLevelWins; + mixin Templ!ubyte; + this(int){topLevelWins = true;} +} + +class G // same as F but change lexicographical order +{ + bool topLevelWins; + this(int){topLevelWins = true;} + mixin Templ!ubyte; +} + +void main() +{ + auto c0 = new C("should work"); + auto c1 = new C(42); + + auto d0 = new D("should work"); + auto d1 = new D(42); + + auto e = new E(0); + assert(e.topLevelWins); + + auto f = new F(ubyte(0)); + assert(f.topLevelWins); + + auto g = new G(ubyte(0)); + assert(g.topLevelWins); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19734.d b/gcc/testsuite/gdc.test/runnable/test19734.d index efa7da3b019..73429202b2a 100644 --- a/gcc/testsuite/gdc.test/runnable/test19734.d +++ b/gcc/testsuite/gdc.test/runnable/test19734.d @@ -9,15 +9,13 @@ class C19734 { // Invalid 'this' parameter because of applied 'extern' storage class. void testin(typeof(this) p) - in { assert(this is p); } - body + in(this is p) { } // Undefined reference to __result. int testout() - out { assert(__result == 2); } - body + out(; __result == 2) { return 2; } diff --git a/gcc/testsuite/gdc.test/runnable/test19774.d b/gcc/testsuite/gdc.test/runnable/test19774.d new file mode 100644 index 00000000000..940a07cc039 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19774.d @@ -0,0 +1,43 @@ +// https://issues.dlang.org/show_bug.cgi?id=19774 +C bar() +{ + return C(42); +} + +C foo() +{ + return bar()[1]; +} + +C gun() +{ + return bar()[$]; +} + +struct C +{ + int x; + + ~this() + { + x = 0; + } + + int opDollar() + { + return 1; + } + + C opIndex(int a) + { + return this; + } +} + +void main() +{ + auto c = foo(); + assert(c.x == 42); /* fails; should pass */ + auto d = gun(); + assert(d.x == 42); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19782.d b/gcc/testsuite/gdc.test/runnable/test19782.d new file mode 100644 index 00000000000..a24d84173ec --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19782.d @@ -0,0 +1,23 @@ +// https://issues.dlang.org/show_bug.cgi?id=19782 +class Inner +{ + int a; +} + +class Outer +{ + Inner inner; alias inner this; + this(Inner i) { inner = i; } +} + +void main() +{ + Inner[] inners = []; + inners ~= new Inner; + inners ~= new Outer(new Inner); // Appends null + + foreach(inner; inners) + { + assert(inner.a == 0); + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test19822.d b/gcc/testsuite/gdc.test/runnable/test19822.d new file mode 100644 index 00000000000..8f0e3f14faf --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19822.d @@ -0,0 +1,29 @@ +// https://issues.dlang.org/show_bug.cgi?id=19822 +struct Quat +{ + static struct Vec { int x; } + + union + { + Vec v; + struct { float x; } + } + + static Quat identity() + { + Quat q; + q.x = 1.0f; + return q; + } +} + +struct QuatContainerWithIncompatibleInit +{ + Quat q = Quat.identity; +} + +void main() +{ + QuatContainerWithIncompatibleInit c; + assert(c.q.x == 1.0f); // fails +} diff --git a/gcc/testsuite/gdc.test/runnable/test19825.d b/gcc/testsuite/gdc.test/runnable/test19825.d new file mode 100644 index 00000000000..a4f85ca0150 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19825.d @@ -0,0 +1,42 @@ +struct JSONValue +{ + TaggedUnion payload; +} + +struct TaggedUnion +{ + size_t[2] m_data; + int m_kind; + + JSONValue opIndex(size_t i) + { + return JSONValue(); + } +} + +void yap(lazy JSONValue arg) +{ + arg(); +} + +struct Foo +{ + int a; + string name; +} + +Foo makeFoo() +{ + JSONValue root; + yap(root.payload[0] + .payload[0] + .payload[0]); + + Foo foo; + return foo; +} + +void main() +{ + auto foo = makeFoo(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test19891.d b/gcc/testsuite/gdc.test/runnable/test19891.d new file mode 100644 index 00000000000..08e51bc0f8d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19891.d @@ -0,0 +1,13 @@ +int g; + +void fun(R)(auto ref int a, auto ref R r = g, auto ref int b = 1) +{ + ++r; +} + +void main() +{ + fun(10, 2); + fun(10); + assert(g == 1); +} diff --git a/gcc/testsuite/gdc.test/runnable/test20.d b/gcc/testsuite/gdc.test/runnable/test20.d index 0e21e30920e..5a1985a1fa2 100644 --- a/gcc/testsuite/gdc.test/runnable/test20.d +++ b/gcc/testsuite/gdc.test/runnable/test20.d @@ -1,3 +1,9 @@ +/* +TEST_OUTPUT: +--- +runnable/test20.d(448): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import core.vararg; extern(C) int printf(const char*, ...); @@ -72,7 +78,7 @@ struct A4 void test4() { - printf("A4.sizeof = %d\n", A4.sizeof); + printf("A4.sizeof = %zd\n", A4.sizeof); assert(A4.sizeof == 1 * int.sizeof); A4 q; @@ -213,7 +219,7 @@ void test10() /*****************************************/ -scope class T11 +class T11 { this(){} ~this(){} @@ -270,7 +276,7 @@ void test13() void write14(bool[] c) { - printf("[%2d]: ", c.length); + printf("[%2zd]: ", c.length); foreach (bool x; c) printf("%d,", x); printf("\n"); @@ -334,12 +340,6 @@ int y16; class C16 { - new(size_t size, byte blah){ - void* v = (new byte[C16.classinfo.initializer.length]).ptr; - y16 = 1; - assert(blah == 3); - return v; - } int x; this() { @@ -349,8 +349,7 @@ class C16 void test16() { - C16 c = new(3) C16; - assert(y16 == 1); + C16 c = new C16(); assert(c.x == 4); } @@ -491,34 +490,6 @@ void test22() /*****************************************/ -void test23() -{ - float f; - double d; - real r; - - if (f > ifloat.max) - goto Loverflow; - if (d > ifloat.max) - goto Loverflow; - if (r > ifloat.max) - goto Loverflow; - - if (ifloat.max < f) - goto Loverflow; - if (ifloat.max < d) - goto Loverflow; - if (ifloat.max < r) - goto Loverflow; - - return; - - Loverflow: - return; -} - -/*****************************************/ - interface I24 { } void test24() @@ -583,15 +554,6 @@ void test29() /*****************************************/ -void test30() -{ - double d = 1; - cdouble cd = 1+0i; - assert(cd == 1.0 + 0i); -} - -/*****************************************/ - void foo31(...) { byte b = va_arg!byte(_argptr); @@ -743,7 +705,7 @@ void test42() string string1 = "ワロスw"; string string2 = r"ワロスw"; string string3 = `ワロスw`; - string string4 = x"E3 83 AF E3 83 AD E3 82 B9 EF BD 97"; + string string4 = "\xE3\x83\xAF\xE3\x83\xAD\xE3\x82\xB9\xEF\xBD\x97"; assert(string1.length==master.length); @@ -806,7 +768,7 @@ struct S45 { double x = 0, y = 0; static S45 opCall(int i) { S45 r; r.x = i; return r; } - S45 opMul(S45 s) + S45 opBinary(string op)(S45 s) if (op == "*") { S45 r; r.x = x * s.x; @@ -842,11 +804,11 @@ void test45() { S45 s = S45(10); S45 val = pow!(S45)(s,2); - printf("x = %2.2lf, y = %2.2lf\n", val.x, val.y); + printf("x = %2.2f, y = %2.2f\n", val.x, val.y); assert(val.x == 100); assert(val.y == 0); double d = pow!(double)(10,3); - printf("%2.2lf\n", d); + printf("%2.2f\n", d); assert(d == 1000); } @@ -873,19 +835,6 @@ void test46() /*****************************************/ -void test47() -{ - cdouble[] a; - cdouble[] b; - foreach(ref cdouble d; b) - { - d = -a[0]; - for(;;){} - } -} - -/*****************************************/ - string foo48(string s) { return s; @@ -915,7 +864,7 @@ void test49() { int i = void; //printf("i = %d\n", i); - int[10] a = void; + int[10] a; foreach (int x; a) { printf("\tx = %d\n", x); @@ -938,7 +887,7 @@ void test51() { bool[9][3] qwert; - printf("qwert.sizeof = %d\n", qwert.sizeof); + printf("qwert.sizeof = %zd\n", qwert.sizeof); for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) @@ -987,13 +936,13 @@ const char[3][13] month = [ void test53() { - printf("%.*s\n", month[1].length, month[1].ptr); - printf("%.*s\n", month[2].length, month[2].ptr); - printf("%.*s\n", month[3].length, month[3].ptr); - printf("%.*s\n", month[4].length, month[4].ptr); - printf("%.*s\n", month[5].length, month[5].ptr); - printf("%.*s\n", month[6].length, month[6].ptr); - printf("%.*s\n", month[8].length, month[8].ptr); + printf("%.*s\n", cast(int)month[1].length, month[1].ptr); + printf("%.*s\n", cast(int)month[2].length, month[2].ptr); + printf("%.*s\n", cast(int)month[3].length, month[3].ptr); + printf("%.*s\n", cast(int)month[4].length, month[4].ptr); + printf("%.*s\n", cast(int)month[5].length, month[5].ptr); + printf("%.*s\n", cast(int)month[6].length, month[6].ptr); + printf("%.*s\n", cast(int)month[8].length, month[8].ptr); assert(month[1] == "Jan"); assert(month[2] == "Feb"); @@ -1032,7 +981,7 @@ struct S54 return S54.foo() * S54.foo(); } - S54 opMul(S54 s) + S54 opBinary(string op)(S54 s) if (op == "*") { return s; } @@ -1052,12 +1001,12 @@ void test55() str = str ~ c; uvw = c ~ uvw; - printf("%.*s\n", str.length, str.ptr); + printf("%.*s\n", cast(int)str.length, str.ptr); assert(str == "a"); assert(uvw == "a"); c = 'b'; - printf("%.*s\n", str.length, str.ptr); + printf("%.*s\n", cast(int)str.length, str.ptr); assert(str == "a"); assert(uvw == "a"); } @@ -1199,7 +1148,7 @@ void foo61(real[] arr) for (size_t j = i; j >= i; j -= i) { // interesting results follow from this: - printf("%d ", i); + printf("%zd ", i); // it prints a _lot_ of ones arr[j] = arr[j - i]; @@ -1253,14 +1202,12 @@ int main() test20(); test21(); test22(); - test23(); test24(); test25(); test26(); test27(); test28(); test29(); - test30(); test31(); test33(); test34(); @@ -1274,7 +1221,6 @@ int main() test44(); test45(); test46(); - test47(); test48(); test49(); test50(); @@ -1294,4 +1240,3 @@ int main() printf("Success\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/test20025.d b/gcc/testsuite/gdc.test/runnable/test20025.d new file mode 100644 index 00000000000..9abee457cb0 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20025.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=20025 +struct B +{ + static int value = 77; + alias value this; + + this(ref return scope inout B rhs) inout { } +} + +void test(int x) +{ + assert(x == 77); +} + +int main() +{ + B b; + test(b); + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test20036.d b/gcc/testsuite/gdc.test/runnable/test20036.d new file mode 100644 index 00000000000..640de192480 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20036.d @@ -0,0 +1,10 @@ + +__gshared int x = 7; +__gshared int*[70000] px = &x; + +void main() +{ + foreach(p; px) + assert(p && *p == 7); +} + diff --git a/gcc/testsuite/gdc.test/runnable/test20130.d b/gcc/testsuite/gdc.test/runnable/test20130.d new file mode 100644 index 00000000000..09eaee36dd4 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20130.d @@ -0,0 +1,44 @@ +// https://issues.dlang.org/show_bug.cgi?id=20130 + +void main() { + auto a1 = cast(char[]) "12345678"; + auto a2 = cast(wchar[]) "12345678"; // Or cast(string|wstring|dstring). + auto a3 = cast(dchar[]) "12345678"; // Encoding conversion. + assert(a1.length == 8); + assert(a2.length == 8); + assert(a3.length == 8); + + auto b1 = cast(char[]) "12345678"c; + auto b2 = cast(wchar[]) "12345678"c; + auto b3 = cast(dchar[]) "12345678"c; + assert(b1.length == 8); + assert(b2.length == 4); + assert(b3.length == 2); + + auto c1 = cast(char[]) "12345678"w; + auto c2 = cast(wchar[]) "12345678"w; + auto c3 = cast(dchar[]) "12345678"w; + assert(c1.length == 16); + assert(c2.length == 8); + assert(c3.length == 4); + + auto d1 = cast(char[]) "12345678"d; + auto d2 = cast(wchar[]) "12345678"d; + auto d3 = cast(dchar[]) "12345678"d; + assert(d1.length == 32); + assert(d2.length == 16); + assert(d3.length == 8); + + auto a = cast(uint[]) "12345678"; + auto b = cast(uint[]) "12345678"d; + auto c = cast(uint[]) "12345678"w; + auto d = cast(const char[5][]) "12345"; + auto e = cast(const wchar[2][]) "12345678"; + immutable f = cast(immutable(uint)[]) "123456789012"; + assert(a.length == 2); + assert(b.length == 8); + assert(c.length == 4); + assert(d.length == 1); + assert(e.length == 2); + assert(f.length == 3); +} diff --git a/gcc/testsuite/gdc.test/runnable/test20401.d b/gcc/testsuite/gdc.test/runnable/test20401.d new file mode 100644 index 00000000000..c3b60721469 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20401.d @@ -0,0 +1,20 @@ +// https://issues.dlang.org/show_bug.cgi?id=20401 + +void main() +{ + int i; + assert(&passthrough(i) == &i); +} + +ref int passthrough(return ref int i) +{ + return get().flag ? i : i; +} + +S get() { return S(); } + +struct S +{ + bool flag; + ~this(){} +} diff --git a/gcc/testsuite/gdc.test/runnable/test20565.d b/gcc/testsuite/gdc.test/runnable/test20565.d new file mode 100644 index 00000000000..47a8db34342 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20565.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=20565 + +void main() +{ + { + int temp(T)() { return 3; } + assert(temp!int() == 3); + } + { + int temp(T)() { return 4; } + assert(temp!int() == 4); + } + { + int temp(T)() { return 5; } + assert(temp!int() == 5); + } +} + diff --git a/gcc/testsuite/gdc.test/runnable/test20649.d b/gcc/testsuite/gdc.test/runnable/test20649.d new file mode 100644 index 00000000000..6c645e696e7 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20649.d @@ -0,0 +1,15 @@ +struct S { int i; } + +auto f() +{ + S[] ss; + ss.length = 1; + return 0; +} + +enum a = f(); + +void main() +{ + f(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test20855.d b/gcc/testsuite/gdc.test/runnable/test20855.d new file mode 100644 index 00000000000..7e43ec801a7 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20855.d @@ -0,0 +1,26 @@ +// https://issues.dlang.org/show_bug.cgi?id=20855 + +string exp() +{ + string s = "a = b + c * d + a;"; + foreach (i; 0 .. 9) + s = s ~ s; + return s; +} + +int test() +{ + auto a=1, b=2, c=3, d=4; + mixin(exp()); + return a; +} + +import core.stdc.stdio; + +int main() +{ + int a = test(); + printf("a = %d\n", a); + assert(test() == 7169); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test20893.d b/gcc/testsuite/gdc.test/runnable/test20893.d new file mode 100644 index 00000000000..18a83aa44f1 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test20893.d @@ -0,0 +1,21 @@ +// REQUIRED_ARGS: -O -inline +// +// https://issues.dlang.org/show_bug.cgi?id=20893 +// caused by https://github.com/dlang/dmd/pull/9722 + +int f(int n) +{ + foreach (i; 0..n) {} + return 10; +} + +int c(int a, int b) +{ + return (f(a) * 1L * f(b)) % 1000; +} + +void main() +{ + int[] a = [1]; + assert(c(2 - 1, 2) == 100); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21040.d b/gcc/testsuite/gdc.test/runnable/test21040.d new file mode 100644 index 00000000000..8e5ee56fa1e --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21040.d @@ -0,0 +1,61 @@ +// REQUIRED_ARGS: +// PERMUTE_ARGS: -mcpu=native +// https://issues.dlang.org/show_bug.cgi?id=21040 + +import core.simd; + +alias AliasSeq(A ...) = A; + +void main() +{ + static foreach (T; AliasSeq!( + float[8], float[4], double[4], double[2], + byte[32], ubyte[32], byte[16], ubyte[16], + short[16], ushort[16], short[8], ushort[8], + int[8], uint[8], int[4], uint[4], + long[4], ulong[4], long[2], ulong[2], + void[32], void[16])) + { + static if (__traits(compiles, __vector(T))) + {{ + __vector(T) v; + + static if (__traits(compiles, { __vector(T) x = 2; })) + v = 2; + static if (__traits(compiles, { __vector(T) x; x = +x; })) + v = +v; + static if (__traits(compiles, { __vector(T) x; x = -x; })) + v = -v; + static if (__traits(compiles, { __vector(T) x; x = x + x; })) + v = v + v; + static if (__traits(compiles, { __vector(T) x; x += 2; })) + v += 2; + static if (__traits(compiles, { __vector(T) x; x = x - x; })) + v = v - v; + static if (__traits(compiles, { __vector(T) x; x -= 2; })) + v -= 2; + static if (__traits(compiles, { __vector(T) x; x = x * x; })) + v = v * v; + static if (__traits(compiles, { __vector(T) x; x *= 2; })) + v *= 2; + static if (__traits(compiles, { __vector(T) x; x = x / x; })) + v = v / v; + static if (__traits(compiles, { __vector(T) x; x /= 2; })) + v /= 2; + static if (__traits(compiles, { __vector(T) x; x = x & x; })) + v = v & v; + static if (__traits(compiles, { __vector(T) x; x &= 2; })) + v &= 2; + static if (__traits(compiles, { __vector(T) x; x = x | x; })) + v = v | v; + static if (__traits(compiles, { __vector(T) x; x |= 2; })) + v |= 2; + static if (__traits(compiles, { __vector(T) x; x = x ^ x; })) + v = v ^ v; + static if (__traits(compiles, { __vector(T) x; x ^= 2; })) + v ^= 2; + static if (__traits(compiles, { __vector(T) x; x = ~x; })) + v = ~v; + }} + } +} diff --git a/gcc/testsuite/gdc.test/runnable/test21120.d b/gcc/testsuite/gdc.test/runnable/test21120.d new file mode 100644 index 00000000000..2714bfc6da8 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21120.d @@ -0,0 +1,27 @@ +// https://issues.dlang.org/show_bug.cgi?id=21120 + +module one.two.three; + +struct S {} + +struct StructTemplate(T) +{ + int a = 123; // non-zero initialized + + ref const(StructTemplate) getInitSymbol() + { + return initSymbol!StructTemplate; + } +} + +template initSymbol(T) +{ + pragma(mangle, "_D" ~ T.mangleof[1..$] ~ "6__initZ") + extern immutable T initSymbol; +} + +void main() +{ + StructTemplate!S inst; + assert(inst.getInitSymbol() == inst); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21357.d b/gcc/testsuite/gdc.test/runnable/test21357.d new file mode 100644 index 00000000000..de219e99480 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21357.d @@ -0,0 +1,35 @@ +// https://issues.dlang.org/show_bug.cgi?id=21357 +// PERMUTE_ARGS: +struct BatchState +{ + int[10] arr; + + BatchState copy() + { + auto ret = BatchState(arr); + arr[0] += 1; + return ret; + } +} + +struct GrayArea +{ + BatchState low; + + this(this) + { + low = low.copy; + } +} + +void main() +{ + GrayArea a; + a.low.arr[0] = 1; + GrayArea b; + b.low.arr[0] = 4; + b = a; // calls the postblit + + assert(a.low.arr[0] == 1); + assert(b.low.arr[0] == 1); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21403.d b/gcc/testsuite/gdc.test/runnable/test21403.d new file mode 100644 index 00000000000..15314b02fe3 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21403.d @@ -0,0 +1,72 @@ +// https://issues.dlang.org/show_bug.cgi?id=21403 + +/***********************************************/ + +int[] cat11ret3(ref int[] s) +{ + s ~= 11; + return [3]; +} + +int[] doit1(int[] val) +{ + (val ~= cat11ret3(val)) ~= 7; + return val; +} + +void test1() +{ + static assert(doit1([2]) == [2, 11, 3, 7]); + assert(doit1([2]) == [2, 11, 3, 7]); +} + +/***********************************************/ + +char catbretc(ref char[] s) +{ + s ~= 'b'; + return 'c'; +} + +char[] doit2(char[] val) +{ + (val ~= catbretc(val)) ~= 'd'; + return val; +} + +void test2() +{ + static assert(doit2(['a']) == ['a', 'b', 'c', 'd']); + assert(doit2(['a']) == ['a', 'b', 'c', 'd']); +} + +/***********************************************/ + +int cat2ret3(ref int[] s) +{ + s ~= 2; + return 3; +} + +int[] doit2(int[] val) +{ + (val ~= cat2ret3(val)) ~= 4; + return val; +} + +void test3() +{ + static assert(doit2([1]) == [1, 2, 3, 4]); + assert(doit2([1]) == [1, 2, 3, 4]); +} + +/***********************************************/ + +int main() +{ + test1(); + test2(); + test3(); + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test21424.d b/gcc/testsuite/gdc.test/runnable/test21424.d new file mode 100644 index 00000000000..72abd3f33cf --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21424.d @@ -0,0 +1,12 @@ +// https://issues.dlang.org/show_bug.cgi?id=21424 + +void main() +{ + ubyte[10] buf; + size_t pos = 0; + size_t num = 5; + buf[pos++] += num; + assert(pos == 1); + assert(buf[0] == 5); + assert(buf[1] == 0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21479.d b/gcc/testsuite/gdc.test/runnable/test21479.d new file mode 100644 index 00000000000..84612ab49ea --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21479.d @@ -0,0 +1,28 @@ +// https://issues.dlang.org/show_bug.cgi?id=21479 +enum Side +{ + left, + right +} + +struct Both(T) +{ + T left; + T right; + + ref T get(Side side) + { + return side == Side.left ? left : right; + } +} + +void main() +{ + Both!(int[]) t; + t.get(Side.left) ~= 1; + assert (t.left.length == 1); + + t.get(Side.right) ~= 1; + t.get(Side.right) ~= 2; + assert (t.right.length == 2); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21515.d b/gcc/testsuite/gdc.test/runnable/test21515.d new file mode 100644 index 00000000000..09aea83ac11 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21515.d @@ -0,0 +1,81 @@ +// https://issues.dlang.org/show_bug.cgi?id=21515 +// DISABLED: win32 win64 + +// ABI layout of native complex +struct _Complex(T) { T re; T im; } + +// Special enum definitions. +version (Posix) +{ + align(float.alignof) enum __c_complex_float : _Complex!float; + align(double.alignof) enum __c_complex_double : _Complex!double; + align(real.alignof) enum __c_complex_real : _Complex!real; +} +else +{ + align(float.sizeof * 2) enum __c_complex_float : _Complex!float; + align(double.sizeof * 2) enum __c_complex_double : _Complex!double; + align(real.alignof) enum __c_complex_real : _Complex!real; +} +alias complex_float = __c_complex_float; +alias complex_double = __c_complex_double; +alias complex_real = __c_complex_real; + +extern(D) complex_float dcomplexf() { return typeof(return)(2, 1); } +extern(D) complex_double dcomplex() { return typeof(return)(2, 1); } +extern(D) complex_real dcomplexl() { return typeof(return)(2, 1); } + +extern(D) void dcomplexf(complex_float c) { assert(c.re == 2 && c.im == 1); } +extern(D) void dcomplex(complex_double c) { assert(c.re == 2 && c.im == 1); } +extern(D) void dcomplexl(complex_real c) { assert(c.re == 2 && c.im == 1); } + +extern(C) complex_float ccomplexf() { return typeof(return)(2, 1); } +extern(C) complex_double ccomplex() { return typeof(return)(2, 1); } +extern(C) complex_real ccomplexl() { return typeof(return)(2, 1); } + +extern(C) void ccomplexf2(complex_float c) { assert(c.re == 2 && c.im == 1); } +extern(C) void ccomplex2(complex_double c) { assert(c.re == 2 && c.im == 1); } +extern(C) void ccomplexl2(complex_real c) { assert(c.re == 2 && c.im == 1); } + +extern(C++) complex_float cpcomplexf() { return typeof(return)(2, 1); } +extern(C++) complex_double cpcomplex() { return typeof(return)(2, 1); } +extern(C++) complex_real cpcomplexl() { return typeof(return)(2, 1); } + +extern(C++) void cpcomplexf(complex_float c) { assert(c.re == 2 && c.im == 1); } +extern(C++) void cpcomplex(complex_double c) { assert(c.re == 2 && c.im == 1); } +extern(C++) void cpcomplexl(complex_real c) { assert(c.re == 2 && c.im == 1); } + +int main() +{ + auto a1 = dcomplexf(); + auto b1 = dcomplex(); + auto c1 = dcomplexl(); + assert(a1.re == 2 && a1.im == 1); + assert(b1.re == 2 && b1.im == 1); + assert(c1.re == 2 && c1.im == 1); + dcomplexf(a1); + dcomplex(b1); + dcomplexl(c1); + + auto a2 = ccomplexf(); + auto b2 = ccomplex(); + auto c2 = ccomplexl(); + assert(a2.re == 2 && a2.im == 1); + assert(b2.re == 2 && b2.im == 1); + assert(c2.re == 2 && c2.im == 1); + ccomplexf2(a2); + ccomplex2(b2); + ccomplexl2(c2); + + auto a3 = cpcomplexf(); + auto b3 = cpcomplex(); + auto c3 = cpcomplexl(); + assert(a3.re == 2 && a3.im == 1); + assert(b3.re == 2 && b3.im == 1); + assert(c3.re == 2 && c3.im == 1); + cpcomplexf(a3); + cpcomplex(b3); + cpcomplexl(c3); + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/test21586.d b/gcc/testsuite/gdc.test/runnable/test21586.d new file mode 100644 index 00000000000..6af695c759d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21586.d @@ -0,0 +1,31 @@ +/* +RUN_OUTPUT: +--- +this +~this 1 +--- +*/ +// https://issues.dlang.org/show_bug.cgi?id=21586 + +import core.stdc.stdio : printf; + +struct S +{ + this(int arg) + { + a = arg; + printf("this\n"); + } + + ~this() + { + printf("~this %d\n", a); + } + + int a; +} + +void main() +{ + auto s = true ? S(1) : S(0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21822.d b/gcc/testsuite/gdc.test/runnable/test21822.d new file mode 100644 index 00000000000..f0a020ade82 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21822.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=21822 + +bool testAliasedString() +{ + auto a = soundexer(); + auto b = soundexer(); + return a == b; +} + +char[4] soundexer() +{ + return "M365"; +} + +void main() +{ + assert(testAliasedString()); +} diff --git a/gcc/testsuite/gdc.test/runnable/test21833.d b/gcc/testsuite/gdc.test/runnable/test21833.d new file mode 100644 index 00000000000..dd59a8e56b6 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test21833.d @@ -0,0 +1,30 @@ +// REQUIRED_ARGS: -O -inline +// https://issues.dlang.org/show_bug.cgi?id=20855 + +void testit() +{ + pragma(inline, false); + short[4] arr = [-1, 6, 0, 4]; + long1 A = *cast(long1*)(arr.ptr); + assert(_mm_extract_pi16(A, 0) == 65535); +} + +struct short4 +{ + short[4] array; +} + +struct long1 +{ + long[1] array; +} + +int _mm_extract_pi16 (long1 a, int imm8) +{ + return cast(ushort)((cast(short4)a).array[imm8]); +} + +void main() +{ + testit(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test22.d b/gcc/testsuite/gdc.test/runnable/test22.d index 2aabb4d95d1..1d806d641ab 100644 --- a/gcc/testsuite/gdc.test/runnable/test22.d +++ b/gcc/testsuite/gdc.test/runnable/test22.d @@ -1,7 +1,5 @@ -// RUNNABLE_PHOBOS_TEST // REQUIRED_ARGS: -import std.math: poly; import core.stdc.stdarg; extern(C) @@ -119,67 +117,6 @@ void test5() /*************************************/ -void test6() -{ - ireal a = 6.5i % 3i; - printf("%Lfi %Lfi\n", a, a - .5i); - assert(a == .5i); - - a = 6.5i % 3; - printf("%Lfi %Lfi\n", a, a - .5i); - assert(a == .5i); - - real b = 6.5 % 3i; - printf("%Lf %Lf\n", b, b - .5); - assert(b == .5); - - b = 6.5 % 3; - printf("%Lf %Lf\n", b, b - .5); - assert(b == .5); -} - -/*************************************/ - -void test7() -{ - cfloat f = 1+0i; - f %= 2fi; - printf("%f + %fi\n", f.re, f.im); - assert(f == 1 + 0i); - - cdouble d = 1+0i; - d %= 2i; - printf("%f + %fi\n", d.re, d.im); - assert(d == 1 + 0i); - - creal r = 1+0i; - r %= 2i; - printf("%Lf + %Lfi\n", r.re, r.im); - assert(r == 1 + 0i); -} - -/*************************************/ - -void test8() -{ - cfloat f = 1+0i; - f %= 2i; - printf("%f + %fi\n", f.re, f.im); - assert(f == 1); - - cdouble d = 1+0i; - d = d % 2i; - printf("%f + %fi\n", d.re, d.im); - assert(d == 1); - - creal r = 1+0i; - r = r % 2i; - printf("%Lf + %Lfi\n", r.re, r.im); - assert(r == 1); -} - -/*************************************/ - class A9 { this(int[] params ...) @@ -219,7 +156,7 @@ void test10() { auto i = 5u; auto s = typeid(typeof(i)).toString; - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(typeid(typeof(i)) == typeid(uint)); } @@ -233,103 +170,6 @@ void test11() /*************************************/ -void assertEqual(real* a, real* b, string file = __FILE__, size_t line = __LINE__) -{ - auto x = cast(ubyte*)a; - auto y = cast(ubyte*)b; - - // Only compare the 10 value bytes, the padding bytes are of undefined - // value. - version (X86) enum count = 10; - else version (X86_64) enum count = 10; - else enum count = real.sizeof; - for (size_t i = 0; i < count; i++) - { - if (x[i] != y[i]) - { - printf("%02d: %02x %02x\n", i, x[i], y[i]); - import core.exception; - throw new AssertError(file, line); - } - } -} - -void assertEqual(creal* a, creal* b, string file = __FILE__, size_t line = __LINE__) -{ - assertEqual(cast(real*)a, cast(real*)b, file, line); - assertEqual(cast(real*)a + 1, cast(real*)b + 1, file, line); -} - -void test12() -{ - creal a = creal.nan; - creal b = real.nan + ireal.nan; - assertEqual(&a, &b); - - real c= real.nan; - real d=a.re; - assertEqual(&c, &d); - - d=a.im; - assertEqual(&c, &d); -} - -/*************************************/ - -void test13() -{ - creal a = creal.infinity; - creal b = real.infinity + ireal.infinity; - assertEqual(&a, &b); - - real c = real.infinity; - real d=a.re; - assertEqual(&c, &d); - - d=a.im; - assertEqual(&c, &d); -} - -/*************************************/ - -void test14() -{ - creal a = creal.nan; - creal b = creal.nan; - b = real.nan + ireal.nan; - assertEqual(&a, &b); - - real c = real.nan; - real d=a.re; - assertEqual(&c, &d); - - d=a.im; - assertEqual(&c, &d); -} - -/*************************************/ - -ireal x15; - -void foo15() -{ - x15 = -x15; -} - -void bar15() -{ - return foo15(); -} - -void test15() -{ - x15=2i; - bar15(); - assert(x15==-2i); -} - -/*************************************/ - real x16; void foo16() @@ -358,7 +198,7 @@ class Bar17 class Foo17 { - void opAdd (Bar17 b) {} + void opBinary(string op : "+") (Bar17 b) {} } void test17() @@ -427,41 +267,6 @@ void test21() /*************************************/ -void test22() -{ - static creal[] params = [1+0i, 3+0i, 5+0i]; - - printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im); - printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im); - printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im); - - creal[] sums = new creal[3]; - sums[] = 0+0i; - - foreach(creal d; params) - { - creal prod = d; - - printf("prod = %Lf + %Lfi\n", prod.re, prod.im); - for(int i; i<2; i++) - { - sums[i] += prod; - prod *= d; - } - sums[2] += prod; - } - - printf("sums[0] = %Lf + %Lfi", sums[0].re, sums[0].im); - assert(sums[0].re==9); - assert(sums[0].im==0); - assert(sums[1].re==35); - assert(sums[1].im==0); - assert(sums[2].re==153); - assert(sums[2].im==0); -} - -/*************************************/ - const int c23 = b23 * b23; const int a23 = 1; const int b23 = a23 * 3; @@ -480,51 +285,6 @@ void test23() /*************************************/ -ifloat func_24_1(ifloat f, double d) -{ -// f /= cast(cdouble)d; - return f; -} - -ifloat func_24_2(ifloat f, double d) -{ - f = cast(ifloat)(f / cast(cdouble)d); - return f; -} - -float func_24_3(float f, double d) -{ -// f /= cast(cdouble)d; - return f; -} - -float func_24_4(float f, double d) -{ - f = cast(float)(f / cast(cdouble)d); - return f; -} - -void test24() -{ - ifloat f = func_24_1(10i, 8); - printf("%fi\n", f); -// assert(f == 1.25i); - - f = func_24_2(10i, 8); - printf("%fi\n", f); - assert(f == 1.25i); - - float g = func_24_3(10, 8); - printf("%f\n", g); -// assert(g == 1.25); - - g = func_24_4(10, 8); - printf("%f\n", g); - assert(g == 1.25); -} - -/*************************************/ - template cat(int n) { const int dog = n; @@ -541,48 +301,11 @@ void test25() /*************************************/ -string toString26(cdouble z) -{ - char[ulong.sizeof*8] buf; - - auto len = snprintf(buf.ptr, buf.sizeof, "%f+%fi", z.re, z.im); - return buf[0 .. len].idup; -} - -void test26() -{ - static cdouble[] A = [1+0i, 0+1i, 1+1i]; - string s; - - foreach( cdouble z; A ) - { - s = toString26(z); - printf("%.*s ", s.length, s.ptr); - } - printf("\n"); - - for(int ii=0; ii<A.length; ii++ ) - A[ii] += -1i*A[ii]; - - assert(A[0] == 1 - 1i); - assert(A[1] == 1 + 1i); - assert(A[2] == 2); - - foreach( cdouble z; A ) - { - s = toString26(z); - printf("%.*s ", s.length, s.ptr); - } - printf("\n"); -} - -/*************************************/ - void test27() { int x; string s = (int*function(int ...)[]).mangleof; - printf("%.*s\n", s.length, s.ptr); + printf("%.*s\n", cast(int)s.length, s.ptr); assert((int*function(int ...)[]).mangleof == "APFiXPi"); assert(typeof(x).mangleof == "i"); assert(x.mangleof == "_D6test226test27FZ1xi"); @@ -590,20 +313,12 @@ void test27() /*************************************/ -void test28() -{ - alias cdouble X; - X four = cast(X) (4.0i + 0.4); -} - -/*************************************/ - void test29() { ulong a = 10_000_000_000_000_000, b = 1_000_000_000_000_000; - printf("test29\n%lx\n%lx\n%lx\n", a, b, a / b); + printf("test29\n%llx\n%llx\n%llx\n", a, b, a / b); assert((a / b) == 10); } @@ -666,7 +381,7 @@ struct particle float yg; /* Y Gravity */ } -particle particles[10000]; +particle[10000] particles; void test32() { @@ -923,7 +638,7 @@ in { assert(A.length > 0); } -body +do { version (D_InlineAsm_X86) { @@ -1086,7 +801,7 @@ in { assert(A.length > 0); } -body +do { ptrdiff_t i = A.length - 1; real r = A[i]; @@ -1101,19 +816,17 @@ body void test47() { real x = 3.1; - static real pp[] = [56.1, 32.7, 6]; + static real[] pp = [56.1, 32.7, 6]; real r; printf("The result should be %Lf\n",(56.1L + (32.7L + 6L * x) * x)); printf("The C version outputs %Lf\n", poly_c(x, pp)); printf("The asm version outputs %Lf\n", poly_asm(x, pp)); - printf("The std.math version outputs %Lf\n", poly(x, pp)); r = (56.1L + (32.7L + 6L * x) * x); assert(r == poly_c(x, pp)); version (D_InlineAsm_X86) assert(r == poly_asm(x, pp)); - assert(r == poly(x, pp)); } /*************************************/ @@ -1211,28 +924,36 @@ void test52() } /*************************************/ -import std.stdio; -import core.stdc.stdarg; void myfunc(int a1, ...) { va_list argument_list; TypeInfo argument_type; string sa; int ia; double da; - writefln("%d variable arguments", _arguments.length); - writefln("argument types %s", _arguments); + assert(_arguments.length == 9); + va_start(argument_list, a1); for (int i = 0; i < _arguments.length; ) { if ((argument_type=_arguments[i++]) == typeid(string)) { va_arg(argument_list, sa); - writefln("%d) string arg = '%s', length %d", i+1, sa.length<=20? sa : "?", sa.length); + switch (i) + { + case 1: assert(sa == "2"); break; + case 7: assert(sa == "8"); break; + case 8: assert(sa == "9"); break; + case 9: assert(sa == "10"); break; + default: + printf("i = %d\n", i); + assert(false); + } } else if (argument_type == typeid(int)) { va_arg(argument_list, ia); - writefln("%d) int arg = %d", i+1, ia); + assert(ia == i+1); } else if (argument_type == typeid(double)) { va_arg(argument_list, da); - writefln("%d) double arg = %f", i+1, da); + const e = i+1; + assert((e - 0.0001) < da && da < (e + 0.0001)); } else { - throw new Exception("invalid argument type"); + assert(false, argument_type.toString()); } } va_end(argument_list); @@ -1248,6 +969,24 @@ void test6758() { /*************************************/ +real f18573() { return 1; } + +void test18573() +{ + cast(void) f18573(); + cast(void) f18573(); + cast(void) f18573(); + cast(void) f18573(); + cast(void) f18573(); + cast(void) f18573(); + cast(void) f18573(); + + real b = 2; + assert(b == 2); /* fails; should pass */ +} + +/*************************************/ + int main() { test1(); @@ -1255,29 +994,18 @@ int main() test3(); test4(); test5(); - test6(); - test7(); - test8(); test9(); test10(); test11(); - test12(); - test13(); - test14(); - test15(); test16(); test17(); test18(); test19(); test20(); test21(); - test22(); test23(); - test24(); test25(); - test26(); test27(); - test28(); test29(); test30(); test31(); @@ -1305,6 +1033,7 @@ int main() test51(); test52(); test6758(); + test18573(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test22209.d b/gcc/testsuite/gdc.test/runnable/test22209.d new file mode 100644 index 00000000000..f2a4bd54a40 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test22209.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=22209 + +struct U { size_t[4] a; } + +struct S +{ + int x; + U u; + alias u this; +} + +U foo() +{ + S s = S(42, U([1, 2, 3, 4])); + return s; +} + +void main() +{ + assert(foo().a[0] == 1); +} diff --git a/gcc/testsuite/gdc.test/runnable/test23.d b/gcc/testsuite/gdc.test/runnable/test23.d index abf8e37f83d..f1fd4a6c2bc 100644 --- a/gcc/testsuite/gdc.test/runnable/test23.d +++ b/gcc/testsuite/gdc.test/runnable/test23.d @@ -1,14 +1,8 @@ -// RUNNABLE_PHOBOS_TEST -// REQUIRED_ARGS: - module test; import core.vararg; import core.stdc.stdlib; -import std.stdio; -import std.string; -import core.stdc.stdlib; - +import core.stdc.stdio; /*******************************************/ @@ -69,13 +63,6 @@ void test3() /*******************************************/ -void test4() -{ - writeln("",true); -} - -/*******************************************/ - void test5() { int[] qwert = new int[6]; @@ -228,9 +215,9 @@ void test11() { Foo11 fooIt = new Foo11(); if (fooIt !is null) - writefln("fooIt should be valid"); + printf("fooIt should be valid\n"); fooIt.f.foo(); - writefln("it worked"); + printf("it worked\n"); } /*******************************************/ @@ -251,7 +238,7 @@ struct B12 { void test12() { A12 a; - printf("%d\n", A12.sizeof); + printf("%zd\n", A12.sizeof); assert(A12.sizeof == 12); } @@ -272,7 +259,7 @@ interface Father {} class Mother { Father test() { - writefln("Called Mother.test!"); + printf("Called Mother.test!\n"); return new Child(42); } } @@ -283,7 +270,7 @@ class Child : Mother, Father { this(int d) { data = d; } override Child test() { - writefln("Called Child.test!"); + printf("Called Child.test!\n"); return new Child(69); } } @@ -294,7 +281,7 @@ void test14() Mother childsMum = aChild; Child childsChild = aChild.test(); Child mumsChild = cast(Child) childsMum.test(); - writefln("Success2"); + printf("Success2\n"); } @@ -335,27 +322,6 @@ void test15() /*******************************************/ -creal x16; - -void foo16() -{ - x16 = -x16; -} - -void bar16() -{ - return foo16(); -} - -void test16() -{ - x16 = 2.0L + 0.0Li; - bar16(); - assert(x16 == -2.0L + 0.0Li); -} - -/*******************************************/ - void test17() { version(D_InlineAsm_X86_64) @@ -557,15 +523,12 @@ void test25() char[6] cstr = "123456"c; auto str1 = cast(wchar[3])(cstr); - writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1)); assert(cast(char[])str1 == "123456"c); auto str2 = cast(wchar[3])("789abc"c); - writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2)); assert(cast(char[])str2 == "789abc"c); auto str3 = cast(wchar[3])("defghi"); - writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3)); version (LittleEndian) assert(cast(char[])str3 == "d\000e\000f\000"c); version (BigEndian) @@ -631,26 +594,20 @@ uint intRes() void test28() { - auto s = std.string.format("%s", "abc123"[intRes() % $] ); - writefln( "%s", s ); - assert(s == "2"); + auto s = "abc123"[intRes() % $]; + assert(s == '2'); static const char[] foo = "abc123"; - s = std.string.format("%s", foo[intRes() % $] ); - assert(s == "2"); - + assert(foo[intRes() % $] == '2'); static string bar = "abc123"; - s = std.string.format("%s", bar[intRes() % $] ); - assert(s == "2"); + assert(bar[intRes() % $] == '2'); const char[] abc = "abc123"; - s = std.string.format("%s", abc[intRes() % $] ); - assert(s == "2"); + assert(abc[intRes() % $] == '2'); string def = "abc123"; - s = std.string.format("%s", def[intRes() % $] ); - assert(s == "2"); + assert(def[intRes() % $] == '2'); } /*******************************************/ @@ -703,72 +660,6 @@ void test31() /*******************************************/ -class Foo32 -{ - static void* ps; - - new (size_t sz) - { - void* p = core.stdc.stdlib.malloc(sz); - printf("new(sz = %d) = %p\n", sz, p); - ps = p; - return p; - } - - delete(void* p) - { - printf("delete(p = %p)\n", p); - assert(p == ps); - if (p) core.stdc.stdlib.free(p); - } -} - -void test32() -{ - Foo32 f = new Foo32; - delete f; -} - -/*******************************************/ - -class Foo33 -{ -// this() { printf("this()\n"); } -// ~this() { printf("~this()\n"); } - - static void* ps; - static int del; - - new (size_t sz, int i) - { - void* p = core.stdc.stdlib.malloc(sz); - printf("new(sz = %d) = %p\n", sz, p); - ps = p; - return p; - } - - delete(void* p) - { - printf("delete(p = %p)\n", p); - assert(p == ps); - if (p) core.stdc.stdlib.free(p); - del += 1; - } -} - -void foo33() -{ - scope Foo33 f = new(3) Foo33; -} - -void test33() -{ - foo33(); - assert(Foo33.del == 1); -} - -/*******************************************/ - struct o_O { int a; } union O_O { int a; } class O_o { int a; } @@ -806,12 +697,6 @@ void test37() { Foo37 f = new Foo37(); - writefln("Foo.array[0] = %s", f.array[0] ); - writefln("Foo.array[1] = %s", f.array[1] ); - writefln("Foo.array[2] = %s", f.array[2] ); - writefln("Foo.array[3] = %s", f.array[3] ); - writefln("Foo.count = %s", f.count ); - assert(f.array[0] == 1.0); assert(f.array[1] == 1.0); assert(f.array[2] == 1.0); @@ -831,7 +716,7 @@ in checkParameters(); } -body +do { } @@ -848,7 +733,7 @@ void delegate() foo39() void dg() { - writefln("delegate!"); + printf("delegate!\n"); assert(a == 3); } }).dg; @@ -1019,7 +904,8 @@ void test45() buffer[i] -= cast(char)'a' - 'A'; // segfault here } } - writeln(buffer); + + assert(buffer == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } /*******************************************/ @@ -1189,10 +1075,10 @@ bool[void[]] reg57; void addToReg57(const(void)[] a, int b, bool v) { if (!v) - writefln("X"); + printf("X\n"); auto key = a~(cast(void*)&b)[0..4]; reg57[cast(immutable(void)[])key] = v; - writefln("OK"); + printf("OK\n"); } void test57() @@ -1232,10 +1118,9 @@ struct S59 void test59() { S59 s; - writefln("s = %s", s); string p; - p = std.string.format("s = %s", s); + p = "s = " ~ s.toString(); assert(p == "s = foo"); } @@ -1263,11 +1148,13 @@ void test60() void test61() { int[][] f = [[1,2],[3,4]]; + assert(f.length == 2); + assert(f[0].length == 2); + assert(f[1].length == 2); assert(f[0][0] == 1); assert(f[0][1] == 2); assert(f[1][0] == 3); assert(f[1][1] == 4); - writeln(f); } /*******************************************/ @@ -1304,7 +1191,7 @@ void test63() arr = [1] ~ 2; // runtime crash, the length == 1 - printf("%d\n", arr.length); + printf("%zd\n", arr.length); assert (arr.length == 2); assert(arr[0] == 1); assert(arr[1] == 2); @@ -1333,7 +1220,6 @@ void test64() foreach_reverse(v; x) { - writeln(v); assert(j == v); j--; } @@ -1342,7 +1228,6 @@ void test64() j = 4; foreach_reverse(i, v; x) { - writefln("[%s] = %s", i, v); assert(i + 1 == j); assert(j == v); j--; @@ -1411,11 +1296,11 @@ void test69() auto n = new NoBug; auto n2 = new NoBug2; - writefln("bug %d", b.t); + printf("bug %d\n", b.t); assert(b.t == 1); - writefln("nobug %d", n.t); + printf("nobug %d\n", n.t); assert(n.t == 2); - writefln("nobug2 %d", n2.t); + printf("nobug2 %d\n", n2.t); assert(n2.t == 3); } @@ -1428,8 +1313,6 @@ void test70() } static const char[0] altsep; - string s = std.string.format("test%spath", altsep); - assert(s == "testpath"); foo(altsep); } @@ -1502,7 +1385,6 @@ void main() test1(); test2(); test3(); - test4(); test5(); test6(); test7(); @@ -1514,7 +1396,6 @@ void main() test13(); test14(); test15(); - test16(); test17(); test18(); test19(); @@ -1530,8 +1411,8 @@ void main() test29(); test30(); test31(); - test32(); - test33(); + + test34(); test37(); test38(); diff --git a/gcc/testsuite/gdc.test/runnable/test24.d b/gcc/testsuite/gdc.test/runnable/test24.d index 2f31d757921..d41d0602cb6 100644 --- a/gcc/testsuite/gdc.test/runnable/test24.d +++ b/gcc/testsuite/gdc.test/runnable/test24.d @@ -1,5 +1,5 @@ -// RUNNABLE_PHOBOS_TEST // EXTRA_SOURCES: imports/test24a.d imports/test24b.d +// EXTRA_FILES: imports/test24c.d // PERMUTE_ARGS: // REQUIRED_ARGS: @@ -7,5 +7,5 @@ import imports.test24a, imports.test24b; void main() { - string hi = std.string.format("%s", 3); + string hi = imports.test24c.format("%s", 3); } diff --git a/gcc/testsuite/gdc.test/runnable/test27.d b/gcc/testsuite/gdc.test/runnable/test27.d index a3e76ea8d62..b45c132620e 100644 --- a/gcc/testsuite/gdc.test/runnable/test27.d +++ b/gcc/testsuite/gdc.test/runnable/test27.d @@ -1,4 +1,3 @@ -// RUNNABLE_PHOBOS_TEST // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test27a.d // PERMUTE_ARGS: diff --git a/gcc/testsuite/gdc.test/runnable/test28.d b/gcc/testsuite/gdc.test/runnable/test28.d index 5355c2cb23a..8fb60b9cc39 100644 --- a/gcc/testsuite/gdc.test/runnable/test28.d +++ b/gcc/testsuite/gdc.test/runnable/test28.d @@ -1,11 +1,7 @@ -// RUNNABLE_PHOBOS_TEST module test; +import core.stdc.stdio; import core.vararg; -import std.stdio; -import std.string; - -extern(C) int printf(const char*, ...); /*******************************************/ @@ -117,41 +113,24 @@ void test8() { int[] test; test.length = 10; - // Show address of array start and its length (10) - writefln("%s %s", cast(uint)test.ptr, test.length); + assert(test.length == 10); + assert(test.ptr != null); test.length = 1; - // Show address of array start and its length (1) - writefln("%s %s", cast(uint)test.ptr, test.length); + assert(test.length == 1); + assert(test.ptr != null); test.length = 8; - // Show address of array start and its length (8) - writefln("%s %s", cast(uint)test.ptr, test.length); + assert(test.length == 8); + assert(test.ptr != null); test.length = 0; - // Shows 0 and 0! - writefln("%s %s", cast(uint)test.ptr, test.length); assert(test.length == 0); assert(test.ptr != null); } /*******************************************/ -cdouble y9; - -cdouble f9(cdouble x) -{ - return (y9 = x); -} - -void test9() -{ - f9(1.0+2.0i); - assert(y9 == 1.0+2.0i); -} - -/*******************************************/ - class CBase10 { this() { } @@ -227,10 +206,10 @@ void test14() void func15(...) in { - writefln("Arguments len = %d\n", _arguments.length); + printf("Arguments len = %d\n", cast(int)_arguments.length); assert(_arguments.length == 2); } -body { +do { } @@ -402,11 +381,9 @@ void test22() void test23() { auto t=['a','b','c','d']; - writeln(typeid(typeof(t))); assert(is(typeof(t) == char[])); const t2=['a','b','c','d','e']; - writeln(typeid(typeof(t2))); assert(is(typeof(t2) == const(const(char)[]))); } @@ -424,16 +401,6 @@ void test24() /*******************************************/ -void test25() -{ - ireal x = 4.0Li; - ireal y = 4.0Li; - ireal z = 4Li; - creal c = 4L + 0Li; -} - -/*******************************************/ - struct Foo26 { int a; @@ -688,7 +655,6 @@ template a34(string name, T...) string localchar; foreach (a34; T) { - writefln(`hello`); localchar ~= a34.mangleof; } return localchar; @@ -697,7 +663,7 @@ template a34(string name, T...) void test34() { - writeln(a34!("Adf"[], typeof("adf"),uint)("Adf"[],"adf",1234)); + assert(a34!("Adf"[], typeof("adf"),uint)("Adf"[],"adf",1234) == "Ayak"); } /*******************************************/ @@ -722,7 +688,6 @@ template a36(AnotherT,string name,T...){ AnotherT localchar; foreach(a;T) { - writefln(`hello`); localchar~=a.mangleof; } return cast(AnotherT)localchar; @@ -734,7 +699,7 @@ void test36() string b="adf"; uint i=123; char[3] c="Adf"; - writeln(a36!(typeof(b),"Adf")()); + assert(a36!(typeof(b),"Adf")() == ""); } /*******************************************/ @@ -780,8 +745,7 @@ void test39() { void print(string[] strs) { - writeln(strs); - assert(format("%s", strs) == `["Matt", "Andrew"]`); + assert(strs == ["Matt", "Andrew"]); } print(["Matt", "Andrew"]); @@ -803,7 +767,7 @@ void test40() with (c.propName) { - writeln(toString()); + assert(toString() == "test.test40.C"); } auto foo = c.propName; @@ -829,7 +793,7 @@ void test41() assert(x3 == 1); //test [0 .. 2] = 'b'; // this line should assert - writef ("%s\n", test.ptr [0 .. 2]); + assert(test.ptr[0 .. 2] == "ba"); } /*******************************************/ @@ -846,6 +810,12 @@ void test42() /*******************************************/ +void vararg43(string fmt, ...) +{ + assert(_arguments[0] is typeid(const string)); + assert(va_arg!(const string)(_argptr) == "hello"); +} + struct A43 { static const MY_CONST_STRING = "hello"; @@ -854,7 +824,7 @@ struct A43 { // This will either print garbage or throw a UTF exception. // But if never_called() is commented out, then it will work. - writefln("%s", MY_CONST_STRING); + vararg43("%s", MY_CONST_STRING); } } @@ -862,7 +832,7 @@ void never_called43() { // This can be anything; there just needs to be a reference to // A43.MY_CONST_STRING somewhere. - writefln("%s", A43.MY_CONST_STRING); + vararg43("%s", A43.MY_CONST_STRING); } void test43() @@ -873,6 +843,12 @@ void test43() /*******************************************/ +void vararg44(string fmt, ...) +{ + assert(_arguments[0] is typeid(const string)); + assert(va_arg!(const string)(_argptr) == "hello"); +} + class A44 { static const MY_CONST_STRING = "hello"; @@ -881,7 +857,7 @@ class A44 { // This will either print garbage or throw a UTF exception. // But if never_called() is commented out, then it will work. - writefln("%s", MY_CONST_STRING); + vararg44("%s", MY_CONST_STRING); } } @@ -889,7 +865,7 @@ void never_called44() { // This can be anything; there just needs to be a reference to // A44.MY_CONST_STRING somewhere. - writefln("%s", A44.MY_CONST_STRING); + vararg44("%s", A44.MY_CONST_STRING); } void test44() @@ -941,9 +917,9 @@ void test47() void test48() { Object o = new Object(); - printf("%.*s\n", typeof(o).classinfo.name.length, typeof(o).classinfo.name.ptr); - printf("%.*s\n", (typeof(o)).classinfo.name.length, (typeof(o)).classinfo.name.ptr); - printf("%.*s\n", (Object).classinfo.name.length, (Object).classinfo.name.ptr); + printf("%.*s\n", cast(int)typeof(o).classinfo.name.length, typeof(o).classinfo.name.ptr); + printf("%.*s\n", cast(int)(typeof(o)).classinfo.name.length, (typeof(o)).classinfo.name.ptr); + printf("%.*s\n", cast(int)(Object).classinfo.name.length, (Object).classinfo.name.ptr); } /*******************************************/ @@ -1076,13 +1052,11 @@ void test58() static S a = {i: 1}; static S b; - writefln("a.bar: %s, %s", a.bar, a.abc); assert(a.i == 1); assert(a.bar[0] == 4); assert(a.bar[1] == 4); assert(a.bar[2] == 4); assert(a.bar[3] == 4); - writefln("b.bar: %s, %s", b.bar, b.abc); assert(b.i == 0); assert(b.bar[0] == 4); assert(b.bar[1] == 4); @@ -1093,10 +1067,18 @@ void test58() /*******************************************/ +void vararg59(...) +{ + if (_arguments[0] is typeid(size_t)) + assert(va_arg!size_t(_argptr) == 454); + else + assert(va_arg!string(_argptr) == "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"); +} + void bug59(string s)() { - writeln(s); - writeln(s.length); + vararg59(s); + vararg59(s.length); } void test59() @@ -1139,7 +1121,6 @@ void test62() Vector62 a; a.set(1,2,24); a = a * 2; - writeln(a.x, a.y, a.z); assert(a.x == 2); assert(a.y == 4); assert(a.z == 48); @@ -1158,7 +1139,7 @@ struct Vector62 z = _z; } - Vector62 opMul(float s) + Vector62 opBinary(string op : "*")(float s) { Vector62 ret; ret.x = x*s; @@ -1191,8 +1172,6 @@ void test63() { Data63 d; d.x = 1; d.y = 2; d = frob(d); - writeln(d.x); - writeln(d.y); assert(d.x == 3 && d.y == -1); } @@ -1200,8 +1179,8 @@ void test63() class Foo64 { - this() { writefln("Foo64 created"); } - ~this() { writefln("Foo64 destroyed"); } + this() { } + ~this() { } } template Mix64() @@ -1249,6 +1228,49 @@ void test65() /*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18576 + +void delegate() callback; + +struct S66 { + int x; + @disable this(this); + + this(int x) { + this.x = x; + callback = &inc; + } + void inc() { + x++; + } +} + +auto f66() +{ + return g66(); // RVO should be done +} + +auto g66() +{ + return h66(); // RVO should be done +} + +auto h66() +{ + return S66(100); +} + +void test18576() +{ + auto s = f66(); + printf("%p vs %p\n", &s, callback.ptr); + callback(); + printf("s.x = %d\n", s.x); + assert(s.x == 101); + assert(&s == callback.ptr); +} + +/*******************************************/ void main() { @@ -1261,7 +1283,6 @@ void main() test6(); test7(); test8(); - test9(); test10(); test11(); test12(); @@ -1276,7 +1297,6 @@ void main() test22(); test23(); test24(); - test25(); test26(); test27(); test28(); @@ -1315,6 +1335,7 @@ void main() test63(); test64(); test65(); + test18576(); printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable/test29.d b/gcc/testsuite/gdc.test/runnable/test29.d index 9156c91923b..03c81c65877 100644 --- a/gcc/testsuite/gdc.test/runnable/test29.d +++ b/gcc/testsuite/gdc.test/runnable/test29.d @@ -1,6 +1,12 @@ -// COMPILE_SEPARATELY -// EXTRA_SOURCES: imports/test29a.d imports/test29b.d -// PERMUTE_ARGS: +/* +COMPILE_SEPARATELY +EXTRA_SOURCES: imports/test29a.d imports/test29b.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +42 +--- +*/ import imports.test29a; import imports.test29b; @@ -10,4 +16,3 @@ extern(C) int printf(const char*, ...); void main() { printf("%d\n", qwert); } - diff --git a/gcc/testsuite/gdc.test/runnable/test3.d b/gcc/testsuite/gdc.test/runnable/test3.d index 11f66c68e6f..4c6b9deaa47 100644 --- a/gcc/testsuite/gdc.test/runnable/test3.d +++ b/gcc/testsuite/gdc.test/runnable/test3.d @@ -34,7 +34,7 @@ int main(string[] args) a.bar = "hello"; a.bar = baz ~ "betty"; - printf("a.bar = '%.*s'\n", a.bar.length, a.bar.ptr); + printf("a.bar = '%.*s'\n", cast(int)a.bar.length, a.bar.ptr); assert(a.bar == "lolobetty"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/test30.d b/gcc/testsuite/gdc.test/runnable/test30.d index 085311a585f..384ff4cb92c 100644 --- a/gcc/testsuite/gdc.test/runnable/test30.d +++ b/gcc/testsuite/gdc.test/runnable/test30.d @@ -1,4 +1,4 @@ -// 444 +// https://issues.dlang.org/show_bug.cgi?id=444 int main() { diff --git a/gcc/testsuite/gdc.test/runnable/test34.d b/gcc/testsuite/gdc.test/runnable/test34.d index e38ab1c858d..dee6609e3d7 100644 --- a/gcc/testsuite/gdc.test/runnable/test34.d +++ b/gcc/testsuite/gdc.test/runnable/test34.d @@ -1,18 +1,8 @@ -// RUNNABLE_PHOBOS_TEST -/* -TEST_OUTPUT: ---- -Object ---- -*/ - module test34; -import std.stdio; -import std.string; -import std.format; import core.exception; - +import core.stdc.stdio; +import core.vararg; /************************************************/ @@ -26,16 +16,12 @@ void test1() auto hfoo = ti_foo.toHash(); auto hbar = ti_bar.toHash(); - writefln("typeid(Foo).toHash: ", hfoo); - writefln("typeid(Bar).toHash: ", hbar); assert(hfoo != hbar); auto e = (ti_foo == ti_bar); - writefln("opEquals: ", e ? "equal" : "not equal"); assert(!e); auto c = (ti_foo.opCmp(ti_bar) == 0); - writefln("opCmp: ", c ? "equal" : "not equal"); assert(!c); } @@ -63,7 +49,6 @@ Struct[1] table; Struct getfirst() { foreach(v; table) { - writeln(v.langID); assert(v.langID == 1); return v; } @@ -73,7 +58,6 @@ Struct getfirst() Struct getsecond() { foreach(ref v; table) { - writeln(v.langID); assert(v.langID == 1); return v; } @@ -85,11 +69,9 @@ void test3() table[0].langID = 1; auto v = getfirst(); - writeln(v.langID); assert(v.langID == 1); v = getsecond(); - writeln(v.langID); assert(v.langID == 1); } @@ -198,11 +180,6 @@ template parseInteger(string s) void test7() { - writeln(parseUinteger!("1234abc").value); - writeln(parseUinteger!("1234abc").rest); - writeln(parseInteger!("-1234abc").value); - writeln(parseInteger!("-1234abc").rest); - assert(parseUinteger!("1234abc").value == "1234"); assert(parseUinteger!("1234abc").rest == "abc"); assert(parseInteger!("-1234abc").value == "-1234"); @@ -284,10 +261,8 @@ class B34 : A34 { } void test11() { A34 test=new B34; - writefln("Test is ", test.toString); assert(test.toString == "test34.B34"); A34 test_2=cast(A34)(new B34); - writefln("Test 2 is ", test_2.toString); assert(test_2.toString == "test34.B34"); } @@ -357,7 +332,6 @@ struct Iterator16(T : Basic16!(T, U), U) { static void Foo() { - writeln(typeid(T), typeid(U)); assert(is(T == int)); assert(is(U == float)); } @@ -529,11 +503,8 @@ template Mang(alias F) template moo(alias A) { - pragma(msg," "); const string a = Mang!(A).mangledname; - pragma(msg," "); static assert(Mang!(A).mangledname == a); // FAILS !!! - pragma(msg," "); } void test27() @@ -658,10 +629,39 @@ struct Vector34 public string toString() { - return std.string.format("<%f, %f, %f>", x, y, z); + return formatImpl("<%f, %f, %f>", x, y, z); + } + + private static string formatImpl(string fmt, ...) + { + string ret = "<"; + bool comma; + foreach (arg; _arguments) + { + assert(arg is typeid(float)); + if (comma) + ret ~= ", "; + auto f = va_arg!float(_argptr); + if (f == 1) + ret ~= "1.000000"; + else if (f == 0) + ret ~= "0.000000"; + else + assert(0); + comma = true; + } + ret ~= ">"; + return ret; } } +string format34(string fmt, ...) +{ + assert(_arguments[0] is typeid(Vector34)); + auto arg = va_arg!Vector34(_argptr); + return arg.toString(); +} + class Foo34 { private Vector34 v; @@ -679,17 +679,12 @@ class Foo34 private void bar() { auto s = foobar(); - writef("Returned: %s\n", s); - assert(std.string.format("%s", s) == "<1.000000, 0.000000, 0.000000>"); + assert(format34("%s", s) == "<1.000000, 0.000000, 0.000000>"); } public Vector34 foobar() { - writef("Returning %s\n", v); - return v; - Vector34 b = Vector34(); - return b; } } @@ -704,18 +699,18 @@ void test34() void foo35() { - uint a; - uint b; - uint c; - extern (Windows) int function(int i, int j, int k) xxx; + uint a; + uint b; + uint c; + extern (Windows) int function(int i, int j, int k) xxx; - a = 1; - b = 2; - c = 3; + a = 1; + b = 2; + c = 3; - xxx = cast(typeof(xxx))(a + b); - throw new Exception("xxx"); - xxx( 4, 5, 6 ); + xxx = cast(typeof(xxx))(a + b); + throw new Exception("xxx"); + xxx( 4, 5, 6 ); } void test35() @@ -737,7 +732,7 @@ void test37() { synchronized { - writefln("Hello world!"); + printf("Hello world!\n"); } } } @@ -768,7 +763,7 @@ static Rect sizeTest(bool empty) { } void print38(Rect r) { - writefln("(%d, %d)-(%d, %d)", r.left, r.top, r.right, r.bottom); + printf("(%d, %d)-(%d, %d)\n", r.left, r.top, r.right, r.bottom); assert(r.left == 0); assert(r.right == 0); assert(r.top == 0); @@ -781,37 +776,66 @@ Rect defaultRect() { /************************************************/ +void varargs39(...) +{ + if (_arguments[0] is typeid(double[])) + { + auto arg = va_arg!(double[])(_argptr); + assert(arg.length == 1 && arg[0] == 1 || arg[0] == 2); + } + else if (_arguments[0] is typeid(double[][])) + { + auto arg = va_arg!(double[][])(_argptr); + assert(arg == [[1],[2]]); + } + else if (_arguments[0] is typeid(double[1][])) + { + auto arg = va_arg!(double[1][])(_argptr); + assert(arg == [[1], [2]]); + } + else + assert(0); +} + void test39() { double[][] foo = [[1.0],[2.0]]; - writeln(foo[0]); // --> [1] , ok - writeln(foo[1]); // --> [2] , ok - - writeln(foo); // --> [[1],4.63919e-306] ack! - writefln("%s", foo); // --> ditto - auto f = std.string.format("%s", foo); - assert(f == "[[1], [2]]"); + varargs39(foo[0]); // --> [1] , ok + varargs39(foo[1]); // --> [2] , ok + varargs39(foo); // --> [[1],4.63919e-306] ack! double[1][2] bar; bar[0][0] = 1.0; bar[1][0] = 2.0; - writeln(bar); // Error: Access violation - auto r = std.string.format("%s", bar); - assert(r == "[[1], [2]]"); + varargs39(bar); // Error: Access violation } /************************************************/ +void varargs40(...) +{ + if (_arguments[0] is typeid(int[char])) + { + auto x = va_arg!(int[char])(_argptr); + assert(x == ['b':123]); + } + else if (_arguments[0] is typeid(int)) + { + auto x = va_arg!int(_argptr); + assert(x == 123); + } + else + assert(0); +} + void test40() { int[char] x; x['b'] = 123; - writeln(x); - auto r = std.string.format("%s", x); - assert(r == "['b':123]"); - writeln(x['b']); + varargs40(x); + varargs40(x['b']); } /************************************************/ @@ -855,12 +879,28 @@ void test44() /************************************************/ +void varargs45(...) +{ + if (_arguments[0] is typeid(const(char[3])[])) + { + auto a = va_arg!(const(char[3])[])(_argptr); + assert(a == ["abc", "def"]); + } + else if (_arguments[0] is typeid(const(char)[][])) + { + auto b = va_arg!(const(char)[][])(_argptr); + assert(b == ["abc", "def"]); + } + else + assert(0); +} + void test45() { - //char[3][] a = ["abc", "def"]; - //writefln(a); - //char[][2] b = ["abc", "def"]; - //writefln(b); + const(char)[3][] a = ["abc", "def"]; + varargs45(a); + const(char)[][2] b = ["abc", "def"]; + varargs45(b); } /************************************************/ @@ -981,26 +1021,22 @@ void test49() version (all) { - writefln("Before test 1: ", a.v); - if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } - else { writeln(a.v,"(a!=a.init)"); assert(a.v == 10); } + if (a == a.init) { assert(0); } + else { assert(a.v == 10); } } else { - writefln("Before test 1: ", a.v); - if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(a.v == 10); } - else { writeln(a.v,"(a!=a.init)"); assert(0); } + if (a == a.init) { assert(a.v == 10); } + else { assert(0); } } a.v = 100; - writefln("Before test 2: ", a.v); - if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } - else { writeln(a.v,"(a!=a.init)"); assert(a.v == 100); } + if (a == a.init) { assert(0); } + else { assert(a.v == 100); } a = A(1000); - writefln("Before test 3: ", a.v); - if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } - else { writeln(a.v,"(a!=a.init)"); assert(a.v == 1000); } + if (a == a.init) { assert(0); } + else { assert(a.v == 1000); } version (all) assert(a.init.v == 0); @@ -1044,14 +1080,6 @@ struct TestStruct void func53(TestStruct[2] testarg) { - writeln(testarg[0].dummy0); - writeln(testarg[0].dummy1); - writeln(testarg[0].dummy2); - - writeln(testarg[1].dummy0); - writeln(testarg[1].dummy1); - writeln(testarg[1].dummy2); - assert(testarg[0].dummy0 == 0); assert(testarg[0].dummy1 == 1); assert(testarg[0].dummy2 == 2); @@ -1061,11 +1089,10 @@ void func53(TestStruct[2] testarg) assert(testarg[1].dummy2 == 2); } -TestStruct m53[2]; +TestStruct[2] m53; void test53() { - writeln(&m53); func53(m53); } @@ -1076,13 +1103,11 @@ void test54() double a = 0; double b = 1; // Internal error: ..\ztc\cg87.c 3233 -// a += (1? b: 1+1i)*1i; - writeln(a); -// assert(a == 0); + a += ((1? b: 1+1i)*1i).re; + assert(a == 0); // Internal error: ..\ztc\cod2.c 1680 -// a += (b?1:b-1i)*1i; - writeln(a); -// assert(a == 0); + a += ((b?1:b-1i)*1i).re; + assert(a == 0); } /************************************************/ @@ -1101,7 +1126,7 @@ void test55() /************************************************/ template t56() { alias Object t56; } -pragma(msg, t56!().stringof); +static assert(t56!().stringof == "Object"); void test56() { @@ -1115,9 +1140,6 @@ void test57() static if (is(AA T : T[U], U : const char[])) { - writeln(typeid(T)); - writeln(typeid(U)); - assert(is(T == long)); assert(is(U == const(char)[])); } @@ -1129,9 +1151,7 @@ void test57() static if (is(int[10] W : W[V], int V)) { - writeln(typeid(W)); assert(is(W == int)); - writeln(V); assert(V == 10); } @@ -1295,7 +1315,7 @@ void main() test61(); test62(); - writefln("Success"); + printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable/test3449.d b/gcc/testsuite/gdc.test/runnable/test3449.d index d330cb95f20..8d389188463 100644 --- a/gcc/testsuite/gdc.test/runnable/test3449.d +++ b/gcc/testsuite/gdc.test/runnable/test3449.d @@ -1,6 +1,6 @@ /******************************************/ -// 3449 +// https://issues.dlang.org/show_bug.cgi?id=3449 template TypeTuple(T...) { alias TypeTuple = T; } @@ -13,6 +13,10 @@ static this() { mg1 = 10; cg1 = 10; +} + +shared static this() +{ ig1 = 10; } static assert(!__traits(compiles, { static assert(mg1 == 0); })); @@ -89,7 +93,7 @@ void test3449() } /******************************************/ -// 10643 +// https://issues.dlang.org/show_bug.cgi?id=10643 struct S10643 { diff --git a/gcc/testsuite/gdc.test/runnable/test3574a.d b/gcc/testsuite/gdc.test/runnable/test3574a.d index c2283f704b8..c6122e757a2 100644 --- a/gcc/testsuite/gdc.test/runnable/test3574a.d +++ b/gcc/testsuite/gdc.test/runnable/test3574a.d @@ -6,7 +6,7 @@ out { g = 100; } -body +do { return; // expected return code == 0 diff --git a/gcc/testsuite/gdc.test/runnable/test3574b.d b/gcc/testsuite/gdc.test/runnable/test3574b.d index d239ab68469..b256c64fe8b 100644 --- a/gcc/testsuite/gdc.test/runnable/test3574b.d +++ b/gcc/testsuite/gdc.test/runnable/test3574b.d @@ -6,7 +6,7 @@ out { g = 100; } -body +do { //return; // expected return code == 0 diff --git a/gcc/testsuite/gdc.test/runnable/test3574c.d b/gcc/testsuite/gdc.test/runnable/test3574c.d index 2974da53383..f93e22a81e8 100644 --- a/gcc/testsuite/gdc.test/runnable/test3574c.d +++ b/gcc/testsuite/gdc.test/runnable/test3574c.d @@ -6,7 +6,7 @@ void main() //{ // g = 100; //} -//body +//do { return; // expected return code == 0 diff --git a/gcc/testsuite/gdc.test/runnable/test3574d.d b/gcc/testsuite/gdc.test/runnable/test3574d.d index 0eaf2dd8e79..7976b345f2a 100644 --- a/gcc/testsuite/gdc.test/runnable/test3574d.d +++ b/gcc/testsuite/gdc.test/runnable/test3574d.d @@ -6,7 +6,7 @@ void main() //{ // g = 100; //} -//body +//do { //return; // expected return code == 0 diff --git a/gcc/testsuite/gdc.test/runnable/test37.d b/gcc/testsuite/gdc.test/runnable/test37.d index f4a454747b4..08305cbff5b 100644 --- a/gcc/testsuite/gdc.test/runnable/test37.d +++ b/gcc/testsuite/gdc.test/runnable/test37.d @@ -1,14 +1,15 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: // REQUIRED_ARGS: -Jrunnable/extra-files // EXTRA_FILES: extra-files/foo37.txt extra-files/std14198/uni.d -import std.stdio; +import core.stdc.stdio; void main() { - writefln(import("foo37.txt")); + auto s = import("foo37.txt"); + printf("%.*s\n", cast(int)s.length, s.ptr); // also want to ensure that we can access // imports in a subdirectory of the -J path - writefln(import("std14198/uni.d")); + s = import("std14198/uni.d"); + printf("%.*s\n", cast(int)s.length, s.ptr); } diff --git a/gcc/testsuite/gdc.test/runnable/test38.d b/gcc/testsuite/gdc.test/runnable/test38.d index 4fc728d4310..4c76e9f9f28 100644 --- a/gcc/testsuite/gdc.test/runnable/test38.d +++ b/gcc/testsuite/gdc.test/runnable/test38.d @@ -1,8 +1,14 @@ -// COMPILE_SEPARATELY -// EXTRA_SOURCES: imports/test38a.d -// PERMUTE_ARGS: +/* +COMPILE_SEPARATELY +EXTRA_SOURCES: imports/test38a.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +b = 49, 49 +--- +*/ -import std.stdio; +import core.stdc.stdio; import imports.test38a; void main() diff --git a/gcc/testsuite/gdc.test/runnable/test4.d b/gcc/testsuite/gdc.test/runnable/test4.d index 1d035726088..9811254cf60 100644 --- a/gcc/testsuite/gdc.test/runnable/test4.d +++ b/gcc/testsuite/gdc.test/runnable/test4.d @@ -1,5 +1,11 @@ // PERMUTE_ARGS: // REQUIRED_ARGS: +/* +TEST_OUTPUT: +--- +runnable/test4.d(717): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ import core.exception; import core.stdc.math; @@ -48,17 +54,17 @@ void test1() void test2() { - byte foo1[5]; - ubyte foo2[6]; - short foo3[7]; - ushort foo4[8]; - int foo5[9]; - uint foo6[10]; - long foo7[11]; - ulong foo8[12]; - float foo9[13]; - double foo10[14]; - real foo11[15]; + byte[5] foo1; + ubyte[6] foo2; + short[7] foo3; + ushort[8] foo4; + int[9] foo5; + uint[10] foo6; + long[11] foo7; + ulong[12] foo8; + float[13] foo9; + double[14] foo10; + real[15] foo11; int i; @@ -96,17 +102,17 @@ void test2() void test3() { - byte foo1[5] = 20; - ubyte foo2[6] = 21; - short foo3[7] = 22; - ushort foo4[8] = 23; - int foo5[9] = 24; - uint foo6[10] = 25; - long foo7[11] = 26; - ulong foo8[12] = 27; - float foo9[13] = 28; - double foo10[14] = 29; - real foo11[15] = 30; + byte[5] foo1 = 20; + ubyte[6] foo2 = 21; + short[7] foo3 = 22; + ushort[8] foo4 = 23; + int[9] foo5 = 24; + uint[10] foo6 = 25; + long[11] foo7 = 26; + ulong[12] foo8 = 27; + float[13] foo9 = 28; + double[14] foo10 = 29; + real[15] foo11 = 30; int i; @@ -257,13 +263,13 @@ struct TestVectors string replace; }; -TestVectors tva[] = +TestVectors[] tva = [ { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" }, { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" }, ]; -TestVectors tvs[2] = +TestVectors[2] tvs = [ { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" }, { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" }, @@ -360,8 +366,8 @@ const uint MAX_PATH1 = 260; enum { MAX_PATH2 = 261 } struct WIN32_FIND_DATA { - char cFileName1[MAX_PATH1]; - char cFileName2[MAX_PATH2]; + char[MAX_PATH1] cFileName1; + char[MAX_PATH2] cFileName2; } void test11() @@ -502,10 +508,10 @@ void test15() struct GUID { // size is 16 align(1): - uint Data1; - ushort Data2; - ushort Data3; - ubyte Data4[8]; + uint Data1; + ushort Data2; + ushort Data3; + ubyte[8] Data4; } @@ -543,26 +549,7 @@ void test16() /* ================================ */ -void test17() -{ - creal z = 1. + 2.0i; - - real r = z.re; - assert(r == 1.0); - - real i = z.im; - assert(i == 2.0); - - assert(r.im == 0.0); - assert(r.re == 1.0); - - assert(i.re == 2.0); - assert(i.im == 0.0i); -} - -/* ================================ */ - -private const uint crc_table[256] = [ +private const uint[256] crc_table = [ 0x00000000u, 0x77073096u, 0xee0e612cu, 0x990951bau, 0x076dc419u, 0x2d02ef8du ]; @@ -640,24 +627,6 @@ void test20() /* ================================ */ -void test21() -{ - ireal imag = 2.5i; - printf ("test of imag*imag = %Lf\n",imag*imag); - assert(imag * imag == -6.25); -} - -/* ================================ */ - -void test22() -{ - creal z1 = 1. - 2.0i; - ireal imag_part = z1.im/1i; -} - - -/* ================================ */ - int def23(int x, int y) { return x * y; @@ -978,11 +947,11 @@ void test43() { string s; - s = __FILE__; printf("file = '%.*s'\n", s.length, s.ptr); + s = __FILE__; printf("file = '%.*s'\n", cast(int)s.length, s.ptr); printf("line = %d\n", __LINE__); - s = __DATE__; printf("date = '%.*s'\n", s.length, s.ptr); - s = __TIME__; printf("time = '%.*s'\n", s.length, s.ptr); - s = __TIMESTAMP__; printf("timestamp = '%.*s'\n", s.length, s.ptr); + s = __DATE__; printf("date = '%.*s'\n", cast(int)s.length, s.ptr); + s = __TIME__; printf("time = '%.*s'\n", cast(int)s.length, s.ptr); + s = __TIMESTAMP__; printf("timestamp = '%.*s'\n", cast(int)s.length, s.ptr); } /* ================================ */ @@ -1143,7 +1112,10 @@ class Cout{ Cout set(int x){ return this; } - alias set opShl; + Cout opBinary(string op)(int x) if (op == "<<") + { + return set(x); + } } void test49() @@ -1250,7 +1222,7 @@ void test54() } catch(Exception e) { - printf("catch %.*s\n", e.msg.length, e.msg.ptr); + printf("catch %.*s\n", cast(int)e.msg.length, e.msg.ptr); assert(e.msg == "first"); assert(e.next.msg == "second"); } @@ -1270,7 +1242,7 @@ void foo55() catch (Exception e) { printf("inner catch %p\n", e); - printf("e.msg == %.*s\n", e.msg.length, e.msg.ptr); + printf("e.msg == %.*s\n", cast(int)e.msg.length, e.msg.ptr); assert(e.msg == "second"); //assert(e.msg == "first"); //assert(e.next.msg == "second"); @@ -1404,6 +1376,46 @@ void test59() /* ================================ */ +// https://issues.dlang.org/show_bug.cgi?id=10664 + +Exception collectExceptionE(int delegate () expression, ref int result) +{ + try + { + result = expression(); + } + catch (Exception e) + { + return e; + } + return null; +} + +RangeError collectExceptionR(int delegate () expression, ref int result) +{ + try + { + result = expression(); + } + catch (RangeError e) + { + return e; + } + return null; +} + +void test10664() +{ + int b; + int foo() { throw new Exception("blah"); } + assert(collectExceptionE(&foo, b)); + + int[] a = new int[3]; + int goo() { return a[4]; } + collectExceptionR(&goo, b); +} + +/* ================================ */ int main() @@ -1424,12 +1436,9 @@ int main() test14(); //test15(); test16(); - test17(); test18(); test19(); test20(); - test21(); - test22(); test23(); test24(); // test26(); @@ -1465,6 +1474,7 @@ int main() test57(); test58(); test59(); + test10664(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test40.d b/gcc/testsuite/gdc.test/runnable/test40.d index 528162b78c1..2c1069d52a4 100644 --- a/gcc/testsuite/gdc.test/runnable/test40.d +++ b/gcc/testsuite/gdc.test/runnable/test40.d @@ -2,7 +2,7 @@ // PERMUTE_ARGS: // REQUIRED_ARGS: -import std.stdio; +import core.stdc.stdio; import imports.test40a; class Foo { diff --git a/gcc/testsuite/gdc.test/runnable/test42.d b/gcc/testsuite/gdc.test/runnable/test42.d index e887faea2eb..57045ba00e7 100644 --- a/gcc/testsuite/gdc.test/runnable/test42.d +++ b/gcc/testsuite/gdc.test/runnable/test42.d @@ -1,4 +1,4 @@ -/* RUNNABLE_PHOBOS_TEST +/* REQUIRED_ARGS: TEST_OUTPUT: --- @@ -13,10 +13,10 @@ C6test427test219FZ8__mixin11C */ module test42; -import std.stdio; + import core.stdc.stdio; -import std.string; import core.memory; +import core.vararg; /***************************************************/ @@ -61,7 +61,7 @@ void test2() void test3() { auto i = mixin("__LINE__"); - writefln("%d", i); + printf("%d\n", i); assert(i == 63); } @@ -94,7 +94,8 @@ void test5() } /***************************************************/ -// Bug 1200. One case moved to deprecate1.d +// https://issues.dlang.org/show_bug.cgi?id=1200 +// One case moved to deprecate1.d void foo6a() { do @@ -162,8 +163,8 @@ void test8() void test9() { - writeln(long.max.stringof); - writeln(ulong.max.stringof); + //writeln(long.max.stringof); + //writeln(ulong.max.stringof); assert(long.max.stringof == "9223372036854775807L"); assert(ulong.max.stringof == "18446744073709551615LU"); } @@ -205,7 +206,7 @@ void test12() assert((foo ~ cast(char[])"foo").length == foo.length + 1); assert((cast(char[])"foo" ~ foo).length == foo.length + 1); - printf("%d\n", (foo ~ cast(char[])"foo")[0].length); + printf("%zd\n", (foo ~ cast(char[])"foo")[0].length); assert((foo ~ [cast(char[])"foo"]).length == foo.length + 1); @@ -421,7 +422,7 @@ void test25() int[10] arrayA = [0,1,2,3,4,5,6,7,8,9]; foreach(int i; arrayA) { - writeln(i); + printf("%d\n", i); } } @@ -532,11 +533,11 @@ struct S35 void test35() { S35 s; auto t = typeid(S35); - writefln("s = %s", s); - writefln("s = %s", t); + //writefln("s = %s", s); + //writefln("s = %s", t); auto tis = cast(TypeInfo_Struct)t; - writefln("s = %s", tis); - writefln("s = %s", tis.xtoString); + //writefln("s = %s", tis); + //writefln("s = %s", tis.xtoString); assert(tis.xtoString != null); } @@ -660,16 +661,6 @@ void test43() /***************************************************/ -void test44() -{ - ifloat f = 1.0fi; -// f *= 2.0fi; // illegal but compiles - writefln("%s", f); -// assert(f == 0i); -} - -/***************************************************/ - int foo45(int i) { if(i==0){ @@ -685,7 +676,7 @@ void test45() assert(foo45(0)==2); try{ foo45(1); - }catch{ + }catch(Throwable){ return cast(void)0; } assert(0); @@ -819,7 +810,7 @@ void test54() string[] k=["adf","AsdfadSF","dfdsfassdf"]; foreach(d;k) { - printf("%.*s\n", d.length, d.ptr); + printf("%.*s\n", cast(int)d.length, d.ptr); string foo() {assert(d!="");return d;} func54(&foo); func54(delegate string() {assert(d!="");return d;}); @@ -827,7 +818,7 @@ void test54() } /***************************************************/ -// bug 1767 +// https://issues.dlang.org/show_bug.cgi?id=1767 class DebugInfo { @@ -862,7 +853,7 @@ void test56() void writecrossing(bool goal) { - writeln(goal?"escape":"return"); + goal ? printf("escape\n") : printf("return\n"); } void test57() @@ -1313,15 +1304,15 @@ class C79 void test79() { C79 c = new C79(); - writeln(c.__vptr); - writeln(c.__vptr[0]); - writeln(cast(void*)c.classinfo); +// writeln(c.__vptr); +// writeln(c.__vptr[0]); +// writeln(cast(void*)c.classinfo); assert(c.__vptr[0] == cast(void*)c.classinfo); - writeln(c.__monitor); +// writeln(c.__monitor); assert(c.__monitor == null); synchronized (c) { - writeln(c.__monitor); +// writeln(c.__monitor); assert(c.__monitor !is null); } } @@ -1396,7 +1387,7 @@ void test83() void test84() { int[0][10] arr; - printf("%u\n", &arr[9] - &arr[0]); + printf("%tu\n", &arr[9] - &arr[0]); auto i = &arr[9] - &arr[0]; assert(i == 0); } @@ -1615,11 +1606,11 @@ void test96() void test97() { const short[] ct = cast(short[]) [cast(byte)1, 1]; - writeln(ct); +// writeln(ct); assert(ct.length == 2 && ct[0] == 1 && ct[1] == 1); short[] rt = cast(short[]) [cast(byte)1, cast(byte)1].dup; - writeln(rt); +// writeln(rt); assert(rt.length == 1 && rt[0] == 257); } @@ -1751,7 +1742,7 @@ void test105() { Templ!(int).Type x; auto s = Templ!(int).XXX; - writeln(s); + printf("%.*s\n", cast(int)s.length, s.ptr); assert(s == "i"); } @@ -1793,7 +1784,7 @@ void test108() void test109() { - double x[] = new double[1]; + double[] x = new double[1]; assert(x[0] != 0); } @@ -1860,7 +1851,7 @@ struct VariantN void bar(int value, int i) { - int args[2] = [ VariantN(value), VariantN(i) ]; + int[2] args = [ VariantN(value), VariantN(i) ]; } } @@ -2100,7 +2091,7 @@ void test129() } /***************************************************/ -// 12725 +// https://issues.dlang.org/show_bug.cgi?id=12725 struct R12725(R : E[], E) { @@ -2118,7 +2109,7 @@ void test12725() } /***************************************************/ -// 12728 +// https://issues.dlang.org/show_bug.cgi?id=12728 struct Matrix12728(T, uint m, uint n = m, ubyte f = 0) { @@ -2226,7 +2217,7 @@ void test135() void test136() { - struct S { int i[3]; } + struct S { int[3] i; } enum S s = S(8); const int i = s.i[2]; assert(i == 8); @@ -2286,7 +2277,7 @@ void test140() class Foo141 { Foo141 next; void start() - in { assert (!next); } body + in { assert (!next); } do { void* p = cast(void*)this; } @@ -2426,7 +2417,7 @@ bool foo150() } /***************************************************/ -// 3521 +// https://issues.dlang.org/show_bug.cgi?id=3521 void crash(int x) { @@ -2724,7 +2715,7 @@ enum FwdEnum : int } /***************************************************/ -// 3740 +// https://issues.dlang.org/show_bug.cgi?id=3740 abstract class Address { abstract int nameLen(); @@ -2848,12 +2839,6 @@ double[100_000] arr = 0.0; /***************************************************/ -alias ireal BUG3919; -alias typeof(BUG3919.init*BUG3919.init) ICE3919; -alias typeof(BUG3919.init/BUG3919.init) ICE3920; - -/***************************************************/ - struct S179 { char a, b, c, d; } @@ -2935,7 +2920,7 @@ void test181() } /***************************************************/ -// 4042 +// https://issues.dlang.org/show_bug.cgi?id=4042 template isQObjectType(T) { @@ -3193,7 +3178,7 @@ void test197() /***************************************************/ -void test198() // Bugzilla 4506 +void test198() // https://issues.dlang.org/show_bug.cgi?id=4506 { int c = 1; for (int k = 0; k < 2; k++) { @@ -3204,7 +3189,7 @@ void test198() // Bugzilla 4506 /***************************************************/ -// Bugzilla 4514 +// https://issues.dlang.org/show_bug.cgi?id=4514 void g199(void delegate(void*, void*) d) { } struct X199 { @@ -3216,7 +3201,7 @@ struct X199 { } /***************************************************/ -// Bugzilla 4443 +// https://issues.dlang.org/show_bug.cgi?id=4443 struct Struct4443 { @@ -3241,10 +3226,10 @@ void test200() /***************************************************/ -// Bugzilla 2931 +// https://issues.dlang.org/show_bug.cgi?id=2931 struct Bug2931 { - int val[3][4]; + int[4][3] val; } struct Outer2931 { @@ -3290,10 +3275,9 @@ void test201() { /***************************************************/ // This was the original varargs example in std.vararg -import core.vararg; void foo202(int x, ...) { - printf("%d arguments\n", _arguments.length); + printf("%zd arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { int j = va_arg!(int)(_argptr); printf("\t%d\n", j); @@ -3302,7 +3286,7 @@ void foo202(int x, ...) { } void fooRef202(ref int x, ...) { - printf("%d arguments\n", _arguments.length); + printf("%zd arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { int j = va_arg!(int)(_argptr); printf("\t%d\n", j); @@ -3321,7 +3305,7 @@ void test202() } /***************************************************/ -// Bugzilla 1418 +// https://issues.dlang.org/show_bug.cgi?id=1418 class A203 { @@ -3343,22 +3327,22 @@ void test203() auto b = a.new B203; auto c = new C203; - writeln(a.tupleof); // prints: A - writeln(b.tupleof); // prints: B main.A - writeln(c.tupleof); // prints: C 0000 +// writeln(a.tupleof); // prints: A +// writeln(b.tupleof); // prints: B main.A +// writeln(c.tupleof); // prints: C 0000 assert(a.tupleof.length == 1 && a.tupleof[0] == 'A'); assert(b.tupleof.length == 1 && b.tupleof[0] == 'B'); assert(c.tupleof.length == 1 && c.tupleof[0] == 'C'); } /***************************************************/ -// Bugzilla 4516 +// https://issues.dlang.org/show_bug.cgi?id=4516 struct A204 { B204 b; } enum B204 { Z } /***************************************************/ -// Bugzilla 4503 +// https://issues.dlang.org/show_bug.cgi?id=4503 class Collection205(T) { } ICollection c; @@ -3451,13 +3435,13 @@ template Bug6602B(U) { enum bug6602Compiles = __traits(compiles, Bug6602A!short); /***************************************************/ -// Bugzilla 3493 +// https://issues.dlang.org/show_bug.cgi?id=3493 const bar209 = foo209; const int * foo209 = null; /***************************************************/ -// 3418 +// https://issues.dlang.org/show_bug.cgi?id=3418 void test210() { @@ -3482,7 +3466,7 @@ void test212() } /***************************************************/ -// 4768 +// https://issues.dlang.org/show_bug.cgi?id=4768 struct A213 { B213 b; } enum B213 { Z213 = 2 } @@ -3515,7 +3499,6 @@ void test215() { class C {} enum assocarrayliteral = Q!( [1:2] ).q.stringof; - enum complex80 = Q!( 1+1.0i ).q.stringof; //enum dottype = Q!( C.Object.toString ).q.stringof; enum halt = 0.stringof; // ICE w/ -release //enum remove = Q!( [1:2].remove(1) ).q.stringof; @@ -3523,7 +3506,7 @@ void test215() } /***************************************************/ -// 4941 +// https://issues.dlang.org/show_bug.cgi?id=4941 template T216(_...) { alias _ T216; } size_t mid216(size_t n) { return n/2; } @@ -3558,7 +3541,7 @@ void test217() } /***************************************************/ -// 2954 +// https://issues.dlang.org/show_bug.cgi?id=2954 void test218() { @@ -3574,7 +3557,7 @@ void test218() } /***************************************************/ -// 2206 +// https://issues.dlang.org/show_bug.cgi?id=2206 template T219(U) { class C {} @@ -3593,7 +3576,7 @@ void test219() /***************************************************/ -// 2206 +// https://issues.dlang.org/show_bug.cgi?id=2206 class D220 {} @@ -3606,9 +3589,9 @@ void test220() mixin T220!(int); // all print 8 - writeln(T220!(int).C.classinfo.initializer.length); - writeln(C.classinfo.initializer.length); - writeln(D220.classinfo.initializer.length); +// writeln(T220!(int).C.classinfo.initializer.length); +// writeln(C.classinfo.initializer.length); +// writeln(D220.classinfo.initializer.length); auto c = new C; // segfault in _d_newclass } @@ -3677,7 +3660,7 @@ synchronized shared class C5105 } /***************************************************/ -// 5145 +// https://issues.dlang.org/show_bug.cgi?id=5145 interface I221{ void bla(); @@ -3692,7 +3675,7 @@ class A221 : B221 { final override I221 sync() in { assert( valid ); } - body + do { return null; } @@ -3702,7 +3685,7 @@ class B221 : J221 { override I221 sync() in { assert( valid ); } - body + do { return null; } @@ -3729,7 +3712,7 @@ template Bug3276_b(alias W) { alias Bug3276_b!(Bug3276) Bug3276_c; /***************************************************/ -// 5294 +// https://issues.dlang.org/show_bug.cgi?id=5294 void foo222(int) {} @@ -3757,7 +3740,7 @@ void test223() } /***************************************************/ -// 4379 +// https://issues.dlang.org/show_bug.cgi?id=4379 template BigTuple(U...) { alias U BigTuple; @@ -3777,7 +3760,7 @@ void test224() } /***************************************************/ -// 3681 +// https://issues.dlang.org/show_bug.cgi?id=3681 public final class A3681 { private this() { @@ -3876,7 +3859,7 @@ static assert(mixin(ice4390()) == ``); static assert(mixin(ice4390()) == ``); /***************************************************/ -// 190 +// https://issues.dlang.org/show_bug.cgi?id=190 alias int avocado; void eat(avocado x225 = .x225); @@ -3887,7 +3870,7 @@ void test225() } /***************************************************/ -// 5534 +// https://issues.dlang.org/show_bug.cgi?id=5534 void doStuff(byte start, byte end, uint increment = 1U) { auto output = new byte[3]; @@ -3903,7 +3886,7 @@ void test226() { } /***************************************************/ -// 5536 +// https://issues.dlang.org/show_bug.cgi?id=5536 void test227() { @@ -3914,7 +3897,7 @@ void test227() } /***************************************************/ -// 4017 +// https://issues.dlang.org/show_bug.cgi?id=4017 struct _A { @@ -3926,7 +3909,7 @@ const A_SIZE = (A4017.sizeof); alias _A A4017; /***************************************************/ -// 5455 +// https://issues.dlang.org/show_bug.cgi?id=5455 void thrw(Data *s) { throw new Exception("xxx"); @@ -3959,7 +3942,7 @@ struct Resp { } /**************************************/ -// 5571 +// https://issues.dlang.org/show_bug.cgi?id=5571 void test228() { auto b = new bool; @@ -3968,7 +3951,7 @@ void test228() { } /***************************************************/ -// 5572 +// https://issues.dlang.org/show_bug.cgi?id=5572 void doSynchronized() { printf("In doSynchronized() 1: %p\n", cast(void*) global229); @@ -3994,10 +3977,10 @@ void test229() { /***************************************************/ -static immutable real negtab[14] = +static immutable real[14] negtab = [ 1e-4096L,1e-2048L,1e-1024L,1e-512L,1e-256L,1e-128L,1e-64L,1e-32L, 1e-16L,1e-8L,1e-4L,1e-2L,1e-1L,1.0L ]; -static immutable real postab[13] = +static immutable real[13] postab = [ 1e+4096L,1e+2048L,1e+1024L,1e+512L,1e+256L,1e+128L,1e+64L,1e+32L, 1e+16L,1e+8L,1e+4L,1e+2L,1e+1L ]; @@ -4095,7 +4078,7 @@ void bug5717() } /***************************************************/ -// 3086 +// https://issues.dlang.org/show_bug.cgi?id=3086 class X231 { void a() {} @@ -4115,7 +4098,7 @@ void test231() { } /***************************************************/ -// 4140 +// https://issues.dlang.org/show_bug.cgi?id=4140 const A232 = [1,2,3]; const B232 = A232[1..A232.length]; @@ -4133,7 +4116,7 @@ void test232() } /***************************************************/ -// 1389 +// https://issues.dlang.org/show_bug.cgi?id=1389 void test233() { @@ -4142,7 +4125,7 @@ void test233() } /***************************************************/ -// 5735 +// https://issues.dlang.org/show_bug.cgi?id=5735 struct A234 {} @@ -4204,7 +4187,7 @@ void bug6184() { bool cmp(ref int[3] a, ref int[3] b) { - return a is b; + return a[] is b[]; } static struct Ary @@ -4224,7 +4207,7 @@ void bug6184() } /***************************************************/ -// 6229 +// https://issues.dlang.org/show_bug.cgi?id=6229 int test6229() { @@ -4288,13 +4271,13 @@ void test236() /***************************************************/ -// 4460 +// https://issues.dlang.org/show_bug.cgi?id=4460 void test237() { foreach (s, i; [ "a":1, "b":2 ]) { - writeln(s, i); + //writeln(s, i); } } @@ -4327,7 +4310,7 @@ void test238() } /***************************************************/ -// 5239 +// https://issues.dlang.org/show_bug.cgi?id=5239 struct S239 { int x; } @@ -4353,22 +4336,25 @@ void test6506() { } /***************************************************/ -// 6505 +// https://issues.dlang.org/show_bug.cgi?id=6505 double foo240() { return 1.0; } void test240() { - double a = foo240(); - double b = foo240(); - double x = a*a + a*a + a*a + a*a + a*a + a*a + a*a + + double a = void; + double b = void; + double x = void; + a = foo240(); + b = foo240(); + x = a*a + a*a + a*a + a*a + a*a + a*a + a*a + a*b + a*b; assert(x > 0); } /***************************************************/ -// 6563 +// https://issues.dlang.org/show_bug.cgi?id=6563 int foo6563(float a, float b, float c, float d, float e, float f, float g, float h) { @@ -4480,7 +4466,7 @@ void test6189() { } /***************************************************/ -// 6997 +// https://issues.dlang.org/show_bug.cgi?id=6997 long fun6997(long a,long b,long c) { @@ -4517,6 +4503,7 @@ void test6997() auto x = S6997().foo(); } + /***************************************************/ ubyte foo7026(uint n) { @@ -4584,7 +4571,7 @@ struct Point6881 } /***************************************************/ -// 7212 +// https://issues.dlang.org/show_bug.cgi?id=7212 void foo7212(scope int delegate(int a) dg) { } @@ -4612,7 +4599,7 @@ void test242() } /***************************************************/ -// 7290 +// https://issues.dlang.org/show_bug.cgi?id=7290 void foo7290a(alias dg)() { @@ -4634,11 +4621,13 @@ void test7290() int add = 2; scope dg = (int a) => a + add; + // This will break with -preview=dip1000 because a closure will no longer be allocated assert(GC.addrOf(dg.ptr) == null); foo7290a!dg(); foo7290b(dg); - foo7290c(dg); + foo7290c(dg); // this will fail with -preview=dip1000 and @safe because a scope delegate gets + // assigned to @system delegate, but no closure was allocated } /***************************************************/ @@ -4651,7 +4640,7 @@ void test7367() } /***************************************************/ -// 7375 +// https://issues.dlang.org/show_bug.cgi?id=7375 class A7375 {} class B7375(int i) : A7375 {} @@ -4833,7 +4822,7 @@ void test243() { } /***************************************************/ -// 7742 +// https://issues.dlang.org/show_bug.cgi?id=7742 struct Foo7742 { static immutable f = Foo7742(1, 2); @@ -4855,7 +4844,7 @@ void test7742() } /***************************************************/ -// 7807 +// https://issues.dlang.org/show_bug.cgi?id=7807 interface Interface7807 { @@ -4890,7 +4879,7 @@ void test7807() } /***************************************************/ -// 7815 +// https://issues.dlang.org/show_bug.cgi?id=7815 enum Closure { Matrix @@ -4985,7 +4974,7 @@ struct Foo7974 } /***************************************************/ -// 4155 +// https://issues.dlang.org/show_bug.cgi?id=4155 float getnanf() { return float.nan; } @@ -5000,7 +4989,7 @@ void test4155() } /***************************************************/ -// 7911 +// https://issues.dlang.org/show_bug.cgi?id=7911 struct Klass7911 { @@ -5020,7 +5009,7 @@ void test7911() } /***************************************************/ -// 8429 +// https://issues.dlang.org/show_bug.cgi?id=8429 static if(true) version = Foo8429; @@ -5028,7 +5017,7 @@ static if(true) version(Foo8429) {} /***************************************************/ -// 8069 +// https://issues.dlang.org/show_bug.cgi?id=8069 interface I8069 { @@ -5044,7 +5033,7 @@ struct A8069 } /***************************************************/ -// 8095 +// https://issues.dlang.org/show_bug.cgi?id=8095 void bug8095(int p0, int *p1, int z, int edx, int *p4, int p5) { @@ -5068,7 +5057,7 @@ void test8095() { } /***************************************************/ -// 8091 +// https://issues.dlang.org/show_bug.cgi?id=8091 int solve1(int n) { int a; @@ -5114,7 +5103,7 @@ void test6189_2() } /***************************************************/ -// 8199 +// https://issues.dlang.org/show_bug.cgi?id=8199 version (D_InlineAsm_X86_64) { @@ -5126,6 +5115,8 @@ else version (D_InlineAsm_X86) version = Check; version (OSX) enum Align = 0xC; +// version (linux) +// enum Align = 0xC; } void onFailure() @@ -5167,6 +5158,21 @@ void test8199() } /***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=13285 +void test13285() +{ + static struct S + { + ~this() + { + checkAlign(); + } + } + S s; // correct alignment of RSP when calling ~this() + S(); // incorrect alignment +} + +/***************************************************/ void test246() { @@ -5178,15 +5184,7 @@ void test246() } /***************************************************/ - -double sqrt8454(double d) { return d/2; } -void foo8454(cdouble m) {} -void test8454() { - foo8454(0 - sqrt8454(1.0) * 1i); -} - -/***************************************************/ -// 8423 +// https://issues.dlang.org/show_bug.cgi?id=8423 struct S8423 { @@ -5217,8 +5215,7 @@ public: ubyte size = value < (0x7fU << 0 ) ? 1 : value < (0x7fU << 14) ? 2 : 3; - import std.stdio; - writeln(size); + printf("%u\n", size); assert(size == 2); } } @@ -5336,7 +5333,7 @@ void test247() } /***************************************************/ -// 8340 +// https://issues.dlang.org/show_bug.cgi?id=8340 void test8340(){ byte[] ba = [1,2,3,4,5]; @@ -5356,7 +5353,7 @@ void test8340(){ } /***************************************************/ -// 8376 +// https://issues.dlang.org/show_bug.cgi?id=8376 void test8376() { int i = 0; @@ -5392,7 +5389,7 @@ void test8987(){ } /***************************************************/ -// 8796 +// https://issues.dlang.org/show_bug.cgi?id=8796 int* wrong8796(int* p) { @@ -5409,7 +5406,7 @@ void test8796() } /***************************************************/ -// 9171 +// https://issues.dlang.org/show_bug.cgi?id=9171 ulong bitcomb9171(ulong v) { @@ -5447,7 +5444,7 @@ void test9171() } /***************************************************/ -// 9248 +// https://issues.dlang.org/show_bug.cgi?id=9248 void test9248() { @@ -5458,7 +5455,7 @@ void test9248() } /***************************************************/ -// 14682 +// https://issues.dlang.org/show_bug.cgi?id=14682 void test14682a() { @@ -5562,8 +5559,9 @@ void test14682b() { auto x = [[[[]]]] ~ a3; static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4b); } // fix } + /***************************************************/ -// 9739 +// https://issues.dlang.org/show_bug.cgi?id=9739 class Foo9739 { @@ -5580,7 +5578,7 @@ void test9739() } /***************************************************/ -// 6057 +// https://issues.dlang.org/show_bug.cgi?id=6057 void test6057() { enum Foo { A=1, B=2 } @@ -5665,7 +5663,7 @@ void testreal_to_ulong() static assert(false, "Test not implemented for this architecture"); auto v = r2ulong(adjust * 1.1); - writefln("%s %s %s", adjust, v, u + u/10); + //writefln("%s %s %s", adjust, v, u + u/10); //assert(v == 10145709240540253389UL); } @@ -5808,7 +5806,7 @@ void test251() } /***************************************************/ -// 9387 +// https://issues.dlang.org/show_bug.cgi?id=9387 void bug9387a(double x) { } @@ -5866,10 +5864,15 @@ void test4414() { assert(x == 7); } { - auto x = bytes4414()[0..4]; + auto u = bytes4414(); + auto x = u[0..4]; if (x[0] != 7 || x[1] != 8 || x[2] != 9 || x[3] != 10) assert(0); } + assert(bytes4414()[0] == 7); + assert(bytes4414()[1] == 8); + assert(bytes4414()[2] == 9); + assert(bytes4414()[3] == 10); } /***************************************************/ @@ -5882,7 +5885,7 @@ void test9844() { } /***************************************************/ -// 10628 +// https://issues.dlang.org/show_bug.cgi?id=10628 abstract class B10628 { @@ -5905,7 +5908,7 @@ void test10628() } /***************************************************/ -// 11265 +// https://issues.dlang.org/show_bug.cgi?id=11265 struct S11265 { @@ -5956,8 +5959,6 @@ void test10633() /***************************************************/ -import std.stdio; - void _assertEq (ubyte lhs, short rhs, string msg, string file, size_t line) { immutable result = lhs == rhs; @@ -5966,9 +5967,9 @@ void _assertEq (ubyte lhs, short rhs, string msg, string file, size_t line) { string op = "=="; if(msg.length > 0) - writefln(`_assertEq failed: [%s] is not [%s].`, lhs, rhs); + printf("_assertEq failed: [%u] is not [%d].\n", lhs, rhs); else - writefln(`_assertEq failed: [%s] is not [%s]: %s`, lhs, rhs, msg); + printf("_assertEq failed: [%u] is not [%d]: %.*s\n", lhs, rhs, cast(int)msg.length, msg.ptr); } assert(result); @@ -5998,7 +5999,7 @@ void test10642() } /***************************************************/ -// 11581 +// https://issues.dlang.org/show_bug.cgi?id=11581 alias TT11581(T...) = T; @@ -6036,7 +6037,7 @@ void test11581() } /***************************************************/ -// 7436 +// https://issues.dlang.org/show_bug.cgi?id=7436 void test7436() { @@ -6047,7 +6048,7 @@ void test7436() } /***************************************************/ -// 12138 +// https://issues.dlang.org/show_bug.cgi?id=12138 struct S12138 { @@ -6064,7 +6065,7 @@ label: } /***************************************************/ -// 14430 +// https://issues.dlang.org/show_bug.cgi?id=14430 void setCookie(long x = 1L << 32L, string y = null){ assert(y.ptr is null); @@ -6075,7 +6076,7 @@ void test14430(){ } /***************************************************/ -// 14510 +// https://issues.dlang.org/show_bug.cgi?id=14510 alias Vector14510 = ulong[3]; @@ -6118,7 +6119,7 @@ double entropy2(double[] probs) __gshared int x; ++x; if (!p) continue; - import std.math : log2; + import core.stdc.math : log2; result -= p * log2(p); } return result; @@ -6126,7 +6127,6 @@ double entropy2(double[] probs) void test16530() { - import std.stdio; if (entropy2([1.0, 0, 0]) != 0.0) assert(0); } @@ -6144,9 +6144,42 @@ void test252() } /***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=7997 + +void test7997() +{ + __gshared int[0] foos; + foreach (f; foos) {} +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=5332 + +int[0] arr5332; + +void test5332() +{ + auto a = arr5332; +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=11742 + +const int x11472 = void; + +static this() { x11472 = 10; } + +void test11472() +{ + assert(x11472 == 10); +} + + +/***************************************************/ int main() { + checkAlign(); test1(); test2(); test3(); @@ -6188,7 +6221,6 @@ int main() test41(); test42(); test43(); - test44(); test45(); test46(); test47(); @@ -6404,7 +6436,6 @@ int main() test6189_2(); test8199(); test246(); - test8454(); test8423(); test8496(); test8840(); @@ -6443,8 +6474,11 @@ int main() test16027(); test16530(); test252(); + test7997(); + test5332(); + test11472(); + test13285(); - writefln("Success"); + printf("Success\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/test42a.d b/gcc/testsuite/gdc.test/runnable/test42a.d index 0bb98efcff0..10c09b3e665 100644 --- a/gcc/testsuite/gdc.test/runnable/test42a.d +++ b/gcc/testsuite/gdc.test/runnable/test42a.d @@ -1,4 +1,10 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Success +--- +*/ module test42; @@ -312,4 +318,3 @@ int main() printf("Success\n"); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/test435.d b/gcc/testsuite/gdc.test/runnable/test435.d index 4dcabd1fcff..700e9fd0eba 100644 --- a/gcc/testsuite/gdc.test/runnable/test435.d +++ b/gcc/testsuite/gdc.test/runnable/test435.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ import core.stdc.stdio; class A @@ -65,7 +71,7 @@ void test1() //------------------------------------------------------------------------------ -// bug 435. +// https://issues.dlang.org/show_bug.cgi?id=435. class B { int i; @@ -90,7 +96,7 @@ void test2() //------------------------------------------------------------------------------ -// bug 4905 +// https://issues.dlang.org/show_bug.cgi?id=4905 class C2 { string x; @@ -114,7 +120,7 @@ void test3() //------------------------------------------------------------------------------ -// bug 4531 test case 2 +// https://issues.dlang.org/show_bug.cgi?id=4531 test case 2 class MyError : Exception { this(T...)(T msg) @@ -139,5 +145,3 @@ void main() test4(); printf("Success\n"); } - - diff --git a/gcc/testsuite/gdc.test/runnable/test45.d b/gcc/testsuite/gdc.test/runnable/test45.d index 49fa548351a..d36b378e250 100644 --- a/gcc/testsuite/gdc.test/runnable/test45.d +++ b/gcc/testsuite/gdc.test/runnable/test45.d @@ -1,5 +1,17 @@ -// EXTRA_SOURCES: imports/test45a.d imports/test45b.d -// PERMUTE_ARGS: +/* +EXTRA_SOURCES: imports/test45a.d imports/test45b.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +foo() +foo(int) +foo() +foo() +foo(int) +bar(t) +bar(t,i) +--- +*/ import imports.test45a; import imports.test45b; diff --git a/gcc/testsuite/gdc.test/runnable/test48.d b/gcc/testsuite/gdc.test/runnable/test48.d index 827d681259b..36160e5637d 100644 --- a/gcc/testsuite/gdc.test/runnable/test48.d +++ b/gcc/testsuite/gdc.test/runnable/test48.d @@ -1,7 +1,7 @@ // EXTRA_SOURCES: imports/test48a.d // PERMUTE_ARGS: -import std.stdio; +import core.stdc.stdio; import imports.test48a; void main() @@ -16,28 +16,28 @@ void main() printf("i = %d\n", i); assert(i == 6); - printf("a = %d %d %d\n", S.tupleof.offsetof); + printf("a = %zd %zd %zd\n", S.tupleof.offsetof); auto o = S.tupleof.offsetof; assert(o[0] == 0); assert(o[1] == 4); assert(o[2] == 8); - printf("a = %d %d %d\n", S.tupleof[0].offsetof, S.tupleof[1].offsetof, S.tupleof[2].offsetof); + printf("a = %zd %zd %zd\n", S.tupleof[0].offsetof, S.tupleof[1].offsetof, S.tupleof[2].offsetof); assert(S.tupleof[0].offsetof == 0); assert(S.tupleof[1].offsetof == 4); assert(S.tupleof[2].offsetof == 8); auto offset0 = cast(void*)&s.tupleof[0] - cast(void*)&s; - printf("offset0 = %d\n", offset0); + printf("offset0 = %td\n", offset0); assert(offset0 == 0); auto offset1 = cast(void*)&s.tupleof[1] - cast(void*)&s; - printf("offset1 = %d\n", offset1); + printf("offset1 = %td\n", offset1); assert(offset1 == 4); auto offset2 = cast(void*)&s.tupleof[2] - cast(void*)&s; - printf("offset2 = %d\n", offset2); + printf("offset2 = %td\n", offset2); assert(offset2 == 8); - int t1[S.tupleof.offsetof[1]]; + int[S.tupleof.offsetof[1]] t1; assert(t1.length == 4); } diff --git a/gcc/testsuite/gdc.test/runnable/test49.d b/gcc/testsuite/gdc.test/runnable/test49.d index fc80d61fd99..641d196b59b 100644 --- a/gcc/testsuite/gdc.test/runnable/test49.d +++ b/gcc/testsuite/gdc.test/runnable/test49.d @@ -1,6 +1,13 @@ -// COMPILE_SEPARATELY -// EXTRA_SOURCES: imports/test49a.d -// PERMUTE_ARGS: +/* +COMPILE_SEPARATELY +EXTRA_SOURCES: imports/test49a.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +static this() +static ~this() +--- +*/ import imports.test49a; @@ -9,4 +16,3 @@ alias Foo!(int) foo; void main() { } - diff --git a/gcc/testsuite/gdc.test/runnable/test5.d b/gcc/testsuite/gdc.test/runnable/test5.d index 7d9769dc03d..a14b4b13271 100644 --- a/gcc/testsuite/gdc.test/runnable/test5.d +++ b/gcc/testsuite/gdc.test/runnable/test5.d @@ -40,7 +40,7 @@ class bar : foo int def(foo f) { - printf("def(%p), %p\n", f, (cast(int*)f)[0]); + printf("def(%p), %d\n", f, (cast(int*)f)[0]); assert(f.testc(3) == 50); assert(f.testd(7) == 54); assert(f.testd(10) == 57); @@ -49,7 +49,7 @@ int def(foo f) void abc(bar b) { - printf("abc(%p), %p\n", b, (cast(int*)b)[3]); + printf("abc(%p), %d\n", b, (cast(int*)b)[3]); def(b); } @@ -57,8 +57,8 @@ int main() { bar b = new bar(); - printf("b.size = x%x\n", b.classinfo.initializer.length); - printf("bar.size = x%x\n", bar.classinfo.initializer.length); + printf("b.size = x%zx\n", b.classinfo.initializer.length); + printf("bar.size = x%zx\n", bar.classinfo.initializer.length); assert(b.classinfo.initializer.length == bar.classinfo.initializer.length); abc(b); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test52.d b/gcc/testsuite/gdc.test/runnable/test52.d index 2a906d0f454..85b8d6725d7 100644 --- a/gcc/testsuite/gdc.test/runnable/test52.d +++ b/gcc/testsuite/gdc.test/runnable/test52.d @@ -1,29 +1,36 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +count = 3 +--- +*/ -// 2311 +// https://issues.dlang.org/show_bug.cgi?id=2311 -extern(C) +extern(C) int printf(const char*, ...); + +__gshared ulong count; + +shared static ~this() { - void exit(int); - int printf(const char*, ...); + printf("count = %llu\n", count); + assert(count == 3); } -struct X() +template X(uint idx) { - static this() - { - printf("this()\n"); - } - static ~this() - { - printf("~this()\n"); - exit(0); - } + static ~this() + { + assert(count == idx); + ++count; + } } -static ~this() +void main() { - printf("g: ~this()\n"); + // Instantiate module destructors in reverse order + alias x = X!(2); + alias y = X!(1); + alias z = X!(0); } - -int main() { alias X!() x; return 1; } diff --git a/gcc/testsuite/gdc.test/runnable/test5305.d b/gcc/testsuite/gdc.test/runnable/test5305.d deleted file mode 100644 index ff52936a8dc..00000000000 --- a/gcc/testsuite/gdc.test/runnable/test5305.d +++ /dev/null @@ -1,8 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// https://issues.dlang.org/show_bug.cgi?id=5305 - -import std.math; -void map(real function(real) f) { } -int main() { map(&sqrt); return 0; } - - diff --git a/gcc/testsuite/gdc.test/runnable/test60.d b/gcc/testsuite/gdc.test/runnable/test60.d deleted file mode 100644 index cfd92b225ca..00000000000 --- a/gcc/testsuite/gdc.test/runnable/test60.d +++ /dev/null @@ -1,23 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; -import std.algorithm; - -void test1() -{ - int[] a = [1,2,3,4,5]; - writeln( remove!("a < 3")(a) ); -} - -void test2() -{ - auto arr = [1,2,3,4,5]; - auto m = map!"a + 1"(filter!"a < 4"(arr)); -} - -void main() -{ - test1(); - test2(); - - writeln("Success"); -} diff --git a/gcc/testsuite/gdc.test/runnable/test61.d b/gcc/testsuite/gdc.test/runnable/test61.d index 6e097699127..016e9a0d237 100644 --- a/gcc/testsuite/gdc.test/runnable/test61.d +++ b/gcc/testsuite/gdc.test/runnable/test61.d @@ -1,7 +1,7 @@ // PERMUTE_ARGS: // EXTRA_SOURCES: imports/test61a.d -// Bugzilla 6556 +// https://issues.dlang.org/show_bug.cgi?id=6556 debug=BUG; diff --git a/gcc/testsuite/gdc.test/runnable/test6795.d b/gcc/testsuite/gdc.test/runnable/test6795.d new file mode 100644 index 00000000000..7e44fd4ad7a --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test6795.d @@ -0,0 +1,26 @@ +// https://issues.dlang.org/show_bug.cgi?id=6795 +void check6795() +{ + enum int[] array = [0]; + // PostExp + assert(array[0]++ == 0); + assert(array[0]-- == 0); + // PreExp + assert(++array[0] == 1); + assert(--array[0] == -1); + // BinAssignExp + assert((array[0] += 3) == 3); +} + +// https://issues.dlang.org/show_bug.cgi?id=21312 +void check21312() +{ + auto p = &[123][0]; + assert(*p == 123); +} + +void main() +{ + check6795(); + check21312(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test711.d b/gcc/testsuite/gdc.test/runnable/test711.d new file mode 100644 index 00000000000..b9fae4e749e --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test711.d @@ -0,0 +1,51 @@ +// https://issues.dlang.org/show_bug.cgi?id=711 +string result; + +template Mixer() +{ + override void test() + { + result ~= "A"; + } +} + +class Foo +{ + void test() + { + result ~= "B"; + } +} + +class Bar : Foo +{ + mixin Mixer!() mixer; + override void test() + { + result ~= "C"; + mixer.test(); + } +} + +class Bar2 : Foo +{ + override void test() + { + result ~= "C"; + mixer.test(); + } + mixin Mixer!() mixer; +} + +void main() +{ + Bar f = new Bar(); + f.test(); + assert(result == "CA"); + + result = ""; + + Bar2 f2 = new Bar2(); + f2.test(); + assert(result == "CA"); +} diff --git a/gcc/testsuite/gdc.test/runnable/test7452.d b/gcc/testsuite/gdc.test/runnable/test7452.d index cc0452907d6..de591f39e76 100644 --- a/gcc/testsuite/gdc.test/runnable/test7452.d +++ b/gcc/testsuite/gdc.test/runnable/test7452.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ import core.stdc.stdio : printf; //------------------------------------------------------------------------------ @@ -71,5 +77,3 @@ int main() printf("Success\n"); return 0; } - - diff --git a/gcc/testsuite/gdc.test/runnable/test7511.d b/gcc/testsuite/gdc.test/runnable/test7511.d index 0d19f5466dd..bb879957d4c 100644 --- a/gcc/testsuite/gdc.test/runnable/test7511.d +++ b/gcc/testsuite/gdc.test/runnable/test7511.d @@ -1,7 +1,13 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); /**********************************/ -// 7511 +// https://issues.dlang.org/show_bug.cgi?id=7511 struct S7511(T) { @@ -186,7 +192,7 @@ void test7511d() } /**********************************/ -// 9952 +// https://issues.dlang.org/show_bug.cgi?id=9952 @system void writeln9952(int) {} // impure throwable @@ -214,7 +220,7 @@ void test9952() } /**********************************/ -// 10373 +// https://issues.dlang.org/show_bug.cgi?id=10373 template isMutable10373(T) { @@ -294,7 +300,7 @@ void test10373() } /**********************************/ -// 10329 +// https://issues.dlang.org/show_bug.cgi?id=10329 auto foo10329(T)(T arg) { @@ -326,7 +332,7 @@ void test10329() pure nothrow @safe } /**********************************/ -// 11896 +// https://issues.dlang.org/show_bug.cgi?id=11896 class Foo11896a(T = int) { @@ -393,7 +399,7 @@ void test11896c() } /**********************************/ -// 12392 +// https://issues.dlang.org/show_bug.cgi?id=12392 void f12392(T)() {} alias fa12392 = f12392; diff --git a/gcc/testsuite/gdc.test/runnable/test7932.d b/gcc/testsuite/gdc.test/runnable/test7932.d index 245cf178648..22aa279ce5b 100644 --- a/gcc/testsuite/gdc.test/runnable/test7932.d +++ b/gcc/testsuite/gdc.test/runnable/test7932.d @@ -1,6 +1,6 @@ -// 7932 +// https://issues.dlang.org/show_bug.cgi?id=7932 -import std.stdio; +import core.stdc.stdio; size_t N; @@ -13,7 +13,7 @@ class C cast(void*) this, &n, n); assert (N == n); } - body + do { int dummy; //printf("\n"); diff --git a/gcc/testsuite/gdc.test/runnable/test8.d b/gcc/testsuite/gdc.test/runnable/test8.d index 4927bbc97ed..7d66eb6c623 100644 --- a/gcc/testsuite/gdc.test/runnable/test8.d +++ b/gcc/testsuite/gdc.test/runnable/test8.d @@ -1,3 +1,9 @@ +/* +TEST_OUTPUT: +--- +runnable/test8.d(261): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference +--- +*/ module testxxx8; @@ -167,28 +173,6 @@ void test8() /***********************************/ -void test9() -{ - ireal imag = 2.5i; - //printf ("test of imag*imag = %Lf\n",imag*imag); - real f = imag * imag; - assert(f == -6.25); -} - -/***********************************/ - -void test10() -{ - creal z = 1 + 2.5i; - real e = z.im; - - printf ("e = %Lf\n", e); - assert(e == 2.5); -} - - -/***********************************/ - class Foo11 { public: @@ -316,11 +300,11 @@ void test17() string s; s = passString(); - printf("passString() = %.*s\n", s.length, s.ptr); + printf("passString() = %.*s\n", cast(int)s.length, s.ptr); assert(s == "First stringConcatenated with second"); s = butThisWorks(); - printf("butThisWorks() = %.*s\n", s.length, s.ptr); + printf("butThisWorks() = %.*s\n", cast(int)s.length, s.ptr); assert(s == "Third stringConcatenated with fourth"); } @@ -453,7 +437,7 @@ in out (result) { } -body +do { int i = 5; while (i) @@ -607,21 +591,6 @@ void test34() assert(b[i][j] == 16); } - -/***********************************/ - -void test35() -{ - ifloat b = cast(ifloat)1i; - assert(b == 1.0i); - - ifloat c = 2fi; - assert(c == 2.0i); - - c = 0fi; - assert(c == 0i); -} - /***********************************/ string itoa(int i) @@ -646,7 +615,7 @@ void test36() { string s = testa36(26, 47, "a", "b", "c"); - printf("s = '%.*s'\n", s.length, s.ptr); + printf("s = '%.*s'\n", cast(int)s.length, s.ptr); assert(s == "string 0;26string 1;47string 2;26string 3;"); } @@ -668,7 +637,7 @@ void test37() void test38() { int n = atoi("1"); - static char flags[8192 + 1]; + static char[8192 + 1] flags; long i, k; int count = 0; @@ -698,7 +667,7 @@ void test38() } catch(Throwable) { - printf("Exception: %d\n", k); + printf("Exception: %lld\n", k); assert(0); } } @@ -776,21 +745,6 @@ void test42() /***********************************/ -void test43() -{ - creal C,Cj; - real y1,x1; - - C = x1 + y1*1i + Cj; - C = 1i*y1 + x1 + Cj; - C = Cj + 1i*y1 + x1; - C = y1*1i + Cj + x1; - C = 1i*y1 + Cj; - C = Cj + 1i*y1; -} - -/***********************************/ - int x44; class A44 { @@ -883,46 +837,6 @@ void test50() /***********************************/ -/+ -void foo51(creal a) -{ - writeln(a); - assert(a == -8i); -} - -void test51() -{ - cdouble a = (2-2i)*(2-2i); - - // This fails - writeln(a); - assert(a == -8i); - - // This works - writeln((2-2i)*(2-2i)); - - // This fails - foo51((2-2i)*(2-2i)); -} -+/ - -void foo51(creal a) -{ - assert(a == -8i); -} - -void test51() -{ - assert((2-2i)*(2-2i) == -8i); - - cdouble a = (2-2i)*(2-2i); - assert(a == -8i); - - foo51((2-2i)*(2-2i)); -} - -/***********************************/ - int main() { test1(); @@ -933,8 +847,6 @@ int main() test6(); test7(); test8(); - test9(); - test10(); test11(); test12(); test13(); @@ -956,21 +868,18 @@ int main() test32(); test33(); test34(); - test35(); test36(); test37(); test38(); test39(); test40(); test42(); - test43(); test44(); test45(); test46(); test48(); test49(); test50(); - test51(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/test809.d b/gcc/testsuite/gdc.test/runnable/test809.d new file mode 100644 index 00000000000..efe4a3704c5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test809.d @@ -0,0 +1,13 @@ +// https://issues.dlang.org/show_bug.cgi?id=809 +void test(lazy int dg) +{ + int delegate() dg_ = &dg; + assert(dg_() == 7); + assert(dg == dg_()); +} + +void main() +{ + int a = 7; + test(a); +} diff --git a/gcc/testsuite/gdc.test/runnable/test8544.d b/gcc/testsuite/gdc.test/runnable/test8544.d index 7c47e867db6..0b8b86bd99f 100644 --- a/gcc/testsuite/gdc.test/runnable/test8544.d +++ b/gcc/testsuite/gdc.test/runnable/test8544.d @@ -1,6 +1,6 @@ // EXECUTE_ARGS: foo bar doo // PERMUTE_ARGS: -import std.stdio; +import core.stdc.stdio; import std.conv; import core.runtime; diff --git a/gcc/testsuite/gdc.test/runnable/test9259.d b/gcc/testsuite/gdc.test/runnable/test9259.d index f870f63a492..abad02b01d4 100644 --- a/gcc/testsuite/gdc.test/runnable/test9259.d +++ b/gcc/testsuite/gdc.test/runnable/test9259.d @@ -1,4 +1,5 @@ -// PERMUTE_ARGS: -inline -release -g -O -d -dw -de +// REQUIRED_ARGS: -de +// PERMUTE_ARGS: -inline -release -g -O void test(int*[] arr...) { diff --git a/gcc/testsuite/gdc.test/runnable/test9271.d b/gcc/testsuite/gdc.test/runnable/test9271.d index 3ce7fc8f189..b10b575ac4e 100644 --- a/gcc/testsuite/gdc.test/runnable/test9271.d +++ b/gcc/testsuite/gdc.test/runnable/test9271.d @@ -1,5 +1,5 @@ // PERMUTE_ARGS: - +// EXTRA_FILES: imports/test9271a.d import algorithm = imports.test9271a; bool any(alias predicate, Range)(Range range) diff --git a/gcc/testsuite/gdc.test/runnable/testCopyCtor.d b/gcc/testsuite/gdc.test/runnable/testCopyCtor.d new file mode 100644 index 00000000000..9d86bdcd3e2 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testCopyCtor.d @@ -0,0 +1,159 @@ +string result; + +struct A +{ + this(ref A rhs) + { + result ~= "A"; + } + this(ref immutable A rhs) + { + result ~= "B"; + } + this(ref const A rhs) + { + result ~= "C"; + } + this(ref A rhs) immutable + { + result ~= "D"; + } + this(ref const A rhs) shared + { + result ~= "E"; + } + this(ref A rhs) shared + { + result ~= "F"; + } + this(ref shared A rhs) immutable + { + result ~= "G"; + } + this(ref shared A rhs) shared + { + result ~= "H"; + } +} + +// copy constructor correctly uses function declaration overload resolution +void test1() +{ + result = ""; + A a; + A a1 = a; + immutable A a2 = a; + const A a3 = a2; + shared A a4 = a3; + A a5 = a3; + assert(result == "ADBEC"); +} + +// copy constructor has priority over alias this +struct B +{ + B fun(immutable B) + { + return B(); + } + + this(ref immutable B rhs) + { + result ~= "A"; + } + alias fun this; +} + +void test2() +{ + result = ""; + immutable B a; + B a1 = a; + assert(result == "A"); +} + +// arguments and return values correctly call the copy constructor +shared(A) fun(A x) +{ + return x; +} + +immutable(A) fun2(shared A x) +{ + return x; +} + +void test3() +{ + result = ""; + A a1; + shared A a2 = fun(a1); + immutable A a3 = fun2(a2); + assert(result == "AFHG"); +} + +// nested structs +int fun() +{ + int x = 1; + struct A + { + struct B + { + int x2 = 2; + } + + B b; + int x1; + + this(int x) + { + this.x1 = x; + b = B(3); + } + this(ref A rhs) + { + this.x1 = rhs.x1 + rhs.b.x2 + x; + } + } + + A a = A(2); + A b = a; + return b.x1; +} + +void test4() +{ + assert(fun() == 6); +} + +// generated copy constructor +struct X +{ + this(ref inout(X) rhs) inout + { + result ~= "A"; + } +} + +struct Y +{ + X a; +} + +void test5() +{ + result = ""; + Y b1; + Y b2 = b1; + assert(result == "A"); +} + +void main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); +} diff --git a/gcc/testsuite/gdc.test/runnable/test_dip1006.d b/gcc/testsuite/gdc.test/runnable/test_dip1006.d new file mode 100644 index 00000000000..c785e2152b5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test_dip1006.d @@ -0,0 +1,38 @@ +// REQUIRED_ARGS: -check=in=off -check=out=off -check=invariant=off +// PERMUTE_ARGS: +class C +{ + int foo(int a) + in { assert(a != 0); } // skipped + out(res) { assert(res != 0); } // skipped + do + { + return a; + } + + invariant // skipped + { + assert(false); + } + + void bar(int a) + { + assert(a != 0); // triggered + } +} + +void main() +{ + import core.exception : AssertError; + + auto c = new C; + c.foo(0); + + bool catched; + try + c.bar(0); + catch (AssertError e) + catched = true; + if (!catched) + assert(0); +} diff --git a/gcc/testsuite/gdc.test/runnable/test_dip1006b.d b/gcc/testsuite/gdc.test/runnable/test_dip1006b.d new file mode 100644 index 00000000000..e1677685a11 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test_dip1006b.d @@ -0,0 +1,35 @@ +// REQUIRED_ARGS: -check=in=off -check=invariant=off +// PERMUTE_ARGS: +class C +{ + int foo(int a) + in { assert(a != 0); } // skipped + out(res) { assert(res != 0, "out"); } // triggered + do + { + return a; + } + + invariant // skipped + { + assert(false); + } +} + +void main() +{ + import core.exception : AssertError; + + auto c = new C; + bool catched; + try + c.foo(0); + catch (AssertError e) + { + assert(e.msg == "out"); + catched = e.msg == "out"; + } + + if (!catched) + assert(0); +} diff --git a/gcc/testsuite/gdc.test/runnable/testaa.d b/gcc/testsuite/gdc.test/runnable/testaa.d index 34cc705c08d..75d541438cb 100644 --- a/gcc/testsuite/gdc.test/runnable/testaa.d +++ b/gcc/testsuite/gdc.test/runnable/testaa.d @@ -1,4 +1,3 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: -fPIC /* Test associative arrays */ @@ -7,11 +6,10 @@ extern(C) int printf(const char*, ...); extern(C) int memcmp(const void *s1, const void *s2, size_t n); import core.memory; // for GC.collect -import std.random; // for uniform random numbers /************************************************/ -int nametable[char[]]; +int[char[]] nametable; void insert(string name, int value) { @@ -272,9 +270,9 @@ struct S12 void test12() { S12[] x; - printf("size %d\n",S12.sizeof); - printf("align %d\n",S12.alignof); - printf("offset %d\n",S12.description.offsetof); + printf("size %zd\n",S12.sizeof); + printf("align %zd\n",S12.alignof); + printf("offset %zd\n",S12.description.offsetof); for (int i=0;i<3;i++) { S12 s; @@ -294,8 +292,8 @@ void test12() x ~= s; */ GC.collect(); - printf("%.*s\n",x[0].font_face.length,x[0].font_face.ptr); - printf("%.*s\n",x[1].font_face.length,x[1].font_face.ptr); + printf("%.*s\n", cast(int)x[0].font_face.length, x[0].font_face.ptr); + printf("%.*s\n", cast(int)x[1].font_face.length, x[1].font_face.ptr); } @@ -316,7 +314,7 @@ void test13() string[] key = array.keys; assert(key.length==3); - bool have[3]; + bool[3] have; assert(!have[0]); assert(!have[1]); @@ -424,13 +422,9 @@ void test16() { int[int] aa; - Random gen; for (int i = 0; i < 50000; i++) { - int key = uniform(0, int.max, gen); - int value = uniform(0, int.max, gen); - - aa[key] = value; + aa[i] = i; } int[] keys = aa.keys; @@ -442,7 +436,7 @@ void test16() assert(k in aa); j += aa[k]; } - printf("test16 = %d\n", j); + assert(j == 1249975000); int m; foreach (k, v; aa) @@ -471,10 +465,7 @@ void test16() for (int i = 0; i < 1000; i++) { - int key2 = uniform(0, int.max, gen); - int value2 = uniform(0, int.max, gen); - - aa[key2] = value2; + aa[i] = i; } foreach(k; aa) { @@ -494,7 +485,7 @@ void dummy17() { } -int bb17[string]; +int[string] bb17; int foo17() { @@ -558,14 +549,14 @@ void test19() printf("%d\n", keys[1]); auto vs = aa.values; - printf("%.*s\n", vs[0].length, vs[0].ptr); - printf("%.*s\n", vs[1].length, vs[1].ptr); + printf("%.*s\n", cast(int)vs[0].length, vs[0].ptr); + printf("%.*s\n", cast(int)vs[1].length, vs[1].ptr); string aavalue_typeid = typeid(typeof(aa.values)).toString(); - printf("%.*s\n", aavalue_typeid.length, aavalue_typeid.ptr); + printf("%.*s\n", cast(int)aavalue_typeid.length, aavalue_typeid.ptr); - printf("%.*s\n", aa[3].length, aa[3].ptr); - printf("%.*s\n", aa[4].length, aa[4].ptr); + printf("%.*s\n", cast(int)aa[3].length, aa[3].ptr); + printf("%.*s\n", cast(int)aa[4].length, aa[4].ptr); } /************************************************/ @@ -582,14 +573,14 @@ void test20() printf("%d\n", keys[1]); auto values = aa.values; - printf("%.*s\n", values[0].length, values[0].ptr); - printf("%.*s\n", values[1].length, values[1].ptr); + printf("%.*s\n", cast(int)values[0].length, values[0].ptr); + printf("%.*s\n", cast(int)values[1].length, values[1].ptr); string aavalue_typeid = typeid(typeof(aa.values)).toString(); - printf("%.*s\n", aavalue_typeid.length, aavalue_typeid.ptr); + printf("%.*s\n", cast(int)aavalue_typeid.length, aavalue_typeid.ptr); - printf("%.*s\n", aa[3].length, aa[3].ptr); - printf("%.*s\n", aa[4].length, aa[4].ptr); + printf("%.*s\n", cast(int)aa[3].length, aa[3].ptr); + printf("%.*s\n", cast(int)aa[4].length, aa[4].ptr); } /************************************************/ @@ -783,7 +774,7 @@ void test4826c() } /************************************************/ -// 5131 +// https://issues.dlang.org/show_bug.cgi?id=5131 struct ICE5131 { @@ -799,7 +790,7 @@ void test5131() } /************************************************/ -// 6178 +// https://issues.dlang.org/show_bug.cgi?id=6178 bool test6178a() { @@ -1036,7 +1027,7 @@ void test6178x() } /************************************************/ -// 10595 +// https://issues.dlang.org/show_bug.cgi?id=10595 struct S10595 { @@ -1073,14 +1064,13 @@ void test10595() Wrap10595[int] wrap; wrap[0] = Wrap10595(); - wrap[0] = 0; // note: using 'alias this' to assign assert(wrap[0].s.test()); // failure } } /************************************************/ -// 10970 +// https://issues.dlang.org/show_bug.cgi?id=10970 struct RefCounted10970(T) //if (!is(T == class)) { @@ -1119,7 +1109,7 @@ void test10970() } /************************************************/ -// 6433 +// https://issues.dlang.org/show_bug.cgi?id=6433 void test6433() { @@ -1138,7 +1128,7 @@ void test6433() } /************************************************/ -// 6612 +// https://issues.dlang.org/show_bug.cgi?id=6612 void test6612() { @@ -1150,7 +1140,7 @@ void test6612() } /************************************************/ -// 7365 +// https://issues.dlang.org/show_bug.cgi?id=7365 struct TickDuration { @@ -1197,7 +1187,7 @@ void test6799() } /************************************************/ -// 11359 +// https://issues.dlang.org/show_bug.cgi?id=11359 void test11359() { @@ -1213,7 +1203,7 @@ void test11359() } /************************************************/ -// 11730 +// https://issues.dlang.org/show_bug.cgi?id=11730 struct SysTime11730 { @@ -1246,7 +1236,7 @@ void test11730() } /************************************************/ -// 14089 +// https://issues.dlang.org/show_bug.cgi?id=14089 struct S14089 { @@ -1263,7 +1253,7 @@ void test14089() } /************************************************/ -// 14144 +// https://issues.dlang.org/show_bug.cgi?id=14144 struct JSON14144 { @@ -1291,7 +1281,7 @@ void test14144() } /************************************************/ -// 14321 +// https://issues.dlang.org/show_bug.cgi?id=14321 void test14321() { @@ -1330,6 +1320,20 @@ void test14321() } /************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19112 + +void test19112() +{ + int[int[1]] aa; + aa[[2]] = 1; + assert([2] in aa); + + int[int[]] aa2 = [[1, 2, 3]: 4]; + int[3] k = [1, 2, 3]; + assert(*(k in aa2) == 4); +} + +/************************************************/ int main() { @@ -1380,6 +1384,7 @@ int main() test11730(); test14089(); test14321(); + test19112(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/testaa2.d b/gcc/testsuite/gdc.test/runnable/testaa2.d index 17de1679d8b..ba8ceecc55c 100644 --- a/gcc/testsuite/gdc.test/runnable/testaa2.d +++ b/gcc/testsuite/gdc.test/runnable/testaa2.d @@ -1,16 +1,26 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: +/* +RUNNABLE_PHOBOS_TEST +PERMUTE_ARGS: +RUN_OUTPUT: +--- +foo() +foo() 2 +foo() 3 +foo() 4 +Success +--- +*/ extern(C) int printf(const char*, ...); /************************************************/ -int a[string]; +int[string] a; size_t foo(immutable char [3] s) { printf("foo()\n"); - int b[string]; + int[string] b; string[] key; int[] value; printf("foo() 2\n"); @@ -23,7 +33,7 @@ size_t foo(immutable char [3] s) void foo2() { - int c[string]; + int[string] c; string[] key; int[] value; int i; @@ -51,10 +61,9 @@ void foo2() value = c.values; assert(value.length == 2); - for (i = 0; i < key.length; i++) - { - printf("c[\"%.*s\"] = %d\n", key[i].length, key[i].ptr, value[i]); - } + const fooIndex = key[1] == "foo"; + assert(key[fooIndex] == "foo" && value[fooIndex] == 3); + assert(key[1 - fooIndex] == "bar" && value[1 - fooIndex] == 4); assert("foo" in c); c.remove("foo"); @@ -70,7 +79,6 @@ void foo2() void testaa() { size_t i = foo("abc"); - printf("i = %d\n", i); assert(i == 0); foo2(); @@ -107,7 +115,7 @@ void test4523() } /************************************************/ -// 3825 +// https://issues.dlang.org/show_bug.cgi?id=3825 import std.math; // necessary for ^^= void test3825() @@ -257,7 +265,7 @@ void test3825x() } /************************************************/ -// 10106 +// https://issues.dlang.org/show_bug.cgi?id=10106 struct GcPolicy10106 {} diff --git a/gcc/testsuite/gdc.test/runnable/testaa3.d b/gcc/testsuite/gdc.test/runnable/testaa3.d index 3e3ae96ba02..4aac1fba1a4 100644 --- a/gcc/testsuite/gdc.test/runnable/testaa3.d +++ b/gcc/testsuite/gdc.test/runnable/testaa3.d @@ -315,7 +315,7 @@ int[int] testRetx() void aafunc(int[int] aa) {} /***************************************************/ -// 12214 +// https://issues.dlang.org/show_bug.cgi?id=12214 void test12214() pure nothrow { @@ -324,7 +324,8 @@ void test12214() pure nothrow } /***************************************************/ -// 12220 & 12221 +// https://issues.dlang.org/show_bug.cgi?id=12220 +// https://issues.dlang.org/show_bug.cgi?id=12221 void test12220() { @@ -338,7 +339,7 @@ void test12220() } /***************************************************/ -// 12403 +// https://issues.dlang.org/show_bug.cgi?id=12403 void test12403() { diff --git a/gcc/testsuite/gdc.test/runnable/testabi.d b/gcc/testsuite/gdc.test/runnable/testabi.d deleted file mode 100644 index c50dfbd0ba6..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testabi.d +++ /dev/null @@ -1,926 +0,0 @@ -// PERMUTE_ARGS: -release -g - -version(Windows) {} -else version(X86_64) -{ - /* uncomment to enable tests! */ - //version = Run_X86_64_Tests; -} - -extern (C) int printf(const char*, ...); - -template tuple(A...) { alias A tuple; } - -alias byte B; -alias short S; -alias int I; -alias long L; -alias float F; -alias double D; -alias real R; - -// Single Type - -struct b { B a; } -struct bb { B a,b; } -struct bbb { B a,b,c; } -struct bbbb { B a,b,c,d; } -struct bbbbb { B a,b,c,d, e; } -struct b6 { B a,b,c,d, e,f; } -struct b7 { B a,b,c,d, e,f,g; } -struct b8 { B a,b,c,d, e,f,g,h; } -struct b9 { B a,b,c,d, e,f,g,h, i; } -struct b10 { B a,b,c,d, e,f,g,h, i,j; } -struct b11 { B a,b,c,d, e,f,g,h, i,j,k; } -struct b12 { B a,b,c,d, e,f,g,h, i,j,k,l; } -struct b13 { B a,b,c,d, e,f,g,h, i,j,k,l, m; } -struct b14 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n; } -struct b15 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o; } -struct b16 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p; } -struct b17 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q; } -struct b18 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r; } -struct b19 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r,s; } -struct b20 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r,s,t;} - -struct s { S a; } -struct ss { S a,b; } -struct sss { S a,b,c; } -struct ssss { S a,b,c,d; } -struct sssss { S a,b,c,d, e; } -struct s6 { S a,b,c,d, e,f; } -struct s7 { S a,b,c,d, e,f,g; } -struct s8 { S a,b,c,d, e,f,g,h; } -struct s9 { S a,b,c,d, e,f,g,h, i; } -struct s10 { S a,b,c,d, e,f,g,h, i,j;} - -struct i { I a; } struct l { L a; } -struct ii { I a,b; } struct ll { L a,b; } -struct iii { I a,b,c; } struct lll { L a,b,c; } -struct iiii { I a,b,c,d; } struct llll { L a,b,c,d; } -struct iiiii { I a,b,c,d,e; } struct lllll { L a,b,c,d,e; } - -struct f { F a; } struct d { D a; } -struct ff { F a,b; } struct dd { D a,b; } -struct fff { F a,b,c; } struct ddd { D a,b,c; } -struct ffff { F a,b,c,d; } struct dddd { D a,b,c,d; } -struct fffff { F a,b,c,d,e; } struct ddddd { D a,b,c,d,e; } - -// Mixed Size - -struct js { I a; S b; } -struct iss { I a; S b,c; } -struct si { S a; I b; } -struct ssi { S a,b; I c; } -struct sis { S a; I b; S c; } - -struct ls { L a; S b; } -struct lss { L a; S b,c; } -struct sl { S a; L b; } -struct ssl { S a,b; L c; } -struct sls { S a; L b; S c; } - -struct li { L a; I b; } -struct lii { L a; I b,c; } -struct il { I a; L b; } -struct iil { I a,b; L c; } -struct ili { I a; L b; I c; } - -struct df { D a; F b; } -struct dff { D a; F b,c; } -struct fd { F a; D b; } -struct ffd { F a,b; D c; } -struct fdf { F a; D b; F c; } - -// Mixed Types - -struct fi { F a; I b; } -struct fii { F a; I b,c; } -struct jf { I a; F b; } -struct iif { I a,b; F c; } -struct ifi { I a; F b; I c; } - -struct ffi { F a,b; I c; } -struct ffii { F a,b; I c,d; } -struct iff { I a; F b,c; } -struct iiff { I a,b; F c,d; } -struct ifif { I a; F b; I c; F d;} - -struct di { D a; I b; } -struct dii { D a; I b,c; } -struct id { I a; D b; } -struct iid { I a,b; D c; } -struct idi { I a; D b; I c; } - -// Real ( long double ) - -struct r { R a; } -struct rr { R a,b; } -struct rb { R a; B b; } -struct rf { R a; F b; } -struct fr { F a; R b; } - - // Int Registers only -alias tuple!( b,bb,bbb,bbbb,bbbbb, - b6, b7, b8, b9, b10, - b11,b12,b13,b14,b15, - b16,b17,b18,b19,b20, - s,ss,sss,ssss,sssss, - s6, s7, s8, s9, s10, - i,ii,iii,iiii,iiiii, - l,ll,lll,llll,lllll, - // - js,iss,si,ssi, sis, - ls,lss,sl,ssl, sls, - li,lii,il,iil, ili, - fi,fii,jf,iif, ifi, - ffi,ffii,iff,iiff,ifif, // INT_END - - // SSE registers only - f,ff,fff,ffff,fffff, - d,dd,ddd,dddd,ddddd, - // - df,dff,fd,ffd, fdf, // SSE_END - - // Int and SSE - di, dii,id, iid, idi, // MIX_END - // --- - ) ALL_T; - -enum INT_END = 65; -enum SSE_END = 80; -enum MIX_END = ALL_T.length; - - // x87 -alias tuple!( r,rr,rb,rf,fr, - // --- - ) R_T; -//"r","rr","rb","rf","fr", - - -string[] ALL_S=[ - "b","bb","bbb","bbbb","bbbbb", - "b6", "b7", "b8", "b9", "b10", - "b11","b12","b13","b14","b15", - "b16","b17","b18","b19","b20", - "s","ss","sss","ssss","sssss", - "s6","s7","s8","s9" , "s10", - "i","ii","iii","iiii","iiiii", - "l","ll","lll","llll","lllll", - // --- - "js","iss","si","ssi", "sis", - "ls","lss","sl","ssl", "sls", - "li","lii","il","iil", "ili", - "fi","fii","jf","iif", "ifi", - "ffi","ffii","iff","iiff","ifif", - // --- - "f","ff","fff","ffff","fffff", - "d","dd","ddd","dddd","ddddd", - "df","dff","fd","ffd", "dfd", - // --- - "di","dii","id","iid","idi", - ]; - -/* *********************************************************************** - All - ************************************************************************/ -// test1 Struct passing and return - -int[MIX_END] results_1; - -T test1_out(T)( ) -{ - T t; - foreach( i, ref e; t.tupleof ) e = i+1; - return t; -} -T test1_inout(T)( T t) -{ - foreach( i, ref e; t.tupleof ) e += 10; - return t; -} - -void test1_call_out(T)( int n ) -{ - T t1; - foreach( i, ref e; t1.tupleof ) e = i+1; - T t2 = test1_out!(T)(); - - if( t1 == t2 ) results_1[n] |= 1; -} -void test1_call_inout(T)( int n ) -{ - T t1; - foreach( i, ref e; t1.tupleof ) e = i+1; - T t2 = test1_inout!(T)( t1 ); - foreach( i, ref e; t1.tupleof ) e += 10; - - if( t1 == t2 ) results_1[n] |= 2; -} - -void D_test1( ) -{ - // Run Tests - foreach( n, T; ALL_T ) - { - test1_call_out!(T)(n); - test1_call_inout!(T)(n); - } - - bool pass = true; - foreach( i, r; results_1 ) - { - if( ~r & 1 ) - { - pass = false; - printf( "Test1 out %s \tFail\n", ALL_S[i].ptr ); - } - if( ~r & 2 ) - { - pass = false; - printf( "Test1 inout %s \tFail\n", ALL_S[i].ptr ); - } - } - assert( pass ); - - results_1[0..5] = 0; - foreach( n, T; R_T ) - { - test1_call_out!(T)(n); - test1_call_inout!(T)(n); - } -} - -/************************************************************************/ -// based on runnable/test23.d : test44() -// Return Struct into an Array - -struct S1 -{ int i,j; - - static S1 foo(int x) - { S1 s; - s.i = x; - return s; -} } -struct S2 -{ int i,j,k; - - static S2 foo(int x) - { S2 s; - s.i = x; - return s; -} } -struct S3 -{ float i,j; - - static S3 foo(int x) - { S3 s; - s.i = x; - return s; -} } -struct S4 -{ float i,j,k; - - static S4 foo(int x) - { S4 s; - s.i = x; - return s; -} } -struct S5 -{ float i,j; - int k; - - static S5 foo(float x) - { S5 s; - s.i = x; - return s; -} } - -void D_test2() -{ - S1[] s1; - S2[] s2; - S3[] s3; - S4[] s4; - S5[] s5; - - s1 = s1 ~ S1.foo(6); s1 = s1 ~ S1.foo(1); - s2 = s2 ~ S2.foo(6); s2 = s2 ~ S2.foo(1); - s3 = s3 ~ S3.foo(6); s3 = s3 ~ S3.foo(1); - s4 = s4 ~ S4.foo(6); s4 = s4 ~ S4.foo(1); - s5 = s5 ~ S5.foo(6); s5 = s5 ~ S5.foo(1); - - assert( s1.length == 2 ); - assert( s1[0].i == 6 ); - assert( s1[1].i == 1 ); - - assert( s2.length == 2 ); - assert( s2[0].i == 6 ); - assert( s2[1].i == 1 ); - -/+ // These Fail on Mainline DMD64 ( Should pass! ) - assert( s3.length == 2 ); - assert( s3[0].i == 6 ); - assert( s3[1].i == 1 ); - - assert( s4.length == 2 ); - assert( s4[0].i == 6 ); - assert( s4[1].i == 1 ); -+/ - assert( s5.length == 2 ); - assert( s5[0].i == 6 ); - assert( s5[1].i == 1 ); - -} - -/* *********************************************************************** - X86_64 - ************************************************************************/ - -version(Run_X86_64_Tests) -{ - - -struct TEST -{ - immutable int num; - immutable string desc; - bool[MIX_END] result; -} - -/** - * 0 = Should Fail - * 1 = Should Pass - */ -immutable int[MIX_END] expected = - [ - 1,1,1,1,1, // b - 1,1,1,1,1, // b6 - 1,1,1,1,1, // b11 - 1,0,0,0,0, // b16 - - 1,1,1,1,1, // s - 1,1,1,0,0, // s6 - 1,1,1,1,0, // i - 1,1,0,0,0, // l - 1,1,1,1,1, // si mix - 1,1,1,1,0, // sl - 1,1,1,1,0, // il - 1,1,1,1,1, // int and float - 1,1,1,1,1, // int and float - - // SSE regs only - 1,1,1,1,0, // f - 1,1,0,0,0, // d - 1,1,1,1,0, // float and double - - // SSE + INT regs - 1,1,1,1,0, // int and double - ]; - - -/** - * Describes value expected in registers - * - * null means do not test - * ( because value is passed on the stack ). - */ - -immutable long[][] RegValue = - [ -/* 0 b */ [ 0x0000000000000001, ], -/* 1 bb */ [ 0x0000000000000201, ], -/* 2 bbb */ [ 0x0000000000030201, ], -/* 3 bbbb */ [ 0x0000000004030201, ], -/* 4 bbbbb */ [ 0x0000000504030201, ], -/* 5 b6 */ [ 0x0000060504030201, ], -/* 6 b7 */ [ 0x0007060504030201, ], -/* 7 b8 */ [ 0x0807060504030201, ], -/* 8 b9 */ [ 0x0807060504030201, 0x0000000000000009 ], -/* 9 b10 */ [ 0x0807060504030201, 0x0000000000000a09 ], -/* 10 b11 */ [ 0x0807060504030201, 0x00000000000b0a09 ], -/* 11 b12 */ [ 0x0807060504030201, 0x000000000c0b0a09 ], -/* 12 b13 */ [ 0x0807060504030201, 0x0000000d0c0b0a09 ], -/* 13 b14 */ [ 0x0807060504030201, 0x00000e0d0c0b0a09 ], -/* 14 b15 */ [ 0x0807060504030201, 0x000f0e0d0c0b0a09 ], -/* 15 b16 */ [ 0x0807060504030201, 0x100f0e0d0c0b0a09 ], -/* 16 b17 */ null, -/* 17 b18 */ null, -/* 18 b19 */ null, -/* 19 b20 */ null, -/* 20 s */ [ 0x0000000000000001, ], -/* 21 ss */ [ 0x0000000000020001, ], -/* 22 sss */ [ 0x0000000300020001, ], -/* 23 ssss */ [ 0x0004000300020001, ], -/* 24 sssss */ [ 0x0004000300020001, 0x0000000000000005 ], -/* 25 s6 */ [ 0x0004000300020001, 0x0000000000060005 ], -/* 26 s7 */ [ 0x0004000300020001, 0x0000000700060005 ], -/* 27 s8 */ [ 0x0004000300020001, 0x0008000700060005 ], -/* 28 s9 */ null, -/* 29 s10 */ null, -/* 30 i */ [ 0x0000000000000001, ], -/* 31 ii */ [ 0x0000000200000001, ], -/* 32 iii */ [ 0x0000000200000001, 0x0000000000000003 ], -/* 33 iiii */ [ 0x0000000200000001, 0x0000000400000003 ], -/* 34 iiiii */ null, -/* 35 l */ [ 0x0000000000000001, ], -/* 36 ll */ [ 0x0000000000000001, 0x0000000000000002 ], -/* 37 lll */ null, -/* 38 llll */ null, -/* 39 lllll */ null, - -/* 40 js */ [ 0x0000000200000001, ], -/* 41 iss */ [ 0x0003000200000001, ], -/* 42 si */ [ 0x0000000200000001, ], -/* 43 ssi */ [ 0x0000000300020001, ], -/* 44 sis */ [ 0x0000000200000001, 0x0000000000000003 ], -/* 45 ls */ [ 0x0000000000000001, 0x0000000000000002 ], -/* 46 lss */ [ 0x0000000000000001, 0x0000000000030002 ], -/* 47 sl */ [ 0x0000000000000001, 0x0000000000000002 ], -/* 48 ssl */ [ 0x0000000000020001, 0x0000000000000003 ], -/* 49 sls */ null, -/* 50 li */ [ 0x0000000000000001, 0x0000000000000002 ], -/* 51 lii */ [ 0x0000000000000001, 0x0000000300000002 ], -/* 52 il */ [ 0x0000000000000001, 0x0000000000000002 ], -/* 53 iil */ [ 0x0000000200000001, 0x0000000000000003 ], -/* 54 ili */ null, - -/* 55 fi */ [ 0x000000023f800000, ], -/* 56 fii */ [ 0x000000023f800000, 0x0000000000000003 ], -/* 57 jf */ [ 0x4000000000000001, ], -/* 58 iif */ [ 0x0000000200000001, 0x0000000040400000 ], -/* 59 ifi */ [ 0x4000000000000001, 0x0000000000000003 ], - -/* 60 ffi */ [ 0x0000000000000003, 0x400000003f800000 ], -/* 61 ffii */ [ 0x0000000400000003, 0x400000003f800000 ], -/* 62 iff */ [ 0x4000000000000001, 0x0000000040400000 ], -/* 63 iiff */ [ 0x0000000200000001, 0x4080000040400000 ], -/* 64 ifif */ [ 0x4000000000000001, 0x4080000000000003 ], - -/* 65 f */ [ 0x000000003f800000, ], -/* 66 ff */ [ 0x400000003f800000, ], -/* 67 fff */ [ 0x400000003f800000, 0x0000000040400000 ], -/* 68 ffff */ [ 0x400000003f800000, 0x4080000040400000 ], -/* 69 fffff */ null, -/* 70 d */ [ 0x3ff0000000000000, ], -/* 71 dd */ [ 0x3ff0000000000000, 0x4000000000000000 ], -/* 72 ddd */ null, -/* 73 dddd */ null, -/* 74 ddddd */ null, - -/* 75 df */ [ 0x3ff0000000000000, 0x0000000040000000 ], -/* 76 dff */ [ 0x3ff0000000000000, 0x4040000040000000 ], -/* 77 fd */ [ 0x000000003f800000, 0x4000000000000000 ], -/* 78 ffd */ [ 0x400000003f800000, 0x4008000000000000 ], -/* 79 fdf */ null, - -/* 80 di */ [ 0x3ff0000000000000, 0x0000000000000002 ], -/* 81 dii */ [ 0x3ff0000000000000, 0x0000000300000002 ], -/* 82 id */ [ 0x4000000000000000, 0x0000000000000001 ], -/* 83 iid */ [ 0x4008000000000000, 0x0000000200000001 ], -/* 84 idi */ null, - ]; - -/* Have to do it this way for OSX: Issue 7354 */ -__gshared long[2] dump; - -/** - * Generate Register capture - */ -string gen_reg_capture( int n, string registers )( ) -{ - if( RegValue[n] == null ) return "return;"; - - string[] REG = mixin(registers); // ["RDI","RSI"]; - - // Which type of compare - static if(n < INT_END) - enum MODE = 1; // Int - else static if(n < SSE_END) - enum MODE = 2; // Float - else enum MODE = 3; // Mix - - /* Begin */ - - string code = "asm {\n"; - - final switch( MODE ) - { - case 1: code ~= "mov [dump], "~REG[0]~";\n"; - REG = REG[1..$]; - break; - case 2: - case 3: code ~= "movq [dump], XMM0;\n"; - } - - if( RegValue[n].length == 2 ) - final switch( MODE ) - { - case 1: - case 3: code ~= "mov [dump+8], "~REG[0]~";\n"; - break; - case 2: code ~= "movq [dump+8], XMM1;\n"; - } else { - code ~= "xor R8, R8;\n"; - code ~= "mov [dump+8], R8;\n"; - } - - return code ~ "}\n"; -} - -/** - * Check the results - */ -bool check( TEST data ) -{ - bool pass = true; - foreach( i, e; expected ) - { - if( data.result[i] != (e & 1) ) - { - printf( "Test%d %s \tFail\n", data.num, ALL_S[i].ptr); - pass = false; - } - } - return pass; -} - -/************************************************************************/ - -// test1 Return Struct in Registers -// ( if RDI == 12 we have no hidden pointer ) - -TEST data1 = { 1, "RDI hidden pointer" }; - -T test1_asm( T, int n )( int i ) -{ - asm { - - cmp EDI, 12; - je L1; - - leave; ret; - } -L1: - data1.result[n] = true; -} - -void test1() -{ - printf("\nRunning iasm Test 1 ( %s )\n", data1.desc.ptr); - - foreach( int n, T; ALL_T ) - test1_asm!(T,n)(12); - - check( data1 ); -} - -/************************************************************************/ -// test2 Pass Struct in Registers -// ( if RDI == 0 we have no stack pointer ) - -TEST data2 = { 2, "RDI struct pointer" }; - -T test2_asm( T, int n )( T t ) -{ - asm { - - mov [dump], RDI; - mov [dump+8], RSP; - cmp EDI, 0; // TODO test RDI is a ptr to stack ? ? - je L1; - - leave; ret; - } -L1: - data2.result[n] = true; -} -T test2f_asm( T, int n )( T t, int x ) -{ - asm { - - cmp EDI, 12; - je L1; - - leave; ret; - } -L1: - data2.result[n] = true; -} - -void test2() -{ - printf("\nRunning iasm Test 2 ( %s )\n", data2.desc.ptr); - - // Integer - foreach( int n, T; ALL_T ) { - T t = { 0 }; - test2_asm!(T,n)( t ); - } - - // float alternative test - foreach( int n, T; ALL_T[INT_END..SSE_END] ) - { - enum n2 = n + INT_END; - data2.result[n2] = false; - test2f_asm!(T,n2)( T.init, 12 ); - } - - check( data2 ); -} - -/************************************************************************/ -// test3 - -TEST data3 = { 3, "Check Return Register value" }; - -void test3_run( T, int n )( ) -{ - test3_ret!T(); - mixin( gen_reg_capture!(n,`["RAX","RDX"]`)() ); - - //dbg!(T,n)( ); - - enum len = RegValue[n].length; - if( dump[0..len] == RegValue[n] ) - data3.result[n] = true; -} - -T test3_ret( T )( ) -{ - T t; - foreach( i, ref e; t.tupleof ) e = i+1; - return t; -} - -void test3() -{ - printf("\nRunning iasm Test 3 ( %s )\n", data3.desc.ptr); - - foreach( int n, T; ALL_T ) - test3_run!(T,n)( ); - - check( data3 ); -} - -/************************************************************************/ -// test4 - -TEST data4 = { 4, "Check Input Register value" }; - -void test4_run( T, int n )( T t ) -{ - mixin( gen_reg_capture!(n,`["RDI","RSI"]`)() ); - - //dbg!(T,n)( ); - - enum len = RegValue[n].length; - if( dump[0..len] == RegValue[n] ) - data4.result[n] = true; -} - -void dbg( T, int n )( ) -{ - import std.stdio; - writefln( "D %s\t[ %16x, %16x ]", T.stringof, dump[0], dump[1], ); - writef( "C %s\t[ %16x", T.stringof, RegValue[n][0] ); - if( RegValue[n].length == 2 ) - writef( ", %16x", RegValue[n][1] ); - writefln( " ]" ); -} -void test4() -{ - printf("\nRunning iasm Test 4 ( %s )\n", data4.desc.ptr); - - foreach( int n, T; ALL_T ) - { - T t; - foreach( i, ref e; t.tupleof ) e = i+1; - test4_run!(T,n)( t ); - } - check( data4 ); -} - - -} // end version(Run_X86_64_Tests) - -/************************************************************************/ - - -void main() -{ - D_test1(); - D_test2(); - - version(Run_X86_64_Tests) - { - test1(); - test2(); - test3(); - test4(); - } -} - -/+ -/** - * C code to generate the table RegValue - */ -string c_generate_returns() -{ - string value = " 1, 2, 3, 4, 5, 6, 7, 8, 9,10," - "11,12,13,14,15,16,17,18,19,20,"; - - string code = "#include \"cgen.h\"\n"; - - // Generate return functions - foreach( int n, T; ALL_T ) - { - auto Ts = T.stringof; - auto len = T.tupleof.length; - - code ~= "struct "~Ts~" func_ret_"~Ts~"(void) { \n"; - code ~= "struct "~Ts~" x = { "; - code ~= value[0..len*3] ~ " };\n"; - code ~= "return x;\n}\n"; - } - return code; -} -string c_generate_pass() -{ - string value = " 1, 2, 3, 4, 5, 6, 7, 8, 9,10," - "11,12,13,14,15,16,17,18,19,20,"; - - string code; - - // Generate return functions - foreach( int n, T; ALL_T ) - { - auto Ts = T.stringof; - auto len = T.tupleof.length; - - code ~= "void func_pass_"~Ts~"( struct "~Ts~" x ) {\n"; - //////////////// - // Which type of compare - static if(n < INT_END) - enum MODE = 1; // Int - else static if(n < SSE_END) - enum MODE = 2; // Float - else enum MODE = 3; // Mix - - auto nn = n.stringof; - - /* Begin */ - - code ~= "asm(\n"; - final switch( MODE ) - { - case 1: - code ~= `"movq %rdi, reg\n" "movq %rsi, reg+8\n"`; - break; - case 2: - code ~= `"movq %xmm0, reg\n" "movq %xmm1, reg+8\n"`; - break; - case 3: - code ~= `"movq %xmm0, reg\n" "movq %rdi, reg+8\n"`; - } - code ~= "\n);\n"; - code ~= "}\n"; - - //////////////// - code ~= "void func_call_"~Ts~"( void ) {\n"; - code ~= "struct "~Ts~" x = { "; - code ~= value[0..len*3] ~ " };\n"; - code ~= "func_pass_"~Ts~"( x );\n}\n"; - } - return code; -} -string c_generate_main() -{ - string code = "void main() {\n"; - - foreach( int n, T; ALL_T ) - { - // Which type of compare - static if(n < INT_END) - enum MODE = 1; // Int - else static if(n < SSE_END) - enum MODE = 2; // Float - else enum MODE = 3; // Mix - - auto nn = n.stringof; - auto Ts = T.stringof; - - /* Begin */ - - code ~= `printf("/* %3d `~Ts~`\t*/ ", `~nn~`);`"\n"; - if( !(expected[n] & 1) ) - { - code ~= `printf("null,\n");`"\n"; - continue; - } - code ~= "asm(\n"; - code ~= `"call func_ret_`~Ts~`\n"`"\n"; - final switch( MODE ) - { - case 1: - code ~= `"movq %rax, reg\n" "movq %rdx, reg+8\n"`; - break; - case 2: - code ~= `"movq %xmm0, reg\n" "movq %xmm1, reg+8\n"`; - break; - case 3: - code ~= `"movq %xmm0, reg\n" "movq %rax, reg+8\n"`; - } - code ~= "\n);\n"; - - code ~= `printf("[ 0x%016lx", reg.r1 );`"\n"; - - if( T.sizeof > 8 || MODE == 3 ) - code ~= `printf(", 0x%016lx ],\n", reg.r2 );`"\n"; - else code ~= `printf(", %015c ],\n", ' ' );`"\n"; - } - - foreach( int n, T; ALL_T ) - { - // Which type of compare - static if(n < INT_END) - enum MODE = 1; // Int - else static if(n < SSE_END) - enum MODE = 2; // Float - else enum MODE = 3; // Mix - - auto nn = n.stringof; - auto Ts = T.stringof; - - /* Begin */ - - code ~= `printf("/* %3d `~Ts~`\t*/ ", `~nn~`);`"\n"; - if( !(expected[n] & 1) ) - { - code ~= `printf("null,\n");`"\n"; - continue; - } - code ~= "func_call_"~Ts~"();\n"; - - code ~= `printf("[ 0x%016lx", reg.r1 );`"\n"; - - if( T.sizeof > 8 || MODE == 3 ) - code ~= `printf(", 0x%016lx ],\n", reg.r2 );`"\n"; - else code ~= `printf(", %015c ],\n", ' ' );`"\n"; - } - - - return code ~ "}"; -} -pragma(msg, c_generate_returns() ); -pragma(msg, c_generate_pass() ); -pragma(msg, c_generate_main() ); -// +/ - -/+ -/** - * Generate Functions that pass/return each Struct type - * - * ( Easier to look at objdump this way ) - */ -string d_generate_functions( ) -{ - string code = "extern(C) {"; - - // pass - foreach( s; ALL_T ) - { - string ss = s.stringof; - - code ~= "void func_in_"~ss~"( "~ss~" t ) { t.a = 12; }\n"; - } - // return - foreach( s; ALL_T[0..10] ) - { - string ss = s.stringof; - - code ~= ` - auto func_out_`~ss~`() - { - `~ss~` t; - foreach( i, ref e; t.tupleof ) e = i+1; - return t; - }`; - } - // pass & return - foreach( s; ALL_T[0..10] ) - { - string ss = s.stringof; - - code ~= ` - auto func_inout_`~ss~`( `~ss~` t ) - { - foreach( i, ref e; t.tupleof ) e += 10; - return t; - }`; - } - return code ~ "\n} // extern(C)\n"; -} -//pragma( msg, d_generate_functions() ); -mixin( d_generate_functions() ); -// +/ diff --git a/gcc/testsuite/gdc.test/runnable/testaliascast.d b/gcc/testsuite/gdc.test/runnable/testaliascast.d new file mode 100644 index 00000000000..c55f8203499 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testaliascast.d @@ -0,0 +1,63 @@ +// https://issues.dlang.org/show_bug.cgi?id=11294 + +string result; + +extern(C) void rt_finalize(void *ptr, bool det=true); +void clear(T)(T obj) if (is(T == class)) +{ + rt_finalize(cast(void*)obj); +} + +class A +{ + ~this() { result ~= "A"; } + string dummy = "0"; +} + +class B +{ + A a; + string dummy = "0"; + alias a this; + ~this() { result ~= "B"; } +} + +void test11294() +{ + auto a = new A; + auto b = new B; + b.a = a; + result ~= b.dummy; + clear(b); + result ~= a.dummy; + result ~= "END"; + clear(a); + + assert(result == "0B0ENDA"); +} + + +// https://issues.dlang.org/show_bug.cgi?id=13392 +void foo(T)(T t) +{ + void* p = cast(void*) t; //Callas alias this +} + +class X {} + +class Y +{ + alias a this; + @property X a(){assert(0);} //Here +} + +void test13392() +{ + foo(B.init); +} + +void main() +{ + test11294(); + test13392(); +} diff --git a/gcc/testsuite/gdc.test/runnable/testappend.d b/gcc/testsuite/gdc.test/runnable/testappend.d index cbdae36b96c..f8bff3e16e8 100644 --- a/gcc/testsuite/gdc.test/runnable/testappend.d +++ b/gcc/testsuite/gdc.test/runnable/testappend.d @@ -1,4 +1,18 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +TEST_OUTPUT: +--- +runnable/testappend.d(54): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +runnable/testappend.d(55): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +runnable/testappend.d(76): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +runnable/testappend.d(77): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- + +RUN_OUTPUT: +--- +Success +--- +*/ import core.stdc.stdio; import core.stdc.math : isnan; diff --git a/gcc/testsuite/gdc.test/runnable/testassert.d b/gcc/testsuite/gdc.test/runnable/testassert.d new file mode 100644 index 00000000000..30fe8d941b5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testassert.d @@ -0,0 +1,380 @@ +/* +REQUIRED_ARGS: -checkaction=context -preview=dip1000 +PERMUTE_ARGS: -O -g -inline +*/ + +void test8765() +{ + string msg; + try + { + int a = 0; + assert(a); + } + catch (Throwable e) + { + // no-message -> assert expression + msg = e.msg; + } + assert(msg == "0 != true"); +} + + void test9255() +{ + string file; + try + { + int x = 0; + assert(x); + } + catch (Throwable e) + { + file = e.file; + } + + version(Windows) + assert(file && file == r"runnable\testassert.d"); + else + assert(file && file == "runnable/testassert.d"); +} + +// https://issues.dlang.org/show_bug.cgi?id=20114 +void test20114() +{ + // Function call returning simple type + static int fun() { + static int i = 0; + assert(i++ == 0); + return 3; + } + + const a = getMessage(assert(fun() == 4)); + assert(a == "3 != 4"); + + // Function call returning complex type with opEquals + static struct S + { + bool opEquals(const int x) const + { + return false; + } + } + + static S bar() + { + static int i = 0; + assert(i++ == 0); + return S.init; + } + + const b = getMessage(assert(bar() == 4)); + assert(b == "S() != 4"); + + // Non-call expression with side effects + int i = 0; + const c = getMessage(assert(++i == 0)); + assert(c == "1 != 0"); +} + +version (DigitalMars) version (Win64) version = DMD_Win64; + +void test20375() @safe +{ + static struct RefCounted + { + // Force temporary through "impure" generator function + static RefCounted create() @trusted + { + __gshared int counter = 0; + return RefCounted(++counter > 0); + } + + static int instances; + static int postblits; + + this(bool) @safe + { + instances++; + } + + this(this) @safe + { + instances++; + postblits++; + } + + ~this() @safe + { + // make the dtor non-nothrow (we are tracking clean-ups during AssertError unwinding) + if (postblits > 100) + throw new Exception(""); + assert(instances > 0); + instances--; + } + + bool opEquals(RefCounted) @safe + { + return true; + } + } + + { + auto a = RefCounted.create(); + RefCounted.instances++; // we're about to construct an instance below, increment manually + assert(a == RefCounted()); // both operands are pure expressions => no temporaries + } + + assert(RefCounted.instances == 0); + assert(RefCounted.postblits == 0); + + { + auto a = RefCounted.create(); + assert(a == RefCounted.create()); // impure rhs is promoted to a temporary lvalue => copy for a.opEquals(rhs) + } + + assert(RefCounted.instances == 0); + assert(RefCounted.postblits == 1); + RefCounted.postblits = 0; + + { + const msg = getMessage(assert(RefCounted.create() != RefCounted.create())); // both operands promoted to temporary lvalues + assert(msg == "RefCounted() == RefCounted()"); + } + + version (DMD_Win64) // FIXME: temporaries apparently not destructed when unwinding via AssertError + { + assert(RefCounted.instances >= 0 && RefCounted.instances <= 2); + RefCounted.instances = 0; + } + else + assert(RefCounted.instances == 0); + assert(RefCounted.postblits == 1); + RefCounted.postblits = 0; + + static int numGetLvalImpureCalls = 0; + ref RefCounted getLvalImpure() @trusted + { + numGetLvalImpureCalls++; + __gshared lval = RefCounted(); // not incrementing RefCounted.instances + return lval; + } + + { + const msg = getMessage(assert(getLvalImpure() != getLvalImpure())); // both operands promoted to ref temporaries + assert(msg == "RefCounted() == RefCounted()"); + } + + assert(numGetLvalImpureCalls == 2); + assert(RefCounted.instances == 0); + assert(RefCounted.postblits == 1); + RefCounted.postblits = 0; +} + +// https://issues.dlang.org/show_bug.cgi?id=21471 +void test21471() +{ + { + static struct S + { + S get()() const { return this; } + } + + static auto f(S s) { return s; } + + auto s = S(); + assert(f(s.get) == s); + } + { + pragma(inline, true) + real exp(real x) pure nothrow + { + return x; + } + + bool isClose(int lhs, real rhs) pure nothrow + { + return false; + } + auto c = 0; + assert(!isClose(c, exp(1))); + } +} + +// https://issues.dlang.org/show_bug.cgi?id=20581 +void test20581() @safe +{ + static auto retro(return scope int[] s) @safe + { + static struct R + { + int[] source; + } + return R(s); + } + + int[5] a = [ 1, 2, 3, 4, 5 ]; + // Creates ref temporary __assertTmpXXXX for source + // Error: address of variable a assigned to __assertOp27 with longer lifetime + assert(retro(a[]).source is a[]); +} + +string getMessage(T)(lazy T expr) @trusted +{ + try + { + expr(); + return null; + } + catch (Throwable t) + { + return t.msg; + } +} + +void testMixinExpression() @safe +{ + static struct S + { + bool opEquals(S) @safe { return true; } + } + + const msg = getMessage(assert(mixin("S() != S()"))); + assert(msg == "S() == S()"); +} + +void testUnaryFormat() +{ + int zero = 0, one = 1; + assert(getMessage(assert(zero)) == "0 != true"); + assert(getMessage(assert(!one)) == "1 == true"); + + assert(getMessage(assert(!cast(int) 1.5)) == "1 == true"); + + assert(getMessage(assert(!!__ctfe)) == "assert(__ctfe) failed!"); + + static struct S + { + int i; + bool opCast() const + { + return i < 2; + } + } + + assert(getMessage(assert(S(4))) == "S(4) != true"); + + S s = S(4); + assert(getMessage(assert(*&s)) == "S(4) != true"); + + assert(getMessage(assert(--(++zero))) == "0 != true"); +} + +void testAssignments() +{ + int a = 1; + int b = 2; + assert(getMessage(assert(a -= --b)) == "0 != true"); + + static ref int c() + { + static int counter; + counter++; + return counter; + } + + assert(getMessage(assert(--c())) == "0 != true"); +} + +/// https://issues.dlang.org/show_bug.cgi?id=21472 +void testTupleFormat() +{ + alias AliasSeq(T...) = T; + + // Default usage + { + alias a = AliasSeq!(1, "ab"); + alias b = AliasSeq!(false, "xyz"); + assert(getMessage(assert(a == b)) == `(1, "ab") != (false, "xyz")`); + } + + // Single elements work but are not formatted as tuples + // Is this acceptable? (a workaround would probably require a + // different name for the tuple formatting hook) + { + alias a = AliasSeq!(1, "ab", []); + alias b = AliasSeq!(false, "xyz", [1]); + assert(getMessage(assert(a == b)) == `(1, "ab", []) != (false, "xyz", [1])`); + } + + // Also works with tupleof (as taken from the bug report) + { + static struct Var { int a, b; } + const a = Var(1, 2); + const b = Var(3, 4); + const msg = getMessage(assert(a.tupleof == b.tupleof)); + assert(msg == `(1, 2) != (3, 4)`); + } + + // Also works when creating temporaries for the TupleExp + { + static struct S + { + int a, b; + } + + static S get() + { + static int i; + return S(i++, i++); + } + + auto a = get().tupleof; + auto b = get().tupleof; + + string msg = getMessage(assert(a == b)); + assert(msg == `(0, 1) != (2, 3)`); + + msg = getMessage(assert(get().tupleof == AliasSeq!(2, 3))); + assert(msg == `(4, 5) != (2, 3)`); + + msg = getMessage(assert(get().tupleof == get().tupleof)); + assert(msg == `(6, 7) != (8, 9)`); + } +} + +// https://issues.dlang.org/show_bug.cgi?id=21682 +void testStaticOperators() +{ + static class environment { + static bool opCmp(scope const(char)[] name) + { + return false; + } + + static bool opBinaryRight(string op : "in")(scope const(char)[] name) + { + return false; + } + } + + string msg = getMessage(assert(environment < "Hello")); + assert(msg == `"environment" >= "Hello"`); + + msg = getMessage(assert("Hello" in environment)); + assert(msg == `"Hello" !in "environment"`); +} + +void main() +{ + test8765(); + test9255(); + test20114(); + test20375(); + test21471(); + test20581(); + testMixinExpression(); + testUnaryFormat(); + testAssignments(); + testTupleFormat(); + testStaticOperators(); +} diff --git a/gcc/testsuite/gdc.test/runnable/testassert_debug.d b/gcc/testsuite/gdc.test/runnable/testassert_debug.d new file mode 100644 index 00000000000..8817a96c547 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testassert_debug.d @@ -0,0 +1,26 @@ +/* +https://issues.dlang.org/show_bug.cgi?id=21598 + +REQUIRED_ARGS: -checkaction=context -debug +PERMUTE_ARGS: +*/ + +void main() +{ + bool caught; + try + assert(foo(1)); + catch (Throwable) + caught = true; + + assert(caught); + assert(counter == 1); +} + +__gshared int counter; + +int foo(int i) pure nothrow +{ + debug counter++; + return i - 1; +} diff --git a/gcc/testsuite/gdc.test/runnable/testassign.d b/gcc/testsuite/gdc.test/runnable/testassign.d index b0009671b19..f47d2b2bd97 100644 --- a/gcc/testsuite/gdc.test/runnable/testassign.d +++ b/gcc/testsuite/gdc.test/runnable/testassign.d @@ -1,4 +1,5 @@ /* +REQUIRED_ARGS: -preview=rvaluerefparam TEST_OUTPUT: --- \ S1 S2a S2b S3a S3b S4a S4b @@ -23,7 +24,7 @@ import core.stdc.stdio; template TypeTuple(T...){ alias T TypeTuple; } /***************************************************/ -// 2625 +// https://issues.dlang.org/show_bug.cgi?id=2625 struct Pair { immutable uint g1; @@ -36,7 +37,7 @@ void test1() { } /***************************************************/ -// 5327 +// https://issues.dlang.org/show_bug.cgi?id=5327 struct ID { @@ -154,12 +155,12 @@ void test3() } /***************************************************/ -// 3511 +// https://issues.dlang.org/show_bug.cgi?id=3511 struct S4 { private int _prop = 42; - ref int property() { return _prop; } + ref int property() return { return _prop; } } void test4() @@ -177,11 +178,11 @@ struct S5 int mX; string mY; - ref int x() + ref int x() return { return mX; } - ref string y() + ref string y() return { return mY; } @@ -230,7 +231,7 @@ void test5() } /***************************************************/ -// 4424 +// https://issues.dlang.org/show_bug.cgi?id=4424 void test4424() { @@ -242,7 +243,7 @@ void test4424() } /***************************************************/ -// 6174 +// https://issues.dlang.org/show_bug.cgi?id=6174 struct CtorTest6174(Data) { @@ -464,12 +465,12 @@ void test6174c() static assert(!is(typeof({ int func1a(int n) in{ n = 10; } - body { return n; } + do { return n; } }))); static assert(!is(typeof({ int func1b(int n) out(r){ r = 20; } - body{ return n; } + do{ return n; } }))); struct DataX @@ -479,18 +480,18 @@ void test6174c() static assert(!is(typeof({ DataX func2a(DataX n) in{ n.x = 10; } - body { return n; } + do { return n; } }))); static assert(!is(typeof({ DataX func2b(DataX n) in{} out(r){ r.x = 20; } - body{ return n; } + do{ return n; } }))); } /***************************************************/ -// 6216 +// https://issues.dlang.org/show_bug.cgi?id=6216 void test6216a() { @@ -658,7 +659,7 @@ void test6216e() } /***************************************************/ -// 6286 +// https://issues.dlang.org/show_bug.cgi?id=6286 void test6286() { @@ -672,7 +673,7 @@ void test6286() } /***************************************************/ -// 6336 +// https://issues.dlang.org/show_bug.cgi?id=6336 void test6336() { @@ -701,7 +702,7 @@ void test6336() } /***************************************************/ -// 8783 +// https://issues.dlang.org/show_bug.cgi?id=8783 struct Foo8783 { @@ -719,7 +720,7 @@ static this() } /***************************************************/ -// 9077 +// https://issues.dlang.org/show_bug.cgi?id=9077 struct S9077a { @@ -735,17 +736,17 @@ struct S9077b } /***************************************************/ -// 9140 +// https://issues.dlang.org/show_bug.cgi?id=9140 immutable(int)[] bar9140() out(result) { foreach (ref r; result) {} -} body { +} do { return null; } /***************************************************/ -// 9154 +// https://issues.dlang.org/show_bug.cgi?id=9154 struct S9154a { @@ -770,7 +771,7 @@ void test9154() } /***************************************************/ -// 9258 +// https://issues.dlang.org/show_bug.cgi?id=9258 class A9258 {} class B9258 : A9258 // Error: class test.B9258 identity assignment operator overload is illegal @@ -797,7 +798,7 @@ class E9258 : A9258 } /***************************************************/ -// 9416 +// https://issues.dlang.org/show_bug.cgi?id=9416 struct S9416 { @@ -818,7 +819,7 @@ void test9416() } /***************************************************/ -// 9658 +// https://issues.dlang.org/show_bug.cgi?id=9658 struct S9658 { @@ -830,7 +831,7 @@ struct S9658 } /***************************************************/ -// 11187 +// https://issues.dlang.org/show_bug.cgi?id=11187 void test11187() { @@ -850,7 +851,7 @@ void test11187() } /***************************************************/ -// 12131 +// https://issues.dlang.org/show_bug.cgi?id=12131 struct X12131 { @@ -872,7 +873,7 @@ void test12131() pure } /***************************************************/ -// 12211 +// https://issues.dlang.org/show_bug.cgi?id=12211 void test12211() { @@ -891,12 +892,12 @@ void test12211() // array ops should make rvalue int[3] sa, sb; void bar(ref int[]) {} - static assert(!__traits(compiles, bar(sa[] = sb[]))); - static assert(!__traits(compiles, bar(sa[] += sb[]))); + static assert(__traits(compiles, bar(sa[] = sb[]))); + static assert(__traits(compiles, bar(sa[] += sb[]))); } /***************************************************/ -// 4791 (dup of 12212) +// https://issues.dlang.org/show_bug.cgi?id=4791 (dup of 12212) void test4791() { @@ -925,7 +926,7 @@ void test4791() } /***************************************************/ -// 12212 +// https://issues.dlang.org/show_bug.cgi?id=12212 void test12212() { @@ -1013,7 +1014,7 @@ void test12212() } /***************************************************/ -// 12650 +// https://issues.dlang.org/show_bug.cgi?id=12650 void test12650() { @@ -1083,7 +1084,7 @@ void test12650() } /***************************************************/ -// 13044 +// https://issues.dlang.org/show_bug.cgi?id=13044 void test13044() { @@ -1106,7 +1107,7 @@ void test13044() } /***************************************************/ -// 12500 +// https://issues.dlang.org/show_bug.cgi?id=12500 void test12500() { @@ -1115,7 +1116,7 @@ void test12500() } /***************************************************/ -// 14672 +// https://issues.dlang.org/show_bug.cgi?id=14672 void test14672() { @@ -1150,7 +1151,7 @@ void test14672() } /***************************************************/ -// 15044 +// https://issues.dlang.org/show_bug.cgi?id=15044 void destroy15044(T)(ref T obj) { @@ -1166,7 +1167,7 @@ struct V15044 { } - RC15044!V15044 dup() + RC15044!V15044 dup() return { return RC15044!V15044(&this); } diff --git a/gcc/testsuite/gdc.test/runnable/testbitarray.d b/gcc/testsuite/gdc.test/runnable/testbitarray.d deleted file mode 100644 index 8a34f886b05..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testbitarray.d +++ /dev/null @@ -1,17 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: - -import std.bitmanip; - -void main() { - BitArray a; - a.length = 5; - foreach (ref bool b; a) { - assert (b == 0); - b = 1; - } - foreach (bool b; a) - assert (b == 1); // FAILS, they're all 0 -} - - diff --git a/gcc/testsuite/gdc.test/runnable/testbounds.d b/gcc/testsuite/gdc.test/runnable/testbounds.d index b23c88f29b6..bb9e54d75c2 100644 --- a/gcc/testsuite/gdc.test/runnable/testbounds.d +++ b/gcc/testsuite/gdc.test/runnable/testbounds.d @@ -1,3 +1,9 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ // REQUIRED_ARGS: // Test array bounds checking @@ -179,44 +185,63 @@ void test1() } /******************************************/ -// 13976 +// https://issues.dlang.org/show_bug.cgi?id=13976 void test13976() { int[] da = new int[](10); int[10] sa; - size_t l = 0; // upperInRange - size_t u = 9; // | lowerLessThan - // | | check code - { auto s = da[l .. u]; } // 0 0 (u <= 10 && l <= u ) - { auto s = da[1 .. u]; } // 0 0 (u <= 10 && l <= u ) - { auto s = da[l .. 10]; } // 0 0 (u <= 10 && l <= u ) - { auto s = da[1 .. u%5]; } // 0 0 (u <= 10 && l <= u%5) - - { auto s = da[l .. u]; } // 0 0 (u <= 10 && l <= u) - { auto s = da[0 .. u]; } // 0 1 (u <= 10 ) - { auto s = da[l .. 10]; } // 0 0 (u <= 10 && l <= u) - { auto s = da[0 .. u%5]; } // 0 1 (u%5 <= 10 ) - - { auto s = sa[l .. u]; } // 0 0 (u <= 10 && l <= u ) - { auto s = sa[1 .. u]; } // 0 0 (u <= 10 && l <= u ) - { auto s = sa[l .. 10]; } // 1 0 ( l <= u ) - { auto s = sa[1 .. u%5]; } // 1 0 ( l <= u%5) - - { auto s = sa[l .. u]; } // 0 0 (u <= 10 && l <= u ) - { auto s = sa[0 .. u]; } // 0 1 (u <= 10 ) - { auto s = sa[l .. 10]; } // 1 0 ( l <= 10) - { auto s = sa[0 .. u%5]; } // 1 1 NULL + enum size_t two = 2; + enum size_t five = 5; + size_t lb = 0; // upperInRange + size_t ub = 9; // | lowerLessThan + // | | check code + { auto s = da[lb .. ub]; } // 0 0 (ub <= $ && lb <= ub ) + { auto s = da[1 .. ub]; } // 0 0 (ub <= $ && 1 <= ub ) + { auto s = da[lb .. 10]; } // 0 0 (10 <= $ && lb <= 10 ) + { auto s = da[1 .. ub%5]; } // 0 0 (ub%5 <= $ && 1 <= ub%5) + + { auto s = da[lb .. ub]; } // 0 0 (ub <= $ && lb <= ub ) + { auto s = da[0 .. ub]; } // 0 1 (ub <= $ ) + { auto s = da[lb .. 10]; } // 0 0 (10 <= $ && lb <= 10 ) + { auto s = da[0 .. ub%5]; } // 0 1 (ub%5 <= $ ) + + { auto s = da[0 .. 0]; } // 1 1 NULL + { auto s = da[0 .. $]; } // 1 1 NULL + { auto s = da[1 .. $]; } // 1 0 ( 1 <= $ ) + { auto s = da[$ .. $]; } // 1 0 ( $ <= $ ) + { auto s = da[0 .. $/two]; } // 0 1 ($/2 <= $ ) + { auto s = da[$/two .. $]; } // 1 0 ( $/2 <= $ ) + { auto s = da[$/five .. $/two]; } // 0 0 ($/2 <= $ && $/5 <= $/2) + + { auto s = sa[lb .. ub]; } // 0 0 (ub <= 10 && lb <= ub ) + { auto s = sa[1 .. ub]; } // 0 0 (ub <= 10 && 1 <= ub ) + { auto s = sa[lb .. 10]; } // 1 0 ( lb <= 10 ) + { auto s = sa[1 .. ub%5]; } // 1 0 ( 1 <= ub%5) + + { auto s = sa[lb .. ub]; } // 0 0 (ub <= 10 && lb <= ub ) + { auto s = sa[0 .. ub]; } // 0 1 (ub <= 10 ) + { auto s = sa[lb .. 10]; } // 1 0 ( lb <= 10 ) + { auto s = sa[0 .. ub%5]; } // 1 1 NULL + + { auto s = sa[0 .. 0]; } // 1 1 NULL + { auto s = sa[0 .. $]; } // 1 1 NULL + { auto s = sa[1 .. $]; } // 1 1 NULL + { auto s = sa[$ .. $]; } // 1 1 NULL + { auto s = sa[0 .. $/two]; } // 1 1 NULL + { auto s = sa[$/two .. $]; } // 1 1 NULL + { auto s = sa[$/five .. $/two]; } // 1 1 NULL int* p = new int[](10).ptr; - { auto s = p[0 .. u]; } // 1 1 NULL - { auto s = p[l .. u]; } // 1 0 (l <= u) - { auto s = p[0 .. u%5]; } // 1 1 NULL - { auto s = p[1 .. u%5]; } // 1 0 (l <= u%5) + { auto s = p[0 .. ub]; } // 1 1 NULL + { auto s = p[lb .. ub]; } // 1 0 (lb <= ub ) + { auto s = p[0 .. ub%5]; } // 1 1 NULL + { auto s = p[1 .. ub%5]; } // 1 0 (1 <= ub%5) + { auto s = p[0 .. 0]; } // 1 1 NULL } /******************************************/ -// 3652 +// https://issues.dlang.org/show_bug.cgi?id=3652 void test3652() { @@ -340,7 +365,7 @@ void test3652b() @safe } /**********************************/ -// 9654 +// https://issues.dlang.org/show_bug.cgi?id=9654 auto foo9654a(ref char[8] str) { return str; } auto foo9654b(ref const char[8] str) { return str; } @@ -364,7 +389,7 @@ static assert( is(typeof(baz9654b("testinfo")) == const char[8])); static assert( is(typeof(baz9654c("testinfo")) == immutable char[8])); /******************************************/ -// 9712 +// https://issues.dlang.org/show_bug.cgi?id=9712 auto func9712(T)(T[2] arg) { return arg; } static assert(is(typeof(func9712([1,2])) == int[2])); @@ -373,7 +398,7 @@ auto deduceLength9712(T,size_t n)(T[n] a) { return a; } static assert(is(typeof(deduceLength9712([1,2,3])) == int[3])); /******************************************/ -// 9743 +// https://issues.dlang.org/show_bug.cgi?id=9743 void test9743() { @@ -436,7 +461,7 @@ void test9743() } /******************************************/ -// 9747 +// https://issues.dlang.org/show_bug.cgi?id=9747 void foo9747A(T)(T[4]) {} void foo9747C(size_t dim)(char[dim]) {} @@ -454,7 +479,7 @@ void test9747() } /******************************************/ -// 12876 +// https://issues.dlang.org/show_bug.cgi?id=12876 void test12876() { @@ -467,24 +492,24 @@ void test12876() } /******************************************/ -// 13775 +// https://issues.dlang.org/show_bug.cgi?id=13775 void test13775() { ubyte[4] ubytes = [1,2,3,4]; - // CT-known slicing (issue 3652) + // CT-known slicing (https://issues.dlang.org/show_bug.cgi?id=3652) auto ok1 = cast(ubyte[2]) ubytes[0 .. 2]; assert(ok1 == [1, 2]); - // CT-known slicing with implicit conversion of SliceExp::e1 (issue 13154) + // CT-known slicing with implicit conversion of SliceExp::e1 (https://issues.dlang.org/show_bug.cgi?id=13154) enum double[] arr = [1.0, 2.0, 3.0]; auto ok2 = cast(float[2]) [1.0, 2.0, 3.0][0..2]; auto ok3 = cast(float[2]) arr[1..3]; // currently this is accepted assert(ok2 == [1f, 2f]); assert(ok3 == [2f, 3f]); - // CT-known slicing with type coercing (issue 13775) + // CT-known slicing with type coercing (https://issues.dlang.org/show_bug.cgi?id=13775) auto ok4 = cast( byte[2]) ubytes[0 .. 2]; // CT-known slicing + type coercing auto ok5 = cast(short[1]) ubytes[0 .. 2]; // CT-known slicing + type coercing assert(ok4 == [1, 2]); @@ -493,6 +518,29 @@ void test13775() } /******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15889 +// Array bounds check should report index and length +void test15889() +{ + int[] a = new int[2]; + + try { + a[3] = 40; + } catch (ArrayIndexError e) { + assert(e.index == 3); + assert(e.length == 2); + } + + try { + a[1 .. 4] = 50; + } catch (ArraySliceError e) { + assert(e.lower == 1); + assert(e.upper == 4); + assert(e.length == 2); + } +} + +/******************************************/ int main() { @@ -504,6 +552,7 @@ int main() test9743(); test9747(); test13775(); + test15889(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/testbtst.d b/gcc/testsuite/gdc.test/runnable/testbtst.d new file mode 100644 index 00000000000..a6967f6c17d --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testbtst.d @@ -0,0 +1,156 @@ +/* PERMUTE_ARGS: -O + * https://issues.dlang.org/show_bug.cgi?id=19813 + */ + +struct BitArray +{ + import core.bitop : btc, bts, btr, bsf, bt; + + size_t _len; + size_t* _ptr; + enum bitsPerSizeT = size_t.sizeof * 8; + + static size_t lenToDim(size_t len) @nogc pure nothrow @safe + { + return (len + (bitsPerSizeT-1)) / bitsPerSizeT; + } + + this(in bool[] ba) nothrow pure + { + length = ba.length; + foreach (i, b; ba) + { + if (b) + bts(_ptr, i); + else + btr(_ptr, i); + } + } + + @property size_t length(size_t newlen) pure nothrow @system + { + if (newlen != _len) + { + size_t olddim = lenToDim(_len); + immutable newdim = lenToDim(newlen); + + if (newdim != olddim) + { + // Create a fake array so we can use D's realloc machinery + auto b = _ptr[0 .. olddim]; + b.length = newdim; // realloc + _ptr = b.ptr; + } + + _len = newlen; + } + return _len; + } + + int opCmp(ref BitArray a2) const @nogc pure nothrow + { + const lesser = this._len < a2._len ? &this : &a2; + immutable fullWords = lesser._len / lesser.bitsPerSizeT; + immutable endBits = lesser._len % lesser.bitsPerSizeT; + auto p1 = this._ptr; + auto p2 = a2._ptr; + + foreach (i; 0 .. fullWords) + { + if (p1[i] != p2[i]) + { + return p1[i] & (size_t(1) << bsf(p1[i] ^ p2[i])) ? 1 : -1; + } + } + + if (endBits) + { + immutable i = fullWords; + immutable diff = p1[i] ^ p2[i]; + if (diff) + { + immutable index = bsf(diff); + if (index < endBits) + { + // This gets optimized into OPbtst, and was doing it incorrectly + return p1[i] & (size_t(1) << index) ? 1 : -1; + } + } + } + + return -1; + } +} + +void test1() +{ + bool[] ba = [1,0,1,0,1]; + bool[] bd = [1,0,1,1,1]; + + auto a = BitArray(ba); + auto d = BitArray(bd); + + assert(a < d); +} + +/***************************************/ + +// https://issues.dlang.org/show_bug.cgi?id=18748 + +int bt_32_imm(in uint* p) +{ + enum bitnum = 1; + return ((p[bitnum >> 5] & (1 << (bitnum & 31)))) != 0; +} + +void test18748() +{ + version (linux) + { + import core.sys.posix.sys.mman; + import core.sys.posix.unistd; + // Allocate two pages. + immutable sz = 2 * sysconf(_SC_PAGESIZE); + auto m = mmap(null, sz, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); + // Discard the higher page. It becomes unreadable. + munmap(m + sz / 2, sz / 2); + // Try looking at the last 4 bytes of the readable page. + uint* p = cast(uint*) (m + sz / 2 - uint.sizeof); + bt_32_imm(p); + munmap(m, sz / 2); // Free the readable page. + } +} + +/***************************************/ + +// https://issues.dlang.org/show_bug.cgi?id=18749 + +ulong f(ulong* p, uint shift) +{ + return (*p >> shift) & 1; +} + +ulong g(ulong* p, ulong shift) +{ + return f(p, cast(uint) shift); +} + +void test18749() +{ + enum shift = uint.max + 1L; + assert(cast(uint) shift == 0); + ulong s = 1; + assert(g(&s, shift)); +} + + +/***************************************/ + +int main() +{ + test1(); + test18748(); + test18749(); + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/testcgelem.d b/gcc/testsuite/gdc.test/runnable/testcgelem.d new file mode 100644 index 00000000000..b5c7f7d1855 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testcgelem.d @@ -0,0 +1,47 @@ +/* +REQUIRED_ARGS: -mcpu=native -preview=intpromote +PERMUTE_ARGS: -O -inline -release +*/ + +/*** + * Do coverage testing of cgelem.d + * Check coverage here: + * https://codecov.io/gh/dlang/dmd/src/master/src/dmd/backend/cgelem.d + */ + +import core.stdc.stdio; + +template tuple(A...) { alias tuple = A; } + +/*************************************************/ + +void test_eladdr() +{ + // & (*p1 = e) => ((*(t = p1) = e), t) + int i = 4; + int* p1 = &i; + int e = 5; + auto x = &(*p1 = e); + assert(i == 5); + assert(x == p1); +} + +/*************************************************/ + +void test_elneg() +{ + static int i = 3; + int j = - -i; + assert(i == j); +} + +/*************************************************/ + +int main() +{ + test_eladdr(); + test_elneg(); + + printf("Success\n"); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/testclass.d b/gcc/testsuite/gdc.test/runnable/testclass.d index c5480da0cc5..cd8dd84c2cf 100644 --- a/gcc/testsuite/gdc.test/runnable/testclass.d +++ b/gcc/testsuite/gdc.test/runnable/testclass.d @@ -1,7 +1,13 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); /******************************************/ -// 12078 +// https://issues.dlang.org/show_bug.cgi?id=12078 class B12078(T) { @@ -26,7 +32,7 @@ void test12078() } /******************************************/ -// 12143 +// https://issues.dlang.org/show_bug.cgi?id=12143 class Node12143 { @@ -39,7 +45,7 @@ class Type12143 : Node12143 {} class Class12143 : Type12143 {} /***************************************************/ -// 13353 +// https://issues.dlang.org/show_bug.cgi?id=13353 interface Base13353(T) { @@ -57,7 +63,7 @@ class Concrete13353 : Derived13353 } /***************************************************/ -// 15733 +// https://issues.dlang.org/show_bug.cgi?id=15733 class CStmt15733 : CNode15733 {} class CDecl15733 : CStmt15733 {} @@ -71,8 +77,48 @@ template IMix(T){ mixin("static " ~ T.stringof ~ " x;"); } /***************************************************/ +// https://issues.dlang.org/show_bug.zip?id=20716 + +extern(C++): + +struct S20716 +{ + void* s; + ~this() {} + // or this(this) {} +} + +interface I20716 +{ + S20716 x(); +} + +final class C20716 : I20716 +{ + int l = 3; + + S20716 x() + { + //printf("this = %p, %p\n", this, &this.l); + assert(l == 3); //fails + return S20716.init; + } +} + +extern(D): + +void test20716() +{ + auto s = new C20716().x; + auto t = new C20716().I20716.x; +} + +/***************************************************/ + int main() { + test20716(); + printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/testconst.d b/gcc/testsuite/gdc.test/runnable/testconst.d index 7ec42452ec5..5c0e75de60f 100644 --- a/gcc/testsuite/gdc.test/runnable/testconst.d +++ b/gcc/testsuite/gdc.test/runnable/testconst.d @@ -53,7 +53,7 @@ template TypeTuple(T...) { alias T TypeTuple; } void showf(string f) { - printf("%.*s\n", f.length, f.ptr); + printf("%.*s\n", cast(int)f.length, f.ptr); } /************************************/ @@ -626,7 +626,7 @@ class C42 void test42() { - printf("%d\n", C42.classinfo.initializer.length); + printf("%zd\n", C42.classinfo.initializer.length); assert(C42.classinfo.initializer.length == 12 + (void*).sizeof + (void*).sizeof); C42 c = new C42; @@ -963,7 +963,7 @@ void test56() { S56 s; S56 t; - printf("S56.sizeof = %d\n", S56.sizeof); + printf("S56.sizeof = %zd\n", S56.sizeof); //t = s; } @@ -1574,7 +1574,7 @@ void test87() } /************************************/ -// 2751 +// https://issues.dlang.org/show_bug.cgi?id=2751 void test88(immutable(int[3]) a) @@ -1603,7 +1603,7 @@ void test88(immutable(int[3]) a) } /************************************/ -// 3748 +// https://issues.dlang.org/show_bug.cgi?id=3748 // version = error8; // version = error11; @@ -1878,7 +1878,7 @@ void test3748c(inout int = 1) } /************************************/ -// 4968 +// https://issues.dlang.org/show_bug.cgi?id=4968 void test4968() { @@ -1924,7 +1924,7 @@ void test4968() } /************************************/ -// 1961 +// https://issues.dlang.org/show_bug.cgi?id=1961 inout(char)[] strstr(inout(char)[] source, const(char)[] pattern) { @@ -2042,7 +2042,7 @@ void test88() } /************************************/ -// 4251 +// https://issues.dlang.org/show_bug.cgi?id=4251 void test4251a() { @@ -2185,7 +2185,7 @@ void test4251b() } /************************************/ -// 5473 +// https://issues.dlang.org/show_bug.cgi?id=5473 void test5473() { @@ -2227,7 +2227,7 @@ void test5473() } /************************************/ -// 5493 +// https://issues.dlang.org/show_bug.cgi?id=5493 void test5493() { @@ -2282,7 +2282,7 @@ void test5493() } /************************************/ -// 5493 + inout +// https://issues.dlang.org/show_bug.cgi?id=5493 + inout void test5493inout() { @@ -2330,7 +2330,7 @@ void test5493inout() } /************************************/ -// 6782 +// https://issues.dlang.org/show_bug.cgi?id=6782 struct Tuple6782(T...) { @@ -2368,7 +2368,7 @@ void test6782() } /************************************/ -// 6864 +// https://issues.dlang.org/show_bug.cgi?id=6864 int fn6864( const int n) { return 1; } int fn6864(shared int n) { return 2; } @@ -2387,7 +2387,7 @@ void test6864() } /************************************/ -// 6865 +// https://issues.dlang.org/show_bug.cgi?id=6865 shared(inout(int)) foo6865(shared(inout(int)) n){ return n; } void test6865() @@ -2397,7 +2397,7 @@ void test6865() } /************************************/ -// 6866 +// https://issues.dlang.org/show_bug.cgi?id=6866 struct S6866 { @@ -2414,7 +2414,7 @@ void test6866() } /************************************/ -// 6867 +// https://issues.dlang.org/show_bug.cgi?id=6867 inout(char)[] test6867(inout(char)[] a) { @@ -2428,7 +2428,7 @@ inout(char)[] test6867(inout(char)[] a) } /************************************/ -// 6870 +// https://issues.dlang.org/show_bug.cgi?id=6870 void test6870() { @@ -2440,7 +2440,8 @@ void test6870() } /************************************/ -// 6338, 6922 +// https://issues.dlang.org/show_bug.cgi?id=6338 +// https://issues.dlang.org/show_bug.cgi?id=6922 alias int T; @@ -2468,7 +2469,7 @@ static assert(is( inout(shared(immutable(T))) == immutable(T) )); static assert(is( inout(immutable(shared(T))) == immutable(T) )); /************************************/ -// 6912 +// https://issues.dlang.org/show_bug.cgi?id=6912 void test6912() { @@ -2585,7 +2586,7 @@ void test6912() } /************************************/ -// 6930 +// https://issues.dlang.org/show_bug.cgi?id=6930 void test6930a() { @@ -2657,7 +2658,7 @@ void test6930b(inout int = 0) } /************************************/ -// 11868 +// https://issues.dlang.org/show_bug.cgi?id=11868 void f11868(A...)(A) { } @@ -2673,7 +2674,7 @@ void test11868() } /************************************/ -// 11924 +// https://issues.dlang.org/show_bug.cgi?id=11924 inout(StringType) localize11924(StringType)(inout StringType str, string locale) { @@ -2695,7 +2696,7 @@ struct S11924 } /************************************/ -// 11966 +// https://issues.dlang.org/show_bug.cgi?id=11966 inout(char)[] stripped11966 (inout(char)[] path) { @@ -2721,7 +2722,7 @@ void test11966() } /************************************/ -// 14788 +// https://issues.dlang.org/show_bug.cgi?id=14788 auto make14788(K, V)(inout V[K] aa) { @@ -2740,7 +2741,7 @@ void test14788() } /************************************/ -// 12089 +// https://issues.dlang.org/show_bug.cgi?id=12089 void foo12089(inout(char[]) a) { @@ -2754,7 +2755,7 @@ void decodeImpl12089(S)(auto ref S str) {} /************************************/ -// 12524 +// https://issues.dlang.org/show_bug.cgi?id=12524 inout(int) dup12524(inout(const(int)) val) { @@ -2771,7 +2772,7 @@ void test12524(inout(int)) } /************************************/ -// 6941 +// https://issues.dlang.org/show_bug.cgi?id=6941 static assert((const(shared(int[])[])).stringof == "const(shared(int[])[])"); // fail static assert((const(shared(int[])[])).stringof != "const(shared(const(int[]))[])"); // fail @@ -2780,7 +2781,7 @@ static assert((inout(shared(int[])[])).stringof == "inout(shared(int[])[])"); static assert((inout(shared(int[])[])).stringof != "inout(shared(inout(int[]))[])"); // fail /************************************/ -// 6872 +// https://issues.dlang.org/show_bug.cgi?id=6872 static assert((shared(inout(int)[])).stringof == "shared(inout(int)[])"); static assert((shared(inout(const(int)[]))).stringof == "shared(inout(const(int)[]))"); @@ -2788,7 +2789,7 @@ static assert((shared(inout(const(int)[])[])).stringof == "shared(inout(const(in static assert((shared(inout(const(immutable(int)[])[])[])).stringof == "shared(inout(const(immutable(int)[])[])[])"); /************************************/ -// 6939 +// https://issues.dlang.org/show_bug.cgi?id=6939 void test6939() { @@ -2808,7 +2809,7 @@ void test6939() } /************************************/ -// 6940 +// https://issues.dlang.org/show_bug.cgi?id=6940 void test6940() { @@ -2830,7 +2831,7 @@ void test6940() } /************************************/ -// 6982 +// https://issues.dlang.org/show_bug.cgi?id=6982 void test6982() { @@ -2847,7 +2848,7 @@ void test6982() } /************************************/ -// 7038 +// https://issues.dlang.org/show_bug.cgi?id=7038 static assert(is(S7038 == const)); const struct S7038{ int x; } @@ -2875,7 +2876,7 @@ void test7038() } /************************************/ -// 7105 +// https://issues.dlang.org/show_bug.cgi?id=7105 void copy(inout(int)** tgt, inout(int)* src){ *tgt = src; } @@ -2909,11 +2910,11 @@ void test7105() } /************************************/ -// 7202 +// https://issues.dlang.org/show_bug.cgi?id=7202 void test7202() { - void writeln(string s) @system { printf("%.*s\n", s.length, s.ptr); } + void writeln(string s) @system { printf("%.*s\n", cast(int)s.length, s.ptr); } void delegate() @system x = { writeln("I am @system"); }; void delegate() @safe y = { }; auto px = &x; @@ -2924,7 +2925,7 @@ void test7202() } /************************************/ -// 7554 +// https://issues.dlang.org/show_bug.cgi?id=7554 T outer7554(T)(immutable T function(T) pure foo) pure { pure int inner() { @@ -2957,7 +2958,7 @@ void test7518() { } /************************************/ -// 7669 +// https://issues.dlang.org/show_bug.cgi?id=7669 shared(inout U)[n] id7669(U, size_t n)( shared(inout U)[n] ); void test7669() @@ -2966,7 +2967,7 @@ void test7669() } /************************************/ -// 7757 +// https://issues.dlang.org/show_bug.cgi?id=7757 inout(int) foo7757a(int x, lazy inout(int) def) { return def; } inout(int)[] foo7757b(int x, lazy inout(int)[] def) { return def; } @@ -2999,7 +3000,7 @@ void test7757() } /************************************/ -// 8098 +// https://issues.dlang.org/show_bug.cgi?id=8098 class Outer8098 { @@ -3033,7 +3034,7 @@ void test8098() } /************************************/ -// 8099 +// https://issues.dlang.org/show_bug.cgi?id=8099 void test8099() { @@ -3068,7 +3069,7 @@ void test8099() } /************************************/ -// 8201 +// https://issues.dlang.org/show_bug.cgi?id=8201 void test8201() { @@ -3080,7 +3081,7 @@ void test8201() } /************************************/ -// 8212 +// https://issues.dlang.org/show_bug.cgi?id=8212 struct S8212 { int x; } @@ -3095,7 +3096,7 @@ void test8212() } /************************************/ -// 8366 +// https://issues.dlang.org/show_bug.cgi?id=8366 class B8366 { @@ -3115,7 +3116,7 @@ class C8366a : B8366 class C8366b : B8366 { bool foo(in Object o) { return false; } - alias super.foo foo; + alias typeof(super).foo foo; bool foo(in Object o) immutable { return false; } bool foo(in Object o) shared { return false; } bool foo(in Object o) shared const { return false; } @@ -3146,7 +3147,7 @@ void test8366() } /************************************/ -// 8408 +// https://issues.dlang.org/show_bug.cgi?id=8408 template hasMutableIndirection8408(T) { @@ -3211,18 +3212,20 @@ void test8408() struct T2 { S2 s; } struct T3 { S1 s1; S2 s2; } - test!(int , true )(); - test!(int[3], true )(); +/* + test!(int , false)(); + test!(int[3], false)(); test!(C , false)(); - test!(S1 , true )(); + test!(S1 , false)(); test!(S2 , false)(); - test!(T1 , true )(); + test!(T1 , false)(); test!(T2 , false)(); test!(T3 , false)(); +*/ } /************************************/ -// 8688 +// https://issues.dlang.org/show_bug.cgi?id=8688 void test8688() { @@ -3236,7 +3239,7 @@ void test8688() } /************************************/ -// 10946 (regression by fixing bug 8688, from 2.061) +// https://issues.dlang.org/show_bug.cgi?id=10946 (regression by fixing bug 8688, from 2.061) enum xlen10946 = 4; alias immutable(char)[xlen10946] e3; @@ -3246,12 +3249,12 @@ alias immutable(char)[vlen10946] i3; alias immutable(char[vlen10946]) i4; // NG -> OK /************************************/ -// 9046 +// https://issues.dlang.org/show_bug.cgi?id=9046 void test9046() { foreach (T; TypeTuple!(byte, ubyte, short, ushort, int, uint, long, ulong, char, wchar, dchar, - float, double, real, ifloat, idouble, ireal, cfloat, cdouble, creal)) + float, double, real)) foreach (U; TypeTuple!(T, const T, immutable T, shared T, shared const T, inout T, shared inout T)) { static assert(is(typeof(U.init) == U)); @@ -3285,7 +3288,7 @@ void test9046() } /************************************/ -// 9090 +// https://issues.dlang.org/show_bug.cgi?id=9090 void test9090() { @@ -3296,7 +3299,7 @@ void test9090() } /************************************/ -// 9461 +// https://issues.dlang.org/show_bug.cgi?id=9461 void test9461() { @@ -3328,15 +3331,15 @@ void test9209() { } /************************************/ -// 10758 +// https://issues.dlang.org/show_bug.cgi?id=10758 struct X10758 { static: inout(int) screwUpVal(ref inout(int) wx) { return wx; } - ref inout(int) screwUpRef(ref inout(int) wx) { return wx; } - inout(int)* screwUpPtr(ref inout(int) wx) { return &wx; } - inout(int)[] screwUpArr(ref inout(int) wx) { return (&wx)[0 .. 1]; } + ref inout(int) screwUpRef(return ref inout(int) wx) { return wx; } + inout(int)* screwUpPtr(return ref inout(int) wx) { return &wx; } + inout(int)[] screwUpArr(return ref inout(int) wx) { return (&wx)[0 .. 1]; } } struct S10758 @@ -3471,7 +3474,7 @@ void test10758(ref inout(int) wx, inout(int)* wp, inout(int)[] wa, inout(S10758) } /************************************/ -// 10761 +// https://issues.dlang.org/show_bug.cgi?id=10761 inout(int)* function(inout(int)*) fptr10761(inout(int)*) { @@ -3545,7 +3548,7 @@ void test10761() } /************************************/ -// 11226 +// https://issues.dlang.org/show_bug.cgi?id=11226 void test11226() { @@ -3573,7 +3576,7 @@ void test11226() } /************************************/ -// 11257 +// https://issues.dlang.org/show_bug.cgi?id=11257 struct R11257 { @@ -3590,7 +3593,7 @@ void test11257() } /************************************/ -// 11215 +// https://issues.dlang.org/show_bug.cgi?id=11215 shared(inout(void)**) f11215(inout int); @@ -3598,7 +3601,7 @@ static assert(is(typeof(f11215(0)) == shared(void**))); static assert(is(typeof(f11215((const int).init)) == shared(const(void)**))); /************************************/ -// 11489 +// https://issues.dlang.org/show_bug.cgi?id=11489 void test11489(inout int = 0) { @@ -3671,7 +3674,7 @@ void test11489(inout int = 0) } /************************************/ -// 11768 +// https://issues.dlang.org/show_bug.cgi?id=11768 void test11768(inout int = 0) { @@ -3683,7 +3686,7 @@ void test11768(inout int = 0) } /************************************/ -// 12403 +// https://issues.dlang.org/show_bug.cgi?id=12403 void test12403() { @@ -3698,7 +3701,7 @@ void test12403() } /************************************/ -// 13011 +// https://issues.dlang.org/show_bug.cgi?id=13011 void test13011() { @@ -3712,7 +3715,7 @@ void test13011() } /************************************/ -// 13030 +// https://issues.dlang.org/show_bug.cgi?id=13030 void va13030(Args...)(const Args args) {} @@ -3722,7 +3725,8 @@ void func13030(int delegate(int n) a) } /************************************/ -// 13802 & 13803 +// https://issues.dlang.org/show_bug.cgi?id=13802 +// https://issues.dlang.org/show_bug.cgi?id=13803 static assert(( string ).stringof == "string" ); static assert(( string[] ).stringof == "string[]" ); diff --git a/gcc/testsuite/gdc.test/runnable/testcontracts.d b/gcc/testsuite/gdc.test/runnable/testcontracts.d index f99a10afff2..786969104f5 100644 --- a/gcc/testsuite/gdc.test/runnable/testcontracts.d +++ b/gcc/testsuite/gdc.test/runnable/testcontracts.d @@ -1,5 +1,21 @@ -// PERMUTE_ARGS: -inline -g -O - +/* PERMUTE_ARGS: -inline -g -O +TEST_OUTPUT: +--- +runnable/testcontracts.d(323): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(324): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(325): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(326): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(328): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(329): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(330): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(331): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(502): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(503): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(504): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(505): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +runnable/testcontracts.d(505): Deprecation: Usage of the `body` keyword is deprecated. Use `do` instead. +--- +*/ extern(C) int printf(const char*, ...); /*******************************************/ @@ -192,7 +208,7 @@ void test5() } /*******************************************/ -// 3273 +// https://issues.dlang.org/show_bug.cgi?id=3273 // original case struct Bug3273 @@ -205,7 +221,7 @@ struct Bug3273 ref int func3273() out(r) { - // Regression check of issue 3390 + // Regression check of https://issues.dlang.org/show_bug.cgi?id=3390 static assert(!__traits(compiles, r = 1)); } do @@ -318,13 +334,13 @@ void test9() /*******************************************/ -auto test10() body { return 3; } -auto test11()() body { return 3; } +auto test10() do { return 3; } +auto test11()() do { return 3; } auto test12() { - auto test10() body { return 3; } - auto test11()() body { return 3; } + auto test10() do { return 3; } + auto test11()() do { return 3; } return 3; } @@ -335,7 +351,7 @@ void test13() } /*******************************************/ -// 4785 +// https://issues.dlang.org/show_bug.cgi?id=4785 int cnt; @@ -360,7 +376,7 @@ void test4785() } /*******************************************/ -// 5039 +// https://issues.dlang.org/show_bug.cgi?id=5039 class C5039 { int x; @@ -375,7 +391,7 @@ class C5039 { } /*******************************************/ -// 5204 +// https://issues.dlang.org/show_bug.cgi?id=5204 interface IFoo5204 { @@ -388,7 +404,7 @@ class Foo5204 : IFoo5204 } /*******************************************/ -// 6417 +// https://issues.dlang.org/show_bug.cgi?id=6417 class Bug6417 { @@ -422,7 +438,7 @@ void test6417() } /*******************************************/ -// 6549 +// https://issues.dlang.org/show_bug.cgi?id=6549 class C6549 { @@ -472,7 +488,7 @@ void test6549() } /*******************************************/ -// 7218 +// https://issues.dlang.org/show_bug.cgi?id=7218 void test7218() { @@ -491,7 +507,55 @@ void test7218() } /*******************************************/ -// 7517 +// https://issues.dlang.org/show_bug.cgi?id=7335 + +class A7335 +{ + int mValue = 10; + + void setValue(int newValue) + in { } + out { assert(mValue == 3); } + do + { + mValue = newValue; + } +} + +class B7335 : A7335 +{ + override void setValue(int newValue) + in { assert(false); } + out { assert(mValue == 3); } + do + { + mValue = newValue; + } +} + +class C7335 : A7335 +{ + override void setValue(int newValue) + in { int a = newValue; } + out { assert(mValue == 3); } + do + { + mValue = newValue; + } +} + +void test7335() +{ + A7335 aObject = new B7335(); + aObject.setValue(3); + + A7335 bObject = new C7335(); + bObject.setValue(3); // <<<<< will crash because undefined mValue in the + // A7335.setValue().out-block. +} + +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=7517 void test7517() { @@ -575,7 +639,7 @@ void test7517() } /*******************************************/ -// 7699 +// https://issues.dlang.org/show_bug.cgi?id=7699 class P7699 { @@ -589,7 +653,7 @@ class D7699 : P7699 } /*******************************************/ -// 7883 +// https://issues.dlang.org/show_bug.cgi?id=7883 // Segmentation fault class AA7883 @@ -665,7 +729,7 @@ class DC7883 : CC7883 } /*******************************************/ -// 7892 +// https://issues.dlang.org/show_bug.cgi?id=7892 struct S7892 { @@ -695,7 +759,7 @@ class C7892 } /*******************************************/ -// 8066 +// https://issues.dlang.org/show_bug.cgi?id=8066 struct CLCommandQueue { @@ -709,7 +773,7 @@ struct CLCommandQueue } /*******************************************/ -// 8073 +// https://issues.dlang.org/show_bug.cgi?id=8073 struct Container8073 { @@ -748,7 +812,7 @@ void test8073() } /*******************************************/ -// 8093 +// https://issues.dlang.org/show_bug.cgi?id=8093 void test8093() { @@ -785,7 +849,7 @@ void test8093() } /*******************************************/ -// 9383 +// https://issues.dlang.org/show_bug.cgi?id=9383 class A9383 { @@ -871,7 +935,8 @@ void test9383() } /*******************************************/ -// 15524 - Different from issue 9383 cases, closed variable size is bigger than REGSIZE. +// https://issues.dlang.org/show_bug.cgi?id=15524 +// Different from issue 9383 cases, closed variable size is bigger than REGSIZE. class A15524 { @@ -1004,7 +1069,7 @@ class Test15524b } /*******************************************/ -// 10479 +// https://issues.dlang.org/show_bug.cgi?id=10479 class B10479 { @@ -1018,7 +1083,7 @@ class D10479 : B10479 } /*******************************************/ -// 10596 +// https://issues.dlang.org/show_bug.cgi?id=10596 class Foo10596 { @@ -1028,7 +1093,7 @@ class Foo10596 } /*******************************************/ -// 10721 +// https://issues.dlang.org/show_bug.cgi?id=10721 class Foo10721 { @@ -1049,7 +1114,7 @@ struct Bar10721 } /*******************************************/ -// 10981 +// https://issues.dlang.org/show_bug.cgi?id=10981 class C10981 { @@ -1060,7 +1125,7 @@ class C10981 } /*******************************************/ -// 14779 +// https://issues.dlang.org/show_bug.cgi?id=14779 class C14779 { @@ -1079,6 +1144,79 @@ void test14779() } /*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15984 + +I15984 i15984; +C15984 c15984; + +void check15984(T)(const char* s, T this_, int i) +{ + printf("%s this = %p, i = %d\n", s, this_, i); + static if (is(T == I15984)) assert(this_ is i15984); + else static if (is(T == C15984)) assert(this_ is c15984); + else static assert(0); + assert(i == 5); +} + +interface I15984 +{ + void f1(int i) + in { check15984("I.f1.i", this, i); assert(0); } + out { check15984("I.f1.o", this, i); } + + int[3] f2(int i) + in { check15984("I.f2.i", this, i); assert(0); } + out { check15984("I.f2.o", this, i); } + + void f3(int i) + in { void nested() { check15984("I.f3.i", this, i); } nested(); assert(0); } + out { void nested() { check15984("I.f3.o", this, i); } nested(); } + + void f4(out int i, lazy int j) + in { } + out { } +} + +class C15984 : I15984 +{ + void f1(int i) + in { check15984("C.f1.i", this, i); } + out { check15984("C.f1.o", this, i); } + do { check15984("C.f1 ", this, i); } + + int[3] f2(int i) + in { check15984("C.f2.i", this, i); } + out { check15984("C.f2.o", this, i); } + do { check15984("C.f2 ", this, i); return [0,0,0]; } + + void f3(int i) + in { void nested() { check15984("C.f3.i", this, i); } nested(); } + out { void nested() { check15984("C.f3.o", this, i); } nested(); } + do { check15984("C.f3 ", this, i); } + + void f4(out int i, lazy int j) + in { assert(0); } + do { i = 10; } +} + +void test15984() +{ + c15984 = new C15984; + i15984 = c15984; + printf("i = %p\n", i15984); + printf("c = %p\n", c15984); + printf("====\n"); + i15984.f1(5); + printf("====\n"); + i15984.f2(5); + printf("====\n"); + i15984.f3(5); + int i; + i15984.f4(i, 1); + assert(i == 10); +} + +/*******************************************/ //******************************************/ // DIP 1009 @@ -1170,6 +1308,7 @@ int main() test6417(); test6549(); test7218(); + test7335(); test7517(); test8073(); test8093(); @@ -1177,6 +1316,7 @@ int main() test15524(); test15524a(); test14779(); + test15984(); dip1009_1(1); dip1009_2(1); dip1009_3(1); diff --git a/gcc/testsuite/gdc.test/runnable/testdefault_after_variadic.d b/gcc/testsuite/gdc.test/runnable/testdefault_after_variadic.d new file mode 100644 index 00000000000..f0bade264e1 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testdefault_after_variadic.d @@ -0,0 +1,98 @@ +/* +PERMUTE_ARGS: +*/ + +version (with_phobos) import std.conv : text; + +struct Tuple(T...) +{ + T expand; + alias expand this; +} + +auto tuple(T...)(T t) +{ + return Tuple!T(t); +} + +void fun0(U, T...)(U gold, int b_gold, T a, int b) +{ + assert(tuple(a) == gold); + assert(b == b_gold); +} + +void fun(U, T...)(U gold, T a, int b = 1) +{ + assert(tuple(a) == gold); + assert(b == 1); +} + +void fun2(U, V, T...)(U gold, V gold2, T a, string file = __FILE__, int line = __LINE__) +{ + assert(tuple(a) == gold); + assert(tuple(file, line) == gold2); +} + +void fun3(int[] gold, int[] a...) +{ + assert(gold == a); +} + +void fun4(T...)(size_t length_gold, int b_gold, T a, int b = 1) +{ + assert(T.length == length_gold); + assert(b == b_gold); +} + +// Example in changelog +string log(T...)(T a, string file = __FILE__, int line = __LINE__) +{ + return text(file, ":", line, " ", a); +} + +void fun_constraint(T...)(T a, string b = "bar") if (T.length == 1) +{ +} + +/+ +NOTE: this is disallowed by the parser: +void fun5(int[] gold, int[] a ..., int b = 1) +{ + assert(gold==a); + assert(b==1); +} ++/ + +void main() +{ + fun0(tuple(10), 7, 10, 7); + + fun(tuple()); + fun(tuple(10), 10); + fun(tuple(10, 11), 10, 11); + + fun2(tuple(10), tuple(__FILE__, __LINE__), 10); + + fun3([1, 2, 3], 1, 2, 3); + + fun_constraint(1); + assert(!__traits(compiles, fun_constraint(1, "baz"))); + + version (with_phobos) + assert(log(10, "abc") == text(__FILE__, ":", __LINE__, " 10abc")); + + // IFTI: `b` is always default-set + fun4(0, 1); + fun4(1, 1, 10); + fun4(2, 1, 10, 11); + + // with explicit instantiation, and default-set `b` + fun4!int(1, 1, 10); + fun4!(int, int)(2, 1, 10, 11); + + // with explicit instantiation, and over-ridden `b` + fun4!int(1, 100, 10, 100); + fun4!(int, int)(2, 100, 10, 11, 100); + + // fun5([1,2,3], 1,2,3); +} diff --git a/gcc/testsuite/gdc.test/runnable/testdstress.d b/gcc/testsuite/gdc.test/runnable/testdstress.d index a416b8a8c85..6ca5500bfb3 100644 --- a/gcc/testsuite/gdc.test/runnable/testdstress.d +++ b/gcc/testsuite/gdc.test/runnable/testdstress.d @@ -1,5 +1,10 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: +/* +TEST_OUTPUT: +--- +runnable/testdstress.d(666): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead. +--- +*/ module run.module_01; @@ -8,6 +13,7 @@ import core.exception; import core.vararg; extern(C) void* malloc(size_t size); +extern(C) int printf(const char*, ...); /* ================================ */ @@ -23,7 +29,7 @@ void test1() assert(1); }out (result){ assert(result.i==1); - }body{ + }do{ MyStruct s; s.i = 1; return s; @@ -37,7 +43,7 @@ void foo2() in{ assert(0); } -body{ +do{ } void test2() @@ -452,7 +458,7 @@ void test21() /* ================================ */ -scope class AutoClass{ +class AutoClass{ } void test22() @@ -467,7 +473,7 @@ void test22() int status23; -scope class C23{ +class C23{ ~this(){ assert(status23==0); status23--; @@ -493,7 +499,7 @@ void test23() int status24; -scope class C24{ +class C24{ this(){ assert(status24==0); status24+=2; @@ -525,7 +531,7 @@ void test24() /* ================================ */ struct S25{ - S25 opSub(int i) { S25 s; return s; } + S25 opBinary(string op)(int i) if (op == "-") { S25 s; return s; } } struct GeomObject{ @@ -539,7 +545,7 @@ void extractTriangles(GeomObject g) void foobar() { g.mesh - g.xlate; - //g.mesh.opSub(g.xlate); + //g.mesh.opBinary!("-")(g.xlate); } foobar(); @@ -672,7 +678,7 @@ void test30() void test31() { - string str = x"F0 9D 83 93"; // utf-8 for U+1D0D3 + string str = "\xF0\x9D\x83\x93"; // utf-8 for U+1D0D3 int count=0; dchar tmp; @@ -686,8 +692,6 @@ void test31() /* ================================ */ -import std.stdio; - union MyUnion32 { int i; @@ -698,31 +702,12 @@ void test32() { TypeInfo ti = typeid(MyUnion32*); assert(!(ti is null)); - writefln("%s %d %d", ti.toString(), ti.tsize, (MyUnion32*).sizeof); assert(ti.tsize==(MyUnion32*).sizeof); assert(ti.toString()=="run.module_01.MyUnion32*"); } /* ================================ */ -void test33() -{ - creal a=1.3L+9.7Li; - assert(a.re == 1.3L); - assert(a.im == 9.7L); -} - -/* ================================ */ - -void test34() -{ - creal c = 2.7L + 0i; - assert(c.re==2.7L); - assert(c.im==0.0L); -} - -/* ================================ */ - void test35() { try{ @@ -845,15 +830,8 @@ int counter41; class C41{ this(){ printf("this: counter41 = %d\n", counter41); - assert(counter41==1); - counter41+=2; - } - - new(size_t size){ - printf("new: size = %d\n", size); assert(counter41==0); - counter41++; - return malloc(size); + counter41+=2; } } @@ -862,7 +840,7 @@ void test41() C41 c; assert(counter41==0); c = new C41(); - assert(counter41==3); + assert(counter41==2); } /* ================================ */ @@ -917,8 +895,6 @@ int main() test30(); test31(); test32(); - test33(); - test34(); test35(); test36(); test37(); diff --git a/gcc/testsuite/gdc.test/runnable/testdt.d b/gcc/testsuite/gdc.test/runnable/testdt.d index 8224abc1356..4b5338fec5a 100644 --- a/gcc/testsuite/gdc.test/runnable/testdt.d +++ b/gcc/testsuite/gdc.test/runnable/testdt.d @@ -2,7 +2,7 @@ /******************************************/ -static int bigarray[100][100]; +static int[100][100] bigarray; void test1() { @@ -17,7 +17,7 @@ void test1() } /******************************************/ -// 10629 +// https://issues.dlang.org/show_bug.cgi?id=10629 class Foo10629 {} @@ -27,7 +27,7 @@ struct Bar10629 } /******************************************/ -// 11233 +// https://issues.dlang.org/show_bug.cgi?id=11233 struct S11233 { @@ -35,7 +35,7 @@ struct S11233 } /******************************************/ -// 11672 +// https://issues.dlang.org/show_bug.cgi?id=11672 void test11672() { @@ -50,7 +50,7 @@ void test11672() } /******************************************/ -// 12509 +// https://issues.dlang.org/show_bug.cgi?id=12509 struct A12509 { @@ -62,7 +62,7 @@ struct B12509 } /******************************************/ -// 13505 +// https://issues.dlang.org/show_bug.cgi?id=13505 class C13505 { void[10] x; } struct S13505 { void[10] x; } @@ -74,7 +74,7 @@ void test13505() } /******************************************/ -// 14699 +// https://issues.dlang.org/show_bug.cgi?id=14699 struct S14699a { ubyte[0][10] values; } struct S14699b { S14699a tbl; } @@ -88,7 +88,7 @@ void test14699() } /******************************************/ -// 14805 +// https://issues.dlang.org/show_bug.cgi?id=14805 struct S14805 { @@ -97,7 +97,7 @@ struct S14805 auto a14805 = new S14805[513*513]; /******************************************/ -// 15664 +// https://issues.dlang.org/show_bug.cgi?id=15664 struct Data15664A { diff --git a/gcc/testsuite/gdc.test/runnable/testenum.d b/gcc/testsuite/gdc.test/runnable/testenum.d index 05327449209..a7529510e9b 100644 --- a/gcc/testsuite/gdc.test/runnable/testenum.d +++ b/gcc/testsuite/gdc.test/runnable/testenum.d @@ -109,7 +109,7 @@ void test6() } /**********************************************/ -// 2407 +// https://issues.dlang.org/show_bug.cgi?id=2407 int i2407; @@ -223,7 +223,7 @@ void test2407() } /**********************************************/ -// 3096 +// https://issues.dlang.org/show_bug.cgi?id=3096 void test3096() { @@ -252,30 +252,30 @@ void test3096() } /**********************************************/ -// 7719 +// https://issues.dlang.org/show_bug.cgi?id=7719 enum foo7719 = bar7719; enum { bar7719 = 1 } /**********************************************/ -// 9845 +// https://issues.dlang.org/show_bug.cgi?id=9845 enum { A9845 = B9845 } enum { B9845 = 1 } /**********************************************/ -// 9846 +// https://issues.dlang.org/show_bug.cgi?id=9846 const int A9846 = B9846; enum { B9846 = 1 } /**********************************************/ -// 10105 +// https://issues.dlang.org/show_bug.cgi?id=10105 enum E10105 : char[1] { a = "a" } /**********************************************/ -// 10113 +// https://issues.dlang.org/show_bug.cgi?id=10113 enum E10113 : string { @@ -299,7 +299,7 @@ void test10113() } /**********************************************/ -// 10503 +// https://issues.dlang.org/show_bug.cgi?id=10503 @property int octal10503(string num)() { @@ -313,7 +313,7 @@ enum } /**********************************************/ -// 10505 +// https://issues.dlang.org/show_bug.cgi?id=10505 enum { @@ -331,7 +331,7 @@ static assert(is(typeof(d10505) == int)); static assert(is(typeof(e10505) == typeof(null))); /**********************************************/ -// 10561 +// https://issues.dlang.org/show_bug.cgi?id=10561 void test10561() { @@ -367,7 +367,7 @@ void test10561() } /**********************************************/ -// 10612 +// https://issues.dlang.org/show_bug.cgi?id=10612 int[E10612] ie10612; E10612[int] ei10612; @@ -376,7 +376,7 @@ E10612[E10612] ee10612; enum E10612 { a } /**********************************************/ -// 10788 +// https://issues.dlang.org/show_bug.cgi?id=10788 enum v10788 = e10788; enum : int { e10788 } @@ -417,7 +417,7 @@ void test8() } /**********************************************/ -// 13220 +// https://issues.dlang.org/show_bug.cgi?id=13220 enum E13220a; @(1) enum E13220b; diff --git a/gcc/testsuite/gdc.test/runnable/testfile.d b/gcc/testsuite/gdc.test/runnable/testfile.d deleted file mode 100644 index 6f568044ea4..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testfile.d +++ /dev/null @@ -1,25 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: - -import std.file; -import std.stdio; - -/***********************************************/ - -void test1() -{ - auto p = std.file.getcwd(); - - writefln("%s '%s'\n", p.length, p); - assert(p[$ - 1] != 0); -} - -/***********************************************/ - -int main() -{ - test1(); - - printf("Success\n"); - return 0; -} diff --git a/gcc/testsuite/gdc.test/runnable/testfloat.d b/gcc/testsuite/gdc.test/runnable/testfloat.d new file mode 100644 index 00000000000..e9fe3970550 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testfloat.d @@ -0,0 +1,239 @@ +/* PERMUTE_ARGS: -O + * Test floating point code generation + */ + +import core.stdc.stdio; +import core.stdc.stdlib; + +double value_1() { + return 1; +} + +double value_2() { + return 2; +} + +/***************************************/ + +void testcse1(T)() // common subexpressions +{ + T a = value_1(); + T b = value_2(); + T x = a*a + a*a + a*a + a*a + a*a + a*a + a*a + + a*b + a*b; + printf("%g\n", cast(double)x); // destroy scratch reg contents + T y = a*a + a*a + a*a + a*a + a*a + a*a + a*a + + a*b + a*b; + assert(x == 11); + assert(x == y); +} + +void test240() +{ + testcse1!float(); + testcse1!double(); + testcse1!real(); +} + +/***************************************/ + +void testcse2(T)() // common subexpressions +{ + T a = value_1(); + T b = value_2(); + T x = a*a + a*a + a*a + a*a + a*a + a*a + a*a + + a*b + a*b + 1; + printf("%g\n", cast(double)x); // destroy scratch reg contents + int i = (a*a + a*a + a*a + a*a + a*a + a*a + a*a + a*b + a*b) != 0; + assert(i); + assert(x == 12); +} + +void test241() +{ + testcse2!float(); + testcse2!double(); + testcse2!real(); +} + +/***************************************/ + +void test1(float f) +{ + real r = f; + double d = f; +} + +void test2(long l) +{ + real r = l; + double d = l; +} + +void test3(float f) +{ + real r = f * f; + double d = f * f; +} + +void test3(long l) +{ + real r = l * l; + double d = l * l; +} + +/***************************************/ + +double foo4(int i, double d) +{ + return ((i << 1) - d) + ((i << 1) - d); +} + +void test4() +{ + double d = foo4(3, 4); + assert(d == 4); +} + +/***************************************/ + +import core.math; // trigger use of sqrt intrinsic + +void test5x(double p) +{ + bool b = p >= 0; + double mean = (1 - p) / p; + double skew = sqrt(1 - p); +} + +void test5() +{ + test5x(2); +} + +/***************************************/ + +import core.math; // trigger use of sqrt intrinsic + +void dstatsEnforce(bool, string) { } + +ulong invNegBinomCDF(double pVal, ulong n, double p) +{ + dstatsEnforce(p >= 0 && p <= 1, + "p must be between 0, 1 for negative binomial distribution."); + dstatsEnforce(pVal >= 0 && pVal <= 1, + "P-values must be between 0, 1."); + + // Normal or gamma approx, then adjust. + double mean = n * (1 - p) / p; + double var = n * (1 - p) / (p * p); + double skew = (2 - p) / sqrt(n * (1 - p)); + double kk = 4.0L / (skew * skew); + double theta = sqrt(var / kk); + double offset = (kk * theta) - mean + 0.5L; + ulong guess; + return 0; +} + +void test6() +{ + invNegBinomCDF(2.0, 3, 4.0); +} + +/***************************************/ + +float expDigamma(F)(in F x) +{ + return x; +} + +float nextDown(float f) { return f; } + +void test7() +{ + foreach (i; 1 .. 2) + { + assert(expDigamma(float(i)) >= expDigamma(float(i).nextDown)); + } +} + +/***************************************/ + +void foo8_1(double x) +{ + printf("x = %g\n", x); + assert(x == 0); +} + +void foo8_2(double x) +{ + printf("x = %g\n", x); + assert(x != 0); +} + +void test8() +{ + foo8_1(0.0); + foo8_2(1.0); +} + +/***************************************/ + +void test9() +{ + double a = 9; + double b = 3; + double c = a * b + 1; + double d = a + b + 1; + printf("%g %g\n", c, d); // clobber XMM registers + assert(c == 28 && d == 13); + double e = a * b - 1; + double f = a + b - 1; // reload 2 CSEs + printf("%g %g\n", e, f); + assert(e == 26 && f == 11); +} + +/***************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20349 + +double f20349(double a, int b) +{ + import core.math; + return core.math.sqrt(-a / b) / b; +} + +void test20349() +{ + assert(f20349(-9, 1) == 3); +} + +/****************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20963 + +void test20963() +{ + ulong v = 0xE3251BACB112CB8B; + double d = cast(double)v; + printf("%a\n", d); //0x1.c64a37596225ap+63 + assert(d == 0x1.c64a375962259p+63); +} + +/***************************************/ + + +int main() +{ + test240(); + test241(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test20349(); + test20963(); + + printf("Success\n"); + return EXIT_SUCCESS; +} diff --git a/gcc/testsuite/gdc.test/runnable/testformat.d b/gcc/testsuite/gdc.test/runnable/testformat.d deleted file mode 100644 index 74f4095c009..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testformat.d +++ /dev/null @@ -1,126 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: - -import std.stdio; -import std.string; - -/*************************************************************/ - -void test1() -{ - double x = 1e6; - float f; - double d; - real r; - - while (x > 1e-5) - { double y = x / 101.0; - - std.stdio.writef("x = %g\t%f\t%e\n",x/101.0,x/101.0,x/101.0); - x /= 10.0; - } - - double a = 123456789.0; - for (int i = 20; i--; a /= 10) - std.stdio.writef("%20.6g|%20.6e|%20.6f\n",a,a,a); - - std.stdio.writef("%e %e %e %e\n",float.nan,double.nan,real.nan,double.infinity); - std.stdio.writef("%e %e %e\n",-float.nan,-double.nan,-double.infinity); - std.stdio.writef("%-5E %5E %E\n",float.nan,double.nan,double.infinity); - - std.stdio.writef("%f %f %f\n",float.nan,double.nan,double.infinity); - std.stdio.writef("%f %f %f\n",-float.nan,-double.nan,-double.infinity); - std.stdio.writef("%+F %+ F %F\n",float.nan,double.nan,double.infinity); - - std.stdio.writef("%g %g %g\n",float.nan,double.nan,double.infinity); - std.stdio.writef("%g %g %g\n",-float.nan,-double.nan,-double.infinity); - std.stdio.writef("% G %G %G\n",float.nan,double.nan,double.infinity); - - r = 0x1.AAp+3L; - std.stdio.writef(" r = %g\n", r); - std.stdio.writef(" r = %a\n", r); - std.stdio.writef(" r = %A\n", r); - - d = 0x1.AAp+3; - std.stdio.writef(" d = %.5a\n", d); - std.stdio.writef(" d = %A\n", d); - - f = 0x1.AAp+3f; - std.stdio.writef(" f = %a\n", f); - std.stdio.writef(" f = %A\n", f); - - f = 0x1.FFp+3f; - std.stdio.writef(" f = %.1a\n", f); - std.stdio.writef(" f = %A\n", f); - - r = 0; - std.stdio.writef(" r = %a\n", r); - std.stdio.writef(" r = %A\n", r); - - std.stdio.writef("%e\n", 1e+300); - std.stdio.writef("%.0f\n%.307f\n", 1e+300, 1e-300); - std.stdio.writef("%.0A\n%.307A\n", 1e+300, 1e-300); -} - -/*************************************************************/ - -void test2() -{ - writefln("%o", 9); - assert(std.string.format("%o", 9) == "11"); - assert(std.string.format("%o", 10) == "12"); - assert(std.string.format("%b", 9) == "1001"); - assert(std.string.format("%b", 10) == "1010"); -} - - -/*************************************************************/ - -void test3() -{ - Object e = new Exception("hello"); - writeln(e.toString()); - //assert(e.toString() == "object.Exception: hello"); - //assert(format(e) == "object.Exception: hello"); - - alias char[] xstring; - assert(format(cast(xstring)"world") == "world"); -} - -/*************************************************************/ - -void test4() -{ - const char[][] x = ["%s","123"]; - writeln(x); - assert(std.string.format("%s", x) == `["%s", "123"]`); -} - -/*************************************************************/ - -void test5() -{ - int[int] foo; - - foo[1] = 2; - foo[7] = 28; - - writefln("%s", foo); - - void[0] v; - assert(format("%s", v) == "[]"); -} - -/*************************************************************/ - -int main() -{ - test1(); - test2(); - test3(); - test4(); - test5(); - - std.stdio.writefln("Success"); - return 0; -} diff --git a/gcc/testsuite/gdc.test/runnable/testgc2.d b/gcc/testsuite/gdc.test/runnable/testgc2.d index 0d7ab8c4e3e..f107f1cc4c1 100644 --- a/gcc/testsuite/gdc.test/runnable/testgc2.d +++ b/gcc/testsuite/gdc.test/runnable/testgc2.d @@ -1,4 +1,10 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +Success +--- +*/ module testgc2; @@ -7,30 +13,34 @@ import core.exception : OutOfMemoryError; /*******************************************/ +__gshared ulong counter; + void test1() { - printf("This should not take a while\n"); try { long[] l = new long[ptrdiff_t.max]; - printf("%lu\n", cast(ulong)l.capacity); // Make sure l is not optimized out. + counter += l.capacity; // Make sure l is not optimized out. assert(0); } catch (OutOfMemoryError o) { } - printf("This may take a while\n"); + assert(counter == 0); + try { byte[] b = new byte[size_t.max / 3]; - printf("%lu\n", cast(ulong)b.capacity); // Make sure b is not optimized out. + counter += b.capacity; // Make sure b is not optimized out. version (Windows) assert(0); } catch (OutOfMemoryError o) { } + + assert(counter >= 0); } /*******************************************/ @@ -41,5 +51,3 @@ void main() printf("Success\n"); } - - diff --git a/gcc/testsuite/gdc.test/runnable/testgc3.d b/gcc/testsuite/gdc.test/runnable/testgc3.d index 88232fefe36..300888fc5cd 100644 --- a/gcc/testsuite/gdc.test/runnable/testgc3.d +++ b/gcc/testsuite/gdc.test/runnable/testgc3.d @@ -1,5 +1,11 @@ -// PERMUTE_ARGS: -// REQUIRED_ARGS: +/* +PERMUTE_ARGS: +REQUIRED_ARGS: +RUN_OUTPUT: +--- +finished +--- +*/ import core.stdc.stdio; @@ -21,4 +27,3 @@ void main() printf("finished\n"); aa[] = null; } - diff --git a/gcc/testsuite/gdc.test/runnable/testinvariant.d b/gcc/testsuite/gdc.test/runnable/testinvariant.d index 93d66efd21a..d3b3b6ffa16 100644 --- a/gcc/testsuite/gdc.test/runnable/testinvariant.d +++ b/gcc/testsuite/gdc.test/runnable/testinvariant.d @@ -17,7 +17,7 @@ int testinvariant() printf("hello\n"); Foo f = new Foo(); printf("f = %p\n", f); - printf("f.sizeof = x%x\n", Foo.sizeof); + printf("f.sizeof = x%zx\n", Foo.sizeof); printf("f.classinfo = %p\n", f.classinfo); printf("f.classinfo._invariant = %p\n", f.classinfo.base); f.test(); @@ -26,7 +26,7 @@ int testinvariant() } /***************************************************/ -// 6453 +// https://issues.dlang.org/show_bug.cgi?id=6453 void test6453() { @@ -107,7 +107,7 @@ void test6453() } /***************************************************/ -// 13113 +// https://issues.dlang.org/show_bug.cgi?id=13113 struct S13113 { @@ -140,7 +140,7 @@ void test13113() } /***************************************************/ -// 13147 +// https://issues.dlang.org/show_bug.cgi?id=13147 version (D_InlineAsm_X86) enum x86iasm = true; diff --git a/gcc/testsuite/gdc.test/runnable/testkeyword.d b/gcc/testsuite/gdc.test/runnable/testkeyword.d index 79f2c29b24b..5fb4d442038 100644 --- a/gcc/testsuite/gdc.test/runnable/testkeyword.d +++ b/gcc/testsuite/gdc.test/runnable/testkeyword.d @@ -97,8 +97,8 @@ void main(string[] args) nothrow auto funcLiteral = (int x, int y) { - enum thisFunc = "testkeyword.main.__lambda3"; - enum thisFunc2 = "testkeyword.main.__lambda3(int x, int y)"; + enum thisFunc = "testkeyword.main.__lambda5"; + enum thisFunc2 = "testkeyword.main.__lambda5(int x, int y)"; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 104); diff --git a/gcc/testsuite/gdc.test/runnable/testline.d b/gcc/testsuite/gdc.test/runnable/testline.d index 5b84204b785..cbf536ce62f 100644 --- a/gcc/testsuite/gdc.test/runnable/testline.d +++ b/gcc/testsuite/gdc.test/runnable/testline.d @@ -1,4 +1,3 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: // $HeadURL$ @@ -7,7 +6,6 @@ module dstress.run.line_token_03; -import std.stdio; import core.exception; int main(){ @@ -22,8 +20,6 @@ int main(){ assert(0); } -import std.stdio; - /* * @WARNING@: this code depends on the phobos implementation. * char[]s returned by wrong assertions have to look like: @@ -39,6 +35,5 @@ void checkFileSpec(Object o){ } } -writeln(str); assert(str[start .. start+3]=="(1)"); } diff --git a/gcc/testsuite/gdc.test/runnable/testmain.d b/gcc/testsuite/gdc.test/runnable/testmain.d index 4619bde2901..d615e1026f7 100644 --- a/gcc/testsuite/gdc.test/runnable/testmain.d +++ b/gcc/testsuite/gdc.test/runnable/testmain.d @@ -1,5 +1,6 @@ // REQUIRED_ARGS: -main +// PERMUTE_ARGS: -betterC void foo() { } diff --git a/gcc/testsuite/gdc.test/runnable/testminit.d b/gcc/testsuite/gdc.test/runnable/testminit.d index 52c99bbf28f..92c2d3a74a7 100644 --- a/gcc/testsuite/gdc.test/runnable/testminit.d +++ b/gcc/testsuite/gdc.test/runnable/testminit.d @@ -1,5 +1,14 @@ -// EXTRA_SOURCES: imports/testminitAA.d imports/testminitBB.d -// PERMUTE_ARGS: +/* +EXTRA_SOURCES: imports/testminitAA.d imports/testminitBB.d +PERMUTE_ARGS: +RUN_OUTPUT: +--- +AA +BB +hello +Success +--- +*/ import core.stdc.stdio; diff --git a/gcc/testsuite/gdc.test/runnable/testmmfile.d b/gcc/testsuite/gdc.test/runnable/testmmfile.d deleted file mode 100644 index 6a9d6e9094a..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testmmfile.d +++ /dev/null @@ -1,120 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: -// REQUIRED_ARGS: - -import std.file; -import std.mmfile; - -int main() -{ - static string name = "test.tmp"; - static string s = "abcd"; - - write(name, s); - - { scope MmFile mmf = new MmFile(name); - string p; - - assert(mmf[0] == 'a'); - p = cast(string)mmf[]; - //printf("p.length = %d\n", p.length); - assert(p[1] == 'b'); - p = cast(string)mmf[0 .. 4]; - assert(p[2] == 'c'); - } - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.read, 0, null); - string p; - - assert(mmf[0] == 'a'); - p = cast(string)mmf[]; - //printf("p.length = %d\n", p.length); - assert(mmf.length == 4); - assert(p[1] == 'b'); - p = cast(string)mmf[0 .. 4]; - assert(p[2] == 'c'); - } - - remove(name); - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWriteNew, 4, null); - char[] p; - - p = cast(char[])mmf[]; - p[] = "1234"; - mmf[3] = '5'; - assert(mmf[2] == '3'); - assert(mmf[3] == '5'); - } - - { string p = cast(string)read(name); - - assert(p[] == "1235"); - } - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWriteNew, 4, null); - char[] p; - - p = cast(char[])mmf[]; - p[] = "5678"; - mmf[3] = '5'; - assert(mmf[2] == '7'); - assert(mmf[3] == '5'); - assert(cast(string)mmf[] == "5675"); - } - - { string p = cast(string)read(name); - - assert(p[] == "5675"); - } - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWrite, 4, null); - char[] p; - - p = cast(char[])mmf[]; - assert(cast(char[])mmf[] == "5675"); - p[] = "9102"; - mmf[2] = '5'; - assert(cast(string)mmf[] == "9152"); - } - - { string p = cast(string)read(name); - - assert(p[] == "9152"); - } - - remove(name); - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWrite, 4, null); - char[] p; - - p = cast(char[])mmf[]; - p[] = "abcd"; - mmf[2] = '5'; - assert(cast(string)mmf[] == "ab5d"); - } - - { string p = cast(string)read(name); - - assert(p[] == "ab5d"); - } - - { scope MmFile mmf = new MmFile(name, MmFile.Mode.readCopyOnWrite, 4, null); - char[] p; - - p = cast(char[])mmf[]; - assert(cast(string)mmf[] == "ab5d"); - p[] = "9102"; - mmf[2] = '5'; - assert(cast(string)mmf[] == "9152"); - } - - { string p = cast(string)read(name); - - assert(p[] == "ab5d"); - } - - remove(name); - - return 0; -} diff --git a/gcc/testsuite/gdc.test/runnable/testmod2.d b/gcc/testsuite/gdc.test/runnable/testmod2.d index c03a8c790c5..111696aa623 100644 --- a/gcc/testsuite/gdc.test/runnable/testmod2.d +++ b/gcc/testsuite/gdc.test/runnable/testmod2.d @@ -1,7 +1,7 @@ // EXTRA_SOURCES: imports/testmod2a.d /**********************************/ -// bug 1904 +// https://issues.dlang.org/show_bug.cgi?id=1904 import imports.testmod2a; void main() diff --git a/gcc/testsuite/gdc.test/runnable/testpic.d b/gcc/testsuite/gdc.test/runnable/testpic.d index 60f67756a86..ef3ab8667fc 100644 --- a/gcc/testsuite/gdc.test/runnable/testpic.d +++ b/gcc/testsuite/gdc.test/runnable/testpic.d @@ -1,4 +1,5 @@ -// PERMUTE_ARGS: -fPIC -O +// PERMUTE_ARGS: -fPIC -O -fPIE +// DISABLED: win32 win64 extern (C) int printf(const char*, ...); @@ -44,10 +45,26 @@ void test17034() /***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20441 + +const(char)* moo(const (char) *s) +{ + return s; +} + +void test20441() +{ + const(char) *x = "abc".ptr; + assert( moo(x) - x == 0 ); +} + +/***************************************************/ + int main() { test11310(); test17034(); + test20441(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/testptrref.d b/gcc/testsuite/gdc.test/runnable/testptrref.d index 5bcf444c739..c616d57888e 100644 --- a/gcc/testsuite/gdc.test/runnable/testptrref.d +++ b/gcc/testsuite/gdc.test/runnable/testptrref.d @@ -7,15 +7,11 @@ version(CRuntime_Microsoft) extern __gshared uint _DP_end; extern __gshared uint _TP_beg; extern __gshared uint _TP_end; - extern int _tls_start; - extern int _tls_end; } alias _DPbegin = _DP_beg; alias _DPend = _DP_end; alias _TPbegin = _TP_beg; alias _TPend = _TP_end; - alias _tlsstart = _tls_start; - alias _tlsend = _tls_end; __gshared void[] dataSection; shared static this() @@ -26,6 +22,15 @@ version(CRuntime_Microsoft) dataSection = findImageSection(".data"); } + void[] tlsRange; + static this() + { + import core.internal.traits : externDFunc; + alias initTLSRanges = externDFunc!("rt.sections_win64.initTLSRanges", + void[] function() nothrow @nogc); + tlsRange = initTLSRanges(); + } + version = ptrref_supported; } else version(Win32) @@ -39,6 +44,13 @@ else version(Win32) extern int _tlsstart; extern int _tlsend; } + + void[] tlsRange; + static this() + { + tlsRange = (cast(void*)&_tlsstart)[0.. cast(void*)&_tlsend - cast(void*)&_tlsstart]; + } + version = ptrref_supported; } @@ -91,13 +103,13 @@ void main() version(ptrref_supported): bool findTlsPtr(const(void)* ptr) -{ +{ debug(PRINT) printf("findTlsPtr %p\n", ptr); for (uint* p = &_TPbegin; p < &_TPend; p++) { - void* addr = cast(void*) &_tlsstart + *p; + void* addr = tlsRange.ptr + *p; debug(PRINT) printf(" try %p\n", addr); - assert(addr < &_tlsend); + assert(*p < tlsRange.length); if (addr == ptr) return true; } @@ -126,6 +138,9 @@ void testRefPtr() debug(PRINT) printf("&_DPbegin %p\n", &_DPbegin); debug(PRINT) printf("&_DPend %p\n", &_DPend); + debug(PRINT) printf("&_TPbegin %p\n", &_TPbegin); + debug(PRINT) printf("&_TPend %p\n", &_TPend); + assert(!findDataPtr(cast(void*)&sharedInt)); assert(!findTlsPtr(&tlsInt)); diff --git a/gcc/testsuite/gdc.test/runnable/testptrref_gc.d b/gcc/testsuite/gdc.test/runnable/testptrref_gc.d new file mode 100644 index 00000000000..3bd6bf5412b --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/testptrref_gc.d @@ -0,0 +1,3 @@ +// REQUIRED_ARGS: -lowmem -Jrunnable +// EXTRA_FILES: testptrref.d +mixin(import("testptrref.d")); diff --git a/gcc/testsuite/gdc.test/runnable/testreturn.d b/gcc/testsuite/gdc.test/runnable/testreturn.d index fcebf79f769..42b93ba1ca8 100644 --- a/gcc/testsuite/gdc.test/runnable/testreturn.d +++ b/gcc/testsuite/gdc.test/runnable/testreturn.d @@ -1,9 +1,15 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); alias TypeTuple(T...) = T; /***************************************************/ -// 13336 +// https://issues.dlang.org/show_bug.cgi?id=13336 struct S13336 { @@ -96,7 +102,7 @@ out(r) assert(r == (f ? sx : sy)); result13336 = r; } -body +do { mixin(fbody13336); } @@ -109,7 +115,7 @@ out(r) assert(r == (f ? sx : sy)); result13336 = r; } -body +do { mixin(fbody13336); } @@ -150,7 +156,7 @@ void test13336() } /***************************************************/ -// 15018 +// https://issues.dlang.org/show_bug.cgi?id=15018 struct S15018(int n) { diff --git a/gcc/testsuite/gdc.test/runnable/testrightthis.d b/gcc/testsuite/gdc.test/runnable/testrightthis.d index 32879ce3e4c..e5d7ba3aec3 100644 --- a/gcc/testsuite/gdc.test/runnable/testrightthis.d +++ b/gcc/testsuite/gdc.test/runnable/testrightthis.d @@ -474,7 +474,7 @@ void test7() } /********************************************************/ -// 4350 +// https://issues.dlang.org/show_bug.cgi?id=4350 template Mix4350() { int b; } @@ -509,7 +509,7 @@ void test4350() } /********************************************************/ -// 6430 +// https://issues.dlang.org/show_bug.cgi?id=6430 auto bug6430(int a) { @@ -528,7 +528,7 @@ auto bug6430(int a, int b) } /********************************************************/ -// 9619 +// https://issues.dlang.org/show_bug.cgi?id=9619 struct Foo9619 { int x; } void test9619() @@ -540,7 +540,7 @@ void test9619() } /********************************************************/ -// 9633 +// https://issues.dlang.org/show_bug.cgi?id=9633 class Foo9633 { @@ -573,7 +573,7 @@ void test9633() } /********************************************************/ -// 11245 +// https://issues.dlang.org/show_bug.cgi?id=11245 struct Vec11245 { @@ -589,7 +589,7 @@ class Bar11245 } /********************************************************/ -// 11614 +// https://issues.dlang.org/show_bug.cgi?id=11614 struct Tuple11614(T...) { @@ -613,7 +613,7 @@ struct Foo11614 } /********************************************************/ -// 11993 +// https://issues.dlang.org/show_bug.cgi?id=11993 struct S11993 { @@ -634,7 +634,7 @@ void test11993() } /********************************************************/ -// 15934 +// https://issues.dlang.org/show_bug.cgi?id=15934 class B15934 { diff --git a/gcc/testsuite/gdc.test/runnable/testsafe.d b/gcc/testsuite/gdc.test/runnable/testsafe.d index cec4c0f7fa4..40496f5b24e 100644 --- a/gcc/testsuite/gdc.test/runnable/testsafe.d +++ b/gcc/testsuite/gdc.test/runnable/testsafe.d @@ -137,7 +137,7 @@ struct uD } @safe -void safeunions() // improved for issue 11510 +void safeunions() // improved for https://issues.dlang.org/show_bug.cgi?id=11510 { SafeUnion1 su1; SafeUnion2 su2; @@ -197,11 +197,6 @@ void safeexception() try {} catch(Throwable e) {} })); - - static assert(!__traits(compiles, () @safe { - try {} - catch {} - })); } @safe @@ -415,7 +410,7 @@ void classcast() } /***************************************************/ -// 6278 +// https://issues.dlang.org/show_bug.cgi?id=6278 @safe { @@ -423,18 +418,18 @@ void classcast() class A6278 { int test() in { assert(0); } - body { return 1; } + do { return 1; } } class B6278 : A6278 { override int test() in { assert(0); } - body { return 1; } + do { return 1; } } } /***************************************************/ -// 7803 +// https://issues.dlang.org/show_bug.cgi?id=7803 @safe int f7803() { scope(success) {/* ... */} @@ -447,13 +442,13 @@ nothrow int g7803() { } /***************************************************/ -// 6405 +// https://issues.dlang.org/show_bug.cgi?id=6405 void foo6405(int[][] args...) @trusted { } void test6405() @safe { foo6405([1,2,3], [1,2,3]); } /***************************************************/ -// 12502 +// https://issues.dlang.org/show_bug.cgi?id=12502 void test12502() @safe { @@ -495,4 +490,3 @@ void main() { test14162(); } - diff --git a/gcc/testsuite/gdc.test/runnable/testscope.d b/gcc/testsuite/gdc.test/runnable/testscope.d index ca5c4c92280..32d66b58c76 100644 --- a/gcc/testsuite/gdc.test/runnable/testscope.d +++ b/gcc/testsuite/gdc.test/runnable/testscope.d @@ -1,5 +1,5 @@ // PERMUTE_ARGS: -// REQUIRED_ARGS: -d -dip1000 +// REQUIRED_ARGS: -d -preview=dip1000 extern(C) int printf(const char*, ...); @@ -293,8 +293,6 @@ void test11() static int* p; static int i; bar11(p, &i); - - bar11((i,p), &i); // comma expressions are deprecated, but need to test them } /********************************************/ @@ -302,7 +300,7 @@ void test11() int test17432(scope int delegate() dg) { - return dg(); + return dg(); } // stripped down version of std.traits.Parameters @@ -342,6 +340,53 @@ template test14(T) test14!(char[] function(return char[])) x14; /********************************************/ +// https://issues.dlang.org/show_bug.cgi?id=17935 + +struct ByChunk(IO) +{ +@safe: + ~this() scope + {} + + ubyte[] buf; + IO io; +} + +struct IO +{ + ~this() @safe @nogc scope + {} +} + +@safe @nogc void test17395() +{ + ubyte[256] buf; + auto chunks = ByChunk!IO(buf[], IO()); + chunks.__xdtor(); // auto-generated inclusive (fields and struct) dtor +} + +/********************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20569 + +void test20569() @safe +{ + static struct S + { + int value; + int* pointer; + } + + /* explicit `scope`: */ + scope S s1; + scope int* p1 = &s1.value; + + /* inferred `scope`: */ + int x; + S s2 = S(0, &x); + int* p2 = &s2.value; +} + +/********************************************/ void main() { @@ -359,6 +404,8 @@ void main() test7049(); test16747(); test11(); + test17395(); + test20569(); printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable/testscope2.d b/gcc/testsuite/gdc.test/runnable/testscope2.d index 85282c2aae8..1b8cf296d3b 100644 --- a/gcc/testsuite/gdc.test/runnable/testscope2.d +++ b/gcc/testsuite/gdc.test/runnable/testscope2.d @@ -1,5 +1,4 @@ -// RUNNABLE_PHOBOS_TEST -// REQUIRED_ARGS: -dip25 +// REQUIRED_ARGS: /* TEST_OUTPUT: --- @@ -30,7 +29,7 @@ pragma(msg, "foo4 ", typeof(&SS.foo4)); void test3() { - version (all) + version (none) { import std.stdio; writeln(SS.foo1.mangleof); @@ -52,7 +51,7 @@ void test3() assert(SS.foo4.mangleof == "_D10testscope22SS4foo4MFNcNkKNgPiZi"); // Test scope pretty-printing - assert(typeof(SS.foo1).stringof == "ref return ulong(return ref int* delegate() return p)"); + assert(typeof(SS.foo1).stringof == "ref ulong(return ref int* delegate() return p) return"); assert(typeof(SS.foo2).stringof == "ref int(return ref int delegate() p)"); assert(typeof(SS.foo3).stringof == "ref int(return ref inout(int*) p)"); assert(typeof(SS.foo4).stringof == "ref int(return ref inout(int*) p)"); @@ -255,4 +254,3 @@ void main() test11(); printf("Success\n"); } - diff --git a/gcc/testsuite/gdc.test/runnable/testsignals.d b/gcc/testsuite/gdc.test/runnable/testsignals.d deleted file mode 100644 index c2fbcee45cb..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testsignals.d +++ /dev/null @@ -1,114 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -import std.stdio; -import std.signals; - -class Observer -{ // our slot - void watch(string msg, int i) - { - writefln("Observed msg '%s' and value %s", msg, i); - } - - void watch2(int i, int j) - { - writefln("Observed msg %s,%s", i, j); - } -} - -class Foo -{ - int value() { return _value; } - - int value(int v) - { - if (v != _value) - { _value = v; - // call all the connected slots with the two parameters - emit("setting new value", v); - } - return v; - } - - // Mix in all the code we need to make Foo into a signal - mixin Signal!(string, int); - - private : - int _value; -} - -void test1() -{ - Foo a = new Foo; - Observer o = new Observer; - - a.value = 3; // should not call o.watch() - a.connect(&o.watch); // o.watch is the slot - a.value = 4; // should call o.watch() - a.disconnect(&o.watch); // o.watch is no longer a slot - a.value = 5; // so should not call o.watch() - a.connect(&o.watch); // connect again - a.value = 6; // should call o.watch() - delete o; // destroying o should automatically disconnect it - a.value = 7; // should not call o.watch() -} - -/******************************************/ - -class Input -{ - mixin Signal!(int, int) click; - mixin Signal!(char) keyDown; -} - -void test2() -{ - Observer o = new Observer(); - Input a = new Input(); - a.click.connect(&o.watch2); - a.click.emit(5,6); -} - -/******************************************/ - -class Args3 -{ - int foo; -} - -class Base3 -{ - ~this() - { - writefln("Base3 dtor!"); - } -} - -class Test3 : Base3 -{ - mixin Signal!(Args3) A; - mixin Signal!(Args3) B; - - ~this() - { - writefln("Test3 dtor"); - } -} - - -void test3() -{ - auto test = new Test3; -} - - -/******************************************/ - -int main() -{ - test1(); - test2(); - test3(); - - printf("Success\n"); - return 0; -} diff --git a/gcc/testsuite/gdc.test/runnable/testsocket.d b/gcc/testsuite/gdc.test/runnable/testsocket.d deleted file mode 100644 index d0619299ece..00000000000 --- a/gcc/testsuite/gdc.test/runnable/testsocket.d +++ /dev/null @@ -1,51 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: - -import std.stdio; -import std.socket; - -class Connection -{ - private - { - Socket sock; - } - - void connect (string host, ushort port) - { - sock.connect (new InternetAddress (host, port)); - } - - void poll () - { - SocketSet rset = new SocketSet (1); /** XXX: here is the bug */ - - rset.reset (); - rset.add (sock); - } - - this () - { - - sock = new TcpSocket; - sock.blocking = false; - } -} - -int main () -{ - try - { - Connection ns; - ns = new Connection (); - ns.connect ("localhost", 80); - ns.poll (); - delete ns; - } - catch(SocketException e) - { - } - return 0; -} - - diff --git a/gcc/testsuite/gdc.test/runnable/teststdio.d b/gcc/testsuite/gdc.test/runnable/teststdio.d deleted file mode 100644 index d340f21892f..00000000000 --- a/gcc/testsuite/gdc.test/runnable/teststdio.d +++ /dev/null @@ -1,34 +0,0 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: -// EXTRA_FILES: extra-files/teststdio.txt - -import std.stdio; -import core.stdc.stdio; - -void main() -{ - auto f = std.stdio.File("runnable/extra-files/teststdio.txt", "r"); - FILE* fp = f.getFP(); - string buf; - int i; - do - { - buf = f.readln('\n'); - foreach (c; buf) - printf("%x\n", c); - printf("\n"); - switch (i) - { - case 0: assert(buf == "asdfasdf\n"); break; - case 1: assert(buf == "a\n"); break; - case 2: assert(buf == "sdf\n"); break; - case 3: assert(buf == "asdf\n"); break; - case 4: assert(buf == "\n"); break; - case 5: assert(buf == "\n"); break; - case 6: assert(buf == null); break; - default: assert(0); - } - i++; - } while (!feof(fp)); - //fclose(fp); -} diff --git a/gcc/testsuite/gdc.test/runnable/testswitch.d b/gcc/testsuite/gdc.test/runnable/testswitch.d index 02633a84525..c7b9378f842 100644 --- a/gcc/testsuite/gdc.test/runnable/testswitch.d +++ b/gcc/testsuite/gdc.test/runnable/testswitch.d @@ -308,7 +308,7 @@ void bar14(A...)(int i) { goto case; case A[j]: - printf("a = %d, A[%d] = %d\n", a, j, A[j]); + printf("a = %d, A[%zd] = %d\n", a, j, A[j]); } break; default: @@ -356,10 +356,14 @@ int foo15(int i) static this() { X15 = 4; - Y15 = 4; Z15 = 5; } +shared static this() +{ + Y15 = 4; +} + void test15() { auto i = foo15(3); @@ -465,7 +469,7 @@ int wrongcode3139(int x) static assert(wrongcode3139(-5)==3); -// bug 3139 +// https://issues.dlang.org/show_bug.cgi?id=3139 static assert(!is(typeof( (long x) { switch(x) { case long.max: .. case -long.max: default:} return 4; }(3) @@ -499,7 +503,7 @@ void test7358() } /*****************************************/ -// 9263 +// https://issues.dlang.org/show_bug.cgi?id=9263 void test9263() { @@ -622,7 +626,7 @@ void test23() } /*****************************************/ -// 14352 +// https://issues.dlang.org/show_bug.cgi?id=14352 int transmogrify14352(int input) { @@ -659,7 +663,8 @@ void test14352() } /*****************************************/ -// Issue 14587 - DMD 2.067.1 generating crashing binary on OSX +// https://issues.dlang.org/show_bug.cgi?id=14587 +// DMD 2.067.1 generating crashing binary on OSX struct Card { int value; @@ -680,7 +685,8 @@ void test14587() { } /*****************************************/ -// Issue 15396 - static immutable not recognized as constant within switch statement +// https://issues.dlang.org/show_bug.cgi?id=15396 +// static immutable not recognized as constant within switch statement void test15396() { @@ -702,6 +708,33 @@ void test15396() } /*****************************************/ +// https://issues.dlang.org/show_bug.cgi?id=15538 + +struct S15538 +{ + int a = 0; + int b = 1; +} + +int f15538(S15538 s) +{ + switch (s.a) + { + case 0: return 10; + case 1: return 20; + case 2: return 30; + case 3: return 40; + default: return 99; + } +} + +void test15538() +{ + S15538 s; + assert(f15538(s) == 10); /* fails */ +} + +/*****************************************/ int main() { @@ -732,6 +765,7 @@ int main() test14352(); test14587(); test15396(); + test15538(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/testthread.d b/gcc/testsuite/gdc.test/runnable/testthread.d index 4ae43950863..139a891072c 100644 --- a/gcc/testsuite/gdc.test/runnable/testthread.d +++ b/gcc/testsuite/gdc.test/runnable/testthread.d @@ -49,7 +49,7 @@ int main() assert(f.x == 3); int i; - Thread tx[5]; + Thread[5] tx; for (i = 0; i < tx.length; i++) tx[i] = new Thread(&f.bar); for (i = 0; i < tx.length; i++) diff --git a/gcc/testsuite/gdc.test/runnable/testthread2.d b/gcc/testsuite/gdc.test/runnable/testthread2.d index 93aace6c650..53f8a3b50f3 100644 --- a/gcc/testsuite/gdc.test/runnable/testthread2.d +++ b/gcc/testsuite/gdc.test/runnable/testthread2.d @@ -1,11 +1,5 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: -import std.algorithm : map; -import std.random : Random, uniform, unpredictableSeed; -import std.range : repeat; -import std.stdio : writeln; - // Quick, dirty and inefficient AA using linear search, useful for testing. struct LinearAA(K, V) { K[] keys; @@ -33,7 +27,7 @@ struct LinearAA(K, V) { return val; } - V* opIn_r(K key) { + V* opBinaryRight(string op : "in")(K key) { foreach(i, k; keys) { if(key == k) { return values.ptr + i; @@ -67,24 +61,35 @@ struct LinearAA(K, V) { } } -void main() { - Random gen; - uint[] seed; - gen.seed(map!((a) { - seed ~= unpredictableSeed; - return seed[$-1]; })(repeat(0))); - writeln(seed); +extern (C) int rand(); + +uint random(const uint max = uint.max) +{ + version (Windows) + { + // RAND_MAX is quite low for windows, extend the range by + // abusing multiple random values and rounding errors. + const a = rand(), b = rand(); + const c = a < b ? double(a) / b : double(b) / a; + return (cast(int) (c * max)) % max; + } + else + return rand() % max; +} + +void main() +{ foreach(iter; 0..10) { // Bug only happens after a few iterations. - writeln(iter); + uint[size_t] builtin; LinearAA!(size_t, uint) linAA; uint[] nums = new uint[100_000]; foreach(ref num; nums) { - num = uniform(0U, uint.max, gen); + num = random(); } foreach(i; 0..10_000) { - auto index = uniform(0, nums.length, gen); + auto index = random(cast(uint) nums.length); if(index in builtin) { assert(index in linAA); assert(builtin[index] == nums[index]); diff --git a/gcc/testsuite/gdc.test/runnable/testtypeid.d b/gcc/testsuite/gdc.test/runnable/testtypeid.d index ebdda30c197..d3f4503a187 100644 --- a/gcc/testsuite/gdc.test/runnable/testtypeid.d +++ b/gcc/testsuite/gdc.test/runnable/testtypeid.d @@ -1,6 +1,6 @@ -// RUNNABLE_PHOBOS_TEST + import core.vararg; -import std.stdio; +import core.stdc.stdio; /******************************************************/ @@ -18,10 +18,10 @@ FOO3 foox3; void foo3(int x, ...) { - printf("%d arguments\n", _arguments.length); + printf("%zd arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { - writeln(_arguments[i].toString()); + //writeln(_arguments[i].toString()); if (_arguments[i] is typeid(int)) { @@ -76,20 +76,6 @@ void test4() ti = typeid(real[]); assert(!(ti is null)); - ti = typeid(ifloat[]); - assert(!(ti is null)); - ti = typeid(idouble[]); - assert(!(ti is null)); - ti = typeid(ireal[]); - assert(!(ti is null)); - - ti = typeid(cfloat[]); - assert(!(ti is null)); - ti = typeid(cdouble[]); - assert(!(ti is null)); - ti = typeid(creal[]); - assert(!(ti is null)); - ti = typeid(void); assert(!(ti is null)); ti = typeid(void[]); @@ -210,26 +196,6 @@ void test16() /******************************************************/ -void test17() -{ - TypeInfo ti = typeid(ifloat*); - assert(!(ti is null)); - assert(ti.tsize==(ifloat*).sizeof); - assert(ti.toString()=="ifloat*"); -} - -/******************************************************/ - -void test18() -{ - TypeInfo ti = typeid(cfloat*); - assert(!(ti is null)); - assert(ti.tsize==(cfloat*).sizeof); - assert(ti.toString()=="cfloat*"); -} - -/******************************************************/ - void test19() { TypeInfo ti = typeid(double*); @@ -240,26 +206,6 @@ void test19() /******************************************************/ -void test20() -{ - TypeInfo ti = typeid(idouble*); - assert(!(ti is null)); - assert(ti.tsize==(idouble*).sizeof); - assert(ti.toString()=="idouble*"); -} - -/******************************************************/ - -void test21() -{ - TypeInfo ti = typeid(cdouble*); - assert(!(ti is null)); - assert(ti.tsize==(cdouble*).sizeof); - assert(ti.toString()=="cdouble*"); -} - -/******************************************************/ - void test22() { TypeInfo ti = typeid(real*); @@ -270,26 +216,6 @@ void test22() /******************************************************/ -void test23() -{ - TypeInfo ti = typeid(ireal*); - assert(!(ti is null)); - assert(ti.tsize==(ireal*).sizeof); - assert(ti.toString()=="ireal*"); -} - -/******************************************************/ - -void test24() -{ - TypeInfo ti = typeid(creal*); - assert(!(ti is null)); - assert(ti.tsize==(creal*).sizeof); - assert(ti.toString()=="creal*"); -} - -/******************************************************/ - void test25() { TypeInfo ti = typeid(char*); @@ -367,10 +293,10 @@ class Bar32 { long y = 4; } void printargs(int x, ...) { - printf("%d arguments\n", _arguments.length); + printf("%zd arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { - writeln(_arguments[i].toString()); + //writeln(_arguments[i].toString()); if (_arguments[i] == typeid(int)) { @@ -506,7 +432,7 @@ void test40() } /******************************************************/ -// 9442 +// https://issues.dlang.org/show_bug.cgi?id=9442 class C { @@ -526,7 +452,7 @@ void test9442() } /******************************************************/ -// 10451 +// https://issues.dlang.org/show_bug.cgi?id=10451 struct Foo10451; @@ -543,7 +469,7 @@ void test10451() } /******************************************************/ -// 11010 +// https://issues.dlang.org/show_bug.cgi?id=11010 struct S11010 { S11010* p; } @@ -567,7 +493,7 @@ void test11010() } /******************************************************/ -// 13045 +// https://issues.dlang.org/show_bug.cgi?id=13045 void test13045a() { @@ -623,7 +549,7 @@ void test13045b() } /******************************************************/ -// 15680 +// https://issues.dlang.org/show_bug.cgi?id=15680 void test15680() { @@ -651,14 +577,8 @@ int main() test14(); test15(); test16(); - test17(); - test18(); test19(); - test20(); - test21(); test22(); - test23(); - test24(); test25(); test26(); test27(); diff --git a/gcc/testsuite/gdc.test/runnable/traits.d b/gcc/testsuite/gdc.test/runnable/traits.d index 9d14ecdcc09..ddd505919d2 100644 --- a/gcc/testsuite/gdc.test/runnable/traits.d +++ b/gcc/testsuite/gdc.test/runnable/traits.d @@ -1,4 +1,3 @@ -// RUNNABLE_PHOBOS_TEST /* PERMUTE_ARGS: EXTRA_FILES: imports/a9546.d @@ -17,7 +16,7 @@ __lambda1 module traits; -import std.stdio; +import core.stdc.stdio; alias int myint; struct S { void bar() { } int x = 4; static int z = 5; } @@ -34,7 +33,6 @@ struct D1 { @disable void true_(); void false_(){} } void test1() { auto t = __traits(isArithmetic, int); - writeln(t); assert(t == true); assert(__traits(isArithmetic) == false); @@ -61,12 +59,6 @@ void test1() assert(__traits(isArithmetic, float) == true); assert(__traits(isArithmetic, double) == true); assert(__traits(isArithmetic, real) == true); - assert(__traits(isArithmetic, ifloat) == true); - assert(__traits(isArithmetic, idouble) == true); - assert(__traits(isArithmetic, ireal) == true); - assert(__traits(isArithmetic, cfloat) == true); - assert(__traits(isArithmetic, cdouble) == true); - assert(__traits(isArithmetic, creal) == true); assert(__traits(isArithmetic, char) == true); assert(__traits(isArithmetic, wchar) == true); assert(__traits(isArithmetic, dchar) == true); @@ -81,7 +73,6 @@ void test1() void test2() { auto t = __traits(isScalar, int); - writeln(t); assert(t == true); assert(__traits(isScalar) == false); @@ -108,12 +99,6 @@ void test2() assert(__traits(isScalar, float) == true); assert(__traits(isScalar, double) == true); assert(__traits(isScalar, real) == true); - assert(__traits(isScalar, ifloat) == true); - assert(__traits(isScalar, idouble) == true); - assert(__traits(isScalar, ireal) == true); - assert(__traits(isScalar, cfloat) == true); - assert(__traits(isScalar, cdouble) == true); - assert(__traits(isScalar, creal) == true); assert(__traits(isScalar, char) == true); assert(__traits(isScalar, wchar) == true); assert(__traits(isScalar, dchar) == true); @@ -147,12 +132,6 @@ void test3() assert(__traits(isIntegral, float) == false); assert(__traits(isIntegral, double) == false); assert(__traits(isIntegral, real) == false); - assert(__traits(isIntegral, ifloat) == false); - assert(__traits(isIntegral, idouble) == false); - assert(__traits(isIntegral, ireal) == false); - assert(__traits(isIntegral, cfloat) == false); - assert(__traits(isIntegral, cdouble) == false); - assert(__traits(isIntegral, creal) == false); assert(__traits(isIntegral, char) == true); assert(__traits(isIntegral, wchar) == true); assert(__traits(isIntegral, dchar) == true); @@ -185,12 +164,6 @@ void test4() assert(__traits(isFloating, float) == true); assert(__traits(isFloating, double) == true); assert(__traits(isFloating, real) == true); - assert(__traits(isFloating, ifloat) == true); - assert(__traits(isFloating, idouble) == true); - assert(__traits(isFloating, ireal) == true); - assert(__traits(isFloating, cfloat) == true); - assert(__traits(isFloating, cdouble) == true); - assert(__traits(isFloating, creal) == true); assert(__traits(isFloating, char) == false); assert(__traits(isFloating, wchar) == false); assert(__traits(isFloating, dchar) == false); @@ -223,12 +196,6 @@ void test5() assert(__traits(isUnsigned, float) == false); assert(__traits(isUnsigned, double) == false); assert(__traits(isUnsigned, real) == false); - assert(__traits(isUnsigned, ifloat) == false); - assert(__traits(isUnsigned, idouble) == false); - assert(__traits(isUnsigned, ireal) == false); - assert(__traits(isUnsigned, cfloat) == false); - assert(__traits(isUnsigned, cdouble) == false); - assert(__traits(isUnsigned, creal) == false); assert(__traits(isUnsigned, char) == true); assert(__traits(isUnsigned, wchar) == true); assert(__traits(isUnsigned, dchar) == true); @@ -261,12 +228,6 @@ void test6() assert(__traits(isAssociativeArray, float) == false); assert(__traits(isAssociativeArray, double) == false); assert(__traits(isAssociativeArray, real) == false); - assert(__traits(isAssociativeArray, ifloat) == false); - assert(__traits(isAssociativeArray, idouble) == false); - assert(__traits(isAssociativeArray, ireal) == false); - assert(__traits(isAssociativeArray, cfloat) == false); - assert(__traits(isAssociativeArray, cdouble) == false); - assert(__traits(isAssociativeArray, creal) == false); assert(__traits(isAssociativeArray, char) == false); assert(__traits(isAssociativeArray, wchar) == false); assert(__traits(isAssociativeArray, dchar) == false); @@ -299,12 +260,6 @@ void test7() assert(__traits(isStaticArray, float) == false); assert(__traits(isStaticArray, double) == false); assert(__traits(isStaticArray, real) == false); - assert(__traits(isStaticArray, ifloat) == false); - assert(__traits(isStaticArray, idouble) == false); - assert(__traits(isStaticArray, ireal) == false); - assert(__traits(isStaticArray, cfloat) == false); - assert(__traits(isStaticArray, cdouble) == false); - assert(__traits(isStaticArray, creal) == false); assert(__traits(isStaticArray, char) == false); assert(__traits(isStaticArray, wchar) == false); assert(__traits(isStaticArray, dchar) == false); @@ -338,12 +293,6 @@ void test8() assert(__traits(isAbstractClass, float) == false); assert(__traits(isAbstractClass, double) == false); assert(__traits(isAbstractClass, real) == false); - assert(__traits(isAbstractClass, ifloat) == false); - assert(__traits(isAbstractClass, idouble) == false); - assert(__traits(isAbstractClass, ireal) == false); - assert(__traits(isAbstractClass, cfloat) == false); - assert(__traits(isAbstractClass, cdouble) == false); - assert(__traits(isAbstractClass, creal) == false); assert(__traits(isAbstractClass, char) == false); assert(__traits(isAbstractClass, wchar) == false); assert(__traits(isAbstractClass, dchar) == false); @@ -400,18 +349,16 @@ void test13() auto j = __traits(getMember, S, "z"); assert(j == 5); - writeln(__traits(hasMember, s, "x")); assert(__traits(hasMember, s, "x") == true); assert(__traits(hasMember, S, "z") == true); assert(__traits(hasMember, S, "aaa") == false); auto k = __traits(classInstanceSize, C); - writeln(k); assert(k == C.classinfo.initializer.length); } /********************************************************/ -// 7123 +// https://issues.dlang.org/show_bug.cgi?id=7123 private struct DelegateFaker7123(F) { @@ -443,7 +390,6 @@ class D14 void test14() { auto a = [__traits(derivedMembers, D14)]; - writeln(a); assert(a == ["__ctor","__dtor","foo", "__xdtor"]); } @@ -461,12 +407,15 @@ void test15() { D15 d = new D15(); - foreach (t; __traits(getVirtualFunctions, D15, "foo")) - writeln(typeid(typeof(t))); + assert(__traits(getVirtualFunctions, D15, "foo").length == 2); + assert(typeid(typeof(__traits(getVirtualFunctions, D15, "foo")[0])).toString() + == "void function()"); + assert(typeid(typeof(__traits(getVirtualFunctions, D15, "foo")[1])).toString() + == "int function(int)"); alias typeof(__traits(getVirtualFunctions, D15, "foo")) b; - foreach (t; b) - writeln(typeid(t)); + assert(typeid(b[0]).toString() == "void function()"); + assert(typeid(b[1]).toString() == "int function(int)"); auto i = __traits(getVirtualFunctions, d, "foo")[1](1); assert(i == 2); @@ -485,8 +434,8 @@ void test16() assert(__traits(isSame, foo16, bar16) == false); assert(__traits(isSame, foo16, S16) == false); assert(__traits(isSame, S16, S16) == true); - assert(__traits(isSame, std, S16) == false); - assert(__traits(isSame, std, std) == true); + assert(__traits(isSame, core, S16) == false); + assert(__traits(isSame, core, core) == true); } /********************************************************/ @@ -508,7 +457,7 @@ void test17() assert(__traits(compiles, typeof(1)) == true); assert(__traits(compiles, S17.s1) == true); assert(__traits(compiles, S17.s3) == false); - assert(__traits(compiles, 1,2,3,int,long,std) == true); + assert(__traits(compiles, 1,2,3,int,long,core) == true); assert(__traits(compiles, 3[1]) == false); assert(__traits(compiles, 1,2,3,int,long,3[1]) == false); } @@ -525,7 +474,6 @@ interface D18 void test18() { auto a = __traits(allMembers, D18); - writeln(a); assert(a.length == 1); } @@ -546,11 +494,10 @@ class C19 void test19() { auto a = __traits(allMembers, C19); - writeln(a); assert(a.length == 9); foreach( m; __traits(allMembers, C19) ) - writeln(m); + printf("%.*s\n", cast(int)m.length, m.ptr); } @@ -603,12 +550,14 @@ void test22() { D22 d = new D22(); - foreach (t; __traits(getOverloads, D22, "foo")) - writeln(typeid(typeof(t))); + assert(typeid(typeof(__traits(getOverloads, D22, "foo")[0])).toString() + == "void function()"); + assert(typeid(typeof(__traits(getOverloads, D22, "foo")[1])).toString() + == "int function(int)"); alias typeof(__traits(getOverloads, D22, "foo")) b; - foreach (t; b) - writeln(typeid(t)); + assert(typeid(b[0]).toString() == "void function()"); + assert(typeid(b[1]).toString() == "int function(int)"); auto i = __traits(getOverloads, d, "foo")[1](1); assert(i == 2); @@ -642,7 +591,7 @@ struct Test24 static assert(__traits(getVisibility, __traits(getOverloads, Test24, "test24")[1]) == "private"); /********************************************************/ -// 1369 +// https://issues.dlang.org/show_bug.cgi?id=1369 void test1369() { @@ -698,7 +647,7 @@ static assert([__traits(allMembers, S2234b)] == ["x"]); static assert([__traits(allMembers, S2234c)] == ["foo"]); /********************************************************/ -// 5878 +// https://issues.dlang.org/show_bug.cgi?id=5878 template J5878(A) { @@ -735,7 +684,7 @@ static assert([__traits(allMembers,Test6674)] == [ "toString","toHash","opCmp","opEquals","Monitor","factory"]); /********************************************************/ -// 6073 +// https://issues.dlang.org/show_bug.cgi?id=6073 struct S6073 {} @@ -747,13 +696,13 @@ alias T6073!(__traits(parent, S6073)) U6073; // error static assert(__traits(isSame, V6073, U6073)); // same instantiation == same arguemnts /********************************************************/ -// 7027 +// https://issues.dlang.org/show_bug.cgi?id=7027 struct Foo7027 { int a; } static assert(!__traits(compiles, { return Foo7027.a; })); /********************************************************/ -// 9213 +// https://issues.dlang.org/show_bug.cgi?id=9213 class Foo9213 { int a; } static assert(!__traits(compiles, { return Foo9213.a; })); @@ -795,7 +744,7 @@ static assert(__traits(isVirtualMethod, FF.YYY)); static assert(__traits(getVirtualMethods, FF, "YYY").length == 1); /********************************************************/ -// 7608 +// https://issues.dlang.org/show_bug.cgi?id=7608 struct S7608a(bool T) { @@ -820,7 +769,7 @@ void test7608() } /********************************************************/ -// 7858 +// https://issues.dlang.org/show_bug.cgi?id=7858 void test7858() { @@ -857,7 +806,7 @@ void test7858() } /********************************************************/ -// 8971 +// https://issues.dlang.org/show_bug.cgi?id=8971 template Tuple8971(TL...){ alias TL Tuple8971; } @@ -873,7 +822,7 @@ class A8971 } /********************************************************/ -// 8972 +// https://issues.dlang.org/show_bug.cgi?id=8972 struct A8972 { @@ -956,7 +905,7 @@ void getVisibility() } /********************************************************/ -// 9546 +// https://issues.dlang.org/show_bug.cgi?id=9546 void test9546() { @@ -1007,7 +956,7 @@ void test9546() } /********************************************************/ -// 9091 +// https://issues.dlang.org/show_bug.cgi?id=9091 template isVariable9091(X...) if (X.length == 1) { @@ -1153,7 +1102,7 @@ void test9237() } /*************************************************************/ -// 5978 +// https://issues.dlang.org/show_bug.cgi?id=5978 void test5978() { @@ -1178,7 +1127,7 @@ void test7408() } /*************************************************************/ -// 9552 +// https://issues.dlang.org/show_bug.cgi?id=9552 class C9552 { @@ -1225,7 +1174,7 @@ void test9136() } /********************************************************/ -// 9939 +// https://issues.dlang.org/show_bug.cgi?id=9939 struct Test9939 { @@ -1245,7 +1194,7 @@ struct Test9939 static assert([__traits(allMembers, Test9939)] == ["f", "A", "B", "NamedEnum"]); /********************************************************/ -// 10043 +// https://issues.dlang.org/show_bug.cgi?id=10043 void test10043() { @@ -1255,7 +1204,7 @@ void test10043() } /********************************************************/ -// 10096 +// https://issues.dlang.org/show_bug.cgi?id=10096 struct S10096X { @@ -1270,7 +1219,7 @@ struct S10096X this(this) {} ~this() {} - string getStr() in { assert(str); } out(r) { assert(r == str); } body { return str; } + string getStr() in(str) out(r; r == str) { return str; } } static assert( [__traits(allMembers, S10096X)] == @@ -1288,7 +1237,7 @@ class C10096X this(int) {} ~this() {} - string getStr() in { assert(str); } out(r) { assert(r == str); } body { return str; } + string getStr() in(str) out(r; r == str) { return str; } } static assert( [__traits(allMembers, C10096X)] == @@ -1341,117 +1290,6 @@ void test_getUnitTests () /********************************************************/ -void test_getFunctionAttributes() -{ - alias tuple(T...) = T; - - struct S - { - int noF() { return 0; } - int constF() const { return 0; } - int immutableF() immutable { return 0; } - int inoutF() inout { return 0; } - int sharedF() shared { return 0; } - - int x; - ref int refF() { return x; } - int propertyF() @property { return 0; } - int nothrowF() nothrow { return 0; } - int nogcF() @nogc { return 0; } - - int systemF() @system { return 0; } - int trustedF() @trusted { return 0; } - int safeF() @safe { return 0; } - - int pureF() pure { return 0; } - } - - static assert(__traits(getFunctionAttributes, S.noF) == tuple!("@system")); - static assert(__traits(getFunctionAttributes, typeof(S.noF)) == tuple!("@system")); - - static assert(__traits(getFunctionAttributes, S.constF) == tuple!("const", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.constF)) == tuple!("const", "@system")); - - static assert(__traits(getFunctionAttributes, S.immutableF) == tuple!("immutable", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.immutableF)) == tuple!("immutable", "@system")); - - static assert(__traits(getFunctionAttributes, S.inoutF) == tuple!("inout", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.inoutF)) == tuple!("inout", "@system")); - - static assert(__traits(getFunctionAttributes, S.sharedF) == tuple!("shared", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.sharedF)) == tuple!("shared", "@system")); - - static assert(__traits(getFunctionAttributes, S.refF) == tuple!("ref", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.refF)) == tuple!("ref", "@system")); - - static assert(__traits(getFunctionAttributes, S.propertyF) == tuple!("@property", "@system")); - static assert(__traits(getFunctionAttributes, typeof(&S.propertyF)) == tuple!("@property", "@system")); - - static assert(__traits(getFunctionAttributes, S.nothrowF) == tuple!("nothrow", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.nothrowF)) == tuple!("nothrow", "@system")); - - static assert(__traits(getFunctionAttributes, S.nogcF) == tuple!("@nogc", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.nogcF)) == tuple!("@nogc", "@system")); - - static assert(__traits(getFunctionAttributes, S.systemF) == tuple!("@system")); - static assert(__traits(getFunctionAttributes, typeof(S.systemF)) == tuple!("@system")); - - static assert(__traits(getFunctionAttributes, S.trustedF) == tuple!("@trusted")); - static assert(__traits(getFunctionAttributes, typeof(S.trustedF)) == tuple!("@trusted")); - - static assert(__traits(getFunctionAttributes, S.safeF) == tuple!("@safe")); - static assert(__traits(getFunctionAttributes, typeof(S.safeF)) == tuple!("@safe")); - - static assert(__traits(getFunctionAttributes, S.pureF) == tuple!("pure", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S.pureF)) == tuple!("pure", "@system")); - - int pure_nothrow() nothrow pure { return 0; } - static ref int static_ref_property() @property { return *(new int); } - ref int ref_property() @property { return *(new int); } - void safe_nothrow() @safe nothrow { } - - static assert(__traits(getFunctionAttributes, pure_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe")); - static assert(__traits(getFunctionAttributes, typeof(pure_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe")); - - static assert(__traits(getFunctionAttributes, static_ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe")); - static assert(__traits(getFunctionAttributes, typeof(&static_ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe")); - - static assert(__traits(getFunctionAttributes, ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe")); - static assert(__traits(getFunctionAttributes, typeof(&ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe")); - - static assert(__traits(getFunctionAttributes, safe_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe")); - static assert(__traits(getFunctionAttributes, typeof(safe_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe")); - - struct S2 - { - int pure_const() const pure { return 0; } - int pure_sharedconst() const shared pure { return 0; } - } - - static assert(__traits(getFunctionAttributes, S2.pure_const) == tuple!("const", "pure", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S2.pure_const)) == tuple!("const", "pure", "@system")); - - static assert(__traits(getFunctionAttributes, S2.pure_sharedconst) == tuple!("const", "shared", "pure", "@system")); - static assert(__traits(getFunctionAttributes, typeof(S2.pure_sharedconst)) == tuple!("const", "shared", "pure", "@system")); - - static assert(__traits(getFunctionAttributes, (int a) { }) == tuple!("pure", "nothrow", "@nogc", "@safe")); - static assert(__traits(getFunctionAttributes, typeof((int a) { })) == tuple!("pure", "nothrow", "@nogc", "@safe")); - - auto safeDel = delegate() @safe { }; - static assert(__traits(getFunctionAttributes, safeDel) == tuple!("pure", "nothrow", "@nogc", "@safe")); - static assert(__traits(getFunctionAttributes, typeof(safeDel)) == tuple!("pure", "nothrow", "@nogc", "@safe")); - - auto trustedDel = delegate() @trusted { }; - static assert(__traits(getFunctionAttributes, trustedDel) == tuple!("pure", "nothrow", "@nogc", "@trusted")); - static assert(__traits(getFunctionAttributes, typeof(trustedDel)) == tuple!("pure", "nothrow", "@nogc", "@trusted")); - - auto systemDel = delegate() @system { }; - static assert(__traits(getFunctionAttributes, systemDel) == tuple!("pure", "nothrow", "@nogc", "@system")); - static assert(__traits(getFunctionAttributes, typeof(systemDel)) == tuple!("pure", "nothrow", "@nogc", "@system")); -} - -/********************************************************/ - class TestIsOverrideFunctionBase { void bar () {} @@ -1469,7 +1307,8 @@ void test_isOverrideFunction () } /********************************************************/ -// 11711 - Add __traits(getAliasThis) +// https://issues.dlang.org/show_bug.cgi?id=11711 +// Add __traits(getAliasThis) alias TypeTuple(T...) = T; @@ -1492,11 +1331,15 @@ void test11711() static assert(__traits(getAliasThis, S2) == TypeTuple!("var")); static assert(is(typeof(__traits(getMember, S2.init, __traits(getAliasThis, S2)[0])) == TypeTuple!(int, string))); + + // https://issues.dlang.org/show_bug.cgi?id=19439 + // Return empty tuple for non-aggregate types. + static assert(__traits(getAliasThis, int).length == 0); } /********************************************************/ -// Issue 12278 +// https://issues.dlang.org/show_bug.cgi?id=12278 class Foo12278 { @@ -1511,7 +1354,7 @@ struct InPlace12278(T) } /********************************************************/ -// 12571 +// https://issues.dlang.org/show_bug.cgi?id=12571 mixin template getScopeName12571() { @@ -1525,7 +1368,7 @@ void test12571() } /********************************************************/ -// 12237 +// https://issues.dlang.org/show_bug.cgi?id=12237 auto f12237(T)(T a) { @@ -1564,7 +1407,7 @@ void async(ARGS...)(ARGS) alias test17495 = async!(int, int); /********************************************************/ -// 15094 +// https://issues.dlang.org/show_bug.cgi?id=15094 void test15094() { @@ -1638,11 +1481,10 @@ int main() test9136(); test10096(); test_getUnitTests(); - test_getFunctionAttributes(); test_isOverrideFunction(); test12237(); test15094(); - writeln("Success"); + printf("Success\n"); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d b/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d index 512bcea79af..3c5a4bd9786 100644 --- a/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d +++ b/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d @@ -1,8 +1,7 @@ module traits_getPointerBitmap; -import std.stdio; -static import std.traits; +import core.stdc.stdio; // version = RTInfo; // debug = LOG; @@ -190,7 +189,7 @@ class N union U { - size_t data[4]; + size_t[4] data; Large*[] arr; // { length, ptr } struct @@ -210,8 +209,6 @@ void testRTInfo() testType!(int) ([ 0b0 ]); testType!(long) ([ 0b00 ]); testType!(double) ([ 0b00 ]); - testType!(ifloat) ([ 0b0 ]); - testType!(cdouble) ([ 0b0000 ]); testType!(dg) ([ 0b01 ]); testType!(fn) ([ 0b0 ]); testType!(S!fn) ([ 0b100 ]); diff --git a/gcc/testsuite/gdc.test/runnable/traits_getUnitTests.d b/gcc/testsuite/gdc.test/runnable/traits_getUnitTests.d index 38295ae446a..2786917ba08 100644 --- a/gcc/testsuite/gdc.test/runnable/traits_getUnitTests.d +++ b/gcc/testsuite/gdc.test/runnable/traits_getUnitTests.d @@ -62,7 +62,7 @@ void test_getUnitTestsFromImport () static assert(__traits(getUnitTests, mixin("imports.traits_getUnitTests_import")).length == 1); } -// 11358 +// https://issues.dlang.org/show_bug.cgi?id=11358 debug { } enum len11358 = __traits(getUnitTests, mixin(__MODULE__)).length; diff --git a/gcc/testsuite/gdc.test/runnable/tuple_default_parameters.d b/gcc/testsuite/gdc.test/runnable/tuple_default_parameters.d new file mode 100644 index 00000000000..a725d31a4d1 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/tuple_default_parameters.d @@ -0,0 +1,64 @@ +void main() +{ + assert(func(1,0) == 1); + assert(func(1) == 1); + assert(func2() == 0); + + assert(func3() == 15); + assert(func3(2) == 10); + assert(func3(2, 1) == 2); + + assert(func4() == 15); + + assert(func5() == 86); + assert(func5(1) == 84); + assert(func5(1, 2) == 81); + assert(func5(1, 2, 3) == 80); + assert(func5(1, 2, 3, 4) == 74); + assert(func5(1, 2, 3, 4, 0) == 69); + assert(func5(1, 2, 3, 4, 0, 5) == 68); + assert(func5(1, 2, 3, 4, 0, 5, 6) == 32); + assert(func5(1, 2, 3, 4, 0, 5, 6, 7) == 37); + assert(func5(1, 2, 3, 4, 0, 5, 6, 7, 8) == 42); + assert(func5(1, 2, 3, 4, 0, 5, 6, 7, 8, 9) == 46); +} + +template AliasSeq(TList...) +{ + alias AliasSeq = TList; +} + +T func(T)(T value, AliasSeq!(int) params = AliasSeq!(0)) +{ + return value; +} + +int func2(AliasSeq!(int) params = AliasSeq!(0)) +{ + return 0; +} + +// https://issues.dlang.org/show_bug.cgi?id=21258 +int func3(AliasSeq!(int, int) args = AliasSeq!(3, 5)) +{ + return args[0] * args[1]; +} + +size_t func4(AliasSeq!(int, string) args = AliasSeq!(3, "hello")) +{ + return args[0] * args[1].length; +} + +int func5(AliasSeq!(int, int, int) a1 = AliasSeq!(3, 5, 4), + AliasSeq!(int, int, int) a2 = AliasSeq!(10, 5, 6), + int a3 = 42, + AliasSeq!(int, int, int) a4 = AliasSeq!(2, 3, 5), + int a5 = 1, + ) +{ + return a1[0] + a1[1] + a1[2] + + a2[0] + a2[1] + a2[2] + + a3 + + a4[0] + a4[1] + a4[2] + + a5; +} diff --git a/gcc/testsuite/gdc.test/runnable/uda.d b/gcc/testsuite/gdc.test/runnable/uda.d index a01a5ca6039..cdb9aa660cb 100644 --- a/gcc/testsuite/gdc.test/runnable/uda.d +++ b/gcc/testsuite/gdc.test/runnable/uda.d @@ -286,7 +286,7 @@ void test12() } /************************************************/ -// 9178 +// https://issues.dlang.org/show_bug.cgi?id=9178 void test9178() { @@ -297,7 +297,7 @@ void test9178() } /************************************************/ -// 9652 +// https://issues.dlang.org/show_bug.cgi?id=9652 struct Bug9652 { @@ -353,7 +353,7 @@ struct Bug9652 } /************************************************/ -// 9741 +// https://issues.dlang.org/show_bug.cgi?id=9741 import imports.a9741; @@ -364,7 +364,7 @@ alias X9741 = ShowAttributes!(B9741); @A9741 struct B9741 {} /************************************************/ -// 12160 +// https://issues.dlang.org/show_bug.cgi?id=12160 auto before12160(alias Hook)(string) { return 0; } @@ -384,7 +384,7 @@ void test12160() } /************************************************/ -// 10208 +// https://issues.dlang.org/show_bug.cgi?id=10208 @( 10) enum int x10208_01 = 100; @( 20) int x10208_02; @@ -416,7 +416,8 @@ static assert(__traits(getAttributes, x10208_13)[0] == 130); // Error -> OK static assert(__traits(getAttributes, x10208_14)[0] == 140); // Error -> OK /************************************************/ -// 11677, 11678 +// https://issues.dlang.org/show_bug.cgi?id=11677 +// https://issues.dlang.org/show_bug.cgi?id=11678 bool test_uda(alias func)() @safe { @@ -445,7 +446,7 @@ static assert(test_uda!func11678b()); static assert(test_uda!func11678c()); /************************************************/ -// 11678 +// https://issues.dlang.org/show_bug.cgi?id=11678 class C11678 { @@ -460,7 +461,7 @@ static ~this() @(10) @(20) {} shared static ~this() @(10) @(20) {} /************************************************/ -// 11679 +// https://issues.dlang.org/show_bug.cgi?id=11679 void test11679() { @@ -469,7 +470,7 @@ void test11679() } /************************************************/ -// 11680 +// https://issues.dlang.org/show_bug.cgi?id=11680 @(10) gvar11680 = 1; // OK <- NG @(10) gfun11680() {} // OK <- NG @@ -481,7 +482,7 @@ void test11680() } /************************************************/ -// 11844 +// https://issues.dlang.org/show_bug.cgi?id=11844 auto make_encode11844(T, string name)() { @@ -687,7 +688,14 @@ void test20() } /************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20831 +void foo20831(int f, float, @("test") string s = "test") {} + +static if(is(typeof(foo20831) Params20831 == __parameters)) + static assert([__traits(getAttributes, Params20831[1..2])] == []); + +/************************************************/ int main() { diff --git a/gcc/testsuite/gdc.test/runnable/ufcs.d b/gcc/testsuite/gdc.test/runnable/ufcs.d index e09c531f38a..2d9bf155983 100644 --- a/gcc/testsuite/gdc.test/runnable/ufcs.d +++ b/gcc/testsuite/gdc.test/runnable/ufcs.d @@ -129,7 +129,6 @@ void test3() assert([1] .init == null); assert([1:1].init == null); assert(1.0 .init is double.nan); - assert(10i .init is idouble.nan); assert('c' .init == 0xFF); assert("s" .init == null); @@ -138,7 +137,6 @@ void test3() assert([1] .init() == 1); assert([1:1].init() == 1); assert(1.0 .init() == 1); - assert(10i .init() == 1); assert('c' .init() == 1); assert("s" .init() == 1); @@ -147,7 +145,6 @@ void test3() assert([1] .init!(int[])() == 1); assert([1:1].init!(int[int])() == 1); assert(1.0 .init!double() == 1); - assert(10i .init!idouble() == 1); assert('c' .init!char() == 1); assert("s" .init!string() == 1); @@ -422,9 +419,7 @@ class C5 : B5 } /*******************************************/ -// 662 - -import std.stdio,std.string, std.conv; +// https://issues.dlang.org/show_bug.cgi?id=662 enum Etest { @@ -450,6 +445,10 @@ int test(Etest test) //{ // return cast(int)i; //} +string to(T)(int i) { + assert(i == 22); + return "22"; +} void test682() { @@ -465,16 +464,56 @@ void test682() } /*******************************************/ -// 3382 - -import std.range, std.algorithm; +// https://issues.dlang.org/show_bug.cgi?id=3382 @property T twice(T)(T x){ return x * x; } -real toreal(ireal x){ return x.im; } char toupper(char c){ return ('a'<=c && c<='z') ? cast(char)(c - 'a' + 'A') : c; } @property ref T setter(T)(ref T x, T v){ x = v; return x; } +auto iota(T)(T min, T max) +{ + static struct Result + { + T cur, end; + + T front() { return cur; } + bool empty() { return front == end; } + void popFront() { cur++; } + } + return Result(min, max); +} + +auto map(string s, R)(R range) +{ + static struct Result + { + R source; + auto front() { auto a = source.front; return mixin(s); } + alias source this; + } + return Result(range); +} + +auto filter(string s, R)(R range) +{ + static struct Result + { + R source; + alias source this; + void popFront() + { + while (true) + { + auto a = source.front; + if (mixin(s)) break; + source.popFront(); + } + } + } + return Result(range); +} + void test3382() { auto r = iota(0, 10).map!"a*3"().filter!"a%2 != 0"(); @@ -483,17 +522,29 @@ void test3382() assert(10.twice == 100); assert(0.5.twice == 0.25); - assert(1.4i.toreal() == 1.4); assert('c'.toupper() == 'C'); } /*******************************************/ -// 6185 +// https://issues.dlang.org/show_bug.cgi?id=6185 -void test6185() +ref T front(T)(T[] array) { return array[0]; } +bool empty(T)(T[] array) { return array.length == 0; } +void popFront(T)(ref T[] array) { array = array[1..$]; } + +bool equal(T, U)(T t, U u) { - import std.algorithm; + while (true) + { + if (t.empty) return u.empty; + if (u.empty || t.front != u.front) return false; + t.popFront(); + u.popFront(); + } +} +void test6185() +{ auto r1 = [1,2,3].map!"a*2"; assert(equal(r1, [2,4,6])); @@ -502,7 +553,7 @@ void test6185() } /*******************************************/ -// 6070 +// https://issues.dlang.org/show_bug.cgi?id=6070 enum test6070a = ["test"].foo6070(); enum test6070b = foo6070(["test"]); @@ -510,13 +561,13 @@ enum test6070b = foo6070(["test"]); string foo6070(string[] s) { return ""; } /*******************************************/ -// 7670 +// https://issues.dlang.org/show_bug.cgi?id=7670 struct A7670 { double x; } -@property ref double y7670(ref A7670 a) +@property ref double y7670(return ref A7670 a) { return a.x; } @@ -528,7 +579,7 @@ void test7670() } /*******************************************/ -// 7703 +// https://issues.dlang.org/show_bug.cgi?id=7703 void f7703(T)(T a) { } void test7703() @@ -541,9 +592,9 @@ void test7703() } /*******************************************/ -// 7773 +// https://issues.dlang.org/show_bug.cgi?id=7773 -//import std.stdio; +//import core.stdc.stdio; void writeln7773(int n){} void test7773() { @@ -552,7 +603,7 @@ void test7773() } /*******************************************/ -// 7943 +// https://issues.dlang.org/show_bug.cgi?id=7943 struct Foo7943 { @@ -570,7 +621,7 @@ void test7943() } /*******************************************/ -// 8180 +// https://issues.dlang.org/show_bug.cgi?id=8180 int writeln8180(T...)(T args) { return 1; } @@ -587,7 +638,7 @@ void test8180() } /*******************************************/ -// 8245 +// https://issues.dlang.org/show_bug.cgi?id=8245 string toStr8245(immutable(char)* p) { return null; } @property string asStr8245(immutable(char)* p) { return null; } @@ -600,7 +651,7 @@ void test8245() } /*******************************************/ -// 8252 +// https://issues.dlang.org/show_bug.cgi?id=8252 bool f(int x) { return !x; } @@ -611,7 +662,7 @@ void test8252() } /*******************************************/ -// 8453 +// https://issues.dlang.org/show_bug.cgi?id=8453 T[] sort8453(T)(T[] a) { return a; } @@ -623,7 +674,7 @@ void test8453() } /*******************************************/ -// 8503 +// https://issues.dlang.org/show_bug.cgi?id=8503 void α8503(int i) {} @@ -634,7 +685,7 @@ void test8503() } /*******************************************/ -// 9014 +// https://issues.dlang.org/show_bug.cgi?id=9014 @property ref int foo9014(int[] a) { @@ -649,7 +700,7 @@ void test9014() } /*******************************************/ -// 9590 +// https://issues.dlang.org/show_bug.cgi?id=9590 auto func9590(E)(lazy E expr) { } @@ -666,7 +717,7 @@ void test9590() } /*******************************************/ -// 9946 +// https://issues.dlang.org/show_bug.cgi?id=9946 size_t count9946(alias x)(int[] haystack) { @@ -682,7 +733,7 @@ void test9946() } /*******************************************/ -// 10618 +// https://issues.dlang.org/show_bug.cgi?id=10618 template Temp10618(T) { @@ -695,7 +746,7 @@ void test10618() } /*******************************************/ -// 10003 +// https://issues.dlang.org/show_bug.cgi?id=10003 void foo10003(void *p) {} void test10003() @@ -705,7 +756,7 @@ void test10003() } /*******************************************/ -// 10041 +// https://issues.dlang.org/show_bug.cgi?id=10041 auto writeln10041(T...)(T args) { return typeof(args[0]).stringof; } @@ -717,7 +768,7 @@ void test10041() } /*******************************************/ -// 10047 +// https://issues.dlang.org/show_bug.cgi?id=10047 struct Typedef10047(T) { @@ -737,7 +788,7 @@ void test10047() } /*******************************************/ -// 10166 +// https://issues.dlang.org/show_bug.cgi?id=10166 auto foo10166() { @@ -752,7 +803,7 @@ void bar10166(alias handler, T)(T t, int i) void buzz10166() {} /*******************************************/ -// 10526 +// https://issues.dlang.org/show_bug.cgi?id=10526 struct S10526 { @@ -781,7 +832,7 @@ void test10526() } /********************************************************/ -// 10609 +// https://issues.dlang.org/show_bug.cgi?id=10609 int foo10609(int x) { return x; } @@ -794,7 +845,7 @@ void test10609() } /*******************************************/ -// 11312 +// https://issues.dlang.org/show_bug.cgi?id=11312 struct S11312; @@ -809,7 +860,7 @@ void test11312() } /*******************************************/ -// 15123 +// https://issues.dlang.org/show_bug.cgi?id=15123 auto keys15123(K, V)(V[K] aa) { return [1]; } auto values15123(K, V)(V[K] aa) { return [2]; } diff --git a/gcc/testsuite/gdc.test/runnable/uniformctor.d b/gcc/testsuite/gdc.test/runnable/uniformctor.d index d56c782bf9e..6cd45827820 100644 --- a/gcc/testsuite/gdc.test/runnable/uniformctor.d +++ b/gcc/testsuite/gdc.test/runnable/uniformctor.d @@ -1,10 +1,16 @@ +/* +RUN_OUTPUT: +--- +Success +--- +*/ extern(C) int printf(const char*, ...); template TypeTuple(TL...) { alias TypeTuple = TL; } import core.stdc.math : isnan; /********************************************/ -// 9112 +// https://issues.dlang.org/show_bug.cgi?id=9112 void test9112a() // T() and T(v) { @@ -40,19 +46,12 @@ void test9112a() // T() and T(v) test!( float )(3.14); test!( double)(3.14); test!( real )(3.14); - test!(ifloat )(1.4142i); - test!(idouble)(1.4142i); - test!(ireal )(1.4142i); - test!(cfloat )(1.2+3.4i); - test!(cdouble)(1.2+3.4i); - test!(creal )(1.2+3.4i); test!( char )('A'); test!(wchar )('A'); test!(dchar )('A'); test!(bool )(true); static assert(!__traits(compiles, int(1.42))); // in curre,t this is disallowed - static assert(!__traits(compiles, double(3.14i))); { int x; @@ -107,12 +106,6 @@ void test9112b() // new T(v) test!( float )(3.14); test!( double)(3.14); test!( real )(3.14); - test!(ifloat )(1.4142i); - test!(idouble)(1.4142i); - test!(ireal )(1.4142i); - test!(cfloat )(1.2+3.4i); - test!(cdouble)(1.2+3.4i); - test!(creal )(1.2+3.4i); test!( char )('A'); test!(wchar )('A'); test!(dchar )('A'); @@ -138,7 +131,6 @@ void test9112b() // new T(v) static assert(!__traits(compiles, new const int(1, 2))); static assert(!__traits(compiles, new int(1.42))); // in curre,t this is disallowed - static assert(!__traits(compiles, new double(3.14i))); // int(1) in directly on statement scope should be parsed as an expression, but // would fail to compile because of "has no effect" error. diff --git a/gcc/testsuite/gdc.test/runnable/unique_typeinfo_names.d b/gcc/testsuite/gdc.test/runnable/unique_typeinfo_names.d new file mode 100644 index 00000000000..120f8ffedca --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/unique_typeinfo_names.d @@ -0,0 +1,93 @@ +module unique_typeinfo_names; + +// https://issues.dlang.org/show_bug.cgi?id=22149 +void structs() +{ + static struct Foo(T) {} + + auto foo() + { + struct S {} + return Foo!S(); + } + + auto bar() + { + struct S {} + return Foo!S(); + } + + auto f = foo(); + auto b = bar(); + + assert(typeid(f) != typeid(b)); + assert(typeid(f).name != typeid(b).name); + + assert(typeid(f).mangledName == typeof(f).mangleof); + assert(typeid(b).mangledName == typeof(b).mangleof); + assert(typeid(f).name == "unique_typeinfo_names.structs().Foo!(unique_typeinfo_names.structs().foo().S).Foo"); + assert(typeid(b).name == "unique_typeinfo_names.structs().Foo!(unique_typeinfo_names.structs().bar().S).Foo"); +} + +// https://issues.dlang.org/show_bug.cgi?id=22150 +void classes() +{ + static class Foo(T) {} + + static auto foo() + { + struct S {} + return new Foo!S(); + } + + static auto bar() + { + struct S {} + return new Foo!S(); + } + + auto f = foo(); + auto b = bar(); + + assert(typeid(f) != typeid(b)); + assert(typeid(f).name != typeid(b).name); + + assert(typeid(f).name == "unique_typeinfo_names.classes.Foo!(unique_typeinfo_names.classes.foo.S).Foo"); + assert(typeid(b).name == "unique_typeinfo_names.classes.Foo!(unique_typeinfo_names.classes.bar.S).Foo"); +} + +void interfaces() +{ + static interface IFoo(T) {} + static class Foo(T) : IFoo!T {} + + static auto foo() + { + struct S {} + IFoo!S r = new Foo!S(); + return r; + } + + static auto bar() + { + struct S {} + IFoo!S r = new Foo!S(); + return r; + } + + auto f = foo(); + auto b = bar(); + + assert(typeid(f) != typeid(b)); + assert(typeid(f).name != typeid(b).name); + + assert(typeid(f).name == "unique_typeinfo_names.interfaces.IFoo!(unique_typeinfo_names.interfaces.foo.S).IFoo"); + assert(typeid(b).name == "unique_typeinfo_names.interfaces.IFoo!(unique_typeinfo_names.interfaces.bar.S).IFoo"); +} + +void main() +{ + structs(); + classes(); + interfaces(); +} diff --git a/gcc/testsuite/gdc.test/runnable/variadic.d b/gcc/testsuite/gdc.test/runnable/variadic.d index 984d896e29a..2d0736ded66 100644 --- a/gcc/testsuite/gdc.test/runnable/variadic.d +++ b/gcc/testsuite/gdc.test/runnable/variadic.d @@ -672,7 +672,7 @@ void test61() template Tuple63(T...){ alias T Tuple63; } -// Bugzilla 3336 +// https://issues.dlang.org/show_bug.cgi?id=3336 static assert(!is(int[ Tuple63!(int, int) ])); void test63() @@ -691,7 +691,7 @@ void test1411() } /***************************************/ -// Bugzilla 4444 +// https://issues.dlang.org/show_bug.cgi?id=4444 void test4444() { @@ -701,7 +701,7 @@ void test4444() } /***************************************/ -// 13864 +// https://issues.dlang.org/show_bug.cgi?id=13864 struct Tuple13864(T...) { @@ -721,7 +721,7 @@ void test13864() } /***************************************/ -// 4884 +// https://issues.dlang.org/show_bug.cgi?id=4884 struct A4884(T...) { @@ -736,7 +736,7 @@ void test4884() } /***************************************/ -// 4920 +// https://issues.dlang.org/show_bug.cgi?id=4920 struct Test4920(parameters_...) { @@ -751,7 +751,7 @@ void test4920() } /***************************************/ -// 4940 +// https://issues.dlang.org/show_bug.cgi?id=4940 template Tuple4940(T...) { @@ -777,7 +777,7 @@ struct S4940add long x; } -ref S4940add get4940add(ref S4940add s){ return s; } +ref S4940add get4940add(return ref S4940add s){ return s; } void test4940add() { @@ -787,7 +787,7 @@ void test4940add() } /***************************************/ -// 6530 +// https://issues.dlang.org/show_bug.cgi?id=6530 struct S6530 { @@ -876,7 +876,7 @@ void testCopy() } /***************************************/ -// 6700 +// https://issues.dlang.org/show_bug.cgi?id=6700 template bug6700(TList ...) { const int bug6700 = 2; @@ -886,7 +886,7 @@ TypeTuple!(int, long) TT6700; static assert(bug6700!( (TT6700[1..$]) )==2); /***************************************/ -// 6966 +// https://issues.dlang.org/show_bug.cgi?id=6966 template X6966(T...) { @@ -896,7 +896,7 @@ static assert(is(X6966!(int) == const(int))); static assert(is(X6966!(int, 0) == const(int))); /***************************************/ -// 7233 +// https://issues.dlang.org/show_bug.cgi?id=7233 struct Foo7233 { int x, y; } Foo7233[] front7233(Foo7233[][] a) @@ -920,7 +920,7 @@ void test7233() } /***************************************/ -// 7263 +// https://issues.dlang.org/show_bug.cgi?id=7263 template TypeTuple7263(T...){ alias T TypeTuple7263; } @@ -940,13 +940,13 @@ void test7263() } /***************************************/ -// 8244 +// https://issues.dlang.org/show_bug.cgi?id=8244 TypeTuple!(int,int)[] x8244; static assert(is(typeof(x8244) == TypeTuple!(int, int))); /***************************************/ -// 9017 +// https://issues.dlang.org/show_bug.cgi?id=9017 template X9017(Args...) { @@ -974,13 +974,13 @@ void test9017() } /***************************************/ -// 10279 +// https://issues.dlang.org/show_bug.cgi?id=10279 void foo10279(int[][] strs...) @trusted { } void bar10279() @safe { foo10279(); } /***************************************/ -// 13508 +// https://issues.dlang.org/show_bug.cgi?id=13508 struct S13508 { @@ -1001,7 +1001,7 @@ void test13508() @safe @nogc } /***************************************/ -// 14395 +// https://issues.dlang.org/show_bug.cgi?id=14395 int v2u14395(uint[1] ar...) { @@ -1019,7 +1019,7 @@ void test14395() } /***************************************/ -// 10414 +// https://issues.dlang.org/show_bug.cgi?id=10414 void foo10414(void delegate()[] ...) { } @@ -1057,7 +1057,7 @@ void test14179() } /***************************************/ -// 10722 +// https://issues.dlang.org/show_bug.cgi?id=10722 struct S10722 { diff --git a/gcc/testsuite/gdc.test/runnable/version.d b/gcc/testsuite/gdc.test/runnable/version.d index 67da1885882..1186e4c6a36 100644 --- a/gcc/testsuite/gdc.test/runnable/version.d +++ b/gcc/testsuite/gdc.test/runnable/version.d @@ -1,5 +1,12 @@ -// PERMUTE_ARGS: -// REQUIRED_ARGS: -version=3 -version=foo +/* +PERMUTE_ARGS: +REQUIRED_ARGS: -version=3 -version=foo +RUN_OUTPUT: +--- +i = 2 +i = 2 +--- +*/ extern(C) int printf(const char*, ...); @@ -64,4 +71,3 @@ int main() test2(); return 0; } - diff --git a/gcc/testsuite/gdc.test/runnable/warning1.d b/gcc/testsuite/gdc.test/runnable/warning1.d index 9dcbea9f471..537088e97cc 100644 --- a/gcc/testsuite/gdc.test/runnable/warning1.d +++ b/gcc/testsuite/gdc.test/runnable/warning1.d @@ -120,7 +120,7 @@ nothrow int foo6() } /******************************************/ -// 6518 +// https://issues.dlang.org/show_bug.cgi?id=6518 template TypeTuple(T...) { alias T TypeTuple; } void test6518() @@ -134,7 +134,7 @@ void test6518() } /******************************************/ -// 7232 +// https://issues.dlang.org/show_bug.cgi?id=7232 bool test7232() { @@ -154,7 +154,7 @@ struct S9332 } /******************************************/ -// 13201 +// https://issues.dlang.org/show_bug.cgi?id=13201 class C13201 { diff --git a/gcc/testsuite/gdc.test/runnable/wc.d b/gcc/testsuite/gdc.test/runnable/wc.d index 8f847c5938f..69d3cf85d1d 100644 --- a/gcc/testsuite/gdc.test/runnable/wc.d +++ b/gcc/testsuite/gdc.test/runnable/wc.d @@ -37,14 +37,14 @@ int main (string[] args) inword = 0; ++c_cnt; } - printf ("%8lu%8lu%8lu %.*s\n", l_cnt, w_cnt, c_cnt, arg.length, arg.ptr); + printf ("%8u%8u%8u %.*s\n", l_cnt, w_cnt, c_cnt, cast(int)arg.length, arg.ptr); l_total += l_cnt; w_total += w_cnt; c_total += c_cnt; } if (args.length > 2) { - printf ("--------------------------------------\n%8lu%8lu%8lu total", + printf ("--------------------------------------\n%8u%8u%8u total", l_total, w_total, c_total); } return 0; diff --git a/gcc/testsuite/gdc.test/runnable/wc2.d b/gcc/testsuite/gdc.test/runnable/wc2.d index a97c6fa8620..97fcdeef621 100644 --- a/gcc/testsuite/gdc.test/runnable/wc2.d +++ b/gcc/testsuite/gdc.test/runnable/wc2.d @@ -54,7 +54,7 @@ int main (string[] args) { string w = input[wstart .. input.length]; dictionary[w]++; } - printf("%8lu%8lu%8lu %.*s\n", l_cnt, w_cnt, c_cnt, arg.length, arg.ptr); + printf("%8u%8u%8u %.*s\n", l_cnt, w_cnt, c_cnt, cast(int)arg.length, arg.ptr); l_total += l_cnt; w_total += w_cnt; c_total += c_cnt; @@ -62,14 +62,14 @@ int main (string[] args) if (args.length > 2) { - printf("--------------------------------------\n%8lu%8lu%8lu total", + printf("--------------------------------------\n%8u%8u%8u total", l_total, w_total, c_total); } printf("--------------------------------------\n"); foreach (string word1; dictionary.keys) { - printf("%3d %.*s\n", dictionary[word1], word1.length, word1.ptr); + printf("%3d %.*s\n", dictionary[word1], cast(int)word1.length, word1.ptr); } return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/whetstone.d b/gcc/testsuite/gdc.test/runnable/whetstone.d new file mode 100644 index 00000000000..9145c74bcfd --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/whetstone.d @@ -0,0 +1,231 @@ +/* +PERMUTE_ARGS: -O +*/ + +/* + WHETSTONE BENCHMARK PROGRAM + + This program uses a carefully chosen mix of instructions typical of + scientific (floating point) calculations. + + See H.J. Curnow and B.A. Wichmann, + "A Synthetic Benchmark", Computer J., V19 #1, Feb. 1976, pp. 43-49. + + Table of times for various computers in <info-ibmpc>whetst.answers + compiled by Richard Gillmann (GILLMANN@ISIB) + +Whetstone Fortran Benchmark +(I=10, optimization off, CPU seconds) + +DEC 1.1 sec DECsystem 2060 (TOPS-20 v4, F66) +PR1ME 1.4 sec PR1ME 750 (PRIMOS v18.1, F66) +PR1ME 1.5 sec PR1ME 750 (PRIMOS v18.1, F77) +DEC 2.1 sec VAX 11/780 (Unix, F77) +Apollo 6.2 sec 10 MHz MC68000 w/hardware float. point (AEGIS v4.0, F77) +Apollo 13.1 sec 10 MHz MC68000 w/software float. point (AEGIS v4.0, F77) +Intel 16.0 sec 8086/8087 (286WD Micro Development System,Intel FORTRAN) +IBM 16.0 sec 4.77 MHz 8088 PC w/8087 (DOS 2, Microsoft F77/3.10) +Z80 124.0 sec 4 MHz Z80 with Microsoft Fortran, CP/M +IBM 268.9 sec 4.77 MHz 8088 PC ($NODEBUG) (DOS 1, Microsoft F77/1.0) +Intel 390.0 sec 8086 alone (286WD Micro Development System,Intel FORTRAN) + +Table compiled by Richard Gillmann (Gillmann@ISIB). +*/ + +import core.stdc.stdio; +import core.stdc.time; +import core.stdc.math; + +double t, t1, t2; +double[5] e1; +int j, k, l; + +int main() +{ + clock_t start, stop; + double x1, x2, x3, x4, x, y, z; + int i, isave, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12; + + start = clock(); + +/* I=10 CORRESPONDS TO ONE MILLION WHETSTONE INSTRUCTIONS */ + + i = 10; + t1 = 0.50025000; + t = 0.499975000; + t2 = 2.0000; + isave = i; + n1 = 0; + n2 = 12 * i; + n3 = 14 * i; + n4 = 348 * i; + n5 = 0; + n6 = 210 * i; + n7 = 32 * i; + n8 = 899 * i; + n9 = 516 * i; + n10 = 0; + n11 = 93 * i; + n12 = 0; + x1 = 1.0; + x2 = -1.0; + x3 = -1.0; + x4 = -1.0; + for (i = 1; i <= n1; i++) + { + x1 = (x1+x2+x3-x4)*t; + x2 = (x1+x2-x3+x4)*t; + x3 = (x1-x2+x3+x4)*t; + x4 = (-x1+x2+x3+x4)*t; + } + auto s = pout(n1,n1,n1,x1,x2,x3,x4); + assert(s[] == " 0 0 0 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); + + e1[1] = 1.0; + e1[2] = -1.0; + e1[3] = -1.0; + e1[4] = -1.0; + + for (i = 1; i <= n2; i++) + { + e1[1] = (e1[1]+e1[2]+e1[3]-e1[4])*t; + e1[2] = (e1[1]+e1[2]-e1[3]+e1[4])*t; + e1[3] = (e1[1]-e1[2]+e1[3]+e1[4])*t; + e1[4] = (-e1[1]+e1[2]+e1[3]+e1[4])*t; + } + pout(n2,n3,n2,e1[1],e1[2],e1[3],e1[4]); + assert(s == " 120 140 120 -6.8342e-02 -4.6264e-01 -7.2972e-01 -1.1240e+00"); + + for (i = 1; i <= n3; i++) + { + pa(e1); + } + pout(n3,n2,n2,e1[1],e1[2],e1[3],e1[4]); + assert(s == " 140 120 120 -5.5336e-02 -4.4744e-01 -7.1097e-01 -1.1031e+00"); + + j = 1; + for (i = 1; i <= n4; i++) + { + j = (j-1) ? 3 : 2; + j = (j-2 < 0) ? 0 : 1; + j = (j-1 < 0) ? 1 : 0; + } + pout(n4, j, j, x1, x2, x3, x4); + assert(s == " 3480 0 0 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); + + j = 1; + k = 2; + l = 3; + for (i = 1; i <= n6; i++) + { + j = j*(k-j)*(l-k); + k = l*k-(l-j)*k; + l = (l-k)*(k+j); + e1[l-1] = j+k+l; + e1[k-1] = j*k*l; + } + pout(n6,j,k,e1[1],e1[2],e1[3],e1[4]); + assert(s == " 2100 1 2 6.0000e+00 6.0000e+00 -7.1097e-01 -1.1031e+00"); + + x = 0.5; + y = 0.5; + for (i = 1; i <= n7; i++) + { + x = t * atan(t2* sin(x)* cos(x) / + ( cos(x+y)+ cos(x-y)-1.0 )); + y = t * atan(t2* sin(y)* cos(y) / + ( cos(x+y)+ cos(x-y)-1.0 )); + } + pout(n7, j, k, x, x, y, y); + assert(s == " 320 1 2 4.9041e-01 4.9041e-01 4.9039e-01 4.9039e-01"); + + x = 1.0; + y = 1.0; + z = 1.0; + + for (i = 1; i <= n8; i++) + { + z = p3(x, y); + } + pout(n8, j, k, x, y, z, z); + assert(s == " 8990 1 2 1.0000e+00 1.0000e+00 9.9994e-01 9.9994e-01"); + + j = 1; + k = 2; + l = 3; + e1[1] = 1.0; + e1[2] = 2.0; + e1[3] = 3.0; + + for (i = 1; i <= n9; i++) + { + p0(); + } + pout(n9, j, k, e1[1], e1[2], e1[3], e1[4]); + assert(s == " 5160 1 2 3.0000e+00 2.0000e+00 3.0000e+00 -1.1031e+00"); + + j = 2; + k = 3; + + for (i = 1; i <= n10; i++) + { + j = j + k; + k = j + k; + j = j - k; + k = k - j - j; + } + pout(n10, j, k, x1, x2, x3, x4); + assert(s == " 0 2 3 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); + + x = 0.75; + + for (i = 1; i <= n11; i++) + { + x = sqrt( exp( log(x) / t1)); + } + + pout(n11,j,k,x,x,x,x); + assert(s == " 930 2 3 8.3467e-01 8.3467e-01 8.3467e-01 8.3467e-01"); + + stop = clock(); + + version (none) + printf("Elapsed time = %d.%02d seconds\n", + cast(int)(stop - start)/CLOCKS_PER_SEC, + cast(int)(stop - start)%CLOCKS_PER_SEC); + return 0; +} + +void pa(double[] e) +{ + for (j = 0; j < 6; j++) + { + e[1] = (e[1] + e[2] + e[3] - e[4]) * t; + e[2] = (e[1] + e[2] - e[3] + e[4]) * t; + e[3] = (e[1] - e[2] + e[3] + e[4]) * t; + e[4] = (-e[1] + e[2] + e[3] + e[4]) / t2; + } +} + +void p0() +{ + e1[j] = e1[k]; + e1[k] = e1[l]; + e1[l] = e1[j]; +} + +double p3(double x, double y) +{ + x = t * (x + y); + y = t * (x + y); + return (x + y) / t2; +} + +char[] pout(int n, int j, int k, double x1, double x2, double x3, double x4) +{ + __gshared char[80] result; + const len = sprintf(result.ptr, " %7d %7d %7d %12.4e %12.4e %12.4e %12.4e", + n, j, k, x1, x2, x3, x4); + printf("%s\n", result.ptr); + return result[0 .. len]; +} diff --git a/gcc/testsuite/gdc.test/runnable/xdtor.d b/gcc/testsuite/gdc.test/runnable/xdtor.d index df3a4d18c44..d4b6e2ba8ff 100644 --- a/gcc/testsuite/gdc.test/runnable/xdtor.d +++ b/gcc/testsuite/gdc.test/runnable/xdtor.d @@ -79,8 +79,34 @@ void test2() @safe @nogc nothrow assert(Counter.cnt == 1); } +struct Bar17257(E) +{ + ~this() @safe @nogc nothrow + { + assert(__traits(hasMember, E, "__xdtor")); + } +} + +struct Foo17257A +{ + Bar17257!Foo17257A foo; + ~this() @safe @nogc nothrow {} +} + +struct Foo17257B +{ + Bar17257!Foo17257B foo; +} + +void test3() @safe @nogc nothrow +{ + Foo17257A foo17257A; + Foo17257B foo17257B; +} + void main() { test1(); test2(); + test3(); } diff --git a/gcc/testsuite/gdc.test/runnable/xpostblit.d b/gcc/testsuite/gdc.test/runnable/xpostblit.d index b364c4cff63..8f8a59d093f 100644 --- a/gcc/testsuite/gdc.test/runnable/xpostblit.d +++ b/gcc/testsuite/gdc.test/runnable/xpostblit.d @@ -70,8 +70,67 @@ void test2() @safe @nogc nothrow assert(Counter.cnt == 1); } +/**************************************************************** + This test is intended to verify the exception safety of field + postblits +*/ +string trace = ""; + +struct FieldThrow +{ + string name; + this(string n) + { + name = n; + } + + bool throwExcept; + this(this) + { + if (throwExcept) + { + throw new Exception(""); + } + } + + ~this() { trace ~= name ~ ".dtor"; } +} + +struct S +{ + auto f1 = FieldThrow("f1"); + FieldThrow[2] f2f3= [FieldThrow("f2"), FieldThrow("f3")]; + auto f4 = FieldThrow("f4"); +} + +void test3() +{ + trace = ""; + + S s1; + + // Cause `s1.f4`'s postblit to throw + s1.f4.throwExcept = true; + + try + { + // `s`'s postblit will be a combination of `f1`, `f2f3`, and `f4`'s + // postblit in that order. However, `f4`'s postblit will throw, + // causing `s1.f2f3` and `s1.f1`'s destructors to execute in that + // order + S s2 = s1; + } + catch(Exception ex){ } + + // Confirm the field destructors were called and were called in the + // corrrect order + assert(trace == "f3.dtor" ~ "f2.dtor" ~ "f1.dtor"); +} +/****************************************************************************/ + void main() { test1(); test2(); + test3(); } diff --git a/gcc/testsuite/gdc.test/runnable/xtest46.d b/gcc/testsuite/gdc.test/runnable/xtest46.d index bf19f57c68b..20cc225759a 100644 --- a/gcc/testsuite/gdc.test/runnable/xtest46.d +++ b/gcc/testsuite/gdc.test/runnable/xtest46.d @@ -1,5 +1,5 @@ -// RUNNABLE_PHOBOS_TEST -// PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g +// REQUIRED_ARGS: -preview=rvaluerefparam +// /* TEST_OUTPUT: --- Boo!double @@ -33,14 +33,14 @@ TFunction1: extern (C) void function() --- */ -import std.stdio; +//import std.stdio; import core.stdc.stdio; /******************************************/ struct S { - int opStar() { return 7; } + int opUnary(string op)() if (op == "*") { return 7; } } void test1() @@ -76,29 +76,6 @@ void bar2(D)(const(void)* arg) D obj = *cast(D*) arg; } -/***************************************************/ - -void test3() -{ - version (unittest) - { - printf("unittest!\n"); - } - else - { - printf("no unittest!\n"); - } - - version (assert) - { - printf("assert!\n"); - } - else - { - printf("no assert!\n"); - } -} - /***************************************************/ @@ -160,7 +137,7 @@ struct T6 S6 s; int b = 7; - S6* opDot() + S6* opDot() return { return &s; } @@ -217,7 +194,7 @@ void test7() void foo8(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__) { assert(n1 < n2); - printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr); + printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr); } void test8() @@ -230,7 +207,7 @@ void test8() void foo9(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)() { assert(n1 < n2); - printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr); + printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr); } void test9() @@ -564,7 +541,7 @@ void test27() /***************************************************/ -ref int foo28(ref int x) { return x; } +ref int foo28(return ref int x) { return x; } void test28() { @@ -687,13 +664,13 @@ void test34() /***************************************************/ -ref int foo35(bool condition, ref int lhs, ref int rhs) +ref int foo35(bool condition, return ref int lhs, return ref int rhs) { if ( condition ) return lhs; return rhs; } -ref int bar35()(bool condition, ref int lhs, ref int rhs) +ref int bar35()(bool condition, return ref int lhs, return ref int rhs) { if ( condition ) return lhs; return rhs; @@ -874,7 +851,7 @@ void test44() } /***************************************************/ -// 2006 +// https://issues.dlang.org/show_bug.cgi?id=2006 void test2006() { @@ -887,7 +864,7 @@ void test2006() } /***************************************************/ -// 8442 +// https://issues.dlang.org/show_bug.cgi?id=8442 void test8442() { @@ -988,7 +965,7 @@ void test48() } /***************************************************/ -// 6408 +// https://issues.dlang.org/show_bug.cgi?id=6408 static assert(!is(typeof(string[0..1].init))); static assert(is(typeof(string[].init) == string[])); @@ -1009,7 +986,7 @@ static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int))); static assert(is(typeof(TT6408!(int, int)[$-1].init) == int)); /***************************************************/ -// 9409 +// https://issues.dlang.org/show_bug.cgi?id=9409 template TT9409(T...) { alias T TT9409; } @@ -1028,7 +1005,7 @@ struct S49 this( string name ) { - printf( "(ctor) &%.*s.x = %p\n", name.length, name.ptr, &x ); + printf( "(ctor) &%.*s.x = %p\n", cast(int)name.length, name.ptr, &x ); p = cast(void*)&x; } @@ -1198,7 +1175,8 @@ pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){ void test61() { - writeln(fooPT("p", "c")); + auto s = fooPT("p", "c"); + printf("%.*s\n", cast(int)s.length, s.ptr); } /***************************************************/ @@ -1347,7 +1325,7 @@ void test67() void test68() { - digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b"); + digestToString(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"); } void digestToString(const ubyte[16] digest) @@ -1360,7 +1338,7 @@ void digestToString(const ubyte[16] digest) void test69() { - digestToString69(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b"); + digestToString69(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"); } void digestToString69(ref const ubyte[16] digest) @@ -1776,7 +1754,7 @@ void test86() /***************************************************/ -// Bugzilla 3379 +// https://issues.dlang.org/show_bug.cgi?id=3379 T1[] find(T1, T2)(T1[] longer, T2[] shorter) if (is(typeof(longer[0 .. 1] == shorter) : bool)) @@ -1832,7 +1810,7 @@ struct S88 { void opDispatch(string s, T)(T i) { - printf("S.opDispatch('%.*s', %d)\n", s.length, s.ptr, i); + printf("S.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i); } } @@ -1840,7 +1818,7 @@ class C88 { void opDispatch(string s)(int i) { - printf("C.opDispatch('%.*s', %d)\n", s.length, s.ptr, i); + printf("C.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i); } } @@ -1874,7 +1852,7 @@ void test89() { int bar() { return x; } } X s; - printf("%d\n", s.sizeof); + printf("%zd\n", s.sizeof); assert(s.sizeof == 4); } @@ -2053,8 +2031,8 @@ void test96() { S96!([12, 3]) s1; S96!([1, 23]) s2; - writeln(s1.content); - writeln(s2.content); + //writeln(s1.content); + //writeln(s2.content); assert(!is(typeof(s1) == typeof(s2))); } @@ -2105,7 +2083,7 @@ void test99() } /***************************************************/ -// 5081 +// https://issues.dlang.org/show_bug.cgi?id=5081 void test5081() { @@ -2222,7 +2200,7 @@ void test104() /***************************************************/ -ref int bump105(ref int x) { return ++x; } +ref int bump105(return ref int x) { return ++x; } void test105() { @@ -2246,8 +2224,8 @@ pure int genFactorials(int n) { void test107() { int[6] a; - writeln(a); - writeln(a.init); + //writeln(a); + //writeln(a.init); assert(a.init == [0,0,0,0,0,0]); } @@ -2289,7 +2267,7 @@ int test11247() /***************************************************/ -// 3716 +// https://issues.dlang.org/show_bug.cgi?id=3716 void test111() { auto k1 = true ? [1,2] : []; // OK @@ -2302,7 +2280,7 @@ void test111() } /***************************************************/ -// 658 +// https://issues.dlang.org/show_bug.cgi?id=658 void test658() { @@ -2333,7 +2311,7 @@ void test3069() } /***************************************************/ -// 4303 +// https://issues.dlang.org/show_bug.cgi?id=4303 template foo112() if (__traits(compiles,undefined)) { @@ -2405,7 +2383,7 @@ template foo114(fun...) pragma(msg, typeof(foo114!"a + b"([1,2,3]))); /***************************************************/ -// Bugzilla 3935 +// https://issues.dlang.org/show_bug.cgi?id=3935 struct Foo115 { void opBinary(string op)(Foo other) { @@ -2421,7 +2399,7 @@ void test115() } /***************************************************/ -// Bugzilla 2477 +// https://issues.dlang.org/show_bug.cgi?id=2477 void foo116(T,)(T t) { T x; } @@ -2458,7 +2436,7 @@ void test1891() } /***************************************************/ -// Bugzilla 4291 +// https://issues.dlang.org/show_bug.cgi?id=4291 void test117() pure { @@ -2474,7 +2452,7 @@ template declareFunction() } /***************************************************/ -// Bugzilla 4177 +// https://issues.dlang.org/show_bug.cgi?id=4177 pure real log118(real x) { if (__ctfe) @@ -2510,7 +2488,7 @@ pure void test120() } /***************************************************/ -// 4866 +// https://issues.dlang.org/show_bug.cgi?id=4866 immutable int[3] statik = [ 1, 2, 3 ]; enum immutable(int)[] dynamic = statik; @@ -2523,7 +2501,7 @@ static if (! is(typeof(dynamic) == immutable(int)[])) pragma(msg, "!! ", typeof(dynamic)); /***************************************************/ -// 2943 +// https://issues.dlang.org/show_bug.cgi?id=2943 struct Foo2943 { @@ -2545,7 +2523,7 @@ void test122() } /***************************************************/ -// 4641 +// https://issues.dlang.org/show_bug.cgi?id=4641 struct S123 { int i; @@ -2558,7 +2536,7 @@ void test123() { } /***************************************************/ -// 2451 +// https://issues.dlang.org/show_bug.cgi?id=2451 struct Foo124 { int z = 3; @@ -2585,21 +2563,6 @@ void test124() { /***************************************************/ -void test3022() -{ - static class Foo3022 - { - new(size_t) - { - assert(0); - } - } - - scope x = new Foo3022; -} - -/***************************************************/ - void doNothing() {} void bug5071(short d, ref short c) { @@ -2681,7 +2644,7 @@ alias const MyInt4434[3] IceConstInt4434; alias immutable string[] Bug4830; /***************************************************/ -// 4254 +// https://issues.dlang.org/show_bug.cgi?id=4254 void bub(const inout int other) {} @@ -2703,12 +2666,12 @@ void bug4915c() } /***************************************************/ -// 5164 +// https://issues.dlang.org/show_bug.cgi?id=5164 static if (is(int Q == int, Z...)) { } /***************************************************/ -// 5195 +// https://issues.dlang.org/show_bug.cgi?id=5195 alias typeof(foo5195) food5195; const int * foo5195 = null; @@ -2727,7 +2690,7 @@ void test5332() { auto x = var5332; } } /***************************************************/ -// 5191 +// https://issues.dlang.org/show_bug.cgi?id=5191 struct Foo129 { @@ -2750,15 +2713,15 @@ void test129() assert(foo.value == 5); foo.add(2); - writeln(foo.value); + printf("%d\n", foo.value); assert(foo.value == 7); foo.add(3); - writeln(foo.value); + printf("%d\n", foo.value); assert(foo.value == 10); foo.add(3); - writeln(foo.value); + printf("%d\n", foo.value); assert(foo.value == 13); void delegate (int) nothrow dg = &foo.add!(int); @@ -2767,7 +2730,7 @@ void test129() } /***************************************************/ -// 6169 +// https://issues.dlang.org/show_bug.cgi?id=6169 auto ctfefunc6169() { return "{}"; } enum ctfefptr6169 = &ctfefunc6169; @@ -2813,7 +2776,7 @@ void test6169() pure @safe } /***************************************************/ -// 10506 +// https://issues.dlang.org/show_bug.cgi?id=10506 void impureFunc10506() {} string join10506(RoR)(RoR ror) @@ -2847,7 +2810,7 @@ immutable struct S3598 } /***************************************************/ -// 4211 +// https://issues.dlang.org/show_bug.cgi?id=4211 @safe struct X130 { @@ -2885,7 +2848,7 @@ alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217; static assert(! is(R4217 == S4217)); /***************************************************/ -// 5094 +// https://issues.dlang.org/show_bug.cgi?id=5094 void test131() { @@ -2913,7 +2876,7 @@ void test7545() } /***************************************************/ -// 5020 +// https://issues.dlang.org/show_bug.cgi?id=5020 void test132() { @@ -2928,7 +2891,7 @@ struct S132 } /***************************************************/ -// 5343 +// https://issues.dlang.org/show_bug.cgi?id=5343 struct Tuple5343(Specs...) { @@ -2944,7 +2907,7 @@ alias Tuple5343!(A5343) TA5343; alias S5343!(A5343) SA5343; /***************************************************/ -// 5365 +// https://issues.dlang.org/show_bug.cgi?id=5365 interface IFactory { @@ -2987,7 +2950,7 @@ void test133() } /***************************************************/ -// 5365 +// https://issues.dlang.org/show_bug.cgi?id=5365 class B134 { @@ -3020,7 +2983,7 @@ void test134() } /***************************************************/ -// 5025 +// https://issues.dlang.org/show_bug.cgi?id=5025 struct S135 { void delegate() d; @@ -3034,7 +2997,7 @@ void test135() } /***************************************************/ -// 5545 +// https://issues.dlang.org/show_bug.cgi?id=5545 bool enforce136(bool value, lazy const(char)[] msg = null) { if(!value) { @@ -3052,7 +3015,7 @@ struct Perm { foreach(elem; input) { enforce136(i < 3); perm[i++] = elem; - std.stdio.stderr.writeln(i); // Never gets incremented. Stays at 0. + printf("%d\n", i); // Never gets incremented. Stays at 0. } } } @@ -3060,12 +3023,12 @@ struct Perm { void test136() { byte[] stuff = [0, 1, 2]; auto perm2 = Perm(stuff); - writeln(perm2.perm); // Prints [2, 0, 0] + //writeln(perm2.perm); // Prints [2, 0, 0] assert(perm2.perm[] == [0, 1, 2]); } /***************************************************/ -// 4097 +// https://issues.dlang.org/show_bug.cgi?id=4097 void foo4097() { } alias typeof(&foo4097) T4097; @@ -3074,7 +3037,7 @@ static assert(is(T4097 X : X*) && is(X == function)); static assert(!is(X)); /***************************************************/ -// 5798 +// https://issues.dlang.org/show_bug.cgi?id=5798 void assign9(ref int lhs) pure { lhs = 9; @@ -3099,7 +3062,7 @@ int test137(){ /***************************************************/ -// 9366 +// https://issues.dlang.org/show_bug.cgi?id=9366 static assert(!is(typeof((void[]).init ~ cast(void)0))); static assert(!is(typeof(cast(void)0 ~ (void[]).init))); @@ -3146,7 +3109,8 @@ void test3822() /***************************************************/ -// 5939, 5940 +// https://issues.dlang.org/show_bug.cgi?id=5939 +// https://issues.dlang.org/show_bug.cgi?id=5940 template map(fun...) { @@ -3176,7 +3140,7 @@ void test139() /***************************************************/ -// 5966 +// https://issues.dlang.org/show_bug.cgi?id=5966 string[] foo5966(string[] a) { @@ -3187,7 +3151,7 @@ string[] foo5966(string[] a) enum var5966 = foo5966([""]); /***************************************************/ -// 5975 +// https://issues.dlang.org/show_bug.cgi?id=5975 int foo5975(wstring replace) { @@ -3199,7 +3163,7 @@ int foo5975(wstring replace) enum X5975 = foo5975("X"w); /***************************************************/ -// 5965 +// https://issues.dlang.org/show_bug.cgi?id=5965 template mapx(fun...) if (fun.length >= 1) { @@ -3232,7 +3196,7 @@ void bug5976() } /***************************************************/ -// 5771 +// https://issues.dlang.org/show_bug.cgi?id=5771 struct S141 { @@ -3253,7 +3217,7 @@ class test5498_C : test5498_A {} static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[])); /***************************************************/ -// 3688 +// https://issues.dlang.org/show_bug.cgi?id=3688 struct S142 { @@ -3290,7 +3254,7 @@ void test142() } /***************************************************/ -// 6072 +// https://issues.dlang.org/show_bug.cgi?id=6072 static assert({ if (int x = 5) {} @@ -3298,7 +3262,7 @@ static assert({ }()); /***************************************************/ -// 5959 +// https://issues.dlang.org/show_bug.cgi?id=5959 int n; @@ -3318,7 +3282,7 @@ void test143() } /***************************************************/ -// 6119 +// https://issues.dlang.org/show_bug.cgi?id=6119 void startsWith(alias pred) () if (is(typeof(pred('c', 'd')) : bool)) { @@ -3349,18 +3313,18 @@ void test146() } /***************************************************/ -// 5856 +// https://issues.dlang.org/show_bug.cgi?id=5856 struct X147 { - void f() { writeln("X.f mutable"); } - void f() const { writeln("X.f const"); } + void f() { printf("X.f mutable\n"); } + void f() const { printf("X.f const\n"); } - void g()() { writeln("X.g mutable"); } - void g()() const { writeln("X.g const"); } + void g()() { printf("X.g mutable\n"); } + void g()() const { printf("X.g const\n"); } - void opOpAssign(string op)(int n) { writeln("X+= mutable"); } - void opOpAssign(string op)(int n) const { writeln("X+= const"); } + void opOpAssign(string op)(int n) { printf("X+= mutable\n"); } + void opOpAssign(string op)(int n) const { printf("X+= const\n"); } } void test147() @@ -3465,7 +3429,7 @@ void test13182() } /***************************************************/ -// 5897 +// https://issues.dlang.org/show_bug.cgi?id=5897 struct A148{ int n; } struct B148{ @@ -3493,7 +3457,7 @@ void test148() } /***************************************************/ -// 4969 +// https://issues.dlang.org/show_bug.cgi?id=4969 class MyException : Exception { @@ -3519,7 +3483,7 @@ void cantthrow() nothrow } /***************************************************/ -// 2356 +// https://issues.dlang.org/show_bug.cgi?id=2356 void test2356() { @@ -3565,7 +3529,7 @@ void test2356() } /***************************************************/ -// 13652 +// https://issues.dlang.org/show_bug.cgi?id=13652 void test13652() { @@ -3633,7 +3597,7 @@ void test13652() } /***************************************************/ -// 11238 +// https://issues.dlang.org/show_bug.cgi?id=11238 void test11238() { @@ -3676,18 +3640,18 @@ class A2540 class B2540 : A2540 { int b; - override super.X foo() { return 1; } + override typeof(super).X foo() { return 1; } - alias this athis; - alias this.b thisb; - alias super.a supera; - alias super.foo superfoo; - alias this.foo thisfoo; + alias typeof(this) athis; + alias typeof(this).b thisb; + alias typeof(super).a supera; + alias typeof(super).foo superfoo; + alias typeof(this).foo thisfoo; } struct X2540 { - alias this athis; + alias typeof(this) athis; } void test2540() @@ -3726,12 +3690,12 @@ B14348 test14348() } /***************************************************/ -// 7295 +// https://issues.dlang.org/show_bug.cgi?id=7295 struct S7295 { int member; - @property ref int refCountedPayload() { return member; } + @property ref int refCountedPayload() return { return member; } alias refCountedPayload this; } @@ -3745,24 +3709,20 @@ void bar7295() pure } /***************************************************/ -// 5659 +// https://issues.dlang.org/show_bug.cgi?id=5659 void test149() { - import std.traits; - char a; immutable(char) b; static assert(is(typeof(true ? a : b) == const(char))); static assert(is(typeof([a, b][0]) == const(char))); - - static assert(is(CommonType!(typeof(a), typeof(b)) == const(char))); } /***************************************************/ -// 1373 +// https://issues.dlang.org/show_bug.cgi?id=1373 void func1373a(){} @@ -3815,7 +3775,7 @@ nothrow void test151() @property int eoo() { return 1; } @property auto ref hoo(int i) { return i; } -// 3359 +// https://issues.dlang.org/show_bug.cgi?id=3359 int goo(int i) pure { return i; } auto ioo(int i) pure { return i; } @@ -3829,7 +3789,7 @@ class A152 { auto eoo(int i) shared { return i; } } -// 4706 +// https://issues.dlang.org/show_bug.cgi?id=4706 struct Foo152(T) { @property auto ref front() { @@ -3846,7 +3806,7 @@ void test152() { } /***************************************************/ -// 6733 +// https://issues.dlang.org/show_bug.cgi?id=6733 void bug6733(int a, int b) pure nothrow { } void test6733() { @@ -3856,7 +3816,7 @@ void test6733() { } /***************************************************/ -// 3799 +// https://issues.dlang.org/show_bug.cgi?id=3799 void test153() { @@ -3868,7 +3828,7 @@ void test153() } /***************************************************/ -// 3632 +// https://issues.dlang.org/show_bug.cgi?id=3632 void test154() { @@ -3905,7 +3865,7 @@ void test6545() } /***************************************************/ -// 3147 +// https://issues.dlang.org/show_bug.cgi?id=3147 void test155() @@ -3924,7 +3884,7 @@ void test155() } /***************************************************/ -// 2486 +// https://issues.dlang.org/show_bug.cgi?id=2486 void test2486() { @@ -3932,7 +3892,7 @@ void test2486() int[] arr = [1,2,3]; foo(arr); //OK - static assert(!__traits(compiles, foo(arr[1..2]))); // should be NG + static assert(__traits(compiles, foo(arr[1..2]))); struct S { @@ -3943,7 +3903,7 @@ void test2486() s[]; // opSlice should return rvalue static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe)); - static assert(!__traits(compiles, foo(s[]))); // should be NG + static assert(__traits(compiles, foo(s[]))); } /***************************************************/ @@ -3963,7 +3923,7 @@ void test15080() } /***************************************************/ -// 2521 +// https://issues.dlang.org/show_bug.cgi?id=2521 immutable int val = 23; const int val2 = 23; @@ -4011,7 +3971,7 @@ void test5554() } /***************************************************/ -// 5962 +// https://issues.dlang.org/show_bug.cgi?id=5962 struct S156 { @@ -4044,7 +4004,7 @@ void test6708(const ref int y) } /***************************************************/ -// 4258 +// https://issues.dlang.org/show_bug.cgi?id=4258 struct Vec4258 { Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") { @@ -4097,7 +4057,7 @@ static assert(!is(typeof(Bar4258.init += 1))); static assert(!is(typeof(1 + Baz4258.init))); /***************************************************/ -// 4539 +// https://issues.dlang.org/show_bug.cgi?id=4539 void test4539() { @@ -4118,20 +4078,20 @@ void test4539() assert(s[4] == 0x61); } - static assert(!__traits(compiles, foo1("hello"))); + static assert(__traits(compiles, foo1("hello"))); static assert(!__traits(compiles, foo2("hello"))); static assert(!__traits(compiles, foo3("hello"))); // same as test68, 69, 70 foo4("hello"); - foo5(cast(ubyte[5])x"c3fcd3d761"); + foo5(cast(ubyte[5])"\xc3\xfc\xd3\xd7\x61"); //import std.conv; //static assert(!__traits(compiles, parse!int("10") == 10)); } /***************************************************/ -// 1471 +// https://issues.dlang.org/show_bug.cgi?id=1471 void test1471() { @@ -4147,14 +4107,6 @@ static assert(!is(typeof(bug6389 = bug6389))); /***************************************************/ -void test10927() -{ - static assert( (1+2i) ^^ 3 == -11 - 2i ); - auto a = (1+2i) ^^ 3; -} - -/***************************************************/ - void test4963() { struct Value { @@ -4178,7 +4130,7 @@ pure int test4031() } /***************************************************/ -// 5437 +// https://issues.dlang.org/show_bug.cgi?id=5437 template EnumMembers5437(E) { @@ -4203,7 +4155,7 @@ void test5437() } /***************************************************/ -// 1962 +// https://issues.dlang.org/show_bug.cgi?id=1962 void test1962() @@ -4213,12 +4165,12 @@ void test1962() } /***************************************************/ -// 6228 - +// https://issues.dlang.org/show_bug.cgi?id=6228 void test6228() { - const(int)* ptr; + int val; + const(int)* ptr = &val; const(int) temp; auto x = (*ptr) ^^ temp; } @@ -4308,7 +4260,7 @@ void test6264() } /***************************************************/ -// 5046 +// https://issues.dlang.org/show_bug.cgi?id=5046 void test5046() { @@ -4328,7 +4280,7 @@ S5046!(p, T) makeS5046(alias p, T)() } /***************************************************/ -// 6335 +// https://issues.dlang.org/show_bug.cgi?id=6335 struct S6335 { @@ -4428,7 +4380,7 @@ void test6293() { } /***************************************************/ -// 3733 +// https://issues.dlang.org/show_bug.cgi?id=3733 class C3733 { @@ -4444,7 +4396,7 @@ void test3733() } /***************************************************/ -// 4392 +// https://issues.dlang.org/show_bug.cgi?id=4392 class C4392 { @@ -4460,7 +4412,7 @@ void test4392() } /***************************************************/ -// 6220 +// https://issues.dlang.org/show_bug.cgi?id=6220 void test6220() { struct Foobar { real x; real y; real z;} @@ -4473,7 +4425,7 @@ void test6220() { } /***************************************************/ -// 5799 +// https://issues.dlang.org/show_bug.cgi?id=5799 void test5799() { @@ -4483,7 +4435,7 @@ void test5799() } /***************************************************/ -// 6529 +// https://issues.dlang.org/show_bug.cgi?id=6529 enum Foo6529 : char { A='a' } ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; } @@ -4536,7 +4488,7 @@ void test157() } /***************************************************/ -// 6473 +// https://issues.dlang.org/show_bug.cgi?id=6473 struct Eins6473 { @@ -4634,7 +4586,7 @@ void test6578() } /***************************************************/ -// 6630 +// https://issues.dlang.org/show_bug.cgi?id=6630 void test6630() { @@ -4674,7 +4626,7 @@ void test199() } /***************************************************/ -// 6690 +// https://issues.dlang.org/show_bug.cgi?id=6690 T useLazy6690(T)(lazy T val) { @@ -4694,7 +4646,7 @@ template Hoge6691() immutable static int[int] dict; immutable static int value; - static this() + shared static this() { dict = [1:1, 2:2]; value = 10; @@ -4716,13 +4668,14 @@ void test10626() double[2] a = v[] * ++z; double[2] b = v[] * --z; double[2] c = v[] * y.u; - double[2] d = v[] * (x[] = 3, x[0]); + x[] = 3; + double[2] d = v[] * x[0]; double[2] e = v[] * (v[] ~ z)[0]; } /***************************************************/ -// 2953 +// https://issues.dlang.org/show_bug.cgi?id=2953 template Tuple2953(T...) { @@ -4743,7 +4696,7 @@ void test2953() } /***************************************************/ -// 2997 +// https://issues.dlang.org/show_bug.cgi?id=2997 abstract class B2997 { void foo(); } interface I2997 { void bar(); } @@ -4758,7 +4711,7 @@ void test2997() } /***************************************************/ -// 6596 +// https://issues.dlang.org/show_bug.cgi?id=6596 extern (C) int function() pfunc6596; extern (C) int cfunc6596(){ return 0; } @@ -4767,7 +4720,7 @@ static assert(typeof(cfunc6596).stringof == "extern (C) int()"); /***************************************************/ -// 4423 +// https://issues.dlang.org/show_bug.cgi?id=4423 struct S4423 { @@ -4813,7 +4766,7 @@ void test4423() } /***************************************************/ -// 4647 +// https://issues.dlang.org/show_bug.cgi?id=4647 interface Timer { @@ -4903,7 +4856,7 @@ void test1064() } /***************************************************/ -// 5696 +// https://issues.dlang.org/show_bug.cgi?id=5696 template Seq5696(T...){ alias T Seq5696; } template Pred5696(T) { alias T Pred5696; } // TOKtemplate @@ -4931,7 +4884,7 @@ void test5696() } /***************************************************/ -// 5933 +// https://issues.dlang.org/show_bug.cgi?id=5933 int dummyfunc5933(); alias typeof(dummyfunc5933) FuncType5933; @@ -4962,7 +4915,7 @@ class C5933d { auto x() { return 0; } } static assert(is(typeof(C5933d.x) == FuncType5933)); /***************************************************/ -// 6084 +// https://issues.dlang.org/show_bug.cgi?id=6084 template TypeTuple6084(T...){ alias T TypeTuple6084; } void test6084() @@ -4973,7 +4926,7 @@ void test6084() } /***************************************************/ -// 6763 +// https://issues.dlang.org/show_bug.cgi?id=6763 template TypeTuple6763(TList...) { @@ -4994,20 +4947,20 @@ void test6763() f6763(0); //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int) c6763(0); - r6763(n); static assert(!__traits(compiles, r6763(0))); + r6763(n); static assert(__traits(compiles, r6763(0))); i6763(0); o6763(n); static assert(!__traits(compiles, o6763(0))); - // 6755 + // https://issues.dlang.org/show_bug.cgi?id=6755 static assert(typeof(f6763).stringof == "void(int _param_0)"); static assert(typeof(c6763).stringof == "void(const(int) _param_0)"); static assert(typeof(r6763).stringof == "void(ref int _param_0)"); - static assert(typeof(i6763).stringof == "void(const(int) _param_0)"); + static assert(typeof(i6763).stringof == "void(in int _param_0)"); static assert(typeof(o6763).stringof == "void(out int _param_0)"); } /***************************************************/ -// 6695 +// https://issues.dlang.org/show_bug.cgi?id=6695 struct X6695 { @@ -5044,7 +4997,7 @@ struct X6695 } /***************************************************/ -// 6087 +// https://issues.dlang.org/show_bug.cgi?id=6087 template True6087(T) { @@ -5061,7 +5014,7 @@ struct Bar6087 } /***************************************************/ -// 6848 +// https://issues.dlang.org/show_bug.cgi?id=6848 class Foo6848 {} @@ -5094,7 +5047,7 @@ else static assert(!__traits(compiles, { cent x; })); /***************************************************/ -// 6847 +// https://issues.dlang.org/show_bug.cgi?id=6847 template True6847(T) { @@ -5144,7 +5097,7 @@ void test6488() } /***************************************************/ -// 6565 +// https://issues.dlang.org/show_bug.cgi?id=6565 void foo6565(out int[2][2] m) {} @@ -5156,7 +5109,7 @@ void test6565() } /***************************************************/ -// 6836 +// https://issues.dlang.org/show_bug.cgi?id=6836 template map6836(fun...) if (fun.length >= 1) { @@ -5194,7 +5147,7 @@ void test5448() } /***************************************************/ -// 6837 +// https://issues.dlang.org/show_bug.cgi?id=6837 struct Ref6837a(T) { @@ -5232,7 +5185,7 @@ void test6837() } /***************************************************/ -// 6927 +// https://issues.dlang.org/show_bug.cgi?id=6927 @property int[] foo6927() { @@ -5286,7 +5239,7 @@ struct Interval6753{ int a,b; } } /***************************************************/ -// 6859 +// https://issues.dlang.org/show_bug.cgi?id=6859 class Parent6859 { @@ -5299,7 +5252,7 @@ public: { assert(isHage); } - body { } + do { } } class Child6859 : Parent6859 @@ -5322,7 +5275,7 @@ void test6859() } /***************************************************/ -// 6910 +// https://issues.dlang.org/show_bug.cgi?id=6910 template Test6910(alias i, B) { @@ -5371,7 +5324,7 @@ void fun12503() b = null; return; } - catch + catch(Throwable) { } } @@ -5387,7 +5340,7 @@ void test12503() } /***************************************************/ -// 6902 +// https://issues.dlang.org/show_bug.cgi?id=6902 void test6902() { @@ -5407,7 +5360,7 @@ void test6902() } /***************************************************/ -// 6330 +// https://issues.dlang.org/show_bug.cgi?id=6330 struct S6330 { @@ -5444,7 +5397,7 @@ void test8269() } /***************************************************/ -// 5311 +// https://issues.dlang.org/show_bug.cgi?id=5311 class C5311 { @@ -5487,7 +5440,7 @@ static void breaksPure5311b(S5311 x) pure } /***************************************************/ -// 6868 +// https://issues.dlang.org/show_bug.cgi?id=6868 @property bool empty6868(T)(in T[] a) @safe pure nothrow { @@ -5504,7 +5457,7 @@ void test6868() } /***************************************************/ -// 2856 +// https://issues.dlang.org/show_bug.cgi?id=2856 struct foo2856 { static void opIndex(int i) { printf("foo\n"); } } struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } } @@ -5539,7 +5492,7 @@ void test13947() } /***************************************************/ -// 3091 +// https://issues.dlang.org/show_bug.cgi?id=3091 void test3091(inout int = 0) { @@ -5563,7 +5516,7 @@ void test3091(inout int = 0) } /***************************************************/ -// 6837 +// https://issues.dlang.org/show_bug.cgi?id=6837 template Id6837(T) { @@ -5573,7 +5526,7 @@ static assert(is(Id6837!(shared const int) == shared const int)); static assert(is(Id6837!(shared inout int) == shared inout int)); /***************************************************/ -// 6056 fixup +// https://issues.dlang.org/show_bug.cgi?id=6056 fixup template ParameterTypeTuple6056(func) { @@ -5599,7 +5552,7 @@ void test6056() } /***************************************************/ -// 6356 +// https://issues.dlang.org/show_bug.cgi?id=6356 int f6356()(int a) { @@ -5619,13 +5572,13 @@ void test6356() } /***************************************************/ -// 7108 +// https://issues.dlang.org/show_bug.cgi?id=7108 static assert(!__traits(hasMember, int, "x")); static assert( __traits(hasMember, int, "init")); /***************************************************/ -// 7073 +// https://issues.dlang.org/show_bug.cgi?id=7073 void test7073() { @@ -5636,7 +5589,7 @@ void test7073() } /***************************************************/ -// 7104 +// https://issues.dlang.org/show_bug.cgi?id=7104 void test7104() { @@ -5645,7 +5598,7 @@ void test7104() } /***************************************************/ -// 7150 +// https://issues.dlang.org/show_bug.cgi?id=7150 struct A7150 { @@ -5669,7 +5622,7 @@ void test7150() } /***************************************************/ -// 7159 +// https://issues.dlang.org/show_bug.cgi?id=7159 alias void delegate() Void7159; @@ -5683,7 +5636,7 @@ class HomeController7159 { } /***************************************************/ -// 7160 +// https://issues.dlang.org/show_bug.cgi?id=7160 class HomeController { static if (false) { @@ -5699,7 +5652,7 @@ void test7160() {} /***************************************************/ -// 7168 +// https://issues.dlang.org/show_bug.cgi?id=7168 void test7168() { @@ -5720,7 +5673,7 @@ void test7168() } /***************************************************/ -// 7170 +// https://issues.dlang.org/show_bug.cgi?id=7170 T to7170(T)(string x) { return 1; } void test7170() @@ -5730,7 +5683,7 @@ void test7170() } /***************************************************/ -// 7196 +// https://issues.dlang.org/show_bug.cgi?id=7196 auto foo7196(int x){return x;} auto foo7196(double x){return x;} @@ -5742,7 +5695,7 @@ void test7196() } /***************************************************/ -// 7285 +// https://issues.dlang.org/show_bug.cgi?id=7285 int[2] spam7285() { @@ -5759,7 +5712,7 @@ void test7285() } /***************************************************/ -// 14737 +// https://issues.dlang.org/show_bug.cgi?id=14737 void test14737() { @@ -5783,7 +5736,7 @@ void test14737() } /***************************************************/ -// 7321 +// https://issues.dlang.org/show_bug.cgi?id=7321 void test7321() { @@ -5810,13 +5763,13 @@ class B158 : A158 } /***************************************************/ -// 9231 +// https://issues.dlang.org/show_bug.cgi?id=9231 class B9231 { void foo() inout pure {} } class D9231 : B9231 { override void foo() inout {} } /***************************************************/ -// 3282 +// https://issues.dlang.org/show_bug.cgi?id=3282 class Base3282 { @@ -5848,7 +5801,7 @@ void test3282() } /***************************************************/ -// 7534 +// https://issues.dlang.org/show_bug.cgi?id=7534 class C7534 { @@ -5877,7 +5830,8 @@ void test7534() } /***************************************************/ -// 7534 + return type covariance +// https://issues.dlang.org/show_bug.cgi?id=7534 +// return type covariance class X7534 {} class Y7534 : X7534 @@ -5913,7 +5867,7 @@ void test7534cov() } /***************************************************/ -// 7562 +// https://issues.dlang.org/show_bug.cgi?id=7562 static struct MyInt { @@ -5946,7 +5900,7 @@ void test13427(void* buffer = alloca(100)) } /***************************************************/ -// 7583 +// https://issues.dlang.org/show_bug.cgi?id=7583 template Tup7583(E...) { alias E Tup7583; } @@ -5966,7 +5920,7 @@ int bug7583() { static assert (bug7583()); /***************************************************/ -// 7618 +// https://issues.dlang.org/show_bug.cgi?id=7618 void test7618(const int x = 1) { @@ -5984,7 +5938,7 @@ void test7618(const int x = 1) } /***************************************************/ -// 7621 +// https://issues.dlang.org/show_bug.cgi?id=7621 void test7621() { @@ -5996,7 +5950,7 @@ void test7621() } /***************************************************/ -// 7682 +// https://issues.dlang.org/show_bug.cgi?id=7682 template ConstOf7682(T) { @@ -6017,7 +5971,7 @@ void test7682() } /***************************************************/ -// 7735 +// https://issues.dlang.org/show_bug.cgi?id=7735 void a7735(void[][] data...) { @@ -6055,7 +6009,7 @@ struct A7823 { void test7823(A7823 a = A7823.b) { } /***************************************************/ -// 7871 +// https://issues.dlang.org/show_bug.cgi?id=7871 struct Tuple7871 { @@ -6076,7 +6030,7 @@ void test7871() } /***************************************************/ -// 7906 +// https://issues.dlang.org/show_bug.cgi?id=7906 void test7906() { @@ -6084,7 +6038,7 @@ void test7906() } /***************************************************/ -// 7907 +// https://issues.dlang.org/show_bug.cgi?id=7907 template Id7907(E) { @@ -6101,7 +6055,7 @@ void test7907() } /***************************************************/ -// 1175 +// https://issues.dlang.org/show_bug.cgi?id=1175 class A1175 { @@ -6116,28 +6070,7 @@ class B1175 : A1175 } /***************************************************/ -// 7983 - -class A7983 { - void f() { - g7983(this); - } - unittest { - } -} - -void g7983(T)(T a) -{ - foreach (name; __traits(allMembers, T)) { - pragma(msg, name); - static if (__traits(compiles, &__traits(getMember, a, name))) - { - } - } -} - -/***************************************************/ -// 8004 +// https://issues.dlang.org/show_bug.cgi?id=8004 void test8004() { @@ -6146,7 +6079,7 @@ void test8004() } /***************************************************/ -// 8064 +// https://issues.dlang.org/show_bug.cgi?id=8064 void test8064() { @@ -6159,7 +6092,7 @@ void test8064() } /***************************************************/ -// 8220 +// https://issues.dlang.org/show_bug.cgi?id=8220 void foo8220(int){} static assert(!__traits(compiles, foo8220(typeof(0)))); // fail @@ -6200,7 +6133,7 @@ void test159() } /***************************************************/ -// 8283 +// https://issues.dlang.org/show_bug.cgi?id=8283 struct Foo8283 { this(long) { } @@ -6222,7 +6155,7 @@ void test8283() { /***************************************************/ -// 8395 +// https://issues.dlang.org/show_bug.cgi?id=8395 struct S8395 { @@ -6238,7 +6171,7 @@ void test8395() } /***************************************************/ -// 5749 +// https://issues.dlang.org/show_bug.cgi?id=5749 void test5749() { @@ -6286,7 +6219,7 @@ void test5749() } /***************************************************/ -// 8396 +// https://issues.dlang.org/show_bug.cgi?id=8396 void test8396() { @@ -6380,7 +6313,7 @@ void test160() } /***************************************************/ -// 8437 +// https://issues.dlang.org/show_bug.cgi?id=8437 class Cgi8437 { @@ -6394,7 +6327,7 @@ class Cgi8437 } /***************************************************/ -// 8665 +// https://issues.dlang.org/show_bug.cgi?id=8665 auto foo8665a(bool val) { @@ -6441,7 +6374,7 @@ void test8108() } /***************************************************/ -// 8360 +// https://issues.dlang.org/show_bug.cgi?id=8360 struct Foo8360 { @@ -6482,7 +6415,7 @@ void test8360() } /***************************************************/ -// 8361 +// https://issues.dlang.org/show_bug.cgi?id=8361 struct Foo8361 { @@ -6496,7 +6429,8 @@ void test8361() } /***************************************************/ -// 6141 + 8526 +// https://issues.dlang.org/show_bug.cgi?id=6141 +// https://issues.dlang.org/show_bug.cgi?id=8526 void test6141() { @@ -6569,7 +6503,7 @@ void test161() } /***************************************************/ -// 7175 +// https://issues.dlang.org/show_bug.cgi?id=7175 void test7175() { @@ -6580,7 +6514,7 @@ void test7175() } /***************************************************/ -// 8819 +// https://issues.dlang.org/show_bug.cgi?id=8819 void test8819() { @@ -6603,7 +6537,7 @@ void test8819() } /***************************************************/ -// 8897 +// https://issues.dlang.org/show_bug.cgi?id=8897 class C8897 { @@ -6614,7 +6548,7 @@ class C8897 template M8897 ( E ) { } /***************************************************/ -// 8917 +// https://issues.dlang.org/show_bug.cgi?id=8917 void test8917() { @@ -6624,7 +6558,7 @@ void test8917() } /***************************************************/ -// 8945 +// https://issues.dlang.org/show_bug.cgi?id=8945 struct S8945 // or `class`, or `union` { @@ -6746,7 +6680,7 @@ struct X164() /***************************************************/ -// 9428 +// https://issues.dlang.org/show_bug.cgi?id=9428 void test9428() { @@ -6783,7 +6717,7 @@ void test9428() } /***************************************************/ -// 9477 +// https://issues.dlang.org/show_bug.cgi?id=9477 template Tuple9477(T...) { alias T Tuple9477; } template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; } @@ -6808,7 +6742,7 @@ void test9477() foreach (b1; Tuple9477!(false, true)) foreach (b2; Tuple9477!(false, true)) { - version (D_PIC) {} else // Work around http://d.puremagic.com/issues/show_bug.cgi?id=9754 + version (D_PIC) {} else version (D_PIE) {} else // Work around http://d.puremagic.com/issues/show_bug.cgi?id=9754 { assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); @@ -6853,7 +6787,7 @@ void test9477() } /***************************************************/ -// 9504 +// https://issues.dlang.org/show_bug.cgi?id=9504 struct Bar9504 { @@ -6884,7 +6818,7 @@ Bar9504 test9504() } /***************************************************/ -// 9538 +// https://issues.dlang.org/show_bug.cgi?id=9538 void test9538() { @@ -6893,7 +6827,7 @@ void test9538() } /***************************************************/ -// 9539 +// https://issues.dlang.org/show_bug.cgi?id=9539 void test9539() { @@ -6911,7 +6845,7 @@ void test9539() } /***************************************************/ -// 9700 +// https://issues.dlang.org/show_bug.cgi?id=9700 mixin template Proxy9700(alias a) { @@ -6931,7 +6865,7 @@ void test9700() } /***************************************************/ -// 9834 +// https://issues.dlang.org/show_bug.cgi?id=9834 struct Event9834 { @@ -6955,7 +6889,7 @@ void test9834() } /***************************************************/ -// 9859 +// https://issues.dlang.org/show_bug.cgi?id=9859 void test9859(inout int[] arr) { @@ -6999,7 +6933,7 @@ void test9859(inout int[] arr) } /***************************************************/ -// 9912 +// https://issues.dlang.org/show_bug.cgi?id=9912 template TypeTuple9912(Stuff...) { @@ -7021,7 +6955,7 @@ struct S9912 } /***************************************************/ -// 9883 +// https://issues.dlang.org/show_bug.cgi?id=9883 struct S9883 { @@ -7041,7 +6975,7 @@ void test9883() /***************************************************/ -// 10091 +// https://issues.dlang.org/show_bug.cgi?id=10091 struct S10091 { @@ -7064,7 +6998,7 @@ label: } /***************************************************/ -// 9130 +// https://issues.dlang.org/show_bug.cgi?id=9130 class S9130 { void bar() { } } @@ -7078,7 +7012,7 @@ struct Function @property void meta(alias m)() { static Function md; - printf("length = %d\n", md.ai.length); + printf("length = %zd\n", md.ai.length); printf("ptr = %p\n", md.ai.ptr); md.ai[0] = 0; } @@ -7090,14 +7024,14 @@ void test9130() } /***************************************************/ -// 10390 +// https://issues.dlang.org/show_bug.cgi?id=10390 class C10390 { this() { this.c = this; } C10390 c; } const c10390 = new C10390(); pragma(msg, c10390); /***************************************************/ -// 10542 +// https://issues.dlang.org/show_bug.cgi?id=10542 class B10542 { @@ -7114,7 +7048,7 @@ void test10542() nothrow pure @safe } /***************************************************/ -// 10539 +// https://issues.dlang.org/show_bug.cgi?id=10539 void test10539() { @@ -7193,7 +7127,7 @@ void test11075() } /***************************************************/ -// 11181 +// https://issues.dlang.org/show_bug.cgi?id=11181 void test11181() { @@ -7207,7 +7141,7 @@ void test11181() } /***************************************************/ -// 11317 +// https://issues.dlang.org/show_bug.cgi?id=11317 void test11317() { @@ -7217,13 +7151,13 @@ void test11317() } void test(ref uint x) {} - static assert(!__traits(compiles, test(fun()))); + static assert(__traits(compiles, test(fun()))); assert(fun() == 0); } /***************************************************/ -// 11888 +// https://issues.dlang.org/show_bug.cgi?id=11888 void test11888() { @@ -7248,7 +7182,7 @@ void test11888() } /***************************************************/ -// 12036 +// https://issues.dlang.org/show_bug.cgi?id=12036 template T12036(alias a) { @@ -7268,7 +7202,7 @@ void test12036() } /***************************************************/ -// 12153 +// https://issues.dlang.org/show_bug.cgi?id=12153 void test12153() { @@ -7284,7 +7218,7 @@ void test12153() } /***************************************************/ -// 12498 +// https://issues.dlang.org/show_bug.cgi?id=12498 string a12498() { @@ -7301,7 +7235,7 @@ void test12498() } /***************************************************/ -// 12900 +// https://issues.dlang.org/show_bug.cgi?id=12900 struct A12900 { @@ -7316,7 +7250,22 @@ void test12900() } /***************************************************/ -// 12937 +// https://issues.dlang.org/show_bug.cgi?id=12929 + +struct Foo12929 +{ + union { } + int var; +} + +struct Bar12929 +{ + struct { } + int var; +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=12937 void test12937() { @@ -7325,7 +7274,7 @@ void test12937() } /***************************************************/ -// 13154 +// https://issues.dlang.org/show_bug.cgi?id=13154 void test13154() { @@ -7341,7 +7290,7 @@ void test13154() } /***************************************************/ -// 13437 +// https://issues.dlang.org/show_bug.cgi?id=13437 ubyte[4] foo13437() { return [1,2,3,4]; } @@ -7353,7 +7302,7 @@ void test13437() } /***************************************************/ -// 13472 +// https://issues.dlang.org/show_bug.cgi?id=13472 class A13472 { @@ -7369,7 +7318,7 @@ void test13472() } /***************************************************/ -// 13476 +// https://issues.dlang.org/show_bug.cgi?id=13476 template ParameterTypeTuple13476(func...) { @@ -7416,16 +7365,16 @@ void test13476() } /***************************************************/ -// 14038 +// https://issues.dlang.org/show_bug.cgi?id=14038 static immutable ubyte[string] wordsAA14038; -static this() +shared static this() { wordsAA14038["zero"] = 0; } /***************************************************/ -// 14192 +// https://issues.dlang.org/show_bug.cgi?id=14192 void test14192() { @@ -7434,7 +7383,7 @@ void test14192() } /***************************************************/ -// 13720 +// https://issues.dlang.org/show_bug.cgi?id=13720 struct FracSec13720 { @@ -7461,7 +7410,7 @@ void test13720() } /***************************************************/ -// 13952 +// https://issues.dlang.org/show_bug.cgi?id=13952 struct Reg13952 { @@ -7507,7 +7456,7 @@ void test13952() } /***************************************************/ -// 14165 +// https://issues.dlang.org/show_bug.cgi?id=14165 class Foo14165 { @@ -7516,7 +7465,7 @@ class Foo14165 } /***************************************************/ -// 13985 +// https://issues.dlang.org/show_bug.cgi?id=13985 interface I13985 { @@ -7552,7 +7501,7 @@ void test13985() } /***************************************************/ -// 14211 +// https://issues.dlang.org/show_bug.cgi?id=14211 extern(C++) // all derived classes won't have invariants class B14211 @@ -7574,7 +7523,7 @@ void test14211() } /***************************************************/ -// 14552 +// https://issues.dlang.org/show_bug.cgi?id=14552 template map14552(fun...) { @@ -7608,7 +7557,7 @@ class Outer14552 } /***************************************************/ -// 14853 +// https://issues.dlang.org/show_bug.cgi?id=14853 struct Queue14853(T) { @@ -7641,7 +7590,7 @@ void test14853() } /********************************************************/ -// 15045 +// https://issues.dlang.org/show_bug.cgi?id=15045 void test15045() { @@ -7700,7 +7649,7 @@ void test15045() } /***************************************************/ -// 15116 +// https://issues.dlang.org/show_bug.cgi?id=15116 alias TypeTuple15116(T...) = T; @@ -7722,7 +7671,7 @@ void test15116() } /***************************************************/ -// 15117 +// https://issues.dlang.org/show_bug.cgi?id=15117 template Mix15117() { @@ -7737,7 +7686,7 @@ struct S15117 } /***************************************************/ -// 15126 +// https://issues.dlang.org/show_bug.cgi?id=15126 struct Json15126 { @@ -7754,7 +7703,7 @@ template isCustomSerializable15126(T) alias bug15126 = isCustomSerializable15126!Json15126; /***************************************************/ -// 15141 +// https://issues.dlang.org/show_bug.cgi?id=15141 class A15141 { @@ -7772,7 +7721,7 @@ void test15141() } /***************************************************/ -// 15366 +// https://issues.dlang.org/show_bug.cgi?id=15366 enum E15366 : bool { A, B }; @@ -7791,7 +7740,7 @@ struct S15366 } /***************************************************/ -// 15369 +// https://issues.dlang.org/show_bug.cgi?id=15369 struct MsgTable15369 { @@ -7856,7 +7805,7 @@ void test15638() } /***************************************************/ -// 15961 +// https://issues.dlang.org/show_bug.cgi?id=15961 struct SliceOverIndexed15961(T) { @@ -7877,13 +7826,26 @@ struct Grapheme15961 } /***************************************************/ -// 16022 +// https://issues.dlang.org/show_bug.cgi?id=16022 bool test16022() { enum Type { Colon, Comma } Type type; - return type == Type.Colon, type == Type.Comma; + return type == Type.Comma; +} + +bool test16022_structs() +{ + struct A + { + int i; + string s; + } + + enum Type { Colon = A(0, "zero"), Comma = A(1, "one") } + Type type; + return type == Type.Comma; } /***************************************************/ @@ -7918,7 +7880,7 @@ void test16466() real r; } real r; - printf("S.alignof: %x, r.alignof: %x\n", S.alignof, r.alignof); + printf("S.alignof: %zx, r.alignof: %zx\n", S.alignof, r.alignof); assert(S.alignof == r.alignof); } @@ -7991,13 +7953,30 @@ struct S17915(T) T owner; } +void test18232() +{ + static struct Canary + { + int x = 0x900D_900D; + } + union U + { + Canary method() + { + Canary c; + return c; + } + } + U u; + assert(u.method() == Canary.init); +} + /***************************************************/ int main() { test1(); test2(); - test3(); test4(); test5(); test6(); @@ -8214,7 +8193,7 @@ int main() test6733(); test6813(); test6859(); - test3022(); + test6910(); test6902(); test6330(); @@ -8312,6 +8291,7 @@ int main() test16408(); test17349(); test17915(); + test18232(); printf("Success\n"); return 0; diff --git a/gcc/testsuite/gdc.test/runnable/xtest46_gc.d b/gcc/testsuite/gdc.test/runnable/xtest46_gc.d new file mode 100644 index 00000000000..14b82a00cd3 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/xtest46_gc.d @@ -0,0 +1,37 @@ +/* +REQUIRED_ARGS: -lowmem -Jrunnable -preview=rvaluerefparam +EXTRA_FILES: xtest46.d +TEST_OUTPUT: +--- +Boo!double +Boo!int +true +int +!! immutable(int)[] +int(int i, long j = 7L) +long +C10390(C10390(<recursion>)) +tuple(height) +tuple(get, get) +tuple(clear) +tuple(draw, draw) +runnable/xtest46_gc.d-mixin-$n$(185): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(187): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(188): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(190): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(217): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(219): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(220): Deprecation: `opDot` is deprecated. Use `alias this` +runnable/xtest46_gc.d-mixin-$n$(222): Deprecation: `opDot` is deprecated. Use `alias this` +const(int) +string[] +double[] +double[] +{} +tuple("m") +true +TFunction1: extern (C) void function() +--- +*/ + +mixin(import("xtest46.d")); diff --git a/gcc/testsuite/gdc.test/runnable/xtest47.d b/gcc/testsuite/gdc.test/runnable/xtest47.d new file mode 100644 index 00000000000..42cabaf9197 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/xtest47.d @@ -0,0 +1,67 @@ +// PERMUTE_ARGS: -unittest +/* TEST_OUTPUT: +--- +f +toString +toHash +opCmp +opEquals +Monitor +factory +--- +*/ + +import core.stdc.stdio; + +/***************************************************/ + +void test3() +{ + version (unittest) + { + printf("unittest!\n"); + } + else + { + printf("no unittest!\n"); + } + + version (assert) + { + printf("assert!\n"); + } + else + { + printf("no assert!\n"); + } +} + +/***************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=7983 + +class A7983 { + void f() { + g7983(this); + } + unittest { + } +} + +void g7983(T)(T a) +{ + foreach (name; __traits(allMembers, T)) { + pragma(msg, name); + static if (__traits(compiles, &__traits(getMember, a, name))) + { + } + } +} + +/***************************************************/ + +int main() +{ + test3(); + + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/xtest55.d b/gcc/testsuite/gdc.test/runnable/xtest55.d index 4b295d8c686..f976520cfa3 100644 --- a/gcc/testsuite/gdc.test/runnable/xtest55.d +++ b/gcc/testsuite/gdc.test/runnable/xtest55.d @@ -1,7 +1,6 @@ -// RUNNABLE_PHOBOS_TEST // PERMUTE_ARGS: -import core.memory, std.stdio; +import core.memory, core.stdc.stdio; Stuff* stuff1; @@ -16,9 +15,9 @@ int main() auto bar = new byte[1024 * 1024]; auto stuff2 = new Stuff; stuff2.num = 2; - writeln(stuff1, "\t", stuff2); // Same address. + printf("%p\t%p\n", stuff1, stuff2); // Same address. assert(stuff1 != stuff2); - writeln(stuff1.num, "\t", stuff2.num); // Both 2. + printf("%d\t%d\n", stuff1.num, stuff2.num); // Both 2. assert(stuff1.num == 1); return 0; } diff --git a/gcc/testsuite/gdc.test/runnable/xtestenum.d b/gcc/testsuite/gdc.test/runnable/xtestenum.d index fa812a121f8..ce77782b88c 100644 --- a/gcc/testsuite/gdc.test/runnable/xtestenum.d +++ b/gcc/testsuite/gdc.test/runnable/xtestenum.d @@ -1,4 +1,11 @@ -// PERMUTE_ARGS: +/* +PERMUTE_ARGS: +RUN_OUTPUT: +--- +foo +Success +--- +*/ extern(C) int printf(const char*, ...); @@ -45,7 +52,7 @@ enum E3 : string void test3() { - printf("%.*s\n", E3.E3a.length, E3.E3a.ptr); + printf("%.*s\n", cast(int)E3.E3a.length, E3.E3a.ptr); assert(E3.E3a == "foo"); assert(E3.E3b == "bar"); |