I came across this while testing some things for another question about aggregate initialization. I am using GCC 4.6.
When I initialize an aggregate with a list, all members are created in place, without copying or moving. To wit:
int main() { std::array<std::array<Goo,2>,2> a { std::array<Goo,2>{Goo{ 1, 2}, Goo{ 3, 4}} , std::array<Goo,2>{Goo{-1,-2}, Goo{-3,-4}} }; }
We confirm by creating several noisy designers:
struct Goo { Goo(int, int) { } Goo(Goo &&) { std::cout << "Goo Moved." << std::endl; } Goo(const Goo &) { std::cout << "Goo Copied." << std::endl; } };
No messages are printed at startup. However, if I make the move constructor private, the compiler complains about 'Goo::Goo(Goo&&)' is private , although the move constructor is clearly not needed.
Does anyone know if there is a standard requirement for a move constructor for accessibility for aggregate initialization like this?
source share