From Jason Turner

[class.conv.fct]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmppkizppza/{from.md → to.md} +11 -12
tmp/tmppkizppza/{from.md → to.md} RENAMED
@@ -1,13 +1,13 @@
1
- ### Conversion functions <a id="class.conv.fct">[[class.conv.fct]]</a>
2
 
3
  A member function of a class `X` having no parameters with a name of the
4
  form
5
 
6
  ``` bnf
7
  conversion-function-id:
8
- 'operator' conversion-type-id
9
  ```
10
 
11
  ``` bnf
12
  conversion-type-id:
13
  type-specifier-seq conversion-declaratorₒₚₜ
@@ -20,16 +20,16 @@ conversion-declarator:
20
 
21
  specifies a conversion from `X` to the type specified by the
22
  *conversion-type-id*. Such functions are called *conversion functions*.
23
  A *decl-specifier* in the *decl-specifier-seq* of a conversion function
24
  (if any) shall be neither a *defining-type-specifier* nor `static`. The
25
- type of the conversion function ([[dcl.fct]]) is “function taking no
26
  parameter returning *conversion-type-id*”. A conversion function is
27
  never used to convert a (possibly cv-qualified) object to the (possibly
28
  cv-qualified) same object type (or a reference to it), to a (possibly
29
  cv-qualified) base class of that type (or a reference to it), or to
30
- (possibly cv-qualified) void.[^2]
31
 
32
  [*Example 1*:
33
 
34
  ``` cpp
35
  struct X {
@@ -47,15 +47,14 @@ void f(X a) {
47
  In all three cases the value assigned will be converted by
48
  `X::operator int()`.
49
 
50
  — *end example*]
51
 
52
- A conversion function may be explicit ([[dcl.fct.spec]]), in which case
53
- it is only considered as a user-defined conversion for
54
- direct-initialization ([[dcl.init]]). Otherwise, user-defined
55
- conversions are not restricted to use in assignments and
56
- initializations.
57
 
58
  [*Example 2*:
59
 
60
  ``` cpp
61
  class Y { };
@@ -63,11 +62,11 @@ struct Z {
63
  explicit operator Y() const;
64
  };
65
 
66
  void h(Z z) {
67
  Y y1(z); // OK: direct-initialization
68
- Y y2 = z; // ill-formed: copy-initialization
69
  Y y3 = (Y)z; // OK: cast notation
70
  }
71
 
72
  void g(X a, X b) {
73
  int i = (a) ? 1+a : 0;
@@ -115,12 +114,12 @@ operator int [[noreturn]] (); // error: noreturn attribute applied to a type
115
 
116
  Conversion functions are inherited.
117
 
118
  Conversion functions can be virtual.
119
 
120
- A conversion function template shall not have a deduced return type (
121
- [[dcl.spec.auto]]).
122
 
123
  [*Example 5*:
124
 
125
  ``` cpp
126
  struct S {
 
1
+ #### Conversion functions <a id="class.conv.fct">[[class.conv.fct]]</a>
2
 
3
  A member function of a class `X` having no parameters with a name of the
4
  form
5
 
6
  ``` bnf
7
  conversion-function-id:
8
+ operator conversion-type-id
9
  ```
10
 
11
  ``` bnf
12
  conversion-type-id:
13
  type-specifier-seq conversion-declaratorₒₚₜ
 
20
 
21
  specifies a conversion from `X` to the type specified by the
22
  *conversion-type-id*. Such functions are called *conversion functions*.
23
  A *decl-specifier* in the *decl-specifier-seq* of a conversion function
24
  (if any) shall be neither a *defining-type-specifier* nor `static`. The
25
+ type of the conversion function [[dcl.fct]] is “function taking no
26
  parameter returning *conversion-type-id*”. A conversion function is
27
  never used to convert a (possibly cv-qualified) object to the (possibly
28
  cv-qualified) same object type (or a reference to it), to a (possibly
29
  cv-qualified) base class of that type (or a reference to it), or to
30
+ cv `void`.[^6]
31
 
32
  [*Example 1*:
33
 
34
  ``` cpp
35
  struct X {
 
47
  In all three cases the value assigned will be converted by
48
  `X::operator int()`.
49
 
50
  — *end example*]
51
 
52
+ A conversion function may be explicit [[dcl.fct.spec]], in which case it
53
+ is only considered as a user-defined conversion for
54
+ direct-initialization [[dcl.init]]. Otherwise, user-defined conversions
55
+ are not restricted to use in assignments and initializations.
 
56
 
57
  [*Example 2*:
58
 
59
  ``` cpp
60
  class Y { };
 
62
  explicit operator Y() const;
63
  };
64
 
65
  void h(Z z) {
66
  Y y1(z); // OK: direct-initialization
67
+ Y y2 = z; // error: no conversion function candidate for copy-initialization
68
  Y y3 = (Y)z; // OK: cast notation
69
  }
70
 
71
  void g(X a, X b) {
72
  int i = (a) ? 1+a : 0;
 
114
 
115
  Conversion functions are inherited.
116
 
117
  Conversion functions can be virtual.
118
 
119
+ A conversion function template shall not have a deduced return type
120
+ [[dcl.spec.auto]].
121
 
122
  [*Example 5*:
123
 
124
  ``` cpp
125
  struct S {