|
4370 | 4370 | and the initializer is a string literal, see~\ref{dcl.init.string}.
|
4371 | 4371 | \item If the initializer is \tcode{()}, the object is value-initialized.
|
4372 | 4372 | \item
|
4373 |
| -Otherwise, if the destination type is an array, the program is ill-formed. |
| 4373 | +Otherwise, if the destination type is an array, |
| 4374 | +the object is initialized as follows. |
| 4375 | +Let $x_1$, $\dotsc$, $x_k$ be |
| 4376 | +the elements of the \grammarterm{expression-list}. |
| 4377 | +If the destination type is an array of unknown bound, |
| 4378 | +it is defined as having $k$ elements. |
| 4379 | +Let $n$ denote the array size after this potential adjustment. |
| 4380 | +If $k$ is greater than $n$, |
| 4381 | +the program is ill-formed. |
| 4382 | +Otherwise, the $i^\text{th}$ array element is copy-initialized with |
| 4383 | +$x_i$ for each $1 \leq i \leq k$, and |
| 4384 | +value-initialized for each $k < i \leq n$. |
| 4385 | +For each $1 \leq i < j \leq n$, |
| 4386 | +every value computation and side effect associated with |
| 4387 | +the initialization of the $i^\text{th}$ element of the array |
| 4388 | +is sequenced before those associated with |
| 4389 | +the initialization of the $j^\text{th}$ element. |
4374 | 4390 | \item
|
4375 | 4391 | If the destination type is a (possibly cv-qualified) class type:
|
4376 | 4392 |
|
|
4390 | 4406 | constructors are considered.
|
4391 | 4407 | The applicable constructors
|
4392 | 4408 | are enumerated\iref{over.match.ctor}, and the best one is chosen
|
4393 |
| -through overload resolution\iref{over.match}. |
4394 |
| -The constructor so selected |
| 4409 | +through overload resolution\iref{over.match}. Then: |
| 4410 | +\begin{itemize} |
| 4411 | +\item |
| 4412 | +If overload resolution is successful, |
| 4413 | +the selected constructor |
4395 | 4414 | is called to initialize the object, with the initializer
|
4396 | 4415 | expression or \grammarterm{expression-list} as its argument(s).
|
4397 |
| -If no constructor applies, or the overload resolution is |
4398 |
| -ambiguous, the initialization is ill-formed. |
| 4416 | +\item |
| 4417 | +Otherwise, if no constructor is viable, |
| 4418 | +the destination type is |
| 4419 | +a (possibly cv-qualified) aggregate class \tcode{A}, and |
| 4420 | +the initializer is a parenthesized \grammarterm{expression-list}, |
| 4421 | +the object is initialized as follows. |
| 4422 | +Let $e_1$, $\dotsc$, $e_n$ be the elements of the aggregate\iref{dcl.init.aggr}. |
| 4423 | +Let $x_1$, $\dotsc$, $x_k$ be the elements of the \grammarterm{expression-list}. |
| 4424 | +If $k$ is greater than $n$, the program is ill-formed. |
| 4425 | +The element $e_i$ is copy-initialized with |
| 4426 | +$x_i$ for $1 \leq i \leq k$. |
| 4427 | +The remaining elements are initialized with |
| 4428 | +their default member initializers, if any, and |
| 4429 | +otherwise are value-initialized. |
| 4430 | +For each $1 \leq i < j \leq n$, |
| 4431 | +every value computation and side effect |
| 4432 | +associated with the initialization of $e_i$ |
| 4433 | +is sequenced before those associated with the initialization of $e_j$. |
| 4434 | +\begin{note} |
| 4435 | +By contrast with direct-list-initialization, |
| 4436 | +narrowing conversions\iref{dcl.init.list} are permitted, |
| 4437 | +designators are not permitted, |
| 4438 | +a temporary object bound to a reference |
| 4439 | +does not have its lifetime extended\iref{class.temporary}, and |
| 4440 | +there is no brace elision. |
| 4441 | +\begin{example} |
| 4442 | +\begin{codeblock} |
| 4443 | +struct A { |
| 4444 | + int a; |
| 4445 | + int&& r; |
| 4446 | +}; |
| 4447 | + |
| 4448 | +int f(); |
| 4449 | +int n = 10; |
| 4450 | + |
| 4451 | +A a1{1, f()}; // OK, lifetime is extended |
| 4452 | +A a2(1, f()); // well-formed, but dangling reference |
| 4453 | +A a3{1.0, 1}; // error: narrowing conversion |
| 4454 | +A a4(1.0, 1); // well-formed, but dangling reference |
| 4455 | +A a5(1.0, std::move(n)); // OK |
| 4456 | +\end{codeblock} |
| 4457 | +\end{example} |
| 4458 | +\end{note} |
| 4459 | +\item |
| 4460 | +Otherwise, the initialization is ill-formed. |
| 4461 | +\end{itemize} |
| 4462 | + |
4399 | 4463 | \item
|
4400 | 4464 | Otherwise (i.e., for the remaining copy-initialization cases),
|
4401 | 4465 | user-defined conversions that can convert from the
|
|
0 commit comments