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 Jan 13, 2025
1 parent caf0e12 commit d7b16b4
Show file tree
Hide file tree
Showing 3 changed files with 29 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 @@ -330,10 +330,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 @@ -10739,7 +10739,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
26 changes: 25 additions & 1 deletion compiler/test/runnable/rvalue1.d
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 @@ -192,6 +192,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);
}

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

struct T9
Expand Down

0 comments on commit d7b16b4

Please sign in to comment.