From Jason Turner

[class.conv]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1u0_q3lj/{from.md → to.md} +19 -27
tmp/tmp1u0_q3lj/{from.md → to.md} RENAMED
@@ -12,11 +12,11 @@ User-defined conversions are applied only where they are unambiguous
12
  [[class.member.lookup]], [[class.conv.fct]]. Conversions obey the access
13
  control rules [[class.access]]. Access control is applied after
14
  ambiguity resolution [[basic.lookup]].
15
 
16
  [*Note 1*: See  [[over.match]] for a discussion of the use of
17
- conversions in function calls as well as examples below. — *end note*]
18
 
19
  At most one user-defined conversion (constructor or conversion function)
20
  is implicitly applied to a single value.
21
 
22
  [*Example 1*:
@@ -39,11 +39,11 @@ int c = X(a); // OK, a.operator X().operator int()
39
 
40
  #### Conversion by constructor <a id="class.conv.ctor">[[class.conv.ctor]]</a>
41
 
42
  A constructor that is not explicit [[dcl.fct.spec]] specifies a
43
  conversion from the types of its parameters (if any) to the type of its
44
- class. Such a constructor is called a *converting constructor*.
45
 
46
  [*Example 1*:
47
 
48
  ``` cpp
49
  struct X {
@@ -95,17 +95,10 @@ Z a6 = { 3, 4 }; // error: no implicit conversion
95
 
96
  — *end example*]
97
 
98
  — *end note*]
99
 
100
- A non-explicit copy/move constructor [[class.copy.ctor]] is a converting
101
- constructor.
102
-
103
- [*Note 2*: An implicitly-declared copy/move constructor is not an
104
- explicit constructor; it can be called for implicit type
105
- conversions. — *end note*]
106
-
107
  #### Conversion functions <a id="class.conv.fct">[[class.conv.fct]]</a>
108
 
109
  ``` bnf
110
  conversion-function-id:
111
  operator conversion-type-id
@@ -124,39 +117,38 @@ conversion-declarator:
124
  A declaration whose *declarator-id* has an *unqualified-id* that is a
125
  *conversion-function-id* declares a *conversion function*; its
126
  *declarator* shall be a function declarator [[dcl.fct]] of the form
127
 
128
  ``` bnf
129
- ptr-declarator '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
130
- ref-qualifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
131
  ```
132
 
133
- where the *ptr-declarator* consists solely of an *id-expression*, an
134
  optional *attribute-specifier-seq*, and optional surrounding
135
  parentheses, and the *id-expression* has one of the following forms:
136
 
137
  - in a *member-declaration* that belongs to the *member-specification*
138
  of a class or class template but is not a friend declaration
139
  [[class.friend]], the *id-expression* is a *conversion-function-id*;
140
  - otherwise, the *id-expression* is a *qualified-id* whose
141
  *unqualified-id* is a *conversion-function-id*.
142
 
143
  A conversion function shall have no non-object parameters and shall be a
144
- non-static member function of a class or class template `X`; it
145
- specifies a conversion from `X` to the type specified by the
146
- *conversion-type-id*, interpreted as a *type-id* [[dcl.name]]. A
147
- *decl-specifier* in the *decl-specifier-seq* of a conversion function
148
- (if any) shall not be a *defining-type-specifier*.
 
149
 
150
- The type of the conversion function is “`noexcept`ₒₚₜ function taking
151
- no parameter *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
152
- *conversion-type-id*”.
153
-
154
- A conversion function is never used to convert a (possibly cv-qualified)
155
- object to the (possibly cv-qualified) same object type (or a reference
156
- to it), to a (possibly cv-qualified) base class of that type (or a
157
- reference to it), or to cv `void`.[^6]
158
 
159
  [*Example 1*:
160
 
161
  ``` cpp
162
  struct X {
@@ -208,11 +200,11 @@ void g(X a, X b) {
208
  The *conversion-type-id* shall not represent a function type nor an
209
  array type. The *conversion-type-id* in a *conversion-function-id* is
210
  the longest sequence of tokens that could possibly form a
211
  *conversion-type-id*.
212
 
213
- [*Note 1*:
214
 
215
  This prevents ambiguities between the declarator operator `*` and its
216
  expression counterparts.
217
 
218
  [*Example 3*:
@@ -237,11 +229,11 @@ operator int [[noreturn]] (); // error: noreturn attribute applied to a type
237
 
238
  — *end example*]
239
 
240
  — *end note*]
241
 
242
- [*Note 2*:
243
 
244
  A conversion function in a derived class hides only conversion functions
245
  in base classes that convert to the same type. A conversion function
246
  template with a dependent return type hides only templates in base
247
  classes that correspond to it [[class.member.lookup]]; otherwise, it
 
12
  [[class.member.lookup]], [[class.conv.fct]]. Conversions obey the access
13
  control rules [[class.access]]. Access control is applied after
14
  ambiguity resolution [[basic.lookup]].
15
 
16
  [*Note 1*: See  [[over.match]] for a discussion of the use of
17
+ conversions in function calls. — *end note*]
18
 
19
  At most one user-defined conversion (constructor or conversion function)
20
  is implicitly applied to a single value.
21
 
22
  [*Example 1*:
 
39
 
40
  #### Conversion by constructor <a id="class.conv.ctor">[[class.conv.ctor]]</a>
41
 
42
  A constructor that is not explicit [[dcl.fct.spec]] specifies a
43
  conversion from the types of its parameters (if any) to the type of its
44
+ class.
45
 
46
  [*Example 1*:
47
 
48
  ``` cpp
49
  struct X {
 
95
 
96
  — *end example*]
97
 
98
  — *end note*]
99
 
 
 
 
 
 
 
 
100
  #### Conversion functions <a id="class.conv.fct">[[class.conv.fct]]</a>
101
 
102
  ``` bnf
103
  conversion-function-id:
104
  operator conversion-type-id
 
117
  A declaration whose *declarator-id* has an *unqualified-id* that is a
118
  *conversion-function-id* declares a *conversion function*; its
119
  *declarator* shall be a function declarator [[dcl.fct]] of the form
120
 
121
  ``` bnf
122
+ noptr-declarator parameters-and-qualifiers
 
123
  ```
124
 
125
+ where the *noptr-declarator* consists solely of an *id-expression*, an
126
  optional *attribute-specifier-seq*, and optional surrounding
127
  parentheses, and the *id-expression* has one of the following forms:
128
 
129
  - in a *member-declaration* that belongs to the *member-specification*
130
  of a class or class template but is not a friend declaration
131
  [[class.friend]], the *id-expression* is a *conversion-function-id*;
132
  - otherwise, the *id-expression* is a *qualified-id* whose
133
  *unqualified-id* is a *conversion-function-id*.
134
 
135
  A conversion function shall have no non-object parameters and shall be a
136
+ non-static member function of a class or class template `X`; its
137
+ declared return type is the *conversion-type-id* and it specifies a
138
+ conversion from `X` to the type specified by the *conversion-type-id*,
139
+ interpreted as a *type-id* [[dcl.name]]. A *decl-specifier* in the
140
+ *decl-specifier-seq* of a conversion function (if any) shall not be a
141
+ *defining-type-specifier*.
142
 
143
+ [*Note 1*: A conversion function is never invoked for implicit or
144
+ explicit conversions of an object to the same object type (or a
145
+ reference to it), to a base class of that type (or a reference to it),
146
+ or to cv `void`. Even though never directly called to perform a
147
+ conversion, such conversion functions can be declared and can
148
+ potentially be reached through a call to a virtual conversion function
149
+ in a base class. *end note*]
 
150
 
151
  [*Example 1*:
152
 
153
  ``` cpp
154
  struct X {
 
200
  The *conversion-type-id* shall not represent a function type nor an
201
  array type. The *conversion-type-id* in a *conversion-function-id* is
202
  the longest sequence of tokens that could possibly form a
203
  *conversion-type-id*.
204
 
205
+ [*Note 2*:
206
 
207
  This prevents ambiguities between the declarator operator `*` and its
208
  expression counterparts.
209
 
210
  [*Example 3*:
 
229
 
230
  — *end example*]
231
 
232
  — *end note*]
233
 
234
+ [*Note 3*:
235
 
236
  A conversion function in a derived class hides only conversion functions
237
  in base classes that convert to the same type. A conversion function
238
  template with a dependent return type hides only templates in base
239
  classes that correspond to it [[class.member.lookup]]; otherwise, it