new file mode 100644
@@ -0,0 +1,69 @@
+alias MT = MyStruct!int;
+
+struct MyStruct(T)
+{
+ T x;
+
+ this(T y)
+ {
+ x = y;
+ }
+
+ MyStruct!T opBinary(string op)(MyStruct!T y) const
+ {
+ alias C = typeof(return);
+ auto w = C(this.x);
+ return w.opOpAssign!(op)(y);
+ }
+
+ MyStruct!T opBinaryRight(string op)(MyStruct!T y) const
+ {
+ return opBinary!(op)(y);
+ }
+
+ ref MyStruct opOpAssign(string op, T)(const MyStruct!T z)
+ {
+ mixin ("x "~op~"= z.x;");
+ return this;
+ }
+
+ MyStruct!T opBinary(string op)(T y) const
+ {
+ alias C = typeof(return);
+ auto w = C(this.x);
+ return w.opOpAssign!(op)(y);
+ }
+
+ MyStruct!T opBinaryRight(string op)(T y) const
+ {
+ return opBinary!(op)(y);
+ }
+
+ ref MyStruct opOpAssign(string op, T)(const T z)
+ {
+ mixin ("x "~op~"= z;");
+ return this;
+ }
+}
+
+void test()
+{
+ MT s = MyStruct!int(1);
+ MT[] arr = [s, 2 * s, 3 * s, 4 * s, 5 * s, 6 * s];
+ MT[] result = new MT[arr.length];
+
+ result[] = arr[] + s;
+ result[] = s + arr[];
+
+ result[] = arr[] - s;
+ result[] = s - arr[];
+
+ result[] = arr[] * s;
+ result[] = s * arr[];
+
+ result[] = arr[] / s;
+ result[] = s / arr[];
+
+ result[] = arr[] ^^ s;
+ result[] = s ^^ arr[];
+}
@@ -2,7 +2,7 @@
// REQUIRED_ARGS: -O
// POST_SCRIPT: compilable/extra-files/objdump-postscript.sh
// only testing on SYSV-ABI, but backend code is identical across platforms
-// DISABLED: win32 win64 osx linux32 freebsd32 freebsd64
+// DISABLED: win32 win64 osx linux32 freebsd32 freebsd64 openbsd32 openbsd64
bool test_ltz(ubyte x) { return x < 0; }
bool test_lez(ubyte x) { return x <= 0; }
new file mode 100644
@@ -0,0 +1,15 @@
+// PERMUTE_ARGS:
+// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o-
+// TEST_OUTPUT_FILE: extra-files/ddoc_markdown_tables_22285.html
+// OUTPUT_FILES: ${RESULTS_DIR}/compilable/ddoc_markdown_tables_22285.html
+
+module test.compilable.ddoc_markdown_tables_22285;
+
+/**
+| A | B | C |
+|---|---|---|
+| a | 0 | |
+| b | 1 1 1 | |
+| c | 2 | |
+*/
+enum _ = 0;
@@ -144,4 +144,7 @@ __gshared void function(ifloat) onVariableFunctionParam;
__gshared ifloat delegate() onVariableDelegate;
-noreturn myExit() {}
+noreturn myExit()
+{
+ assert(false);
+}
deleted file mode 100644
@@ -1,6 +0,0 @@
-// check bugs in importing C files
-
-int squared(int a)
-{
- return a * a;
-}
@@ -66,3 +66,52 @@ static assert(is(T8 == const(ubyte*)));
alias T8 = mixin(q{immutable(__traits(getMember, S, "T"))})*;
static assert(is(T8 == immutable(float*)*));
*/
+
+/**************************************************/
+// https://issues.dlang.org/show_bug.cgi?id=22356
+
+mixin("void") func22356(int) { }
+static assert(is(typeof(&func22356) == void function(int)));
+
+static mixin("void") func22356_s(char) { }
+static assert(is(typeof(&func22356_s) == void function(char)));
+
+mixin("int")[2] func22356_2(int) { return [1, 2]; }
+static assert(is(typeof(&func22356_2) == int[2] function(int)));
+
+mixin("int") func22356tp(S, T)(S, T) { return 1; }
+static assert(is(typeof(&func22356tp!(char, float)) == int function(char, float) pure nothrow @nogc @safe));
+
+mixin("int") x22356;
+static assert(is(typeof(x22356) == int));
+
+mixin("int")** xpp22356;
+static assert(is(typeof(xpp22356) == int**));
+
+mixin("int") y22356, z22356;
+static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));
+
+// Already working but for completeness
+void test_statements_22356()
+{
+ mixin("void") func22356(int) { }
+ static assert(is(typeof(&func22356) == void delegate(int) pure nothrow @nogc @safe));
+
+ static mixin("void") func22356_s(char) { }
+ static assert(is(typeof(&func22356_s) == void function(char) pure nothrow @nogc @safe));
+
+ mixin("int")[2] func22356_2(int) { return [1, 2]; }
+ static assert(is(typeof(&func22356_2) == int[2] delegate(int) pure nothrow @nogc @safe));
+
+ mixin("int") func22356tp(S, T)(S, T) { return 1; }
+ static assert(is(typeof(&func22356tp!(char, float)) == int delegate(char, float) pure nothrow @nogc @safe));
+
+ mixin("int") x22356;
+ static assert(is(typeof(x22356) == int));
+
+ mixin("int")** xpp22356;
+ static assert(is(typeof(xpp22356) == int**));
+
+ mixin("int") y22356, z22356;
+ static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));
+}
@@ -49,8 +49,17 @@ static assert(noreturn.alignof == 0);
static assert((noreturn*).sizeof == (int*).sizeof);
static assert((noreturn[]).sizeof == (int[]).sizeof);
+static assert(is(typeof(noreturn.init) == noreturn));
+static assert(is(typeof((const noreturn).init) == const noreturn));
+static assert(is(typeof((immutable noreturn).init) == immutable noreturn));
+static assert(is(typeof((shared noreturn).init) == shared noreturn));
+
version (DigitalMars)
- noreturn exits(int* p) { *p = 3; }
+ noreturn exits(int* p)
+ {
+ *p = 3;
+ assert(false); // *p could be valid
+ }
noreturn exit();
@@ -58,9 +67,47 @@ noreturn pureexits() @nogc nothrow pure @safe { assert(0); }
noreturn callpureexits() { pureexits(); }
+noreturn returnExits()
+{
+ return pureexits();
+}
+
+void alsoExits()
+{
+ return assert(0);
+}
+
+int thisAlsoExits()
+{
+ return assert(0);
+}
+
+void cast_()
+{
+ noreturn n;
+ int i = n;
+}
+
int test1(int i)
{
if (exit())
return i + 1;
return i - 1;
}
+
+noreturn tlsNoreturn;
+__gshared noreturn globalNoreturn;
+
+template CreateTLS(A)
+{
+ A a;
+}
+
+void* useTls()
+{
+ alias Tnr = CreateTLS!noreturn;
+ void* a1 = &Tnr.a;
+ void* a2 = &tlsNoreturn;
+ void* a3 = &globalNoreturn;
+ return a1 < a2 ? a2 : a3;
+}
deleted file mode 100644
@@ -1,10 +0,0 @@
-// ARG_SETS: -preview=all
-// ARG_SETS: -transition=all
-// ARG_SETS: -revert=all
-import core.stdc.stdio;
-
-void main (string[] args)
-{
- if (args.length == 42)
- printf("Hello World\n");
-}
@@ -1,5 +1,11 @@
// https://issues.dlang.org/show_bug.cgi?id=21997
+struct Strukt
+{
+ int i;
+ string s;
+}
+
int nonPureFunc(int i)
{
return 2 * i;
@@ -28,6 +34,14 @@ int mainCtfe()
auto baseDel = cast(int delegate(int)) pureDel;
assert(baseDel(4) == 20);
*/
+
+ {
+ shared Strukt shStr;
+ Strukt str = *cast(Strukt*) &shStr;
+
+ shared(Strukt)* ptr = cast(shared(Strukt)*) &str;
+ }
+
return 0;
}
new file mode 100644
@@ -0,0 +1,55 @@
+/* REQUIRED_ARGS: -O -release -inline
+This compares two different ways to do a for loop. The range
+version should SROA the VecRange struct into two register variables.
+*/
+
+extern (C):
+
+nothrow:
+@nogc:
+@safe:
+
+alias vec_base_t = size_t; // base type of vector
+alias vec_t = vec_base_t*;
+
+@trusted
+pure
+size_t vec_index(size_t b, const vec_t vec);
+
+@trusted
+pure ref inout(vec_base_t) vec_numbits(inout vec_t v) { return v[-1]; }
+@trusted
+pure ref inout(vec_base_t) vec_dim(inout vec_t v) { return v[-2]; }
+
+struct VecRange
+{
+ size_t i;
+ const vec_t v;
+
+ @nogc @safe nothrow pure:
+ this(const vec_t v) { this.v = v; i = vec_index(0, v); }
+ bool empty() const { return i == vec_numbits(v); }
+ size_t front() const { return i; }
+ void popFront() { i = vec_index(i + 1, v); }
+}
+
+@safe
+pure
+uint vec_numBitsSet(const vec_t vec)
+{
+ uint n = 0;
+ size_t length = vec_numbits(vec);
+ for (size_t i = 0; (i = vec_index(i, vec)) < length; ++i)
+ ++n;
+ return n;
+}
+
+@safe
+pure
+uint vec_numBitsSet2(const vec_t vec)
+{
+ uint n = 0;
+ foreach (j; VecRange(vec))
+ ++n;
+ return n;
+}
new file mode 100644
@@ -0,0 +1,172 @@
+// REQUIRED_ARGS: -preview=dip1000 -preview=in
+/*
+TEST_OUTPUT:
+---
+100 tuple()
+101 tuple("return", "ref")
+102 tuple("ref")
+103 tuple()
+104 tuple("ref")
+105 tuple()
+106 tuple()
+107 tuple("ref")
+108 tuple("ref")
+109 tuple("ref")
+110 tuple("ref")
+111 tuple()
+112 tuple("ref")
+113 tuple("ref")
+114 tuple("ref")
+115 tuple("ref")
+116 tuple()
+117 tuple("ref")
+118 tuple("ref")
+119 tuple()
+120 tuple("ref")
+121 tuple()
+122 tuple("ref")
+123 tuple("in")
+124 tuple("in")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("return", "ref")
+m-mixin tuple("return", "ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple()
+m-mixin tuple()
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("ref")
+m-mixin tuple("ref")
+m tuple("in")
+m-mixin tuple("in")
+---
+*/
+
+void func(int i) {}
+void func(return ref bool i) {}
+void func(ref float a, int b) {}
+void get(T : int)(ref T t) {}
+void get()(float t) {}
+void get(T)(ref T[] t) {}
+void funcautoi()(auto ref int i) {}
+void funcauto(T)(auto ref T a) {}
+void funcin(in int i) {}
+
+struct Foo {
+ void foo(int i) {}
+ void foo(ref bool i) {}
+ static void sfoo(ref int i) {}
+}
+
+struct FooT(T) {
+ void foo(ref T i) {}
+ static void sfoo(ref T i) {}
+}
+
+class Bar {
+ void bar(int i) {}
+ void bar(ref bool i) {}
+ static void sbar(ref int i) {}
+}
+
+class BarT(T) {
+ void bar(ref T i) {}
+ static void sbar(ref T i) {}
+}
+
+int i;
+
+template match(handlers...)
+{
+ static foreach(h; handlers)
+ {
+ // should give the same result
+ pragma(msg, "m ", __traits(getParameterStorageClasses, h(i), 0));
+ pragma(msg, "m-mixin ", __traits(getParameterStorageClasses, mixin("h(i)"), 0));
+ }
+
+ enum match = (){};
+}
+
+void funcT(T)(ref T t) {}
+
+void main() {
+ int i;
+ bool b;
+ float f;
+ int[] ia;
+ Foo foo;
+ FooT!int foot;
+ Bar bar = new Bar;
+ BarT!int bart = new BarT!int;
+
+ ref int _foo(return ref const int* p, scope int* a, out int b, lazy int c);
+
+ // From SPEC_RUNNABLE_EXAMPLE_COMPILE:
+ int* p, a;
+ int _b, c;
+
+ static assert(__traits(getParameterStorageClasses, _foo(p, a, _b, c), 1)[0] == "scope");
+ static assert(__traits(getParameterStorageClasses, _foo(p, a, _b, c), 2)[0] == "out");
+ static assert(__traits(getParameterStorageClasses, _foo(p, a, _b, c), 3)[0] == "lazy");
+
+#line 100
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, func(0), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, func(b), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, func(f, i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, func(f, i), 1));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, get(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, get(0.0), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, get(f), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, get(ia), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, mixin("get(i)"), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, Foo.sfoo(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, FooT!int.sfoo(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, foo.foo(0), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, foo.foo(b), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, foot.foo(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, Bar.sbar(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, BarT!int.sbar(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, bar.bar(0), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, bar.bar(b), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, bart.bar(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcautoi(10), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcautoi(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcauto(10), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcauto(i), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcin(1), 0));
+ pragma(msg, __LINE__, " ", __traits(getParameterStorageClasses, funcin(i), 0));
+
+ cast(void) match!(
+ function(ref int i) => true,
+ delegate(ref int i) => true,
+ (ref int i) => true,
+ (return ref int i) => &i,
+ get,
+ funcT,
+ (int i) => true,
+ FooT!int.sfoo,
+ Foo.sfoo,
+ BarT!int.sbar,
+ Bar.sbar,
+ funcautoi,
+ funcauto,
+ funcin,
+ );
+}
new file mode 100644
@@ -0,0 +1,31 @@
+// https://issues.dlang.org/show_bug.cgi?id=15711
+
+struct Quu {
+ string val;
+}
+
+string[] result = foo!(0, [Quu(['z']), Quu("")]);
+
+template foo(size_t i, Quu[] data, string[] results = []) {
+ static if (i < data.length) {
+ enum def = data[i];
+ enum foo = foo!(i+1, data, results ~ def.val);
+ }
+ else {
+ enum foo = results;
+ }
+}
+
+// Run-time version already works
+
+string[] result_rt = foo_rt(0, [Quu(['z']), Quu("")]);
+
+string[] foo_rt(size_t i, Quu[] data, string[] results = []) {
+ if (i < data.length) {
+ auto def = data[i];
+ return foo_rt(i+1, data, results ~ def.val);
+ }
+ else {
+ return results;
+ }
+}
deleted file mode 100644
@@ -1,87 +0,0 @@
-// ARG_SETS: -debug; -o-; -debug -preview=dip1000
-// https://issues.dlang.org/show_bug.cgi?id=16492
-
-void mayCallGC();
-
-void test() @nogc pure
-{
- debug new int(1);
- debug
- {
- mayCallGC();
- auto b = [1, 2, 3];
- b ~= 4;
- }
-}
-
-void debugSafe() @safe
-{
- debug unsafeSystem();
- debug unsafeTemplated();
-}
-
-void unsafeSystem() @system {}
-void unsafeTemplated()() {
- int[] arr;
- auto b = arr.ptr;
-}
-
-void debugSafe2() @safe
-{
- char[] arr1, arr2;
- debug unsafeDIP1000Lifetime(arr1, arr2);
-
- char* ptr;
- char[] arr;
- debug ptr = arr.ptr;
-}
-
-void unsafeDIP1000Lifetime()(ref char[] p, scope char[] s)
-{
- p = s;
-}
-
-
-void test2() nothrow
-{
- debug throw new Exception("");
-}
-
-void test3() nothrow
-{
- debug {
- foreach (_; 0 .. 10) {
- if (1) {
- throw new Exception("");
- }
- }
- }
-}
-
-void test4() nothrow
-{
- debug throwException();
-}
-
-void test5() nothrow
-{
- debug willThrowException();
-}
-
-void willThrowException()()
-{
- throwException();
-}
-
-void throwException()
-{
- throw new Exception("");
-}
-
-void test6() nothrow
-{
- debug
- {
- () {throw new Exception("");}();
- }
-}
new file mode 100644
@@ -0,0 +1,68 @@
+// https://issues.dlang.org/show_bug.cgi?id=19482
+
+alias AliasSeq(T...) = T;
+
+extern (C++, "cppns")
+@("asd", 123)
+private
+deprecated
+immutable
+static foreach (i; 0 .. 1)
+{
+ static assert(is(typeof(i) == int));
+ static assert(__traits(getLinkage, i) == "D");
+ static assert(__traits(isDeprecated, i) == false);
+ static assert(__traits(getAttributes, i).length == 0);
+ static assert(__traits(getCppNamespaces, i).length == 0);
+ static assert(__traits(getVisibility, i) == "public");
+
+ extern int x;
+ static assert(is(typeof(x) == immutable int));
+ static assert(__traits(getLinkage, x) == "C++");
+ static assert(__traits(isDeprecated, x) == true);
+ static assert(__traits(getAttributes, x) == AliasSeq!("asd", 123));
+ static assert(__traits(getCppNamespaces, x) == AliasSeq!("cppns"));
+ static assert(__traits(getVisibility, x) == "private");
+}
+
+struct S
+{
+ @disable static foreach (j; 0 .. 1)
+ {
+ int y;
+ static assert(__traits(isDisabled, j) == false);
+ static assert(__traits(isDisabled, S.y) == true);
+ }
+}
+
+const
+static foreach (i, v; ['a'])
+{
+ static assert(is(typeof(i) == size_t));
+ static assert(is(typeof(v) == char));
+}
+
+const
+static foreach (i, s, f; Range())
+{
+ static assert(is(typeof(i) == int));
+ static assert(is(typeof(s) == string));
+ static assert(is(typeof(f) == float));
+}
+
+struct Range
+{
+ int i;
+ auto front()
+ {
+ return Tup!(int, string, float)(123, "asd", 3.14f);
+ }
+ bool empty() { return i > 0; }
+ void popFront() { ++i; }
+}
+
+struct Tup(T...)
+{
+ T fields;
+ alias fields this;
+}
new file mode 100644
@@ -0,0 +1,15 @@
+// https://issues.dlang.org/show_bug.cgi?id=21438
+
+int genGBPLookup() {
+ static struct Table {
+ int[1] entries;
+ }
+
+ auto table = new Table;
+ auto x = table.entries[0];
+
+ static assert(is(typeof(x) == int));
+ return 0;
+}
+
+enum x = genGBPLookup;
new file mode 100644
@@ -0,0 +1,52 @@
+// https://issues.dlang.org/show_bug.cgi?id=21794
+/*
+TEST_OUTPUT:
+---
+0
+0u
+0L
+0LU
+0.0F
+0.0
+0.0L
+---
+*/
+
+bool fun(void* p) {
+ const x = cast(ulong)p;
+ return 1;
+}
+
+static assert(fun(null));
+
+T fun2(T)(void* p) {
+ const x = cast(T)p;
+ return x;
+}
+
+// These were an error before, they were returning a NullExp instead of IntegerExp/RealExp
+
+static assert(fun2!int(null) == 0);
+static assert(fun2!uint(null) == 0);
+static assert(fun2!long(null) == 0);
+static assert(fun2!ulong(null) == 0);
+static assert(fun2!float(null) == 0);
+static assert(fun2!double(null) == 0);
+static assert(fun2!real(null) == 0);
+
+// These were printing 'null' instead of the corresponding number
+
+const i = cast(int)null;
+const ui = cast(uint)null;
+const l = cast(long)null;
+const ul = cast(ulong)null;
+const f = cast(float)null;
+const d = cast(double)null;
+const r = cast(real)null;
+pragma(msg, i);
+pragma(msg, ui);
+pragma(msg, l);
+pragma(msg, ul);
+pragma(msg, f);
+pragma(msg, d);
+pragma(msg, r);
new file mode 100644
@@ -0,0 +1,35 @@
+// https://issues.dlang.org/show_bug.cgi?id=21850
+
+struct Strukt2 {
+ this(int* _block) { }
+}
+
+struct Strukt {
+ int* block;
+ Strukt2 foo() { return Strukt2(null); }
+ alias foo this;
+}
+
+bool wrapper(T)(ref T a, ref T b)
+{
+ return doesPointTo(a, b);
+}
+
+void johan() pure {
+ Strukt a;
+ Strukt b;
+ assert(wrapper(a, b)); // error wrapper is not pure
+ assert(doesPointTo(a, b)); // fine
+}
+
+bool doesPointTo(S, T)(S , T) {
+ return false;
+}
+
+bool doesPointTo(S)(shared S) {
+ return false;
+}
+
+bool mayPointTo(){
+ return false;
+}
new file mode 100644
@@ -0,0 +1,16 @@
+// https://issues.dlang.org/show_bug.cgi?id=22214
+
+struct S
+{
+ struct T
+ {
+ }
+}
+
+void main() {
+ const S s;
+ static if (__traits(compiles, { auto t = s.T; }))
+ {
+ auto t = s.T;
+ }
+}
new file mode 100644
@@ -0,0 +1,4 @@
+// REQUIRED_ARGS: -profile -c
+
+import core.stdc.stdarg;
+void error(...) { }
new file mode 100644
@@ -0,0 +1,11 @@
+// https://issues.dlang.org/show_bug.cgi?id=22228
+// Note: fixed by reverting pull #11545
+
+auto f()
+{ immutable int i;
+ auto p = (() => &i)();
+
+ return 0;
+}
+
+enum ctfeInvocation = f;
new file mode 100644
@@ -0,0 +1,155 @@
+// https://issues.dlang.org/show_bug.cgi?id=22292
+
+// Original case
+
+class C1
+{
+ C1 c1;
+ this () pure
+ {
+ c1 = this;
+ }
+}
+immutable x = cast(immutable)r;
+
+auto r()
+{
+ C1 c1 = new C1;
+ return c1;
+}
+
+// Reference stored in another class
+
+template Test2()
+{
+ class C1
+ {
+ C2 c2;
+ this () pure
+ {
+ C1 a = this;
+ c2 = new C2(a);
+ }
+ }
+ class C2
+ {
+ C1 c1;
+ this (C1 c) pure
+ {
+ c1 = c;
+ }
+ }
+ immutable x = cast(immutable)r;
+
+ auto r()
+ {
+ C1 c1 = new C1();
+ return c1;
+ }
+}
+
+alias test2 = Test2!();
+
+// Ditto but using a struct in the middle
+
+template Test3()
+{
+ class C0
+ {
+ S1 s1;
+
+ this()
+ {
+ s1 = S1(this);
+ }
+ }
+ struct S1
+ {
+ C1 c1;
+ this (C0 c)
+ {
+ c1 = new C1(c);
+ }
+ }
+ class C1
+ {
+ C0 c0;
+ this(C0 c)
+ {
+ c0 = c;
+ }
+ }
+ immutable x = cast(immutable)r;
+
+ auto r()
+ {
+ C0 c0 = new C0();
+ return c0;
+ }
+}
+
+alias test3 = Test3!();
+
+// From https://issues.dlang.org/show_bug.cgi?id=22114
+
+template Test4()
+{
+ public class Test1(T)
+ {
+ private Test2!T val;
+
+ this()
+ {
+ val = new Test2!T(this);
+ }
+
+ private class Test2(T)
+ {
+ private Test1!(T) m_source;
+
+ this(Test1!T source)
+ {
+ m_source = source;
+ }
+ }
+ }
+
+ public class Demo
+ {
+ auto val = new Test1!int();
+ }
+}
+
+alias test4 = Test4!();
+
+// ditto
+
+template Test5()
+{
+ public @nogc class TestA(T)
+ {
+ private TestB!T valA;
+ private TestB!T valB;
+ this()
+ {
+ valB = valA = new TestB!T(this);
+ }
+
+ private @nogc class TestB(T)
+ {
+ private TestA!(T) m_source;
+
+ this(TestA!T source)
+ {
+ m_source = source;
+ }
+ }
+ }
+
+ public class Demo
+ {
+ auto val = new TestA!int();
+ }
+}
+
+alias test5 = Test5!();
new file mode 100644
@@ -0,0 +1,22 @@
+// https://issues.dlang.org/show_bug.cgi?id=22388
+
+void setTimer(void delegate()) @system;
+void setTimer(void delegate() @safe) @safe;
+
+void setTimer2(void delegate() @safe) @safe;
+void setTimer2(void delegate()) @system;
+
+void main() @safe
+{
+ setTimer(() => assert(false));
+
+ alias lambda = () => assert(false);
+ setTimer(lambda);
+
+ // Reversed order
+
+ setTimer2(() => assert(false));
+
+ alias lambda2 = () => assert(false);
+ setTimer2(lambda2);
+}
new file mode 100644
@@ -0,0 +1,59 @@
+// https://issues.dlang.org/show_bug.cgi?id=22410
+
+alias A(T...) = T;
+
+void fun0(const A!(int, string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(const int, const string)));
+}
+
+void fun1(const A!(immutable int, string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(immutable int, const string)));
+}
+
+void fun2(shared A!(int, string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(shared int, shared string)));
+}
+
+void fun3(shared const A!(int, string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(shared const int, shared const string)));
+}
+
+void fun4(inout A!(int, const string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(inout int, inout const string)));
+}
+
+void fun5(ref const A!(int, string) x = A!(1, "asdf"))
+{
+ static assert(is(typeof(x) == A!(const int, const string)));
+ static assert(__traits(isRef, x[0]) && __traits(isRef, x[1]));
+}
+
+// Implicitly conversion is also fixed, for example:
+// from (ulong, double) to (int, float)
+
+// Integral narrowing here, ulong(uint.max + 1UL) would fail.
+void fun10(A!(uint, float) x = A!(ulong(uint.max), 3.14))
+{
+ static assert(is(typeof(x) == A!(uint, float)));
+}
+
+void fun11(A!(int, double) x = A!(byte(1), 2.5f))
+{
+ static assert(is(typeof(x) == A!(int, double)));
+}
+
+void fun12(A!(byte, float) x = A!(1, 'a'))
+{
+ static assert(is(typeof(x) == A!(byte, float)));
+}
+
+A!(const int, shared char) tup = A!(1, 'a');
+void fun13(A!(byte, float) x = tup)
+{
+ static assert(is(typeof(x) == A!(byte, float)));
+}
new file mode 100644
@@ -0,0 +1,88 @@
+// https://issues.dlang.org/show_bug.cgi?id=22420
+
+struct File
+{
+ ~this()
+ {
+ }
+ File impl()
+ {
+ return File.init;
+ }
+ alias impl this;
+}
+struct Variable
+{
+ this(File)(File) { }
+ this(File)(File[]) { }
+}
+Variable wrapFunctionReturn(alias handler)(Variable params)
+{
+ return Variable(handler(params));
+}
+void registerFile()
+{
+ wrapFunctionReturn!((Variable) {
+ return File.init;
+ })(Variable.init);
+}
+
+// Reduction from an 'automem' test
+
+struct Issue156 {}
+
+void test2()
+{
+ RefCounted!Issue156 s;
+ auto r1 = repeat(s);
+ zip(r1);
+}
+
+struct RefCounted(RefCountedType)
+{
+ ~this() {}
+ alias _impl this;
+
+ struct Impl {}
+ alias ImplType = Impl;
+
+ private ImplType* _impl;
+
+}
+template Tuple(Specs)
+{
+ struct Tuple
+ {
+ this(U)(U) {}
+ this()(int) {}
+ }
+}
+
+template ElementType(R)
+{
+ static if (is(typeof(R.init) T))
+ alias ElementType = T;
+}
+
+struct Repeat(T)
+{
+ inout(T) front() inout {assert(0);}
+}
+
+Repeat!T repeat(T)(T ) {assert(0);}
+
+auto zip(Ranges)(Ranges )
+{
+ return ZipShortest!Ranges();
+}
+
+struct ZipShortest(Ranges...)
+{
+ Ranges ranges;
+ alias ElementType = Tuple!(.ElementType!(Ranges[0]));
+
+ ElementType front()
+ {
+ return typeof(return)(ranges[0].front);
+ }
+}
new file mode 100644
@@ -0,0 +1,19 @@
+// https://issues.dlang.org/show_bug.cgi?id=22421
+
+alias AliasSeq(T...) = T;
+
+template staticMap(alias fun, args...)
+{
+ alias staticMap = AliasSeq!();
+ static foreach(arg; args)
+ staticMap = AliasSeq!(staticMap, fun!arg);
+}
+
+template id(alias what)
+{
+ enum id = __traits(identifier, what);
+}
+
+enum A { a }
+
+static assert(staticMap!(id, A.a) == AliasSeq!("a"));
new file mode 100644
@@ -0,0 +1,19 @@
+// LINK:
+// PERMUTE_ARGS: -version=C_Main
+
+version (C_Main)
+{
+ // Fine, infers int
+ extern(C) auto main(int argc, const char** argv)
+ {
+ return argc;
+ }
+}
+else
+{
+ // Fine, infers void
+ auto main()
+ {
+
+ }
+}
@@ -12,9 +12,6 @@ void test4090a()
// inference + qualifier + ref
foreach ( ref x; arr) static assert(is(typeof(x) == int));
foreach ( const ref x; arr) static assert(is(typeof(x) == const int));
- static assert(!__traits(compiles, {
- foreach (immutable ref x; arr) {}
- }));
// with exact type + qualifier
foreach ( int x; arr) static assert(is(typeof(x) == int));
@@ -24,25 +21,11 @@ void test4090a()
// with exact type + qualifier + ref
foreach ( ref int x; arr) static assert(is(typeof(x) == int));
foreach ( const ref int x; arr) static assert(is(typeof(x) == const int));
- static assert(!__traits(compiles, {
- foreach (immutable ref int x; arr) {}
- }));
// convertible type + qualifier
foreach ( double x; arr) static assert(is(typeof(x) == double));
foreach ( const double x; arr) static assert(is(typeof(x) == const double));
foreach (immutable double x; arr) static assert(is(typeof(x) == immutable double));
-
- // convertible type + qualifier + ref
- static assert(!__traits(compiles, {
- foreach ( ref double x; arr) {}
- }));
- static assert(!__traits(compiles, {
- foreach ( const ref double x; arr) {}
- }));
- static assert(!__traits(compiles, {
- foreach (immutable ref double x; arr) {}
- }));
}
// for the immutable elements
{
@@ -69,9 +69,9 @@ static assert(U9766.var4.offsetof == 40);
struct TestMaxAlign
{
-align(1u << 31):
+align(1u << 15):
ubyte a;
ubyte b;
}
-static assert(TestMaxAlign.b.offsetof == 2147483648u);
+static assert(TestMaxAlign.b.offsetof == (1 << 15));
deleted file mode 100644
@@ -1,4 +0,0 @@
-// EXTRA_FILES: imports/cstuff3.c
-import imports.cstuff3;
-
-static assert(squared(4) == 16);
new file mode 100644
@@ -0,0 +1,26 @@
+// REQUIRED_ARGS: -transition=in
+/*
+TRANSFORM_OUTPUT: remove_lines(druntime)
+TEST_OUTPUT:
+---
+compilable/transition_in.d(3): Usage of 'in' on parameter
+compilable/transition_in.d(3): Usage of 'in' on parameter
+compilable/transition_in.d(8): Usage of 'in' on parameter
+compilable/transition_in.d(13): Usage of 'in' on parameter
+---
+*/
+#line 1
+struct Foobar
+{
+ void bar (in int a, in Object c);
+}
+
+version (none)
+{
+ void barfoo (in string arg);
+}
+
+void main ()
+{
+ void nested (in char c) {}
+}
@@ -1,12 +1,17 @@
extern (C) struct S { }
-static assert(S.sizeof == 0);
-static assert(S.alignof == 1);
+version (CRuntime_Microsoft)
+ static assert(S.sizeof == 4);
+else
+ static assert(S.sizeof == 0);
+
+version (CRuntime_DigitalMars)
+ static assert(S.alignof == 0);
+else
+ static assert(S.alignof == 1);
extern (C++) struct T { }
static assert(T.sizeof == 1);
static assert(T.alignof == 1);
-
-
@@ -1,7 +1,8 @@
/*
TEST_OUTPUT:
---
-fail_compilation/diag10327.d(11): Error: module `test10327` is in file 'imports/test10327.d' which cannot be read
+fail_compilation/diag10327.d(12): Error: unable to read module `test10327`
+fail_compilation/diag10327.d(12): Expected 'imports/test10327.d' or 'imports/test10327/package.d' in one of the following import paths:
import path[0] = fail_compilation
import path[1] = $p:druntime/import$
import path[2] = $p:phobos$
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
-fail_compilation/diag20059.d(15): Error: Expected return type of `string`, not `string[]`:
+fail_compilation/diag20059.d(15): Error: expected return type of `string`, not `string[]`:
fail_compilation/diag20059.d(13): Return type of `string` inferred here.
---
*/
new file mode 100644
@@ -0,0 +1,16 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail20618.d(13): Error: in slice `a[1 .. 12]`, upper bound is greater than array length `10`
+fail_compilation/fail20618.d(14): Error: in slice `a[4 .. 3]`, lower bound is greater than upper bound
+fail_compilation/fail20618.d(15): Error: in slice `a[0 .. 11]`, upper bound is greater than array length `10`
+---
+*/
+
+void main()
+{
+ int[10] a;
+ auto b = a[1..12];
+ auto c = a[4..3];
+ auto d = a[0..$ + 1];
+}
@@ -3,7 +3,8 @@
/*
TEST_OUTPUT:
----
-fail_compilation/fail21091a.d(15): Error: module `Ternary` is in file 'Ternary.d' which cannot be read
+fail_compilation/fail21091a.d(16): Error: unable to read module `Ternary`
+fail_compilation/fail21091a.d(16): Expected 'Ternary.d' or 'Ternary/package.d' in one of the following import paths:
import path[0] = fail_compilation
import path[1] = $p:druntime/import$
import path[2] = $p:phobos$
@@ -3,7 +3,8 @@
/*
TEST_OUTPUT:
----
-fail_compilation/fail21091b.d(15): Error: module `Tid` is in file 'Tid.d' which cannot be read
+fail_compilation/fail21091b.d(16): Error: unable to read module `Tid`
+fail_compilation/fail21091b.d(16): Expected 'Tid.d' or 'Tid/package.d' in one of the following import paths:
import path[0] = fail_compilation
import path[1] = $p:druntime/import$
import path[2] = $p:phobos$
@@ -18,6 +18,6 @@ struct Destructor
void test()
{
- auto a0 = Destructor;
+ auto a0 = Destructor();
testVariadic(1, a0);
}
new file mode 100644
@@ -0,0 +1,24 @@
+// https://issues.dlang.org/show_bug.cgi?id=22151
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail22151.d(14): Error: function `test` is not an lvalue and cannot be modified
+fail_compilation/fail22151.d(15): Error: function `test2` is not an lvalue and cannot be modified
+fail_compilation/fail22151.d(18): Error: function pointed to by `fp` is not an lvalue and cannot be modified
+fail_compilation/fail22151.d(21): Error: function pointed to by `ff` is not an lvalue and cannot be modified
+---
+*/
+
+void test()
+{
+ *&test = *&test;
+ *&test2 = *&test;
+
+ void function() fp;
+ *fp = *fp;
+
+ auto ff = &test2;
+ *ff = *&test2;
+}
+
+void test2();
new file mode 100644
@@ -0,0 +1,15 @@
+// REQUIRED_ARGS: -dip1000
+
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail22366.d(13): Error: scope variable `__aaval2` assigned to non-scope `aa[0]`
+---
+*/
+
+int* fun(scope int* x) @safe
+{
+ int*[int] aa;
+ aa[0] = x; // should give an error
+ return aa[0];
+}
deleted file mode 100644
@@ -1,17 +0,0 @@
-/*
-TEST_OUTPUT:
----
-fail_compilation/fail225.d(15): Error: cannot implicitly convert expression `1` of type `int` to `immutable(char*)`
-fail_compilation/fail225.d(15): Error: cannot implicitly convert expression `& ch` of type `char*` to `immutable(char*)`
----
-*/
-struct Struct {
- char* chptr;
-}
-
-void main()
-{
- char ch = 'd';
- immutable Struct iStruct = {1, &ch};
-}
-
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
-fail_compilation/fail287.d(14): Error: had 299 cases which is more than 256 cases in case range
+fail_compilation/fail287.d(14): Error: had 300 cases which is more than 257 cases in case range
---
*/
deleted file mode 100644
@@ -1,8 +0,0 @@
-/*
-TEST_OUTPUT:
----
-fail_compilation/fail318.d(8): Error: function `D main` must return `int` or `void`
----
-*/
-
-auto main() { }
new file mode 100644
@@ -0,0 +1,11 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail318_b.d(8): Error: function `D main` must return `int`, `void` or `noreturn`, not `string`
+---
+*/
+
+auto main()
+{
+ return "";
+}
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
-fail_compilation/fail7173.d(23): Error: cannot implicitly convert expression `b1._a.opBinary(b2._a).fun()` of type `void` to `B`
+fail_compilation/fail7173.d(23): Error: expression `b1._a.opBinary(b2._a).fun()` is `void` and has no value
---
*/
struct A{
new file mode 100644
@@ -0,0 +1,14 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/foreach.d(12): Error: cannot declare `out` loop variable, use `ref` instead
+fail_compilation/foreach.d(13): Error: cannot declare `out` loop variable, use `ref` instead
+fail_compilation/foreach.d(13): Error: cannot declare `out` loop variable, use `ref` instead
+---
+*/
+void main ()
+{
+ int[] array;
+ foreach (out val; array) {}
+ foreach (out idx, out val; array) {}
+}
new file mode 100644
@@ -0,0 +1,22 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/foreach2.d(15): Error: argument type mismatch, `int` to `ref immutable(int)`
+fail_compilation/foreach2.d(16): Error: argument type mismatch, `int` to `ref immutable(int)`
+fail_compilation/foreach2.d(19): Error: argument type mismatch, `int` to `ref double`
+fail_compilation/foreach2.d(20): Error: argument type mismatch, `int` to `ref const(double)`
+fail_compilation/foreach2.d(21): Error: argument type mismatch, `int` to `ref immutable(double)`
+---
+*/
+void test4090 ()
+{
+ // From https://issues.dlang.org/show_bug.cgi?id=4090
+ int[] arr = [1,2,3];
+ foreach (immutable ref x; arr) {}
+ foreach (immutable ref int x; arr) {}
+
+ // convertible type + qualifier + ref
+ foreach ( ref double x; arr) {}
+ foreach ( const ref double x; arr) {}
+ foreach (immutable ref double x; arr) {}
+}
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
-fail_compilation/ice10212.d(13): Error: Expected return type of `int`, not `int function() pure nothrow @nogc @safe`:
+fail_compilation/ice10212.d(13): Error: expected return type of `int`, not `int function() pure nothrow @nogc @safe`:
fail_compilation/ice10212.d(13): Return type of `int` inferred here.
---
*/
new file mode 100644
@@ -0,0 +1,8 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/ice22377.d(8): Error: Internal Compiler Error: type `string` cannot be mapped to C++
+---
+*/
+
+extern(C++) void foo(string a) {}
@@ -2,7 +2,8 @@
EXTRA_FILES: imports/ice7782algorithm.d imports/ice7782range.d
TEST_OUTPUT:
----
-fail_compilation/ice7782.d(13): Error: module `ice7782math` is in file 'imports/ice7782range/imports/ice7782math.d' which cannot be read
+fail_compilation/ice7782.d(14): Error: unable to read module `ice7782math`
+fail_compilation/ice7782.d(14): Expected 'imports/ice7782range/imports/ice7782math.d' or 'imports/ice7782range/imports/ice7782math/package.d' in one of the following import paths:
import path[0] = fail_compilation
import path[1] = $p:druntime/import$
import path[2] = $p:phobos$
new file mode 100644
@@ -0,0 +1,4 @@
+void func(T)(T arg)
+{
+ auto a = arg + 1;
+}
@@ -72,7 +72,7 @@ noreturn casting(int i)
return cast() n;
}
}
-
+ assert(false);
}
enum forceCasting0 = casting(0);
new file mode 100644
@@ -0,0 +1,90 @@
+/*
+REQUIRED_ARGS: -w -o-
+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(18): Error: expected return type of `noreturn`, not `void`
+---
+
+https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
+*/
+
+alias noreturn = typeof(*null);
+
+void doStuff();
+
+noreturn returnVoid()
+{
+ return doStuff();
+}
+
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(37): Error: expected return type of `int`, not `string`:
+fail_compilation/noreturn2.d(35): Return type of `int` inferred here.
+---
++/
+
+auto missmatch(int i)
+{
+ if (i < 0)
+ return assert(false);
+ if (i == 0)
+ return i;
+ if (i > 0)
+ return "";
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(50): Error: function `noreturn2.returns` is typed as `NR` but does return
+fail_compilation/noreturn2.d(50): `noreturn` functions must either throw, abort or loop indefinitely
+---
++/
+
+enum NR : noreturn;
+
+NR returns()
+{
+ // Fallthrough despite noreturn
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(64): Error: cannot implicitly convert expression `1` of type `int` to `noreturn`
+---
++/
+
+noreturn returnsValue()
+{
+ return 1;
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(75): Error: expected return type of `int`, not `void`
+---
++/
+int returnVoid2()
+{
+ return doStuff();
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(89): Error: mismatched function return type inference of `void` and `int`
+---
++/
+auto returnVoid3(int i)
+{
+ if (i > 0)
+ return i;
+ else
+ return doStuff();
+}
@@ -113,6 +113,8 @@ fail_compilation/reserved_version.d(214): Error: version identifier `CppRuntime_
fail_compilation/reserved_version.d(215): Error: version identifier `CppRuntime_Sun` is reserved and cannot be set
fail_compilation/reserved_version.d(216): Error: version identifier `D_PIE` is reserved and cannot be set
fail_compilation/reserved_version.d(217): Error: version identifier `AVR` is reserved and cannot be set
+fail_compilation/reserved_version.d(218): Error: version identifier `D_PreConditions` is reserved and cannot be set
+fail_compilation/reserved_version.d(219): Error: version identifier `D_PostConditions` is reserved and cannot be set
---
*/
@@ -232,6 +234,8 @@ version = CppRuntime_Microsoft;
version = CppRuntime_Sun;
version = D_PIE;
version = AVR;
+version = D_PreConditions;
+version = D_PostConditions;
// This should work though
debug = DigitalMars;
@@ -340,3 +344,5 @@ debug = none;
debug = D_P16;
debug = MSP430;
debug = AVR;
+debug = D_PreConditions;
+debug = D_PostConditions;
@@ -103,6 +103,8 @@
// REQUIRED_ARGS: -version=assert
// REQUIRED_ARGS: -version=all
// REQUIRED_ARGS: -version=none
+// REQUIRED_ARGS: -version=D_PreConditions
+// REQUIRED_ARGS: -version=D_PostConditions
// REQUIRED_ARGS: -debug=DigitalMars
// REQUIRED_ARGS: -debug=GNU
// REQUIRED_ARGS: -debug=LDC
@@ -203,6 +205,8 @@
// REQUIRED_ARGS: -debug=assert
// REQUIRED_ARGS: -debug=all
// REQUIRED_ARGS: -debug=none
+// REQUIRED_ARGS: -debug=D_PreConditions
+// REQUIRED_ARGS: -debug=D_PostConditions
/*
TEST_OUTPUT:
---
@@ -309,5 +313,7 @@ Error: version identifier `unittest` is reserved and cannot be set
Error: version identifier `assert` is reserved and cannot be set
Error: version identifier `all` is reserved and cannot be set
Error: version identifier `none` is reserved and cannot be set
+Error: version identifier `D_PreConditions` is reserved and cannot be set
+Error: version identifier `D_PostConditions` is reserved and cannot be set
---
*/
@@ -1,7 +1,7 @@
/* TEST_OUTPUT:
---
fail_compilation/test17425.d(24): Error: parameter index must be in range 0..4 not 4
-fail_compilation/test17425.d(27): Error: first argument to `__traits(getParameterStorageClasses, i, 4)` is not a function
+fail_compilation/test17425.d(27): Error: first argument to `__traits(getParameterStorageClasses, i, 4)` is not a function or a function call
fail_compilation/test17425.d(29): Error: expression expected as second argument of `__traits(getParameterStorageClasses, foo, int)`
fail_compilation/test17425.d(31): Error: expected 2 arguments for `getParameterStorageClasses` but had 3
---
@@ -1,9 +1,9 @@
/*
TEST_OUTPUT:
----
+fail_compilation/test17868b.d(9): Error: pragma `crt_constructor` can only apply to a single declaration
fail_compilation/test17868b.d(10): Error: function `test17868b.foo` must be `extern(C)` for `pragma(crt_constructor)`
fail_compilation/test17868b.d(14): Error: function `test17868b.bar` must be `extern(C)` for `pragma(crt_constructor)`
-fail_compilation/test17868b.d(9): Error: pragma `crt_constructor` can only apply to a single declaration
----
*/
pragma(crt_constructor):
new file mode 100644
@@ -0,0 +1,120 @@
+// https://issues.dlang.org/show_bug.cgi?id=20998
+/*
+REQUIRED_ARGS: -verrors=context
+TEST_OUTPUT:
+---
+fail_compilation/test20998.d(76): Error: undefined identifier `invalid`
+X x = { invalid, 2, "asd" };
+ ^
+fail_compilation/test20998.d(76): Error: too many initializers for `X`
+X x = { invalid, 2, "asd" };
+ ^
+fail_compilation/test20998.d(83): Error: cannot implicitly convert expression `"a"` of type `string` to `int`
+X2 x2 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(83): Error: duplicate initializer for field `ptr`
+X2 x2 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(83): Error: too many initializers for `X2`
+X2 x2 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(90): Error: overlapping initialization for field `ptr` and `x`
+X3 x3 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(90): Error: cannot implicitly convert expression `"a"` of type `string` to `int`
+X3 x3 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(90): Error: duplicate initializer for field `ptr`
+X3 x3 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(90): Error: too many initializers for `X3`
+X3 x3 = { ptr: null, "a", ptr: 2, 444 };
+ ^
+fail_compilation/test20998.d(98): Error: field `X4.ptr` cannot assign to misaligned pointers in `@safe` code
+ X4 x4 = { ptr: null, "a", 444, ptr: 2, true };
+ ^
+fail_compilation/test20998.d(98): Error: cannot implicitly convert expression `"a"` of type `string` to `int`
+ X4 x4 = { ptr: null, "a", 444, ptr: 2, true };
+ ^
+fail_compilation/test20998.d(98): Error: too many initializers for `X4`
+ X4 x4 = { ptr: null, "a", 444, ptr: 2, true };
+ ^
+fail_compilation/test20998.d(102): called from here: `test()`
+auto e = test();
+ ^
+fail_compilation/test20998.d(104): Error: cannot implicitly convert expression `1` of type `int` to `void*`
+X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 };
+ ^
+fail_compilation/test20998.d(104): Error: duplicate initializer for field `ptr`
+X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 };
+ ^
+fail_compilation/test20998.d(104): Error: duplicate initializer for field `ptr`
+X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 };
+ ^
+fail_compilation/test20998.d(104): Error: too many initializers for `X2`
+X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 };
+ ^
+fail_compilation/test20998.d(107): Error: too many initializers for `X2`
+X2 c6 = { null, 2, true, null };
+ ^
+fail_compilation/test20998.d(116): Error: cannot implicitly convert expression `1` of type `int` to `immutable(char*)`
+ immutable Struct iStruct = {1, &ch};
+ ^
+fail_compilation/test20998.d(116): Error: too many initializers for `Struct`
+ immutable Struct iStruct = {1, &ch};
+ ^
+fail_compilation/test20998.d(120): called from here: `test2()`
+auto t = test2();
+ ^
+---
+*/
+
+struct X {
+ void* ptr;
+ int x;
+}
+X x = { invalid, 2, "asd" };
+
+struct X2 {
+ void* ptr;
+ int x;
+ bool y;
+}
+X2 x2 = { ptr: null, "a", ptr: 2, 444 };
+
+union X3 {
+ void* ptr;
+ int x;
+ bool y;
+}
+X3 x3 = { ptr: null, "a", ptr: 2, 444 };
+
+int test() @safe
+{
+ align (1) struct X4 {
+ void* ptr;
+ int x;
+ }
+ X4 x4 = { ptr: null, "a", 444, ptr: 2, true };
+ return 0;
+}
+
+auto e = test();
+
+X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 };
+X2 b5 = { ptr: null, y: true };
+X2 c5 = { x: 2, true, ptr: null };
+X2 c6 = { null, 2, true, null };
+
+struct Struct {
+ char* chptr;
+}
+
+int test2()
+{
+ char ch = 'd';
+ immutable Struct iStruct = {1, &ch};
+ return 0;
+}
+
+auto t = test2();
new file mode 100644
@@ -0,0 +1,56 @@
+// https://issues.dlang.org/show_bug.cgi?id=21093
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21093.d(24): Error: function `test21093.LocalTime.hasDST` does not override any function
+fail_compilation/test21093.d(32): Error: class `test21093.LocalTime2` cannot implicitly generate a default constructor when base class `test21093.TimeZone2` is missing a default constructor
+fail_compilation/test21093.d(44): Error: function `test21093.LocalTime3.string` does not override any function
+fail_compilation/test21093.d(55): Error: cannot implicitly override base class method `test21093.TimeZone4.hasDST` with `test21093.LocalTime4.hasDST`; add `override` attribute
+---
+*/
+
+void fromUnixTime(immutable TimeZone tz = LocalTime()) { }
+void fromUnixTime(immutable TimeZone2 tz = LocalTime2()) { }
+void fromUnixTime(immutable TimeZone3 tz = LocalTime3()) { }
+void fromUnixTime(immutable TimeZone4 tz = LocalTime4()) { }
+
+class TimeZone
+{
+}
+
+class LocalTime : TimeZone
+{
+ static immutable(LocalTime) opCall() { }
+ override hasDST() { }
+}
+
+class TimeZone2
+{
+ this(string) { }
+}
+
+class LocalTime2 : TimeZone2
+{
+ static immutable(LocalTime2) opCall() { }
+}
+
+class TimeZone3
+{
+}
+
+class LocalTime3 : TimeZone3
+{
+ static immutable(LocalTime3) opCall() { }
+ override string () { }
+}
+
+class TimeZone4
+{
+ bool hasDST();
+}
+
+class LocalTime4 : TimeZone4
+{
+ static immutable(LocalTime4) opCall() { }
+ bool hasDST() { }
+}
new file mode 100644
@@ -0,0 +1,46 @@
+// https://issues.dlang.org/show_bug.cgi?id=21380
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21380.d(39): Error: partial template instance `MySerializer().serializeSinkType!int` has no value
+fail_compilation/test21380.d(44): Error: template instance `test21380.SupportSinkTypeSer!(MySerializer!int)` error instantiating
+---
+*/
+
+template isSomeFunction(T...)
+if (T.length == 1)
+{
+ static if (is(typeof(& T[0]) U : U*) && is(U == function) || is(typeof(& T[0]) U == delegate))
+ {
+ // T is a (nested) function symbol.
+ enum bool isSomeFunction = true;
+ }
+ else static if (is(T[0] W) || is(typeof(T[0]) W))
+ {
+ // T is an expression or a type. Take the type of it and examine.
+ static if (is(W F : F*) && is(F == function))
+ enum bool isSomeFunction = true; // function pointer
+ else
+ enum bool isSomeFunction = is(W == function) || is(W == delegate);
+ }
+ else
+ enum bool isSomeFunction = false;
+}
+
+struct MySerializer (T)
+{
+ void serializeSinkType(T2) (scope auto ref T2 record) {}
+}
+
+template SupportSinkTypeSer(SerT)
+{
+ /* Note: Partial template instance because it needs inference, in this case
+ it cannot infer 'auto ref' parameter */
+ enum SupportSinkTypeSer = isSomeFunction!(SerT.init.serializeSinkType!int);
+}
+
+int main()
+{
+ enum x = SupportSinkTypeSer!(MySerializer!int);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,27 @@
+// https://issues.dlang.org/show_bug.cgi?id=21930
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21930.d(21): Error: variable `string` is used as a type
+fail_compilation/test21930.d(15): variable `string` is declared here
+fail_compilation/test21930.d(26): Error: constructor `test21930.R.this(string)` is not callable using argument types `()`
+---
+*/
+
+alias AliasSeq(T...) = T;
+
+alias TP(alias name) = AliasSeq!name;
+
+int string; // 'string' declared as a variable
+
+alias a = TP!(main);
+
+class R
+{
+ this(string) { } // so constructor have errors
+}
+
+@system main()
+{
+ new R;
+}
new file mode 100644
@@ -0,0 +1,21 @@
+// https://issues.dlang.org/show_bug.cgi?id=22329
+// EXTRA_FILES: imports/imp22329.d
+/*
+TEST_OUTPUT:
+---
+fail_compilation/imports/imp22329.d(3): Error: no property `values` for type `test22329.Foo`
+fail_compilation/imports/imp22329.d(3): Error: incompatible types for `(arg) + (1)`: `Foo` and `int`
+fail_compilation/test22329.d(20): Error: template instance `imp22329.func!(Foo)` error instantiating
+---
+*/
+
+public struct Foo {
+ private int values;
+ alias values this;
+}
+
+void main()
+{
+ import imports.imp22329 : func;
+ func(Foo());
+}
new file mode 100644
@@ -0,0 +1,11 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test22361.d(11): Error: unable to read module `this_module_does_not_exist`
+fail_compilation/test22361.d(11): Expected 'this_module_does_not_exist.d' or 'this_module_does_not_exist/package.d' in one of the following import paths:
+import path[0] = fail_compilation
+import path[1] = $p:druntime/import$
+import path[2] = $p:phobos$
+---
+*/
+import this_module_does_not_exist;
new file mode 100644
@@ -0,0 +1,161 @@
+/+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(27): Error: `testOpApply.SameAttr.opApply` called with argument types `(int delegate(int i) pure nothrow @nogc @safe)` matches both:
+fail_compilation/testOpApply.d(13): `testOpApply.SameAttr.opApply(int delegate(int) @system dg)`
+and:
+fail_compilation/testOpApply.d(18): `testOpApply.SameAttr.opApply(int delegate(int) @system dg)`
+---
++/
+
+struct SameAttr
+{
+ int opApply(int delegate(int) @system dg) @system
+ {
+ return 0;
+ }
+
+ int opApply(int delegate(int) @system dg) @safe
+ {
+ return 0;
+ }
+}
+
+void testSameAttr() @safe
+{
+ SameAttr sa;
+ foreach (int i; sa) {}
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(104): Error: `testOpApply.SameAttr.opApply` called with argument types `(int delegate(int i) pure nothrow @nogc @system)` matches both:
+fail_compilation/testOpApply.d(13): `testOpApply.SameAttr.opApply(int delegate(int) @system dg)`
+and:
+fail_compilation/testOpApply.d(18): `testOpApply.SameAttr.opApply(int delegate(int) @system dg)`
+---
++/
+#line 100
+
+void testSameAttr() @system
+{
+ SameAttr sa;
+ foreach (int i; sa) {}
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(217): Error: `sa.opApply` matches more than one declaration:
+`fail_compilation/testOpApply.d(203)`: `int(int delegate(int) dg)`
+and:
+`fail_compilation/testOpApply.d(208)`: `int(int delegate(string) dg)`
+fail_compilation/testOpApply.d(217): Error: cannot uniquely infer `foreach` argument types
+---
++/
+#line 200
+
+struct DifferentTypes
+{
+ int opApply(int delegate(int) dg)
+ {
+ return 0;
+ }
+
+ int opApply(int delegate(string) dg)
+ {
+ return 0;
+ }
+}
+
+void testDifferentTypes()
+{
+ DifferentTypes sa;
+ foreach (i; sa) {}
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(317): Error: `sa.opApply` matches more than one declaration:
+`fail_compilation/testOpApply.d(303)`: `int(int delegate(int) dg)`
+and:
+`fail_compilation/testOpApply.d(308)`: `int(int delegate(long) dg)`
+fail_compilation/testOpApply.d(317): Error: cannot uniquely infer `foreach` argument types
+---
++/
+#line 300
+
+struct CovariantTypes
+{
+ int opApply(int delegate(int) dg)
+ {
+ return 0;
+ }
+
+ int opApply(int delegate(long) dg)
+ {
+ return 0;
+ }
+}
+
+void testCovariantTypes()
+{
+ CovariantTypes sa;
+ foreach (i; sa) {}
+}
+
+/+
+See https://issues.dlang.org/show_bug.cgi?id=21683
+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(420): Error: `sa.opApply` matches more than one declaration:
+`fail_compilation/testOpApply.d(404)`: `int(int delegate(int) dg)`
+and:
+`fail_compilation/testOpApply.d(410)`: `int(int delegate(ref int) dg)`
+fail_compilation/testOpApply.d(420): Error: cannot uniquely infer `foreach` argument types
+---
++/
+#line 400
+
+struct DifferentQualifiers
+{
+ int x;
+ int opApply(int delegate(int) dg)
+ {
+ x = 1;
+ return 0;
+ }
+
+ int opApply(int delegate(ref int) dg)
+ {
+ x = 2;
+ return 0;
+ }
+}
+
+void testDifferentQualifiers()
+{
+ DifferentQualifiers sa;
+ foreach (i; sa) {}
+}
+
+/+
+TEST_OUTPUT:
+---
+fail_compilation/testOpApply.d(504): Error: `sa.opApply` matches more than one declaration:
+`fail_compilation/testOpApply.d(404)`: `int(int delegate(int) dg)`
+and:
+`fail_compilation/testOpApply.d(410)`: `int(int delegate(ref int) dg)`
+fail_compilation/testOpApply.d(504): Error: cannot uniquely infer `foreach` argument types
+---
++/
+#line 500
+
+void testDifferentQualifiersRef()
+{
+ DifferentQualifiers sa;
+ foreach (ref i; sa) {}
+}
@@ -2102,6 +2102,42 @@ void test16633()
root.populate;
}
+/***************************************************/
+// https://issues.dlang.org/show_bug.cgi?id=13009
+
+struct RefCounted13009_2(T)
+{
+ ref T refCountedPayload()
+ {
+ assert(false);
+ }
+
+ ref inout(T) refCountedPayload() inout
+ {
+ assert(false);
+ }
+
+ alias refCountedPayload this;
+}
+
+struct S13009_2
+{
+ struct Payload
+ {
+ int[] data;
+ }
+
+ RefCounted13009_2!Payload payload;
+ alias X = typeof(payload.data[0]);
+
+ void foo()
+ {
+ payload.data[0] = 0;
+ }
+}
+
+/***************************************************/
+
int main()
{
test1();
@@ -929,3 +929,19 @@ version (NetBSD)
return q;
}
}
+
+version (OpenBSD)
+{
+ 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;
+ }
+}
new file mode 100644
@@ -0,0 +1,38 @@
+/* PERMUTE_ARGS: -O
+ */
+
+// https://issues.dlang.org/show_bug.cgi?id=22104
+
+struct S { int a1, a2, a3; }
+
+version (none)
+void throws2ndCall(ref S x);
+else
+{
+void throws2ndCall(ref S x)
+{
+ __gshared bool b;
+ if (b)
+ throw new Exception("n == 1");
+ b = true;
+}
+}
+
+void main() { foo(); }
+
+void foo()
+{
+ S[] arr = [S(), S()];
+ size_t i;
+ try
+ {
+ for (i = 0; i < 2; i++)
+ throws2ndCall(arr[i]);
+ }
+ catch (Exception o)
+ {
+ //printf("Exception: i = %lu\n", i);
+ assert(i == 1); // this fails
+ }
+}
+
@@ -3604,6 +3604,62 @@ void test21878()
ctfeFunc21878(); // succeeds at runtime
}
+/************************************************/
+// https://issues.dlang.org/show_bug.cgi?id=20133
+
+void bar20133(ref string text)
+{
+ text = text[1 .. $];
+ assert(text.length < 3);
+ if (text.length == 2) assert(text == "oo");
+ if (text.length == 1) assert(text == "o");
+ if (text.length == 0) assert(text == "");
+ string tcopy = text;
+ if (tcopy.length > 0)
+ bar20133(tcopy);
+ assert(tcopy.length < 2);
+ if (tcopy.length == 1) assert(tcopy == "o");
+ if (tcopy.length == 0) assert(tcopy == "");
+}
+
+void bar20133_2(ref string text)
+{
+ auto ptext = &text;
+ *ptext = text[1 .. $];
+ assert(text.length < 3);
+ if (text.length == 2) assert(text == "oo");
+ if (text.length == 1) assert(text == "o");
+ if (text.length == 0) assert(text == "");
+ string tcopy = text;
+ if (tcopy.length > 0)
+ bar20133_2(tcopy);
+ assert(tcopy.length < 2);
+ if (tcopy.length == 1) assert(tcopy == "o");
+ if (tcopy.length == 0) assert(tcopy == "");
+}
+
+alias fun20133 = {
+ string input = "foo";
+ bar20133(input);
+ assert(input == "oo");
+ return input;
+};
+
+alias fun20133_2 = {
+ string input = "foo";
+ bar20133_2(input);
+ assert(input == "oo");
+ return input;
+};
+
+void test20133()
+{
+ enum ctest = fun20133();
+ enum ctest2 = fun20133_2();
+ auto rtest = fun20133();
+ auto rtest2 = fun20133_2();
+}
+
/************************************************/
int main()
@@ -3732,6 +3788,7 @@ int main()
test20366();
test20400();
test21878();
+ test20133();
printf("Success\n");
return 0;
@@ -66,9 +66,56 @@ void test2()
/*****************************************/
+struct BasicStruct
+{
+ int firstInt;
+ noreturn noRet;
+ long lastLong;
+}
+
+struct AlignedStruct
+{
+ int firstInt;
+ align(16) noreturn noRet;
+ long lastLong;
+}
+
+void takeBasic(BasicStruct bs)
+{
+ assert(bs.firstInt == 13);
+ assert(bs.lastLong == 42);
+
+ assert(&bs.noRet == (&bs.firstInt + 1));
+}
+
+void takeAligned(AlignedStruct as)
+{
+ assert(as.firstInt == 99);
+ assert(as.lastLong == 0xDEADBEEF);
+
+ assert(&as.noRet == &as.lastLong);
+}
+
+void test3()
+{
+ {
+ BasicStruct bs;
+ bs.firstInt = 13;
+ bs.lastLong = 42;
+ takeBasic(bs);
+ }
+ {
+ AlignedStruct as;
+ as.firstInt = 99;
+ as.lastLong = 0xDEADBEEF;
+ takeAligned(as);
+ }
+}
+
int main()
{
test1();
test2();
+ test3();
return 0;
}
new file mode 100644
@@ -0,0 +1,220 @@
+/*
+PERMUTE_ARGS: -O -inline
+RUN_OUTPUT:
+---
+getAndPrintS
+---
+*/
+
+import core.stdc.stdio;
+import core.exception : AssertError;
+
+/*****************************************/
+
+// noreturn is inferred for functions that always throw
+// The code must not strip the destructor when calling a noreturn function
+
+struct WithDtor
+{
+ __gshared int destroyed;
+
+ int num;
+
+ int acceptNoreturn(int a, int b, int c)
+ {
+ puts("unreachable");
+ return num + a + b + c;
+ }
+
+ ~this()
+ {
+ destroyed += num;
+ }
+}
+
+noreturn doesThrow()
+{
+ WithDtor wd = WithDtor(1);
+ throw new Exception("");
+}
+
+noreturn callDoesThrow()
+{
+ WithDtor wd = WithDtor(2);
+ doesThrow();
+}
+
+
+void testDtors()
+{
+ try
+ {
+ callDoesThrow();
+ assert(0);
+ } catch (Exception e) {}
+
+ assert(WithDtor.destroyed == 3);
+}
+
+/*****************************************************************************/
+
+/// Verifies that `func` throws a `Throwable` with `message` at `line`
+void testAssertFailure(size_t expLine, string expMsg, void function() func, size_t callLine = __LINE__)
+{
+ void enforce(bool check, string error)
+ {
+ if (!check)
+ throw new AssertError(error, __FILE__, callLine);
+ }
+
+ bool caught;
+ try
+ {
+ func();
+ }
+ catch (Throwable t)
+ {
+ // Save members because t might be overwritten by an Assertion failure below
+ string actFile = t.file;
+ size_t actLine = t.line;
+ string actMsg = t.msg;
+ caught = true;
+
+ scope (failure)
+ {
+ printf("\nfile = \"%.*s\"\nline = %zu\nmsg = \"%.*s\"\n\n",
+ cast(int) actFile.length, actFile.ptr,
+ actLine,
+ cast(int) actMsg.length, actMsg.ptr
+ );
+ fflush(stdout);
+ }
+
+ enforce(actFile == __FILE__, "Wrong file");
+ enforce(actLine == expLine, "Wrong line");
+ enforce(actMsg == expMsg, "Wrong message");
+ }
+
+ enforce(caught, "No Throwable was thrown!");
+}
+
+void testAccess()
+{
+ enum msg = "Accessed expression of type `noreturn`";
+
+ // FIXME: Another assertion failure in the backend trying to generate noreturn.sizeof = 0 byte assignment
+ version (FIXME)
+ testAssertFailure(__LINE__ + 3, msg, function noreturn()
+ {
+ noreturn a;
+ noreturn b = a;
+ });
+
+ if (false) // read does not assert!
+ testAssertFailure(__LINE__ + 3, msg, function noreturn()
+ {
+ noreturn a;
+ int b = a;
+ assert(false, "Unreachable!"); // Statement above not detected as noreturn
+ });
+
+ testAssertFailure(__LINE__ + 2, msg, function noreturn()
+ {
+ cast(noreturn) 1;
+ });
+
+ version (FIXME)
+ testAssertFailure(__LINE__ + 3, msg, function noreturn()
+ {
+ noreturn a;
+ noreturn b = cast(noreturn) 1;
+ });
+
+ if (false) // Read does not assert
+ testAssertFailure(__LINE__ + 3, msg, function noreturn()
+ {
+ noreturn a;
+ return a;
+ });
+
+ if (false) // Read does not assert
+ testAssertFailure(__LINE__ + 4, msg, function noreturn()
+ {
+ static void foo(noreturn) {}
+ noreturn a;
+ foo(a);
+ assert(false, "Unreachable!"); // Ditto
+ });
+}
+
+/*****************************************/
+
+void testFuncCall()
+{
+ enum msg = "Called abort()";
+ enum line = __LINE__ + 1;
+ static noreturn abort() { assert(0, msg); }
+
+ // Canaries to check for side effects
+ __gshared int countLeft, countRight;
+
+ scope (failure) printf("countLeft = %d\ncountRight = %d\n", countLeft, countRight);
+
+
+ // D function arguments are evaluated left to right
+ testAssertFailure(line, msg, function()
+ {
+ static void acceptNoreturnD(int, int, int) { puts("unreachable"); }
+
+ acceptNoreturnD(countLeft++, abort(), countRight++);
+ });
+
+ assert(countLeft == 1);
+ assert(countRight == 0);
+
+// // C function arguments are still evaluated left to right
+// // Despite them being push in reverse order
+ testAssertFailure(line, msg, function()
+ {
+ static extern(C) void acceptNoreturnC(int, int, int) { puts("unreachable"); }
+
+ acceptNoreturnC(countLeft++, abort(), countRight++);
+
+ assert(false);
+ });
+
+ assert(countLeft == 2);
+ assert(countRight == 0);
+
+ WithDtor.destroyed = 0;
+
+ testAssertFailure(__LINE__ + 2, "Error", function()
+ {
+ static WithDtor getS() { assert(false, "Error"); }
+
+ getS().acceptNoreturn(countLeft++, abort(), countRight++);
+ });
+
+ assert(countLeft == 2); // No changes
+ assert(countRight == 0);
+ assert(WithDtor.destroyed == 0); // No temporary to destruct
+
+ testAssertFailure(line, msg, function()
+ {
+ static WithDtor getAndPrintS() { puts("getAndPrintS"); return WithDtor(1); }
+
+ getAndPrintS().acceptNoreturn(countLeft++, abort(), countRight++);
+ });
+
+ assert(countLeft == 3);
+ assert(countRight == 0);
+ assert(WithDtor.destroyed == 1);
+}
+
+int main()
+{
+ testDtors();
+ testAccess();
+ testFuncCall();
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,103 @@
+/* REQUIRED_ARGS: -O -inline -noboundscheck
+ */
+// https://github.com/dlang/pull/13220
+
+version (D_SIMD)
+{
+
+mixin template VectorOps(VectorType, ArrayType: BaseType[N], BaseType, size_t N)
+{
+ enum Count = N;
+ alias Base = BaseType;
+
+ BaseType* ptr() return pure nothrow @nogc
+ {
+ return array.ptr;
+ }
+
+ // Unary operators
+ VectorType opUnary(string op)() pure nothrow @safe @nogc
+ {
+ VectorType res = void;
+ mixin("res.array[] = " ~ op ~ "array[];");
+ return res;
+ }
+
+ // Binary operators
+ VectorType opBinary(string op)(VectorType other) pure const nothrow @safe @nogc
+ {
+ VectorType res = void;
+ mixin("res.array[] = array[] " ~ op ~ " other.array[];");
+ return res;
+ }
+
+ // Assigning a BaseType value
+ void opAssign(BaseType e) pure nothrow @safe @nogc
+ {
+ array[] = e;
+ }
+
+ // Assigning a static array
+ void opAssign(ArrayType v) pure nothrow @safe @nogc
+ {
+ array[] = v[];
+ }
+
+ void opOpAssign(string op)(VectorType other) pure nothrow @safe @nogc
+ {
+ mixin("array[] " ~ op ~ "= other.array[];");
+ }
+
+ // Assigning a dyn array
+ this(ArrayType v) pure nothrow @safe @nogc
+ {
+ array[] = v[];
+ }
+
+ // Broadcast constructor
+ this(BaseType x) pure nothrow @safe @nogc
+ {
+ array[] = x;
+ }
+
+ ref inout(BaseType) opIndex(size_t i) inout pure nothrow @safe @nogc
+ {
+ return array[i];
+ }
+}
+
+// Note: can't be @safe with this signature
+Vec loadUnaligned(Vec)(const(BaseType!Vec)* pvec) @trusted
+{
+ // Since this vector is emulated, it doesn't have alignement constraints
+ // and as such we can just cast it.
+ return *cast(Vec*)(pvec);
+}
+
+private template BaseType(V)
+{
+ alias typeof( ( { V v; return v; }()).array[0]) BaseType;
+}
+
+struct int4
+{
+ int[4] array;
+ mixin VectorOps!(int4, int[4]);
+}
+
+alias __m128i = int4;
+}
+
+int main()
+{
+ version (D_SIMD)
+ {
+ int4 A = [1, 2, 3, 4];
+ int4 ia = A;
+ ia.ptr[2] = 5;
+ int4 C = ia;
+ int[4] result = [1, 2, 5, 4];
+ assert(C.array == result);
+ }
+ return 0;
+}
deleted file mode 100644
@@ -1,51 +0,0 @@
-/* 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;
-}
new file mode 100644
@@ -0,0 +1,27 @@
+// https://issues.dlang.org/show_bug.cgi?id=21039
+
+class Inner {}
+
+class Outer {
+ Inner inner;
+ alias inner this;
+ this(Inner i) { inner = i; }
+}
+
+void main() {
+ auto inner = new Inner;
+ auto outer = new Outer(new Inner);
+
+ // implicit cast goes through 'alias this'
+
+ Inner inner1 = outer; // Already does it
+ assert(inner1);
+
+ Inner[] inners = [inner, outer]; // Fixed
+
+ assert(inners[0], "first element is null");
+ assert(inners[1], "second element is null");
+
+ Inner inner2 = 1 ? outer : inner; // Fixed
+ assert(inner2);
+}
new file mode 100644
@@ -0,0 +1,17 @@
+// REQUIRED_ARGS: -debug
+
+void main() nothrow
+{
+ debug
+ {
+ try
+ {
+ throw new Exception("2");
+ }
+ catch (Exception) {}
+ catch (Throwable)
+ {
+ assert(0);
+ }
+ }
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+REQUIRED_ARGS: -release
+PERMUTE_ARGS: -check=in=on -check=out=on
+*/
+
+// https://issues.dlang.org/show_bug.cgi?id=22278
+
+bool resultIn;
+bool resultOut;
+
+void foo22278()
+ in { resultIn = true; }
+ out { resultOut = true; }
+do {}
+
+int main()
+{
+ foo22278();
+
+ version(D_PreConditions) assert(resultIn); else assert(!resultIn);
+ version(D_PostConditions) assert(resultOut); else assert(!resultOut);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,142 @@
+/* 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();
+ testDifferentTypes();
+ testSameAttributes();
+ testInverseAttributes();
+ return 0;
+}
+
+void testDifferentTypes()
+{
+ static struct DifferentTypes
+ {
+ int x;
+ int opApply(int delegate(int) dg) @safe {
+ x = 1;
+ return 0;
+ }
+ int opApply(int delegate(long) dg) @safe {
+ x = 2;
+ return 0;
+ }
+ }
+
+ DifferentTypes dt;
+ foreach (int i; dt) {}
+ assert(dt.x == 1);
+
+ foreach (long i; dt) {}
+ assert(dt.x == 2);
+}
+
+void testSameAttributes()
+{
+ static struct SameAttributes
+ {
+ int x;
+ int opApply(int delegate(int) @system dg) @safe {
+ x = 1;
+ return 0;
+ }
+ int opApply(int delegate(int) @safe dg) @safe {
+ x = 2;
+ return 0;
+ }
+ }
+
+ static void safe() @safe
+ {
+ SameAttributes sa;
+ foreach (i; sa) {}
+ assert(sa.x == 2);
+ }
+ safe();
+
+ static void system() @system
+ {
+ SameAttributes sa;
+ foreach (i; sa) {}
+ assert(sa.x == 1);
+ }
+ system();
+}
+
+// Not useful but enabled by the associated patch
+void testInverseAttributes()
+{
+ static struct InverseAttributes
+ {
+ int x;
+ int opApply(int delegate(int) @system dg) @safe {
+ x = 1;
+ return 0;
+ }
+ int opApply(int delegate(int) @safe dg) @system {
+ x = 2;
+ return 0;
+ }
+ }
+
+ static void system() @system
+ {
+ InverseAttributes sa;
+ foreach (i; sa) {}
+ assert(sa.x == 1);
+ }
+ system();
+
+ static void safe() @safe
+ {
+ InverseAttributes sa;
+ (() @trusted { foreach (i; sa) {} })();
+ assert(sa.x == 2);
+ }
+ safe();
+}
new file mode 100644
@@ -0,0 +1,15 @@
+/*
+Test that -main does nothing when main is already defined
+
+REQUIRED_ARGS: -main
+RUN_OUTPUT:
+---
+Success
+---
+*/
+extern(C) int printf(const char*, ...);
+
+void main()
+{
+ printf("Success\n");
+}
@@ -697,6 +697,54 @@ static if(is(typeof(foo20831) Params20831 == __parameters))
/************************************************/
+/************************************************/
+// https://issues.dlang.org/show_bug.cgi?id=15804
+
+template test15804()
+{
+ alias AliasSeq(T...) = T;
+
+ @(42) struct Foo(D) {}
+ auto fooFac(T)()
+ {
+ static assert(__traits(getAttributes, Foo) == AliasSeq!42);
+ static assert(__traits(getAttributes, Foo!int) == AliasSeq!42);
+ return Foo!T();
+ }
+
+ auto booFac(T)()
+ {
+ @(43) struct Boo {}
+ static assert(__traits(getAttributes, Boo) == AliasSeq!43);
+ return Boo();
+ }
+
+ auto barFac(T)()
+ {
+ @(44) struct Bar(D) {}
+ static assert(__traits(getAttributes, Bar) == AliasSeq!44); // Fixed
+ static assert(__traits(getAttributes, Bar!int) == AliasSeq!44);
+ return Bar!T();
+ }
+
+ auto bazFac(T)()
+ {
+ @(45) static struct Baz(D) {}
+ static assert(__traits(getAttributes, Baz) == AliasSeq!45); // Fixed
+ static assert(__traits(getAttributes, Baz!int) == AliasSeq!45);
+ return Baz!T();
+ }
+
+ auto foo = fooFac!int;
+ auto boo = booFac!int;
+ auto bar = barFac!int;
+ auto baz = bazFac!int;
+}
+
+alias a15804 = test15804!();
+
+/************************************************/
+
int main()
{
test1();
@@ -196,6 +196,7 @@ void test5()
{
// f5_1 .. f5_5 are symbols which declared in module scope
assert(100.f5_1() == 1);
+ assert(001.f5_1() == 1); // https://issues.dlang.org/show_bug.cgi?id=8346
assert("s".f5_2() == 2);
assert(1.4.f5_3() == 3);
assert(100.f5_4() == 1);
new file mode 100644
@@ -0,0 +1,337 @@
+#include <assert.h>
+
+class X
+{
+public:
+ virtual ~X();
+ int i;
+};
+
+X::~X()
+{
+}
+
+class Y : public X
+{
+};
+
+class A
+{
+public:
+ virtual ~A();
+ virtual int f1() const;
+
+ int i;
+};
+
+class I
+{
+public:
+ virtual int f2() const = 0;
+ virtual X *f4() = 0;
+};
+
+class B : public A, public I
+{
+public:
+ virtual int f1() const;
+ virtual int f2() const;
+ virtual int f3() const;
+ virtual X *f4();
+};
+
+class C : public B
+{
+public:
+ virtual int f1() const;
+ virtual int f2() const;
+ virtual int f3() const;
+ virtual Y *f4();
+};
+
+#ifdef _WIN32
+class D : public B
+{
+public:
+ virtual int f1() const;
+ virtual int f2() const;
+ virtual int f3() const;
+ virtual Y *f4();
+};
+
+class E : public B
+{
+public:
+ virtual int f1() const;
+ virtual int f2() const;
+ virtual int f3() const;
+ virtual Y *f4();
+};
+#endif
+
+A::~A()
+{
+}
+
+int A::f1() const
+{
+ return i + 11;
+}
+
+int B::f1() const
+{
+ return i + 21;
+}
+
+int B::f2() const
+{
+ return i + 22;
+}
+
+int B::f3() const
+{
+ return i + 23;
+}
+
+X *B::f4()
+{
+ X *r = new X;
+ r->i = i + 24;
+ return r;
+}
+
+int C::f1() const
+{
+ return i + 31;
+}
+
+int C::f2() const
+{
+ return i + 32;
+}
+
+int C::f3() const
+{
+ return i + 33;
+}
+
+Y *C::f4()
+{
+ Y *r = new Y;
+ r->i = i + 34;
+ return r;
+}
+
+I *createIFromCPP(char type, int i)
+{
+ switch (type)
+ {
+ case 'B':
+ {
+ B *b = new B();
+ b->i = i;
+ return b;
+ }
+ case 'C':
+ {
+ C *c = new C();
+ c->i = i;
+ return c;
+ }
+#ifdef _WIN32
+ case 'D':
+ {
+ D *d = new D();
+ d->i = i;
+ return d;
+ }
+ case 'E':
+ {
+ E *e = new E();
+ e->i = i;
+ return e;
+ }
+#endif
+ default:
+ return 0;
+ }
+}
+
+B *createBFromCPP(char type, int i)
+{
+ switch (type)
+ {
+ case 'B':
+ {
+ B *b = new B();
+ b->i = i;
+ return b;
+ }
+ case 'C':
+ {
+ C *c = new C();
+ c->i = i;
+ return c;
+ }
+#ifdef _WIN32
+ case 'D':
+ {
+ D *d = new D();
+ d->i = i;
+ return d;
+ }
+ case 'E':
+ {
+ E *e = new E();
+ e->i = i;
+ return e;
+ }
+#endif
+ default:
+ return 0;
+ }
+}
+
+C *createCFromCPP(int i)
+{
+ C *c = new C();
+ c->i = i;
+ return c;
+}
+
+#ifdef _WIN32
+D *createDFromCPP(int i)
+{
+ D *d = new D();
+ d->i = i;
+ return d;
+}
+
+E *createEFromCPP(int i)
+{
+ E *e = new E();
+ e->i = i;
+ return e;
+}
+#endif
+
+I *createIFromD(char type, int i);
+B *createBFromD(char type, int i);
+C *createCFromD(int i);
+#ifdef _WIN32
+D *createDFromD(int i);
+E *createEFromD(int i);
+#endif
+
+void runCPPTests()
+{
+ {
+ B *b = new B();
+ b->i = 100;
+ assert(b->f1() == 121);
+ assert(b->f2() == 122);
+ assert(b->f3() == 123);
+ assert(b->f4()->i == 124);
+ }
+ {
+ C *c = new C();
+ c->i = 100;
+ assert(c->f1() == 131);
+ assert(c->f2() == 132);
+ assert(c->f3() == 133);
+ assert(c->f4()->i == 134);
+ }
+#ifdef _WIN32
+ {
+ D *d = new D();
+ d->i = 100;
+ assert(d->f1() == 141);
+ assert(d->f2() == 142);
+ assert(d->f3() == 143);
+ assert(d->f4()->i == 144);
+ }
+ {
+ E *e = new E();
+ e->i = 100;
+ assert(e->f1() == 151);
+ assert(e->f2() == 152);
+ assert(e->f3() == 153);
+ assert(e->f4()->i == 154);
+ }
+#endif
+ {
+ I *i = createIFromD('B', 100);
+ assert(i->f2() == 122);
+ assert(i->f4()->i == 124);
+ }
+ {
+ I *i = createIFromD('C', 100);
+ assert(i->f2() == 132);
+ assert(i->f4()->i == 134);
+ }
+#ifdef _WIN32
+ {
+ I *i = createIFromD('D', 100);
+ assert(i->f2() == 142);
+ assert(i->f4()->i == 144);
+ }
+ {
+ I *i = createIFromD('E', 100);
+ assert(i->f2() == 152);
+ assert(i->f4()->i == 154);
+ }
+#endif
+ {
+ B *b = createBFromD('B', 100);
+ assert(b->f1() == 121);
+ assert(b->f2() == 122);
+ assert(b->f3() == 123);
+ assert(b->f4()->i == 124);
+ }
+ {
+ B *b = createBFromD('C', 100);
+ assert(b->f1() == 131);
+ assert(b->f2() == 132);
+ assert(b->f3() == 133);
+ assert(b->f4()->i == 134);
+ }
+#ifdef _WIN32
+ {
+ B *b = createBFromD('D', 100);
+ assert(b->f1() == 141);
+ assert(b->f2() == 142);
+ assert(b->f3() == 143);
+ assert(b->f4()->i == 144);
+ }
+ {
+ B *b = createBFromD('E', 100);
+ assert(b->f1() == 151);
+ assert(b->f2() == 152);
+ assert(b->f3() == 153);
+ assert(b->f4()->i == 154);
+ }
+#endif
+ {
+ C *c = createCFromD(100);
+ assert(c->f1() == 131);
+ assert(c->f2() == 132);
+ assert(c->f3() == 133);
+ assert(c->f4()->i == 134);
+ }
+#ifdef _WIN32
+ {
+ D *d = createDFromD(100);
+ assert(d->f1() == 141);
+ assert(d->f2() == 142);
+ assert(d->f3() == 143);
+ assert(d->f4()->i == 144);
+ }
+ {
+ E *e = createEFromD(100);
+ assert(e->f1() == 151);
+ assert(e->f2() == 152);
+ assert(e->f3() == 153);
+ assert(e->f4()->i == 154);
+ }
+#endif
+}
new file mode 100644
@@ -0,0 +1,327 @@
+// EXTRA_CPP_SOURCES: cpp22287.cpp
+
+extern(C++):
+
+class X
+{
+public:
+ ~this();
+ int i;
+}
+
+class Y : X
+{
+}
+
+class A
+{
+ ~this();
+ int f1() const;
+
+ int i;
+}
+
+interface I
+{
+ int f2() const;
+ X f4();
+}
+
+class B : A, I
+{
+ override int f1() const;
+ override int f2() const;
+ int f3() const;
+ override X f4();
+}
+
+class C : B
+{
+ override int f1() const;
+ override int f2() const;
+ override int f3() const;
+ override Y f4();
+}
+
+version(Windows)
+{
+class D : B
+{
+ override int f1() const
+ {
+ return i + 41;
+ }
+
+ override int f2() const
+ {
+ return i + 42;
+ }
+
+ override int f3() const
+ {
+ return i + 43;
+ }
+
+ override Y f4()
+ {
+ Y r = new Y;
+ r.i = i + 44;
+ return r;
+ }
+}
+
+mixin template MixinE()
+{
+ override int f1() const
+ {
+ return i + 51;
+ }
+
+ override int f2() const
+ {
+ return i + 52;
+ }
+
+ override int f3() const
+ {
+ return i + 53;
+ }
+
+ override Y f4()
+ {
+ Y r = new Y;
+ r.i = i + 54;
+ return r;
+ }
+}
+
+class E : B
+{
+ mixin MixinE;
+}
+}
+
+I createIFromCPP(char type, int i);
+B createBFromCPP(char type, int i);
+C createCFromCPP(int i);
+version(Windows)
+{
+D createDFromCPP(int i);
+E createEFromCPP(int i);
+}
+
+I createIFromD(char type, int i)
+{
+ switch (type)
+ {
+ case 'B':
+ {
+ B b = new B();
+ b.i = i;
+ return b;
+ }
+ case 'C':
+ {
+ C c = new C();
+ c.i = i;
+ return c;
+ }
+ version(Windows)
+ {
+ case 'D':
+ {
+ D d = new D();
+ d.i = i;
+ return d;
+ }
+ case 'E':
+ {
+ E e = new E();
+ e.i = i;
+ return e;
+ }
+ }
+ default:
+ return null;
+ }
+}
+
+B createBFromD(char type, int i)
+{
+ switch (type)
+ {
+ case 'B':
+ {
+ B b = new B();
+ b.i = i;
+ return b;
+ }
+ case 'C':
+ {
+ C c = new C();
+ c.i = i;
+ return c;
+ }
+ version(Windows)
+ {
+ case 'D':
+ {
+ D d = new D();
+ d.i = i;
+ return d;
+ }
+ case 'E':
+ {
+ E e = new E();
+ e.i = i;
+ return e;
+ }
+ }
+ default:
+ return null;
+ }
+}
+
+C createCFromD(int i)
+{
+ C c = new C();
+ c.i = i;
+ return c;
+}
+
+version(Windows)
+{
+D createDFromD(int i)
+{
+ D d = new D();
+ d.i = i;
+ return d;
+}
+
+E createEFromD(int i)
+{
+ E e = new E();
+ e.i = i;
+ return e;
+}
+}
+
+void runCPPTests();
+
+extern(D) void main()
+{
+ {
+ B b = new B();
+ b.i = 100;
+ assert(b.f1() == 121);
+ assert(b.f2() == 122);
+ assert(b.f3() == 123);
+ assert(b.f4().i == 124);
+ }
+ {
+ C c = new C();
+ c.i = 100;
+ assert(c.f1() == 131);
+ assert(c.f2() == 132);
+ assert(c.f3() == 133);
+ assert(c.f4().i == 134);
+ }
+ version(Windows)
+ {
+ {
+ D d = new D();
+ d.i = 100;
+ assert(d.f1() == 141);
+ assert(d.f2() == 142);
+ assert(d.f3() == 143);
+ assert(d.f4().i == 144);
+ }
+ {
+ E e = new E();
+ e.i = 100;
+ assert(e.f1() == 151);
+ assert(e.f2() == 152);
+ assert(e.f3() == 153);
+ assert(e.f4().i == 154);
+ }
+ }
+ {
+ I i = createIFromCPP('B', 100);
+ assert(i.f2() == 122);
+ assert(i.f4().i == 124);
+ }
+ {
+ I i = createIFromCPP('C', 100);
+ assert(i.f2() == 132);
+ assert(i.f4().i == 134);
+ }
+ version(Windows)
+ {
+ {
+ I i = createIFromCPP('D', 100);
+ assert(i.f2() == 142);
+ assert(i.f4().i == 144);
+ }
+ {
+ I i = createIFromCPP('E', 100);
+ assert(i.f2() == 152);
+ assert(i.f4().i == 154);
+ }
+ }
+ {
+ B b = createBFromCPP('B', 100);
+ assert(b.f1() == 121);
+ assert(b.f2() == 122);
+ assert(b.f3() == 123);
+ assert(b.f4().i == 124);
+ }
+ {
+ B b = createBFromCPP('C', 100);
+ assert(b.f1() == 131);
+ assert(b.f2() == 132);
+ assert(b.f3() == 133);
+ assert(b.f4().i == 134);
+ }
+ version(Windows)
+ {
+ {
+ B b = createBFromCPP('D', 100);
+ assert(b.f1() == 141);
+ assert(b.f2() == 142);
+ assert(b.f3() == 143);
+ assert(b.f4().i == 144);
+ }
+ {
+ B b = createBFromCPP('E', 100);
+ assert(b.f1() == 151);
+ assert(b.f2() == 152);
+ assert(b.f3() == 153);
+ assert(b.f4().i == 154);
+ }
+ }
+ {
+ C c = createCFromCPP(100);
+ assert(c.f1() == 131);
+ assert(c.f2() == 132);
+ assert(c.f3() == 133);
+ assert(c.f4().i == 134);
+ }
+ version(Windows)
+ {
+ {
+ D d = createDFromCPP(100);
+ assert(d.f1() == 141);
+ assert(d.f2() == 142);
+ assert(d.f3() == 143);
+ assert(d.f4().i == 144);
+ }
+ {
+ E e = createEFromCPP(100);
+ assert(e.f1() == 151);
+ assert(e.f2() == 152);
+ assert(e.f3() == 153);
+ assert(e.f4().i == 154);
+ }
+ }
+ runCPPTests();
+}