Skip to content

Commit

Permalink
Merge pull request #8098 from RazvanN7/Issue_18474
Browse files Browse the repository at this point in the history
Fix Issue 18474 - Postblit not working in shared structs
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Apr 2, 2018
2 parents 80157ad + 3a0f75d commit e1aaf4c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,17 @@ private extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope*
postblitCalls.push(new OnScopeStatement(loc, TOK.onScopeFailure, new ExpStatement(loc, ex)));
}

void checkShared()
{
if (sd.type.isShared())
stc |= STC.shared_;
}

// Build our own "postblit" which executes a, but only if needed.
if (postblitCalls.dim || (stc & STC.disable))
{
//printf("Building __fieldPostBlit()\n");
checkShared();
auto dd = new PostBlitDeclaration(declLoc, Loc.initial, stc, Id.__fieldPostblit);
dd.generated = true;
dd.storage_class |= STC.inference;
Expand Down Expand Up @@ -283,6 +290,8 @@ private extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope*
ex = new CallExp(loc, ex);
e = Expression.combine(e, ex);
}

checkShared();
auto dd = new PostBlitDeclaration(declLoc, Loc.initial, stc, Id.__aggrPostblit);
dd.generated = true;
dd.storage_class |= STC.inference;
Expand Down
2 changes: 2 additions & 0 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6748,6 +6748,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
*/
Expression e = e1x.copy();
e.type = e.type.mutableOf();
if (e.type.isShared && !sd.type.isShared)
e.type = e.type.unSharedOf();
e = new BlitExp(exp.loc, e, e2x);
e = new DotVarExp(exp.loc, e, sd.postblit, false);
e = new CallExp(exp.loc, e);
Expand Down
15 changes: 15 additions & 0 deletions test/compilable/test18474.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
shared struct A
{
this(this);
}

struct B
{
A a;
}

void main()
{
shared B b1;
auto b2 = b1;
}

0 comments on commit e1aaf4c

Please sign in to comment.