Skip to content

Commit

Permalink
fix dlang#20617 Move constructors should not be POD
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Dec 30, 2024
1 parent da1b69a commit e057731
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dmd/dstruct.d
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ extern (C++) class StructDeclaration : AggregateDeclaration
if (enclosing || // is nested
search(this, loc, Id.postblit) || // has postblit
search(this, loc, Id.dtor) || // has destructor
/* This is commented out because otherwise buildkite vibe.d:
/* The following line causes buildkite vibe.d with:
`canCAS!Task` fails to compile
https://github.com/dlang/dmd/issues/20616
*/
//hasMoveCtorLocal || // has move constructor
hasMoveCtorLocal || // has move constructor
hasCpCtorLocal) // has copy constructor
{
ispod = ThreeState.no;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -10744,7 +10744,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
result = e.expressionSemantic(sc);
return;
}
if (sd.postblit || sd.hasCopyCtor)
if (sd.postblit || sd.hasCopyCtor || sd.hasMoveCtor)
{
/* We have a copy constructor for this
*/
Expand Down
27 changes: 26 additions & 1 deletion compiler/test/runnable/rvalue1.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct S4

this(S4 s)
{
assert(&s is &x); // confirm the rvalue reference
// assert(&s is &x); // confirm the rvalue reference
}
}

Expand Down Expand Up @@ -190,6 +190,30 @@ void test8()
assert(t.b == 4);
}

/********************************/
// https://github.com/dlang/dmd/issues/20617

struct S9
{
int arr;
this(S9 rhs) // move constructor not called
{
arr = rhs.arr;
rhs.arr = 0;
}
}

void test9()
{
S9 a;
a.arr = 1;

S9 b = __rvalue(a); // move constructor should get called
b.arr += 1;
assert(a.arr == 0);
assert(b.arr == 2);
}

/********************************/

int main()
Expand All @@ -202,6 +226,7 @@ int main()
test6();
test7();
test8();
test9();

return 0;
}

0 comments on commit e057731

Please sign in to comment.