From Jason Turner

[over.best.ics]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpg97dlgex/{from.md → to.md} +132 -97
tmp/tmpg97dlgex/{from.md → to.md} RENAMED
@@ -1,30 +1,32 @@
1
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
2
 
3
  An *implicit conversion sequence* is a sequence of conversions used to
4
  convert an argument in a function call to the type of the corresponding
5
  parameter of the function being called. The sequence of conversions is
6
- an implicit conversion as defined in Clause  [[conv]], which means it is
7
  governed by the rules for initialization of an object or reference by a
8
  single expression ([[dcl.init]], [[dcl.init.ref]]).
9
 
10
  Implicit conversion sequences are concerned only with the type,
11
  cv-qualification, and value category of the argument and how these are
12
- converted to match the corresponding properties of the parameter. Other
13
- properties, such as the lifetime, storage class, alignment,
14
- accessibility of the argument, whether the argument is a bit-field, and
15
- whether a function is deleted ([[dcl.fct.def.delete]]), are ignored.
16
- So, although an implicit conversion sequence can be defined for a given
17
- argument-parameter pair, the conversion from the argument to the
18
- parameter might still be ill-formed in the final analysis.
 
 
19
 
20
  A well-formed implicit conversion sequence is one of the following
21
  forms:
22
 
23
- - a *standard conversion sequence* ([[over.ics.scs]]),
24
- - a *user-defined conversion sequence* ([[over.ics.user]]), or
25
- - an *ellipsis conversion sequence* ([[over.ics.ellipsis]]).
26
 
27
  However, if the target is
28
 
29
  - the first parameter of a constructor or
30
  - the implicit object parameter of a user-defined conversion function
@@ -41,25 +43,25 @@ by
41
  is the first parameter of a constructor of class `X`, and the
42
  conversion is to `X` or reference to cv `X`,
43
 
44
  user-defined conversion sequences are not considered.
45
 
46
- [*Note 1*: These rules prevent more than one user-defined conversion
47
  from being applied during overload resolution, thereby avoiding infinite
48
  recursion. — *end note*]
49
 
50
  [*Example 1*:
51
 
52
  ``` cpp
53
  struct Y { Y(int); };
54
  struct A { operator int(); };
55
  Y y1 = A(); // error: A::operator int() is not a candidate
56
 
57
- struct X { };
58
  struct B { operator X(); };
59
  B b;
60
- X x({b}); // error: B::operator X() is not a candidate
61
  ```
62
 
63
  — *end example*]
64
 
65
  For the case where the parameter type is a reference, see 
@@ -69,12 +71,12 @@ When the parameter type is not a reference, the implicit conversion
69
  sequence models a copy-initialization of the parameter from the argument
70
  expression. The implicit conversion sequence is the one required to
71
  convert the argument expression to a prvalue of the type of the
72
  parameter.
73
 
74
- [*Note 2*: When the parameter has a class type, this is a conceptual
75
- conversion defined for the purposes of Clause  [[over]]; the actual
76
  initialization is defined in terms of constructors and is not a
77
  conversion. — *end note*]
78
 
79
  Any difference in top-level cv-qualification is subsumed by the
80
  initialization itself and does not constitute a conversion.
@@ -86,39 +88,39 @@ case is the identity sequence; it contains no “conversion” from
86
 
87
  When the parameter has a class type and the argument expression has the
88
  same type, the implicit conversion sequence is an identity conversion.
89
  When the parameter has a class type and the argument expression has a
90
  derived class type, the implicit conversion sequence is a
91
- derived-to-base Conversion from the derived class to the base class.
92
 
93
- [*Note 3*: There is no such standard conversion; this derived-to-base
94
- Conversion exists only in the description of implicit conversion
95
  sequences. — *end note*]
96
 
97
- A derived-to-base Conversion has Conversion rank ([[over.ics.scs]]).
98
 
99
  In all contexts, when converting to the implicit object parameter or
100
  when converting to the left operand of an assignment operation only
