diff --git a/src/ddmd/declaration.d b/src/ddmd/declaration.d index b4bdd2ce08ca..92543bd79cad 100644 --- a/src/ddmd/declaration.d +++ b/src/ddmd/declaration.d @@ -2236,12 +2236,13 @@ extern (C++) class VarDeclaration : Declaration //if (cd.isInterfaceDeclaration()) // error("interface %s cannot be scope", cd.toChars()); + // Destroying C++ scope classes crashes currently. Since C++ class dtors are not currently supported, simply do not run dtors for them. + // See https://issues.dlang.org/show_bug.cgi?id=13182 if (cd.cpp) { - // Destructors are not supported on extern(C++) classes break; } - if (mynew || onstack || cd.dtors.dim) // if any destructors + if (mynew || onstack) // if any destructors { // delete this; Expression ec; diff --git a/src/ddmd/escape.d b/src/ddmd/escape.d index 2e30b15f6cdf..812473e1b0dd 100644 --- a/src/ddmd/escape.d +++ b/src/ddmd/escape.d @@ -323,8 +323,7 @@ bool checkAssignEscape(Scope* sc, Expression e, bool gag) { if (va && !va.isDataseg() && !va.doNotInferScope) { - if (!va.isScope() && inferScope && - va.type.toBasetype().ty != Tclass) // scope classes are special + if (!va.isScope() && inferScope) { //printf("inferring scope for %s\n", va.toChars()); va.storage_class |= STCscope; } diff --git a/test/fail_compilation/test17422.d b/test/fail_compilation/test17422.d new file mode 100644 index 000000000000..cf7790754dca --- /dev/null +++ b/test/fail_compilation/test17422.d @@ -0,0 +1,24 @@ +/* +REQUIRED_ARGS: -dip1000 +TEST_OUTPUT: +--- +fail_compilation/test17422.d(23): Error: scope variable p may not be returned +--- +*/ +struct RC +{ + Object get() return scope @trusted + { + return cast(Object) &store[0]; + } + +private: + ubyte[__traits(classInstanceSize, Object)] store; +} + +Object test() @safe +{ + RC rc; + auto p = rc.get; // p must be inferred as scope variable, works for int* + return p; +} diff --git a/test/runnable/fix17429.d b/test/runnable/fix17429.d new file mode 100644 index 000000000000..ed28663795a3 --- /dev/null +++ b/test/runnable/fix17429.d @@ -0,0 +1,17 @@ +class Klazz +{ + __gshared size_t count; + ~this() + { + ++count; + } +} + +void main() +{ + auto s = new Klazz; + { + scope s2 = s; // calls delete even though it does not own s + } + assert(Klazz.count == 0); +}