Re: auto-generated move assignment and base or member with a
by-value assignment
W dniu poniedzia?ek, 17 lutego 2014 07:10:52 UTC+1 u?ytkownik Daniel Kr?gler napisa?:
Am 16.02.2014 06:37, schrieb Krzysztof Czai?ski:
If class B has a base or member of type A with an assignment operator
taking A by value, does it implie B's auto-generated move assignment is:
- deleted?
- defaulted?
- not present?
In your example, class A has a user-provided copy-assignment operator.
Thank you for the explanation, Daniel.
So the standard treats A's assignment operator taking A by value as
copy-assignment. I think that's a shame. It works equally well as
copy-assignment, move-assignment or any other assignment from a
type convertible to A. That's the point of taking by value here.
[...]
This means, that based on C++11 rules class B does neither implicitly
declare a defaulted move-assignment operator nor a move-constructor
But this is not the end of it. In fact, especially the "non-trivial"
exclusion rule had lead to the following core issue
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1402
and as result of accepting this issue as language defect, the following
behaviour changes happened:
Class A still does not implicitly declare a move-assignment operator,
but class B does and this move-assignment operator will invoke the best
matching A constructor (which is now the move constructor) to construct
an A object, followed by the call of the selected copy-assignment
operator of A. This explains why all newer compiler output "move"
instead of "copy".
I'm glad things are going this way - for me the above is expected
behavior.
But:
struct A
{
A& operator=( A ) { return *this; }
};
The point here is to implement the assignment in terms of a call to
an appropriate constructor (copy-, move-, or any other constructor),
and then swapping or moving the result into *this. Wouldn't it be
better to treat it as a universal-assignment, instead of just
copy-assignment?
Cheers,
Kris
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]