Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #20617 Move constructors should not be POD #20618

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading