[dcl.init.list] (original) (raw)

:

typedef std::complex cmplx; std::vector v1 = { 1, 2, 3 };

void f() { std::vector v2{ 1, 2, 3 }; std::initializer_list i3 = { 1, 2, 3 }; }

struct A { std::initializer_list i4; A() : i4{ 1, 2, 3 } {}
};

For v1 and v2, the initializer_­list object is a parameter in a function call, so the array created for{ 1, 2, 3 } has full-expression lifetime.

For i3, the initializer_­list object is a variable, so the array persists for the lifetime of the variable.

For i4, the initializer_­list object is initialized in the constructor's ctor-initializer as if by binding a temporary array to a reference member, so the program is ill-formed ([class.base.init]).

end example