For the aggregate
struct S{int i, j;};
the declarations S s({1, 2});
and S s({1});
perform direct-initialization according to N3797 §8.5 p16:
The initialization that occurs in the forms
T x(a); T x{a};
as well as in
new
expressions (5.3.4),static_cast
expressions (5.2.9), functional notation type conversions (5.2.3), and base and member initializers (12.6.2) is called direct-initialization.
But §8.5 p17 doesn't seem to characterize them:
The semantics of initializers are as follows. The destination type is the type of the object or reference being initialized and the source type is the type of the initializer expression. If the initializer is not a single (possibly parenthesized) expression, the source type is not defined.
If the initializer is a (non-parenthesized) braced-init-list, the object or reference is list-initialized (8.5.4).
If the destination type is a reference type, see 8.5.3.
If the destination type is an array of characters, an array of
char16_t
, an array ofchar32_t
, or an array ofwchar_t
, and the initializer is a string literal, see 8.5.2.If the initializer is
()
, the object is value-initialized.Otherwise, if the destination type is an array, the program is ill-formed.
If the destination type is a (possibly cv-qualified) class type:
If the initialization is direct-initialization, or if it is copy-initialization where the cv-unqualified version of the source type is the same class as, or a derived class of, the class of the destination, constructors are considered. The applicable constructors are enumerated (13.3.1.3), and the best one is chosen through overload resolution (13.3). The constructor so selected is called to initialize the object, with the initializer expression or expression-list as its argument(s). If no constructor applies, or the overload resolution is ambiguous, the initialization is ill-formed.
Otherwise (i.e., for the remaining copy-initialization cases), user-defined conversion sequences that can convert from the source type to the destination type or (when a conversion function is used) to a derived class thereof are enumerated as described in 13.3.1.4, and the best one is chosen through overload resolution (13.3). If the conversion cannot be done or is ambiguous, the initialization is ill-formed. The function selected is called with the initializer expression as its argument; if the function is a constructor, the call initializes a temporary of the cv-unqualified version of the destination type. The temporary is a prvalue. The result of the call (which is the temporary for the constructor case) is then used to direct-initialize, according to the rules above, the object that is the destination of the copy-initialization. In certain cases, an implementation is permitted to eliminate the copying inherent in this direct-initialization by constructing the intermediate result directly into the object being initialized; see 12.2, 12.8.
Otherwise, if the source type is a (possibly cv-qualified) class type, conversion functions are considered. The applicable conversion functions are enumerated (13.3.1.5), and the best one is chosen through overload resolution (13.3). The user-defined conversion so selected is called to convert the initializer expression into the object being initialized. If the conversion cannot be done or is ambiguous, the initialization is ill-formed.
Otherwise, the initial value of the object being initialized is the (possibly converted) value of the initializer expression. Standard conversions (Clause 4) will be used, if necessary, to convert the initializer expression to the cv-unqualified version of the destination type; no user-defined conversions are considered. If the conversion cannot be done, the initialization is ill-formed. [Note: An expression of type “cv1
T
” can initialize an object of type “cv2T
” independently of the cv-qualifiers cv1 and cv2.int a; const int b = a; int c = b;
— end note ]
The subject declarations, S s({1, 2});
and S s({1});
:
- are not list-initialization, since each initializer is a parenthesized braced-init-list.
- the destination types are not references
- the destination types are not array of characters, in general.
- the initializers are not
()
- the destination types are not arrays.
Should the spec also say "blah blah blah" ?
– David-SkyMeshS s({1, 2});
is an expression. It's a declaration, and the{1,2}
certainly is not an expression. Apart from that, I thinkS s(..)
is always direct-initialization, therefore, constructors are considered. The only two applicable are copy+move, which try to bind{1,2}
to a reference. Also see [over.ics.list]/5 – dyp