Skip to content

Commit

Permalink
Merge pull request #7874 from RazvanN7/Issue_17970
Browse files Browse the repository at this point in the history
Fix Issue 17970 - shared struct destructor doesn't compile anymore
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Feb 12, 2018
2 parents 0d69394 + 8a61a31 commit 2c70923
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 2c70923

Please sign in to comment.