Skip to content

Ensure Move Constructor Requires Copy Constructor (#20942) #21041

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions compiler/src/dmd/dstruct.d
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,15 @@ extern (C++) class StructDeclaration : AggregateDeclaration
bool needMoveCtor;
needCopyOrMoveCtor(this, hasCpCtorLocal, hasMoveCtorLocal, needCopyCtor, needMoveCtor);

if (hasMoveCtorLocal && !hasCpCtorLocal) {
error(this.loc, "Move constructor declared without a corresponding copy constructor.");
}


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:
`canCAS!Task` fails to compile
*/
//hasMoveCtorLocal || // has move constructor
hasMoveCtorLocal && !hasCpCtorLocal || // Error: Move constructor without copy constructor
hasCpCtorLocal) // has copy constructor
{
ispod = ThreeState.no;
Expand Down Expand Up @@ -372,7 +374,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration
*/
final bool hasCopyConstruction()
{
return postblit || hasCopyCtor;
return postblit || hasCopyCtor || hasMoveCtor;
}

override void accept(Visitor v)
Expand Down
Loading