diff --git a/src/dclass.d b/src/dclass.d index 5a5bf034d9ac..490be4493ee3 100644 --- a/src/dclass.d +++ b/src/dclass.d @@ -922,12 +922,15 @@ extern (C++) class ClassDeclaration : AggregateDeclaration // this() { } if (!ctor && baseClass && baseClass.ctor) { - auto fd = resolveFuncCall(loc, sc2, baseClass.ctor, null, null, null, 1); + auto fd = resolveFuncCall(loc, sc2, baseClass.ctor, null, type, null, 1); + if (!fd) // try shared base ctor instead + fd = resolveFuncCall(loc, sc2, baseClass.ctor, null, type.sharedOf, null, 1); if (fd && !fd.errors) { //printf("Creating default this(){} for class %s\n", toChars()); auto btf = cast(TypeFunction)fd.type; auto tf = new TypeFunction(null, null, 0, LINKd, fd.storage_class); + tf.mod = btf.mod; tf.purity = btf.purity; tf.isnothrow = btf.isnothrow; tf.isnogc = btf.isnogc; diff --git a/test/compilable/test17130.d b/test/compilable/test17130.d index c8c4c244d26d..f3f5c3b45b97 100644 --- a/test/compilable/test17130.d +++ b/test/compilable/test17130.d @@ -7,10 +7,32 @@ class Base {} } -class Derived : Base +class Derived1 : Base { this() { // implicit super(); } } + +class Derived2 : Base +{ + // implicit this() +} + +class Base2 +{ + this() shared + {} +} + +class Derived3 : Base2 +{ + // implicit this() shared +} + +void test() +{ + auto d2 = new Derived2; + auto d3 = new shared(Derived3); +}