[cfe-dev] Move constructor forces copy assignment to be implicitly defaulted?
Howard Hinnant
hhinnant at apple.com
Mon May 28 07:28:09 PDT 2012
On May 28, 2012, at 2:52 AM, Suman Kar wrote:
>> Right. I mean that they don't exist, just as in C++98/03. Deleted move members are generally problematic as they inhibit "copying" from rvalues. If you have valid copy members and deleted move members, you can't return such an object from a function.
>>
>
> Okay, I still can't wrap my head around the last sentence. This looks ominous.
struct A
{
A() = default;
A(const A&) = default;
A& operator=(const A&) = default;
A(A&&) = delete;
A& operator=(A&&) = delete;
};
A
make()
{
A a;
return a;
}
int main()
{
A a = make();
}
test.cpp:67:7: error: call to deleted constructor of 'A'
A a = make();
^ ~~~~~~
test.cpp:54:5: note: function has been explicitly marked deleted here
A(A&&) = delete;
^
1 error generated.
But:
struct A
{
A() = default;
A(const A&) = default;
A& operator=(const A&) = default;
};
A
make()
{
A a;
return a;
}
int main()
{
A a = make();
}
Compiles and runs fine.
Howard
More information about the cfe-dev
mailing list