tmp/tmp6prmi8vq/{from.md → to.md}
RENAMED
|
@@ -1,30 +1,65 @@
|
|
| 1 |
##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
|
| 2 |
|
| 3 |
-
When an argument is an initializer list
|
| 4 |
-
|
| 5 |
type.
|
| 6 |
|
| 7 |
-
If the
|
| 8 |
-
|
| 9 |
-
from
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
initializer list has a single element that is an appropriately-typed
|
| 14 |
-
string
|
| 15 |
is the identity conversion.
|
| 16 |
|
| 17 |
Otherwise, if the parameter type is `std::initializer_list<X>` and all
|
| 18 |
the elements of the initializer list can be implicitly converted to `X`,
|
| 19 |
the implicit conversion sequence is the worst conversion necessary to
|
| 20 |
convert an element of the list to `X`, or if the initializer list has no
|
| 21 |
elements, the identity conversion. This conversion can be a user-defined
|
| 22 |
conversion even in the context of a call to an initializer-list
|
| 23 |
constructor.
|
| 24 |
|
| 25 |
-
[*Example
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
void f(std::initializer_list<int>);
|
| 29 |
f( {} ); // OK: f(initializer_list<int>) identity conversion
|
| 30 |
f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
|
|
@@ -46,15 +81,16 @@ void h(const IA&);
|
|
| 46 |
h({ 1, 2, 3 }); // OK: identity conversion
|
| 47 |
```
|
| 48 |
|
| 49 |
— *end example*]
|
| 50 |
|
| 51 |
-
Otherwise, if the parameter type is “array of `N` `X`”
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
implicit conversion sequence
|
|
|
|
| 56 |
|
| 57 |
Otherwise, if the parameter is a non-aggregate class `X` and overload
|
| 58 |
resolution per [[over.match.list]] chooses a single best constructor
|
| 59 |
`C` of `X` to perform the initialization of an object of type `X` from
|
| 60 |
the argument initializer list:
|
|
@@ -71,11 +107,11 @@ If multiple constructors are viable but none is better than the others,
|
|
| 71 |
the implicit conversion sequence is the ambiguous conversion sequence.
|
| 72 |
User-defined conversions are allowed for conversion of the initializer
|
| 73 |
list elements to the constructor parameter types except as noted in
|
| 74 |
[[over.best.ics]].
|
| 75 |
|
| 76 |
-
[*Example
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
struct A {
|
| 80 |
A(std::initializer_list<int>);
|
| 81 |
};
|
|
@@ -107,15 +143,15 @@ i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::st
|
|
| 107 |
|
| 108 |
— *end example*]
|
| 109 |
|
| 110 |
Otherwise, if the parameter has an aggregate type which can be
|
| 111 |
initialized from the initializer list according to the rules for
|
| 112 |
-
aggregate initialization
|
| 113 |
sequence is a user-defined conversion sequence with the second standard
|
| 114 |
conversion sequence an identity conversion.
|
| 115 |
|
| 116 |
-
[*Example
|
| 117 |
|
| 118 |
``` cpp
|
| 119 |
struct A {
|
| 120 |
int m1;
|
| 121 |
double m2;
|
|
@@ -128,14 +164,14 @@ f( {1.0} ); // error: narrowing
|
|
| 128 |
|
| 129 |
— *end example*]
|
| 130 |
|
| 131 |
Otherwise, if the parameter is a reference, see [[over.ics.ref]].
|
| 132 |
|
| 133 |
-
[*Note
|
| 134 |
underlying temporary for the reference. — *end note*]
|
| 135 |
|
| 136 |
-
[*Example
|
| 137 |
|
| 138 |
``` cpp
|
| 139 |
struct A {
|
| 140 |
int m1;
|
| 141 |
double m2;
|
|
@@ -154,21 +190,21 @@ g({1}); // same conversion as int to double
|
|
| 154 |
Otherwise, if the parameter type is not a class:
|
| 155 |
|
| 156 |
- if the initializer list has one element that is not itself an
|
| 157 |
initializer list, the implicit conversion sequence is the one required
|
| 158 |
to convert the element to the parameter type;
|
| 159 |
-
\[*Example
|
| 160 |
``` cpp
|
| 161 |
void f(int);
|
| 162 |
f( {'a'} ); // OK: same conversion as char to int
|
| 163 |
f( {1.0} ); // error: narrowing
|
| 164 |
```
|
| 165 |
|
| 166 |
— *end example*]
|
| 167 |
- if the initializer list has no elements, the implicit conversion
|
| 168 |
sequence is the identity conversion.
|
| 169 |
-
\[*Example
|
| 170 |
``` cpp
|
| 171 |
void f(int);
|
| 172 |
f( { } ); // OK: identity conversion
|
| 173 |
```
|
| 174 |
|
|
|
|
| 1 |
##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
|
| 2 |
|
| 3 |
+
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 4 |
+
expression and special rules apply for converting it to a parameter
|
| 5 |
type.
|
| 6 |
|
| 7 |
+
If the initializer list is a *designated-initializer-list*, a conversion
|
| 8 |
+
is only possible if the parameter has an aggregate type that can be
|
| 9 |
+
initialized from the initializer list according to the rules for
|
| 10 |
+
aggregate initialization [[dcl.init.aggr]], in which case the implicit
|
| 11 |
+
conversion sequence is a user-defined conversion sequence whose second
|
| 12 |
+
standard conversion sequence is an identity conversion.
|
| 13 |
|
| 14 |
+
[*Note 9*:
|
| 15 |
+
|
| 16 |
+
Aggregate initialization does not require that the members are declared
|
| 17 |
+
in designation order. If, after overload resolution, the order does not
|
| 18 |
+
match for the selected overload, the initialization of the parameter
|
| 19 |
+
will be ill-formed [[dcl.init.list]].
|
| 20 |
+
|
| 21 |
+
[*Example 6*:
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
struct A { int x, y; };
|
| 25 |
+
struct B { int y, x; };
|
| 26 |
+
void f(A a, int); // #1
|
| 27 |
+
void f(B b, ...); // #2
|
| 28 |
+
void g(A a); // #3
|
| 29 |
+
void g(B b); // #4
|
| 30 |
+
void h() {
|
| 31 |
+
f({.x = 1, .y = 2}, 0); // OK; calls #1
|
| 32 |
+
f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails
|
| 33 |
+
// due to non-matching member order[dcl.init.list]
|
| 34 |
+
g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4
|
| 35 |
+
}
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
— *end example*]
|
| 39 |
+
|
| 40 |
+
— *end note*]
|
| 41 |
+
|
| 42 |
+
Otherwise, if the parameter type is an aggregate class `X` and the
|
| 43 |
+
initializer list has a single element of type cv `U`, where `U` is `X`
|
| 44 |
+
or a class derived from `X`, the implicit conversion sequence is the one
|
| 45 |
+
required to convert the element to the parameter type.
|
| 46 |
+
|
| 47 |
+
Otherwise, if the parameter type is a character array [^10] and the
|
| 48 |
initializer list has a single element that is an appropriately-typed
|
| 49 |
+
*string-literal* [[dcl.init.string]], the implicit conversion sequence
|
| 50 |
is the identity conversion.
|
| 51 |
|
| 52 |
Otherwise, if the parameter type is `std::initializer_list<X>` and all
|
| 53 |
the elements of the initializer list can be implicitly converted to `X`,
|
| 54 |
the implicit conversion sequence is the worst conversion necessary to
|
| 55 |
convert an element of the list to `X`, or if the initializer list has no
|
| 56 |
elements, the identity conversion. This conversion can be a user-defined
|
| 57 |
conversion even in the context of a call to an initializer-list
|
| 58 |
constructor.
|
| 59 |
|
| 60 |
+
[*Example 7*:
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
void f(std::initializer_list<int>);
|
| 64 |
f( {} ); // OK: f(initializer_list<int>) identity conversion
|
| 65 |
f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
|
|
|
|
| 81 |
h({ 1, 2, 3 }); // OK: identity conversion
|
| 82 |
```
|
| 83 |
|
| 84 |
— *end example*]
|
| 85 |
|
| 86 |
+
Otherwise, if the parameter type is “array of `N` `X`” or “array of
|
| 87 |
+
unknown bound of `X`”, if there exists an implicit conversion sequence
|
| 88 |
+
from each element of the initializer list (and from `{}` in the former
|
| 89 |
+
case if `N` exceeds the number of elements in the initializer list) to
|
| 90 |
+
`X`, the implicit conversion sequence is the worst such implicit
|
| 91 |
+
conversion sequence.
|
| 92 |
|
| 93 |
Otherwise, if the parameter is a non-aggregate class `X` and overload
|
| 94 |
resolution per [[over.match.list]] chooses a single best constructor
|
| 95 |
`C` of `X` to perform the initialization of an object of type `X` from
|
| 96 |
the argument initializer list:
|
|
|
|
| 107 |
the implicit conversion sequence is the ambiguous conversion sequence.
|
| 108 |
User-defined conversions are allowed for conversion of the initializer
|
| 109 |
list elements to the constructor parameter types except as noted in
|
| 110 |
[[over.best.ics]].
|
| 111 |
|
| 112 |
+
[*Example 8*:
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
struct A {
|
| 116 |
A(std::initializer_list<int>);
|
| 117 |
};
|
|
|
|
| 143 |
|
| 144 |
— *end example*]
|
| 145 |
|
| 146 |
Otherwise, if the parameter has an aggregate type which can be
|
| 147 |
initialized from the initializer list according to the rules for
|
| 148 |
+
aggregate initialization [[dcl.init.aggr]], the implicit conversion
|
| 149 |
sequence is a user-defined conversion sequence with the second standard
|
| 150 |
conversion sequence an identity conversion.
|
| 151 |
|
| 152 |
+
[*Example 9*:
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
struct A {
|
| 156 |
int m1;
|
| 157 |
double m2;
|
|
|
|
| 164 |
|
| 165 |
— *end example*]
|
| 166 |
|
| 167 |
Otherwise, if the parameter is a reference, see [[over.ics.ref]].
|
| 168 |
|
| 169 |
+
[*Note 10*: The rules in this subclause will apply for initializing the
|
| 170 |
underlying temporary for the reference. — *end note*]
|
| 171 |
|
| 172 |
+
[*Example 10*:
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
struct A {
|
| 176 |
int m1;
|
| 177 |
double m2;
|
|
|
|
| 190 |
Otherwise, if the parameter type is not a class:
|
| 191 |
|
| 192 |
- if the initializer list has one element that is not itself an
|
| 193 |
initializer list, the implicit conversion sequence is the one required
|
| 194 |
to convert the element to the parameter type;
|
| 195 |
+
\[*Example 11*:
|
| 196 |
``` cpp
|
| 197 |
void f(int);
|
| 198 |
f( {'a'} ); // OK: same conversion as char to int
|
| 199 |
f( {1.0} ); // error: narrowing
|
| 200 |
```
|
| 201 |
|
| 202 |
— *end example*]
|
| 203 |
- if the initializer list has no elements, the implicit conversion
|
| 204 |
sequence is the identity conversion.
|
| 205 |
+
\[*Example 12*:
|
| 206 |
``` cpp
|
| 207 |
void f(int);
|
| 208 |
f( { } ); // OK: identity conversion
|
| 209 |
```
|
| 210 |
|