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