From Jason Turner

[over.ics.ref]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpi_3sid88/{from.md → to.md} +27 -21
tmp/tmpi_3sid88/{from.md → to.md} RENAMED
@@ -4,51 +4,57 @@ When a parameter of reference type binds directly ([[dcl.init.ref]]) to
4
  an argument expression, the implicit conversion sequence is the identity
5
  conversion, unless the argument expression has a type that is a derived
6
  class of the parameter type, in which case the implicit conversion
7
  sequence is a derived-to-base Conversion ([[over.best.ics]]).
8
 
 
 
9
  ``` cpp
10
  struct A {};
11
  struct B : public A {} b;
12
  int f(A&);
13
  int f(B&);
14
- int i = f(b); // calls f(B&), an exact match, rather than
15
- // f(A&), a conversion
16
  ```
17
 
 
 
18
  If the parameter binds directly to the result of applying a conversion
19
  function to the argument expression, the implicit conversion sequence is
20
  a user-defined conversion sequence ([[over.ics.user]]), with the second
21
  standard conversion sequence either an identity conversion or, if the
22
  conversion function returns an entity of a type that is a derived class
23
  of the parameter type, a derived-to-base Conversion.
24
 
25
  When a parameter of reference type is not bound directly to an argument
26
  expression, the conversion sequence is the one required to convert the
27
- argument expression to the underlying type of the reference according
28
- to  [[over.best.ics]]. Conceptually, this conversion sequence
29
- corresponds to copy-initializing a temporary of the underlying type with
30
- the argument expression. Any difference in top-level cv-qualification is
31
- subsumed by the initialization itself and does not constitute a
32
- conversion.
33
 
34
  Except for an implicit object parameter, for which see 
35
  [[over.match.funcs]], a standard conversion sequence cannot be formed if
36
  it requires binding an lvalue reference other than a reference to a
37
  non-volatile `const` type to an rvalue or binding an rvalue reference to
38
- an lvalue other than a function lvalue. This means, for example, that a
39
- candidate function cannot be a viable function if it has a non-`const`
40
- lvalue reference parameter (other than the implicit object parameter)
41
- and the corresponding argument is a temporary or would require one to be
42
- created to initialize the lvalue reference (see  [[dcl.init.ref]]).
 
 
43
 
44
  Other restrictions on binding a reference to a particular argument that
45
  are not based on the types of the reference and the argument do not
46
- affect the formation of a standard conversion sequence, however. a
47
- function with an “lvalue reference to `int`” parameter can be a viable
48
- candidate even if the corresponding argument is an `int` bit-field. The
49
- formation of implicit conversion sequences treats the `int` bit-field as
50
- an `int` lvalue and finds an exact match with the parameter. If the
51
- function is selected by overload resolution, the call will nonetheless
52
- be ill-formed because of the prohibition on binding a non-`const` lvalue
53
- reference to a bit-field ([[dcl.init.ref]]).
 
 
54
 
 
4
  an argument expression, the implicit conversion sequence is the identity
5
  conversion, unless the argument expression has a type that is a derived
6
  class of the parameter type, in which case the implicit conversion
7
  sequence is a derived-to-base Conversion ([[over.best.ics]]).
8
 
9
+ [*Example 4*:
10
+
11
  ``` cpp
12
  struct A {};
13
  struct B : public A {} b;
14
  int f(A&);
15
  int f(B&);
16
+ int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
 
17
  ```
18
 
19
+ — *end example*]
20
+
21
  If the parameter binds directly to the result of applying a conversion
22
  function to the argument expression, the implicit conversion sequence is
23
  a user-defined conversion sequence ([[over.ics.user]]), with the second
24
  standard conversion sequence either an identity conversion or, if the
25
  conversion function returns an entity of a type that is a derived class
26
  of the parameter type, a derived-to-base Conversion.
27
 
28
  When a parameter of reference type is not bound directly to an argument
29
  expression, the conversion sequence is the one required to convert the
30
+ argument expression to the referenced type according to 
31
+ [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
32
+ copy-initializing a temporary of the referenced type with the argument
33
+ expression. Any difference in top-level cv-qualification is subsumed by
34
+ the initialization itself and does not constitute a conversion.
 
35
 
36
  Except for an implicit object parameter, for which see 
37
  [[over.match.funcs]], a standard conversion sequence cannot be formed if
38
  it requires binding an lvalue reference other than a reference to a
39
  non-volatile `const` type to an rvalue or binding an rvalue reference to
40
+ an lvalue other than a function lvalue.
41
+
42
+ [*Note 7*: This means, for example, that a candidate function cannot be
43
+ a viable function if it has a non-`const` lvalue reference parameter
44
+ (other than the implicit object parameter) and the corresponding
45
+ argument would require a temporary to be created to initialize the
46
+ lvalue reference (see  [[dcl.init.ref]]). — *end note*]
47
 
48
  Other restrictions on binding a reference to a particular argument that
49
  are not based on the types of the reference and the argument do not
50
+ affect the formation of a standard conversion sequence, however.
51
+
52
+ [*Example 5*: A function with an “lvalue reference to `int` parameter
53
+ can be a viable candidate even if the corresponding argument is an `int`
54
+ bit-field. The formation of implicit conversion sequences treats the
55
+ `int` bit-field as an `int` lvalue and finds an exact match with the
56
+ parameter. If the function is selected by overload resolution, the call
57
+ will nonetheless be ill-formed because of the prohibition on binding a
58
+ non-`const` lvalue reference to a bit-field (
59
+ [[dcl.init.ref]]). — *end example*]
60