According to C ++ 11 rules, B not an aggregate type. C ++ 11 [dcl.init.aggr] / 1:
An aggregate is an array or class (section 9) without constructors provided by the user (12.1), without elements with alignment or equal for non-static data elements (9.2) there are no private or protected non-static data (section 11), there are no base classes (section 10) and there are no virtual functions (10.3).
B has only the default constructor and therefore cannot be initialized from the braced-initializer-list {2} list.
C ++ 14 allows parenthesis initializers or equal for non-static data elements in the aggregate. N4140 [dcl.init.aggr] / 1:
An aggregate is an array or class (section 9) without constructors provided by the user (12.1), without private or protected non-static data elements (section 11), without base classes (section 10) and without virtual functions (10.3).
With fairly straightforward semantics: fields for which there is no specified initializer are initialized from their logical or equal-initializer, if any, and are otherwise initialized with {} [dcl.init.aggr] / 7:
If there are fewer initializer proposals in the list than in the aggregate, then each member that is not explicitly initialized should be initialized from its element with an equal-equal-initializer or, if there are no brackets or equal to -initializer from the empty initializer list (8.5.4) .
So your program is valid C ++ 14 ( DEMO ). In fact, the ban on alignment-alignment in C ++ 11 was a bug that C ++ 14 fixed.
Casey source share