cpp/language/list initialization

Initializes an object from.

Direct-list-initialization
{{sdsc|num=5| {{spar|Class}}{{ttb|::}}{{spar|Class}}{{ttb| :}} {{spar|member}} {{ttb|{}} {{spar|arg1, arg2, ...}} {{ttb|} {...}} {{rrev|since=c++20| {{spar|Class}}{{ttb|::}}{{spar|Class}}{{ttb| :}} {{spar|member}} {{ttb|{.}}{{spar|des1}} {{ttb|1==}} {{spar|arg1}} {{ttb|, .}}{{spar|des2}} {{ttb|{}} {{spar|arg2}} {{ttb|}}} {{spar|...}}{{ttb|} {...}} }} }} {{sdsc end}}

Copy-list-initialization
List initialization is performed in the following situations:
 * direct-list-initialization (both explicit and non-explicit constructors are considered)

@1@ initialization of a named variable with a (that is, a possibly empty brace-enclosed list of expressions or nested braced-init-lists) @2@ initialization of an unnamed temporary with a @3@ initialization of an object with dynamic storage duration with a, where the initializer is a @4@ in a non-static that does not use the equals sign @5@ in a of a constructor if  is used


 * copy-list-initialization (both explicit and non-explicit constructors are considered, but only non-explicit constructors may be called)

@6@ initialization of a named variable with a after an equals sign @7@ in a function call expression, with used as an argument and list-initialization initializes the function parameter @8@ in a statement with  used as the return expression and list-initialization initializes the returned object @9@ in a with a user-defined, where list-initialization initializes the parameter of the overloaded operator @10@ in an, where list-initialization initializes the parameter of the overloaded operator @11@ or other constructor invocations, where  is used in place of a constructor argument. Copy-list-initialization initializes the constructor's parameter (note; the type U in this example is not the type that's being list-initialized; U's constructor's parameter is) @12@ in a non-static that uses the equals sign

Explanation
The effects of list-initialization of an object of type are:


 * If is an aggregate class and the  has a single element of the same or derived type (possibly cv-qualified), the object is initialized from that element (by  for copy-list-initialization, or by  for direct-list-initialization).
 * Otherwise, if is a character array and the  has a single element that is an appropriately-typed string literal, the array is.


 * Otherwise, if is an,  is performed.


 * Otherwise, if the is empty and  is a class type with a default constructor,  is performed.


 * Otherwise, if is a specialization of std, the  object is direct-initialized or copy-initialized, depending on context, from  the.


 * Otherwise, the constructors of are considered, in two phases:


 * All constructors that take std as the only argument, or as the first argument if the remaining arguments have default values, are examined, and matched by against a single argument of type std


 * If the previous stage does not produce a match, all constructors of participate in  against the set of arguments that consists of the elements of the, with the restriction that only non-narrowing conversions are allowed. If this stage produces an explicit constructor as the best match for a copy-list-initialization, compilation fails (note, in simple copy-initialization, explicit constructors are not considered at all).


 * Otherwise (if is not a class type), if the  has only one element and either  is not a reference type or is a reference type whose referenced type is same as or is a base class of the type of the element,  is  (in direct-list-initialization) or  (in copy-list-initialization), except that narrowing conversions are not allowed.


 * Otherwise, if is a reference type that is not compatible with the type of the element:


 * Otherwise, if the has no elements,  is.

Narrowing conversions
List-initialization limits the allowed s by prohibiting the following:


 * conversion from a floating-point type to an integer type


 * conversion from an integer type to a floating-point type, except where the source is a constant expression whose value can be stored exactly in the target type


 * conversion from integer or unscoped enumeration type to integer type that cannot represent all values of the original, except where
 * the source is a whose width  is less than that of its type (or, for an, its underlying type) and the target type can represent all the values of a hypothetical extended integer type with width  and with the same signedness as the original type, or
 * the source is a constant expression whose value can be stored exactly in the target type


 * conversion from a pointer type or pointer-to-member type to