I'm trying to wrap my head around some corner cases with c++11 uniform initialization and I can't figure out why is this:
struct Base
{
int x,y,z;
};
struct Derived : Base
{
};
static_assert (std::is_trivial<Base>::value, "Base must be trivial");
static_assert (std::is_trivial<Derived>::value, "Derived must be trivial");
Base b{1, 2, 3}; // 1) This compiles fine
Derived d{10, 20, 30}; // 2) This fails
Line marked 2 fails with a "no matching constructor for initialization of Derived" message both with clang 3.1
and g++ 4.7
.
I can't understand why, in case of Derived, it is trying to call a constructor and not performing (I don't know how to call it, maybe aggregate initialization?) as is the case for line 1).
Something in the following reasoning is wrong?:
A) Being trivial guarantees it can be statically initialized
B) To be statically initialized no code must be executed at runtime and hence no constructor call is required
A+B
=> why is it trying to call a constructor on a type that it knows being trivial?
I'm very confused....