[cfe-dev] deprecating copy construction and assignment

Jeffrey Yasskin jyasskin at gmail.com
Thu Mar 29 08:28:42 PDT 2012


On Thu, Mar 29, 2012 at 7:31 AM, Jonathan Sauer <jonathan.sauer at gmx.de> wrote:
> Hello,
>
>> One needs to be more careful with defaulting the move members.  It is easy to default them and have them get implicitly deleted:
>>
>> struct member
>> {
>>    member();
>>    member(const member&);
>>    member& operator=(const member&);
>>    ~member();
>> };
>>
>> struct A
>> {
>>    member m_;
>>
>>    A() = default;
>>    A(const A&) = default;
>>    A& operator=(const A&) = default;
>>    A(A&&) = default;
>>    A& operator=(A&&) = default;
>>    ~A() = default;
>> };
>>
>> A is neither move constructible nor move assignable.  The following is probably what was intended:
>
> I suggest enhancing the error message with an explanation: "A is not move assignable because member 'm_'
> has an {explicitly|implicitly} deleted move assignment operator." Or even "... has a move assignment
> operator that was implicitly deleted by the explicit copy assignment operator".

I prefer the last one. Users (including me) get confused when we tell
them that something was deleted but not why/how to avoid deleting it.




More information about the cfe-dev mailing list