auto-generated move assignment and base or member with a by-value
assignment
{ Please limit your text to fit within 80 columns, preferably around 70,
so that readers don't have to scroll horizontally to read each line.
This article has been reformatted manually by the moderator. -mod }
Hello,
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?
That is, should this sample print "copy" or "move"?
#include <iostream>
struct A
{
A() = default;
A( A const& ) { std::cout << "copy" << std::endl; }
A( A&& ) { std::cout << "move" << std::endl; }
A& operator=( A ) { return *this; }
};
struct B
{
A a;
};
int main()
{
B x, y;
x = std::move(y);
}
For me it prints "copy" in GCC-4.7, and "move" in MinGW-4.8.
This question originated from [1], where Adam Wulkiewicz tested a
similar sample and from that I expect compilers he used to produce
"copy". Those compilers are:
GCC4.7, Clang3.2, MinGW 4.7, VS2010, VS2013
Regards,
Kris
[1] http://boost.2283326.n4.nabble.com/move-interest-the-pass-by-value-and-swap-idiom-and-explicit-copy-constructors-td4659419.html
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]