Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ddmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/ddmd/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions test/fail_compilation/test17422.d
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 17 additions & 0 deletions test/runnable/fix17429.d
Original file line number Diff line number Diff line change
@@ -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);
}