101
  standard conversion sequences are allowed.
102
 
103
  If no conversions are required to match an argument to a parameter type,
104
  the implicit conversion sequence is the standard conversion sequence
105
- consisting of the identity conversion ([[over.ics.scs]]).
106
 
107
  If no sequence of conversions can be found to convert an argument to a
108
  parameter type, an implicit conversion sequence cannot be formed.
109
 
110
- If several different sequences of conversions exist that each convert
111
- the argument to the parameter type, the implicit conversion sequence
112
- associated with the parameter is defined to be the unique conversion
113
- sequence designated the *ambiguous conversion sequence*. For the purpose
114
- of ranking implicit conversion sequences as described in 
115
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
116
  user-defined conversion sequence that is indistinguishable from any
117
  other user-defined conversion sequence.
118
 
119
- [*Note 4*:
120
 
121
  This rule prevents a function from becoming non-viable because of an
122
  ambiguous conversion sequence for one of its parameters.
123
 
124
  [*Example 3*:
@@ -129,11 +131,11 @@ class A { A (B&);};
129
  class B { operator A (); };
130
  class C { C (B&); };
131
  void f(A) { }
132
  void f(C) { }
133
  B b;
134
- f(b); // ill-formed: ambiguous because there is a conversion b → C (via constructor)
135
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
136
  void f(B) { }
137
  f(b); // OK, unambiguous
138
  ```
139
 
@@ -148,69 +150,66 @@ conversion of one of the arguments in the call is ambiguous.
148
  The three forms of implicit conversion sequences mentioned above are
149
  defined in the following subclauses.
150
 
151
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
152
 
153
- Table  [[tab:over.conversions]] summarizes the conversions defined in
154
- Clause  [[conv]] and partitions them into four disjoint categories:
155
- Lvalue Transformation, Qualification Adjustment, Promotion, and
156
- Conversion.
157
 
158
- [*Note 5*: These categories are orthogonal with respect to value
159
  category, cv-qualification, and data representation: the Lvalue
160
  Transformations do not change the cv-qualification or data
161
  representation of the type; the Qualification Adjustments do not change
162
  the value category or data representation of the type; and the
163
  Promotions and Conversions do not change the value category or
164
  cv-qualification of the type. — *end note*]
165
 
166
- [*Note 6*: As described in Clause  [[conv]], a standard conversion
167
- sequence is either the Identity conversion by itself (that is, no
168
- conversion) or consists of one to three conversions from the other four
169
- categories. If there are two or more conversions in the sequence, the
170
- conversions are applied in the canonical order: **Lvalue
171
- Transformation**, **Promotion** or **Conversion**, **Qualification
172
- Adjustment**. — *end note*]
173
 
174
- Each conversion in Table  [[tab:over.conversions]] also has an
175
- associated rank (Exact Match, Promotion, or Conversion). These are used
176
- to rank standard conversion sequences ([[over.ics.rank]]). The rank of
177
- a conversion sequence is determined by considering the rank of each
178
- conversion in the sequence and the rank of any reference binding (
179
- [[over.ics.ref]]). If any of those has Conversion rank, the sequence has
180
- Conversion rank; otherwise, if any of those has Promotion rank, the
181
- sequence has Promotion rank; otherwise, the sequence has Exact Match
182
- rank.
183
 
184
- **Table: Conversions** <a id="tab:over.conversions">[tab:over.conversions]</a>
185
 
186
  | Conversion | Category | Rank | Subclause |
187
  | ----------------------- | -------- | ---- | ----------------- |
188
  | No conversions required | Identity | | |
189
  | Integral promotions | | | [[conv.prom]] |
190
  | Integral conversions | | | [[conv.integral]] |
191
 
192
 
193
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
194
 
195
- A user-defined conversion sequence consists of an initial standard
196
- conversion sequence followed by a user-defined conversion (
197
- [[class.conv]]) followed by a second standard conversion sequence. If
198
- the user-defined conversion is specified by a constructor (
199
- [[class.conv.ctor]]), the initial standard conversion sequence converts
200
- the source type to the type required by the argument of the constructor.
201
- If the user-defined conversion is specified by a conversion function (
202
- [[class.conv.fct]]), the initial standard conversion sequence converts
203
- the source type to the implicit object parameter of the conversion
204
- function.
205
 
206
  The second standard conversion sequence converts the result of the
207
- user-defined conversion to the target type for the sequence. Since an
208
- implicit conversion sequence is an initialization, the special rules for
209
- initialization by user-defined conversion apply when selecting the best
210
- user-defined conversion for a user-defined conversion sequence (see 
211
- [[over.match.best]] and  [[over.best.ics]]).
 
212
 
213
  If the user-defined conversion is specified by a specialization of a
214
  conversion function template, the second standard conversion sequence
215
  shall have exact match rank.
216
 
@@ -226,15 +225,15 @@ An ellipsis conversion sequence occurs when an argument in a function
226
  call is matched with the ellipsis parameter specification of the
227
  function called (see  [[expr.call]]).
228
 
229
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
230
 
231
- When a parameter of reference type binds directly ([[dcl.init.ref]]) to
232
- an argument expression, the implicit conversion sequence is the identity
233
  conversion, unless the argument expression has a type that is a derived
234
  class of the parameter type, in which case the implicit conversion
235
- sequence is a derived-to-base Conversion ([[over.best.ics]]).
236
 
237
  [*Example 4*:
238
 
239
  ``` cpp
240
  struct A {};
@@ -246,73 +245,108 @@ int i = f(b); // calls f(B&), an exact match, rather than f(A&), a convers
246
 
247
  — *end example*]
248
 
249
  If the parameter binds directly to the result of applying a conversion
250
  function to the argument expression, the implicit conversion sequence is
251
- a user-defined conversion sequence ([[over.ics.user]]), with the second
252
  standard conversion sequence either an identity conversion or, if the
253
  conversion function returns an entity of a type that is a derived class
254
- of the parameter type, a derived-to-base Conversion.
255
 
256
  When a parameter of reference type is not bound directly to an argument
257
  expression, the conversion sequence is the one required to convert the
258
  argument expression to the referenced type according to 
259
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
260
  copy-initializing a temporary of the referenced type with the argument
261
  expression. Any difference in top-level cv-qualification is subsumed by
262
  the initialization itself and does not constitute a conversion.
263
 
264
  Except for an implicit object parameter, for which see 
265
- [[over.match.funcs]], a standard conversion sequence cannot be formed if
266
- it requires binding an lvalue reference other than a reference to a
267
  non-volatile `const` type to an rvalue or binding an rvalue reference to
268
  an lvalue other than a function lvalue.
269
 
270
- [*Note 7*: This means, for example, that a candidate function cannot be
271
  a viable function if it has a non-`const` lvalue reference parameter
272
  (other than the implicit object parameter) and the corresponding
273
  argument would require a temporary to be created to initialize the
274
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
275
 
276
  Other restrictions on binding a reference to a particular argument that
277
  are not based on the types of the reference and the argument do not
278
- affect the formation of a standard conversion sequence, however.
279
 
280
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
281
  can be a viable candidate even if the corresponding argument is an `int`
282
  bit-field. The formation of implicit conversion sequences treats the
283
  `int` bit-field as an `int` lvalue and finds an exact match with the
284
  parameter. If the function is selected by overload resolution, the call
285
  will nonetheless be ill-formed because of the prohibition on binding a
286
- non-`const` lvalue reference to a bit-field (
287
- [[dcl.init.ref]]). — *end example*]
288
 
289
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
290
 
291
- When an argument is an initializer list ([[dcl.init.list]]), it is not
292
- an expression and special rules apply for converting it to a parameter
293
  type.
294
 
295
- If the parameter type is an aggregate class `X` and the initializer list
296
- has a single element of type cv `U`, where `U` is `X` or a class derived
297
- from `X`, the implicit conversion sequence is the one required to
298
- convert the element to the parameter type.
 
 
299
 
300
- Otherwise, if the parameter type is a character array [^11] and the
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  initializer list has a single element that is an appropriately-typed
302
- string literal ([[dcl.init.string]]), the implicit conversion sequence
303
  is the identity conversion.
304
 
305
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
306
  the elements of the initializer list can be implicitly converted to `X`,
307
  the implicit conversion sequence is the worst conversion necessary to
308
  convert an element of the list to `X`, or if the initializer list has no
309
  elements, the identity conversion. This conversion can be a user-defined
310
  conversion even in the context of a call to an initializer-list
311
  constructor.
312
 
313
- [*Example 6*:
314
 
315
  ``` cpp
316
  void f(std::initializer_list<int>);
317
  f( {} ); // OK: f(initializer_list<int>) identity conversion
318
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
@@ -334,15 +368,16 @@ void h(const IA&);
334
  h({ 1, 2, 3 }); // OK: identity conversion
335
  ```
336
 
337
  — *end example*]
338
 
339
- Otherwise, if the parameter type is “array of `N` `X`”, if there exists
340
- an implicit conversion sequence for each element of the array from the
341
- corresponding element of the initializer list (or from `{}` if there is
342
- no such element), the implicit conversion sequence is the worst such
343
- implicit conversion sequence.
 
344
 
345
  Otherwise, if the parameter is a non-aggregate class `X` and overload
346
  resolution per  [[over.match.list]] chooses a single best constructor
347
  `C` of `X` to perform the initialization of an object of type `X` from
348
  the argument initializer list:
@@ -359,11 +394,11 @@ If multiple constructors are viable but none is better than the others,
359
  the implicit conversion sequence is the ambiguous conversion sequence.
360
  User-defined conversions are allowed for conversion of the initializer
361
  list elements to the constructor parameter types except as noted in 
362
  [[over.best.ics]].
363
 
364
- [*Example 7*:
365
 
366
  ``` cpp
367
  struct A {
368
  A(std::initializer_list<int>);
369
  };
@@ -395,15 +430,15 @@ i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::st
395
 
396
  — *end example*]
397
 
398
  Otherwise, if the parameter has an aggregate type which can be
399
  initialized from the initializer list according to the rules for
400
- aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
401
  sequence is a user-defined conversion sequence with the second standard
402
  conversion sequence an identity conversion.
403
 
404
- [*Example 8*:
405
 
406
  ``` cpp
407
  struct A {
408
  int m1;
409
  double m2;
@@ -416,14 +451,14 @@ f( {1.0} ); // error: narrowing
416
 
417
  — *end example*]
418
 
419
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
420
 
421
- [*Note 8*: The rules in this section will apply for initializing the
422
  underlying temporary for the reference. — *end note*]
423
 
424
- [*Example 9*:
425
 
426
  ``` cpp
427
  struct A {
428
  int m1;
429
  double m2;
@@ -442,21 +477,21 @@ g({1}); // same conversion as int to double
442
  Otherwise, if the parameter type is not a class:
443
 
444
  - if the initializer list has one element that is not itself an
445
  initializer list, the implicit conversion sequence is the one required
446
  to convert the element to the parameter type;
447
- \[*Example 10*:
448
  ``` cpp
449
  void f(int);
450
  f( {'a'} ); // OK: same conversion as char to int
451
  f( {1.0} ); // error: narrowing
452
  ```
453
 
454
  — *end example*]
455
  - if the initializer list has no elements, the implicit conversion
456
  sequence is the identity conversion.
457
- \[*Example 11*:
458
  ``` cpp
459
  void f(int);
460
  f( { } ); // OK: identity conversion
461
  ```
462
 
 
1
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
2
 
3
  An *implicit conversion sequence* is a sequence of conversions used to
4
  convert an argument in a function call to the type of the corresponding
5
  parameter of the function being called. The sequence of conversions is
6
+ an implicit conversion as defined in [[conv]], which means it is
7
  governed by the rules for initialization of an object or reference by a
8
  single expression ([[dcl.init]], [[dcl.init.ref]]).
9
 
10
  Implicit conversion sequences are concerned only with the type,
11
  cv-qualification, and value category of the argument and how these are
12
+ converted to match the corresponding properties of the parameter.
13
+
14
+ [*Note 1*: Other properties, such as the lifetime, storage class,
15
+ alignment, accessibility of the argument, whether the argument is a
16
+ bit-field, and whether a function is deleted [[dcl.fct.def.delete]], are
17
+ ignored. So, although an implicit conversion sequence can be defined for
18
+ a given argument-parameter pair, the conversion from the argument to the
19
+ parameter might still be ill-formed in the final
20
+ analysis. — *end note*]
21
 
22
  A well-formed implicit conversion sequence is one of the following
23
  forms:
24
 
25
+ - a standard conversion sequence [[over.ics.scs]],
26
+ - a user-defined conversion sequence [[over.ics.user]], or
27
+ - an ellipsis conversion sequence [[over.ics.ellipsis]].
28
 
29
  However, if the target is
30
 
31
  - the first parameter of a constructor or
32
  - the implicit object parameter of a user-defined conversion function
 
43
  is the first parameter of a constructor of class `X`, and the
44
  conversion is to `X` or reference to cv `X`,
45
 
46
  user-defined conversion sequences are not considered.
47
 
48
+ [*Note 2*: These rules prevent more than one user-defined conversion
49
  from being applied during overload resolution, thereby avoiding infinite
50
  recursion. — *end note*]
51
 
52
  [*Example 1*:
53
 
54
  ``` cpp
55
  struct Y { Y(int); };
56
  struct A { operator int(); };
57
  Y y1 = A(); // error: A::operator int() is not a candidate
58
 
59
+ struct X { X(); };
60
  struct B { operator X(); };
61
  B b;
62
+ X x{{b}}; // error: B::operator X() is not a candidate
63
  ```
64
 
65
  — *end example*]
66
 
67
  For the case where the parameter type is a reference, see 
 
71
  sequence models a copy-initialization of the parameter from the argument
72
  expression. The implicit conversion sequence is the one required to
73
  convert the argument expression to a prvalue of the type of the
74
  parameter.
75
 
76
+ [*Note 3*: When the parameter has a class type, this is a conceptual
77
+ conversion defined for the purposes of [[over]]; the actual
78
  initialization is defined in terms of constructors and is not a
79
  conversion. — *end note*]
80
 
81
  Any difference in top-level cv-qualification is subsumed by the
82
  initialization itself and does not constitute a conversion.
 
88
 
89
  When the parameter has a class type and the argument expression has the
90
  same type, the implicit conversion sequence is an identity conversion.
91
  When the parameter has a class type and the argument expression has a
92
  derived class type, the implicit conversion sequence is a
93
+ derived-to-base conversion from the derived class to the base class.
94
 
95
+ [*Note 4*: There is no such standard conversion; this derived-to-base
96
+ conversion exists only in the description of implicit conversion
97
  sequences. — *end note*]
98
 
99
+ A derived-to-base conversion has Conversion rank [[over.ics.scs]].
100
 
101
  In all contexts, when converting to the implicit object parameter or
102
  when converting to the left operand of an assignment operation only
103
  standard conversion sequences are allowed.
104
 
105
  If no conversions are required to match an argument to a parameter type,
106
  the implicit conversion sequence is the standard conversion sequence
107
+ consisting of the identity conversion [[over.ics.scs]].
108
 
109
  If no sequence of conversions can be found to convert an argument to a
110
  parameter type, an implicit conversion sequence cannot be formed.
111
 
112
+ If there are multiple well-formed implicit conversion sequences
113
+ converting the argument to the parameter type, the implicit conversion
114
+ sequence associated with the parameter is defined to be the unique
115
+ conversion sequence designated the *ambiguous conversion sequence*. For
116
+ the purpose of ranking implicit conversion sequences as described in 
117
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
118
  user-defined conversion sequence that is indistinguishable from any
119
  other user-defined conversion sequence.
120
 
121
+ [*Note 5*:
122
 
123
  This rule prevents a function from becoming non-viable because of an
124
  ambiguous conversion sequence for one of its parameters.
125
 
126
  [*Example 3*:
 
131
  class B { operator A (); };
132
  class C { C (B&); };
133
  void f(A) { }
134
  void f(C) { }
135
  B b;
136
+ f(b); // error: ambiguous because there is a conversion b → C (via constructor)
137
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
138
  void f(B) { }
139
  f(b); // OK, unambiguous
140
  ```
141
 
 
150
  The three forms of implicit conversion sequences mentioned above are
151
  defined in the following subclauses.
152
 
153
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
154
 
155
+ summarizes the conversions defined in [[conv]] and partitions them into
156
+ four disjoint categories: Lvalue Transformation, Qualification
157
+ Adjustment, Promotion, and Conversion.
 
158
 
159
+ [*Note 6*: These categories are orthogonal with respect to value
160
  category, cv-qualification, and data representation: the Lvalue
161
  Transformations do not change the cv-qualification or data
162
  representation of the type; the Qualification Adjustments do not change
163
  the value category or data representation of the type; and the
164
  Promotions and Conversions do not change the value category or
165
  cv-qualification of the type. — *end note*]
166
 
167
+ [*Note 7*: As described in [[conv]], a standard conversion sequence
168
+ either is the Identity conversion by itself (that is, no conversion) or
169
+ consists of one to three conversions from the other four categories. If
170
+ there are two or more conversions in the sequence, the conversions are
171
+ applied in the canonical order: **Lvalue Transformation**, **Promotion**
172
+ or **Conversion**, **Qualification Adjustment**. *end note*]
 
173
 
174
+ Each conversion in [[over.ics.scs]] also has an associated rank (Exact
175
+ Match, Promotion, or Conversion). These are used to rank standard
176
+ conversion sequences [[over.ics.rank]]. The rank of a conversion
177
+ sequence is determined by considering the rank of each conversion in the
178
+ sequence and the rank of any reference binding [[over.ics.ref]]. If any
179
+ of those has Conversion rank, the sequence has Conversion rank;
180
+ otherwise, if any of those has Promotion rank, the sequence has
181
+ Promotion rank; otherwise, the sequence has Exact Match rank.
 
182
 
183
+ **Table: Conversions** <a id="over.ics.scs">[over.ics.scs]</a>
184
 
185
  | Conversion | Category | Rank | Subclause |
186
  | ----------------------- | -------- | ---- | ----------------- |
187
  | No conversions required | Identity | | |
188
  | Integral promotions | | | [[conv.prom]] |
189
  | Integral conversions | | | [[conv.integral]] |
190
 
191
 
192
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
193
 
194
+ A *user-defined conversion sequence* consists of an initial standard
195
+ conversion sequence followed by a user-defined conversion [[class.conv]]
196
+ followed by a second standard conversion sequence. If the user-defined
197
+ conversion is specified by a constructor [[class.conv.ctor]], the
198
+ initial standard conversion sequence converts the source type to the
199
+ type required by the argument of the constructor. If the user-defined
200
+ conversion is specified by a conversion function [[class.conv.fct]], the
201
+ initial standard conversion sequence converts the source type to the
202
+ implicit object parameter of the conversion function.
 
203
 
204
  The second standard conversion sequence converts the result of the
205
+ user-defined conversion to the target type for the sequence; any
206
+ reference binding is included in the second standard conversion
207
+ sequence. Since an implicit conversion sequence is an initialization,
208
+ the special rules for initialization by user-defined conversion apply
209
+ when selecting the best user-defined conversion for a user-defined
210
+ conversion sequence (see  [[over.match.best]] and  [[over.best.ics]]).
211
 
212
  If the user-defined conversion is specified by a specialization of a
213
  conversion function template, the second standard conversion sequence
214
  shall have exact match rank.
215
 
 
225
  call is matched with the ellipsis parameter specification of the
226
  function called (see  [[expr.call]]).
227
 
228
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
229
 
230
+ When a parameter of reference type binds directly [[dcl.init.ref]] to an
231
+ argument expression, the implicit conversion sequence is the identity
232
  conversion, unless the argument expression has a type that is a derived
233
  class of the parameter type, in which case the implicit conversion
234
+ sequence is a derived-to-base Conversion [[over.best.ics]].
235
 
236
  [*Example 4*:
237
 
238
  ``` cpp
239
  struct A {};
 
245
 
246
  — *end example*]
247
 
248
  If the parameter binds directly to the result of applying a conversion
249
  function to the argument expression, the implicit conversion sequence is
250
+ a user-defined conversion sequence [[over.ics.user]], with the second
251
  standard conversion sequence either an identity conversion or, if the
252
  conversion function returns an entity of a type that is a derived class
253
+ of the parameter type, a derived-to-base conversion.
254
 
255
  When a parameter of reference type is not bound directly to an argument
256
  expression, the conversion sequence is the one required to convert the
257
  argument expression to the referenced type according to 
258
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
259
  copy-initializing a temporary of the referenced type with the argument
260
  expression. Any difference in top-level cv-qualification is subsumed by
261
  the initialization itself and does not constitute a conversion.
262
 
263
  Except for an implicit object parameter, for which see 
264
+ [[over.match.funcs]], an implicit conversion sequence cannot be formed
265
+ if it requires binding an lvalue reference other than a reference to a
266
  non-volatile `const` type to an rvalue or binding an rvalue reference to
267
  an lvalue other than a function lvalue.
268
 
269
+ [*Note 8*: This means, for example, that a candidate function cannot be
270
  a viable function if it has a non-`const` lvalue reference parameter
271
  (other than the implicit object parameter) and the corresponding
272
  argument would require a temporary to be created to initialize the
273
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
274
 
275
  Other restrictions on binding a reference to a particular argument that
276
  are not based on the types of the reference and the argument do not
277
+ affect the formation of an implicit conversion sequence, however.
278
 
279
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
280
  can be a viable candidate even if the corresponding argument is an `int`
281
  bit-field. The formation of implicit conversion sequences treats the
282
  `int` bit-field as an `int` lvalue and finds an exact match with the
283
  parameter. If the function is selected by overload resolution, the call
284
  will nonetheless be ill-formed because of the prohibition on binding a
285
+ non-`const` lvalue reference to a bit-field
286
+ [[dcl.init.ref]]. — *end example*]
287
 
288
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
289
 
290
+ When an argument is an initializer list [[dcl.init.list]], it is not an
291
+ expression and special rules apply for converting it to a parameter
292
  type.
293
 
294
+ If the initializer list is a *designated-initializer-list*, a conversion
295
+ is only possible if the parameter has an aggregate type that can be
296
+ initialized from the initializer list according to the rules for
297
+ aggregate initialization [[dcl.init.aggr]], in which case the implicit
298
+ conversion sequence is a user-defined conversion sequence whose second
299
+ standard conversion sequence is an identity conversion.
300
 
301
+ [*Note 9*:
302
+
303
+ Aggregate initialization does not require that the members are declared
304
+ in designation order. If, after overload resolution, the order does not
305
+ match for the selected overload, the initialization of the parameter
306
+ will be ill-formed [[dcl.init.list]].
307
+
308
+ [*Example 6*:
309
+
310
+ ``` cpp
311
+ struct A { int x, y; };
312
+ struct B { int y, x; };
313
+ void f(A a, int); // #1
314
+ void f(B b, ...); // #2
315
+ void g(A a); // #3
316
+ void g(B b); // #4
317
+ void h() {
318
+ f({.x = 1, .y = 2}, 0); // OK; calls #1
319
+ f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails
320
+ // due to non-matching member order[dcl.init.list]
321
+ g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4
322
+ }
323
+ ```
324
+
325
+ — *end example*]
326
+
327
+ — *end note*]
328
+
329
+ Otherwise, if the parameter type is an aggregate class `X` and the
330
+ initializer list has a single element of type cv `U`, where `U` is `X`
331
+ or a class derived from `X`, the implicit conversion sequence is the one
332
+ required to convert the element to the parameter type.
333
+
334
+ Otherwise, if the parameter type is a character array [^10] and the
335
  initializer list has a single element that is an appropriately-typed
336
+ *string-literal* [[dcl.init.string]], the implicit conversion sequence
337
  is the identity conversion.
338
 
339
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
340
  the elements of the initializer list can be implicitly converted to `X`,
341
  the implicit conversion sequence is the worst conversion necessary to
342
  convert an element of the list to `X`, or if the initializer list has no
343
  elements, the identity conversion. This conversion can be a user-defined
344
  conversion even in the context of a call to an initializer-list
345
  constructor.
346
 
347
+ [*Example 7*:
348
 
349
  ``` cpp
350
  void f(std::initializer_list<int>);
351
  f( {} ); // OK: f(initializer_list<int>) identity conversion
352
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
 
368
  h({ 1, 2, 3 }); // OK: identity conversion
369
  ```
370
 
371
  — *end example*]
372
 
373
+ Otherwise, if the parameter type is “array of `N` `X`” or “array of
374
+ unknown bound of `X`”, if there exists an implicit conversion sequence
375
+ from each element of the initializer list (and from `{}` in the former
376
+ case if `N` exceeds the number of elements in the initializer list) to
377
+ `X`, the implicit conversion sequence is the worst such implicit
378
+ conversion sequence.
379
 
380
  Otherwise, if the parameter is a non-aggregate class `X` and overload
381
  resolution per  [[over.match.list]] chooses a single best constructor
382
  `C` of `X` to perform the initialization of an object of type `X` from
383
  the argument initializer list:
 
394
  the implicit conversion sequence is the ambiguous conversion sequence.
395
  User-defined conversions are allowed for conversion of the initializer
396
  list elements to the constructor parameter types except as noted in 
397
  [[over.best.ics]].
398
 
399
+ [*Example 8*:
400
 
401
  ``` cpp
402
  struct A {
403
  A(std::initializer_list<int>);
404
  };
 
430
 
431
  — *end example*]
432
 
433
  Otherwise, if the parameter has an aggregate type which can be
434
  initialized from the initializer list according to the rules for
435
+ aggregate initialization [[dcl.init.aggr]], the implicit conversion
436
  sequence is a user-defined conversion sequence with the second standard
437
  conversion sequence an identity conversion.
438
 
439
+ [*Example 9*:
440
 
441
  ``` cpp
442
  struct A {
443
  int m1;
444
  double m2;
 
451
 
452
  — *end example*]
453
 
454
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
455
 
456
+ [*Note 10*: The rules in this subclause will apply for initializing the
457
  underlying temporary for the reference. — *end note*]
458
 
459
+ [*Example 10*:
460
 
461
  ``` cpp
462
  struct A {
463
  int m1;
464
  double m2;
 
477
  Otherwise, if the parameter type is not a class:
478
 
479
  - if the initializer list has one element that is not itself an
480
  initializer list, the implicit conversion sequence is the one required
481
  to convert the element to the parameter type;
482
+ \[*Example 11*:
483
  ``` cpp
484
  void f(int);
485
  f( {'a'} ); // OK: same conversion as char to int
486
  f( {1.0} ); // error: narrowing
487
  ```
488
 
489
  — *end example*]
490
  - if the initializer list has no elements, the implicit conversion
491
  sequence is the identity conversion.
492
+ \[*Example 12*:
493
  ``` cpp
494
  void f(int);
495
  f( { } ); // OK: identity conversion
496
  ```
497