Skip to content

Ref parameter overload not called when struct implements copy constructor #21478

@ibuclaw

Description

@ibuclaw

When there is a move assignment implemented, the copy assignment is ignored, even though it is the correct function to call.

struct S
{
    int data;

    ~this()                     // I. destructor
    { assert(true); }
    this(ref return scope S)    // II. copy constructor
    { assert(false); }
    ref S opAssign(const ref S) // III. copy assignment
    { return this; }
    this(return scope S)        // IV. move constructor
    { assert(false); }
    ref S opAssign(const S)     // V. move assignment 
    { assert(false); }
}

void test()
{
    S o1, o2;
    o2 = o1;    // Should use III, instead uses II + V.
}

Remove the move assignment, and the copy assignment path is correctly used.

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