In updating some code to use uniform initialization, I thought it would be a drop-in modern substitue for the now "old style" parentheses style. I know this isn't always the case (obvious example, vector<int>
) but I've stumbled over another difference that I don't understand.
class Object {
public:
Object() = default;
Object(const Object&) = default;
};
int main() {
Object o;
Object copy{o}; // error
Object copy2(o); // OK
}
fails to compile under clang3.5 with the error: (also fails under gcc)
error: excess elements in struct initializer
There are two different changes to Object
that make this work. Either adding a data member to it, or giving it an empty copy constructor body
class Object {
private:
int i; // this fixes it
public:
Object() = default;
Object(const Object&) { } // and/or this fixes it as well
};
I don't see why these should make a difference.