Skip to content

Presence of move constructor causes overload error #21476

Closed

Description

@ibuclaw
struct S
{
    string field;
    this(ref return scope S); // cpctor
    this(return scope S); // mvctor
}

void test()
{
    auto o = S("aoe");
}

Comment out the move constructor declaration, and the code compiles.

Activity

  1. ibuclaw commented on Jun 24, 2025

    @ibuclaw
    MemberAuthor
  2. TurkeyMan commented on Jun 24, 2025

    @TurkeyMan
    Contributor

    What's A? That's not a copy constructor.
    If it was a typo, this is for @WalterBright

  3. ibuclaw commented on Jun 24, 2025

    @ibuclaw
    MemberAuthor

    What's A? That's not a copy constructor.
    If it was a typo, this is for @WalterBright

    Typo.

    Fix is simple, just fyi'ing you to look over correctness of code.

    This line needs changing

    if (!ctorDecl.isCpCtor && (!ignoreDisabled || !(ctorDecl.storage_class & STC.disable)))

    Move constructor is not a regular constructor.

    Additionally there's this for distinguishing between move constructor and regular constructors in error messages.

    return isCpCtor ? "copy constructor" : "constructor";

  4. added a commit that references this issue on Jun 24, 2025
    9556c38
  5. added theissue type on Jun 24, 2025
  6. added a commit that references this issue on Jun 25, 2025
    ccb4ffe
  7. added a commit that references this issue on Jun 27, 2025
    17184b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions