Skip to content

Commit

Permalink
Fix Issue 17970 - shared struct destructor doesn't compile anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Feb 12, 2018
1 parent 2bb137a commit 8a61a31
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,24 @@ void functionResolve(Match* m, Dsymbol dstart, Loc loc, Scope* sc, Objects* tiar
else
return 0; // MATCH.nomatch
}
/* Fix Issue 17970:
If a struct is declared as shared the dtor is automatically
considered to be shared, but when the struct is instantiated
the instance is no longer considered to be shared when the
function call matching is done. The fix makes it so that if a
struct declaration is shared, when the destructor is called,
the instantiated struct is also considered shared.
*/
if (auto dt = fd.isDtorDeclaration())
{
auto dtmod = dt.type.toTypeFunction();
auto shared_dtor = dtmod.mod & MODFlags.shared_;
auto shared_this = tthis_fd.mod & MODFlags.shared_;
if (shared_dtor && !shared_this)
tthis_fd = dtmod;
else if (shared_this && !shared_dtor)
tf.mod = tthis_fd.mod;
}
MATCH mfa = tf.callMatch(tthis_fd, fargs, 0, pMessage);
//printf("test1: mfa = %d\n", mfa);
if (mfa > MATCH.nomatch)
Expand Down
28 changes: 28 additions & 0 deletions test/compilable/test17970.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
shared struct Shared
{
static Shared make()
{
return Shared();
}

~this()
{
}
}

shared struct Foo
{
~this()
{
}
}

struct Inner { ~this() {} }
struct Outer { shared(Inner) inner; }

void main()
{
Foo x = Foo();
auto s = Shared.make();
Outer _;
}

0 comments on commit 8a61a31

Please sign in to comment.