From Jason Turner

[conv]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp4l8k2m19/{from.md → to.md} +190 -100
tmp/tmp4l8k2m19/{from.md → to.md} RENAMED
@@ -7,20 +7,25 @@ the following order:
7
 
8
  - Zero or one conversion from the following set: lvalue-to-rvalue
9
  conversion, array-to-pointer conversion, and function-to-pointer
10
  conversion.
11
  - Zero or one conversion from the following set: integral promotions,
12
- floating point promotion, integral conversions, floating point
13
  conversions, floating-integral conversions, pointer conversions,
14
  pointer to member conversions, and boolean conversions.
 
15
  - Zero or one qualification conversion.
16
 
17
- A standard conversion sequence can be empty, i.e., it can consist of no
18
- conversions. A standard conversion sequence will be applied to an
19
- expression if necessary to convert it to a required destination type.
20
 
21
- expressions with a given type will be implicitly converted to other
 
 
 
 
 
22
  types in several contexts:
23
 
24
  - When used as operands of operators. The operator’s requirements for
25
  its operands dictate the destination type (Clause  [[expr]]).
26
  - When used in the condition of an `if` statement or iteration
@@ -32,10 +37,12 @@ types in several contexts:
32
  includes use as an argument in a function call and use as the
33
  expression in a `return` statement). The type of the entity being
34
  initialized is (generally) the destination type. See  [[dcl.init]], 
35
  [[dcl.init.ref]].
36
 
 
 
37
  An expression `e` can be *implicitly converted* to a type `T` if and
38
  only if the declaration `T t=e;` is well-formed, for some invented
39
  temporary variable `t` ([[dcl.init]]).
40
 
41
  Certain language constructs require that an expression be converted to a
@@ -45,34 +52,35 @@ the declaration `bool t(e);` is well-formed, for some invented temporary
45
  variable `t` ([[dcl.init]]).
46
 
47
  Certain language constructs require conversion to a value having one of
48
  a specified set of types appropriate to the construct. An expression `e`
49
  of class type `E` appearing in such a context is said to be
50
- *contextually implicitly converted to* a specified type `T` and is
51
  well-formed if and only if `e` can be implicitly converted to a type `T`
52
- that is determined as follows: `E` is searched for conversion functions
53
- whose return type is *cv* `T` or reference to *cv* `T` such that `T` is
54
- allowed by the context. There shall be exactly one such `T`.
 
55
 
56
  The effect of any implicit conversion is the same as performing the
57
  corresponding declaration and initialization and then using the
58
  temporary variable as the result of the conversion. The result is an
59
  lvalue if `T` is an lvalue reference type or an rvalue reference to
60
  function type ([[dcl.ref]]), an xvalue if `T` is an rvalue reference to
61
  object type, and a prvalue otherwise. The expression `e` is used as a
62
  glvalue if and only if the initialization uses it as a glvalue.
63
 
64
- For class types, user-defined conversions are considered as well; see 
65
- [[class.conv]]. In general, an implicit conversion sequence (
66
  [[over.best.ics]]) consists of a standard conversion sequence followed
67
  by a user-defined conversion followed by another standard conversion
68
- sequence.
69
 
70
- There are some contexts where certain conversions are suppressed. For
71
- example, the lvalue-to-rvalue conversion is not done on the operand of
72
- the unary `&` operator. Specific exceptions are given in the
73
- descriptions of those operators and contexts.
74
 
75
  ## Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
76
 
77
  A glvalue ([[basic.lval]]) of a non-function, non-array type `T` can be
78
  converted to a prvalue.[^1] If `T` is an incomplete type, a program that
@@ -88,10 +96,12 @@ either
88
  the set of potential results of `e`, and `ex` names a variable `x`
89
  that is not odr-used by `ex` ([[basic.def.odr]]),
90
 
91
  the value contained in the referenced object is not accessed.
92
 
 
 
93
  ``` cpp
94
  struct S { int n; };
95
  auto f() {
96
  S x { 1 };
97
  constexpr S y { 2 };
@@ -100,60 +110,107 @@ auto f() {
100
  auto g = f();
101
  int m = g(false); // undefined behavior due to access of x.n outside its lifetime
102
  int n = g(true); // OK, does not access y.n
103
  ```
104
 
105
- In all other cases, the result of the conversion is determined according
106
- to the following rules:
107
 
108
- - If `T` is (possibly cv-qualified) `std::nullptr_t`, the result is a
109
- null pointer constant ([[conv.ptr]]).
110
- - Otherwise, if `T` has a class type, the conversion copy-initializes a
111
- temporary of type `T` from the glvalue and the result of the
112
- conversion is a prvalue for the temporary.
 
 
 
 
 
113
  - Otherwise, if the object to which the glvalue refers contains an
114
  invalid pointer value ([[basic.stc.dynamic.deallocation]],
115
- [[basic.stc.dynamic.safety]]), the behavior is implementation-defined.
 
116
  - Otherwise, the value contained in the object indicated by the glvalue
117
  is the prvalue result.
118
 
119
- See also  [[basic.lval]].
120
 
121
  ## Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
122
 
123
  An lvalue or rvalue of type “array of `N` `T`” or “array of unknown
124
  bound of `T`” can be converted to a prvalue of type “pointer to `T`”.
 
125
  The result is a pointer to the first element of the array.
126
 
127
  ## Function-to-pointer conversion <a id="conv.func">[[conv.func]]</a>
128
 
129
  An lvalue of function type `T` can be converted to a prvalue of type
130
- “pointer to `T`.” The result is a pointer to the function.[^3]
131
 
132
- See  [[over.over]] for additional rules for the case where the function
133
- is overloaded.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
  ## Qualification conversions <a id="conv.qual">[[conv.qual]]</a>
136
 
137
- A prvalue of type “pointer to *cv1* `T` can be converted to a prvalue
138
- of type “pointer to *cv2* `T` if “*cv2* `T`” is more cv-qualified than
139
- “*cv1* `T`”.
140
 
141
- A prvalue of type “pointer to member of `X` of type *cv1* `T`” can be
142
- converted to a prvalue of type “pointer to member of `X` of type *cv2*
143
- `T`” if “*cv2* `T`is more cv-qualified than*cv1* `T`”.
 
 
 
144
 
145
- Function types (including those used in pointer to member function
146
- types) are never cv-qualified ([[dcl.fct]]).
 
147
 
148
- A conversion can add cv-qualifiers at levels other than the first in
149
- multi-level pointers, subject to the following rules:[^4]
 
150
 
151
- if a program could assign a pointer of type `T**` to a pointer of type
152
- `const` `T**` (that is, if line `#1` below were allowed), a program
153
- could inadvertently modify a `const` object (as it is done on line
154
- `#2`). For example,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  ``` cpp
157
  int main() {
158
  const char c = 'c';
159
  char* pc;
@@ -161,25 +218,21 @@ int main() {
161
  *pcc = &c;
162
  *pc = 'C'; // #2: modifies a const object
163
  }
164
  ```
165
 
166
- A *multi-level* pointer to member type, or a *multi-level mixed* pointer
167
- and pointer to member type has the form:
168
 
169
- where Pᵢ is either a pointer or pointer to member and where *T* is not a
170
- pointer type or pointer to member type.
 
 
 
 
171
 
172
- Two multi-level pointer to member types or two multi-level mixed pointer
173
- and pointer to member types T1 and T2 are *similar* if there exists a
174
- type *T* and integer n > 0 such that:
175
-
176
- and
177
-
178
- For similar multi-level pointer to member types and similar multi-level
179
- mixed pointer and pointer to member types, the rules for adding
180
- cv-qualifiers are the same as those used for similar pointer types.
181
 
182
  ## Integral promotions <a id="conv.prom">[[conv.prom]]</a>
183
 
184
  A prvalue of an integer type other than `bool`, `char16_t`, `char32_t`,
185
  or `wchar_t` whose integer conversion rank ([[conv.rank]]) is less than
@@ -188,26 +241,26 @@ can represent all the values of the source type; otherwise, the source
188
  prvalue can be converted to a prvalue of type `unsigned int`.
189
 
190
  A prvalue of type `char16_t`, `char32_t`, or `wchar_t` (
191
  [[basic.fundamental]]) can be converted to a prvalue of the first of the
192
  following types that can represent all the values of its underlying
193
- type: `int`, `unsigned int`, `long` `int`, `unsigned long` `int`,
194
  `long long int`, or `unsigned long long int`. If none of the types in
195
  that list can represent all the values of its underlying type, a prvalue
196
  of type `char16_t`, `char32_t`, or `wchar_t` can be converted to a
197
  prvalue of its underlying type.
198
 
199
  A prvalue of an unscoped enumeration type whose underlying type is not
200
  fixed ([[dcl.enum]]) can be converted to a prvalue of the first of the
201
  following types that can represent all the values of the enumeration
202
  (i.e., the values in the range bₘin to bₘax as described in 
203
- [[dcl.enum]]): `int`, `unsigned int`, `long` `int`, `unsigned long`
204
- `int`, `long long int`, or `unsigned long long int`. If none of the
205
- types in that list can represent all the values of the enumeration, a
206
- prvalue of an unscoped enumeration type can be converted to a prvalue of
207
- the extended integer type with lowest integer conversion rank (
208
- [[conv.rank]]) greater than the rank of `long` `long` in which all the
209
  values of the enumeration can be represented. If there are two such
210
  extended types, the signed one is chosen.
211
 
212
  A prvalue of an unscoped enumeration type whose underlying type is
213
  fixed ([[dcl.enum]]) can be converted to a prvalue of its underlying
@@ -227,69 +280,76 @@ that type for promotion purposes.
227
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
228
  with `false` becoming zero and `true` becoming one.
229
 
230
  These conversions are called *integral promotions*.
231
 
232
- ## Floating point promotion <a id="conv.fpprom">[[conv.fpprom]]</a>
233
 
234
  A prvalue of type `float` can be converted to a prvalue of type
235
  `double`. The value is unchanged.
236
 
237
- This conversion is called *floating point promotion*.
238
 
239
  ## Integral conversions <a id="conv.integral">[[conv.integral]]</a>
240
 
241
  A prvalue of an integer type can be converted to a prvalue of another
242
  integer type. A prvalue of an unscoped enumeration type can be converted
243
  to a prvalue of an integer type.
244
 
245
  If the destination type is unsigned, the resulting value is the least
246
  unsigned integer congruent to the source integer (modulo 2ⁿ where n is
247
- the number of bits used to represent the unsigned type). In a two’s
248
- complement representation, this conversion is conceptual and there is no
249
- change in the bit pattern (if there is no truncation).
 
 
250
 
251
  If the destination type is signed, the value is unchanged if it can be
252
- represented in the destination type (and bit-field width); otherwise,
253
- the value is *implementation-defined*.
254
 
255
  If the destination type is `bool`, see  [[conv.bool]]. If the source
256
  type is `bool`, the value `false` is converted to zero and the value
257
  `true` is converted to one.
258
 
259
  The conversions allowed as integral promotions are excluded from the set
260
  of integral conversions.
261
 
262
- ## Floating point conversions <a id="conv.double">[[conv.double]]</a>
263
 
264
- A prvalue of floating point type can be converted to a prvalue of
265
- another floating point type. If the source value can be exactly
266
  represented in the destination type, the result of the conversion is
267
  that exact representation. If the source value is between two adjacent
268
  destination values, the result of the conversion is an
269
  *implementation-defined* choice of either of those values. Otherwise,
270
  the behavior is undefined.
271
 
272
- The conversions allowed as floating point promotions are excluded from
273
- the set of floating point conversions.
274
 
275
  ## Floating-integral conversions <a id="conv.fpint">[[conv.fpint]]</a>
276
 
277
- A prvalue of a floating point type can be converted to a prvalue of an
278
  integer type. The conversion truncates; that is, the fractional part is
279
  discarded. The behavior is undefined if the truncated value cannot be
280
- represented in the destination type. If the destination type is `bool`,
281
- see  [[conv.bool]].
 
 
282
 
283
  A prvalue of an integer type or of an unscoped enumeration type can be
284
- converted to a prvalue of a floating point type. The result is exact if
285
  possible. If the value being converted is in the range of values that
286
  can be represented but the value cannot be represented exactly, it is an
287
  *implementation-defined* choice of either the next lower or higher
288
- representable value. Loss of precision occurs if the integral value
289
- cannot be represented exactly as a value of the floating type. If the
290
- value being converted is outside the range of values that can be
 
 
 
291
  represented, the behavior is undefined. If the source type is `bool`,
292
  the value `false` is converted to zero and the value `true` is converted
293
  to one.
294
 
295
  ## Pointer conversions <a id="conv.ptr">[[conv.ptr]]</a>
@@ -302,19 +362,18 @@ value of object pointer or function pointer type. Such a conversion is
302
  called a *null pointer conversion*. Two null pointer values of the same
303
  type shall compare equal. The conversion of a null pointer constant to a
304
  pointer to cv-qualified type is a single conversion, and not the
305
  sequence of a pointer conversion followed by a qualification
306
  conversion ([[conv.qual]]). A null pointer constant of integral type
307
- can be converted to a prvalue of type `std::nullptr_t`. The resulting
308
- prvalue is not a null pointer value.
309
 
310
- A prvalue of type “pointer to *cv* `T`,” where `T` is an object type,
 
 
 
311
  can be converted to a prvalue of type “pointer to *cv* `void`”. The
312
- result of converting a non-null pointer value of a pointer to object
313
- type to a “pointer to *cv* `void`” represents the address of the same
314
- byte in memory as the original pointer value. The null pointer value is
315
- converted to the null pointer value of the destination type.
316
 
317
  A prvalue of type “pointer to *cv* `D`”, where `D` is a class type, can
318
  be converted to a prvalue of type “pointer to *cv* `B`”, where `B` is a
319
  base class (Clause  [[class.derived]]) of `D`. If `B` is an inaccessible
320
  (Clause  [[class.access]]) or ambiguous ([[class.member.lookup]]) base
@@ -350,10 +409,30 @@ to member of `D` of type *cv* `T`”, indirection through it with a `D`
350
  object is valid. The result is the same as if indirecting through the
351
  pointer to member of `B` with the `B` subobject of `D`. The null member
352
  pointer value is converted to the null member pointer value of the
353
  destination type.[^5]
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  ## Boolean conversions <a id="conv.bool">[[conv.bool]]</a>
356
 
357
  A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to
358
  member type can be converted to a prvalue of type `bool`. A zero value,
359
  null pointer value, or null member pointer value is converted to
@@ -369,20 +448,20 @@ Every integer type has an *integer conversion rank* defined as follows:
369
  - No two signed integer types other than `char` and `signed
370
  char` (if `char` is signed) shall have the same rank, even if they
371
  have the same representation.
372
  - The rank of a signed integer type shall be greater than the rank of
373
  any signed integer type with a smaller size.
374
- - The rank of `long` `long` `int` shall be greater than the rank of
375
- `long` `int`, which shall be greater than the rank of `int`, which
376
- shall be greater than the rank of `short` `int`, which shall be
377
- greater than the rank of `signed` `char`.
378
  - The rank of any unsigned integer type shall equal the rank of the
379
  corresponding signed integer type.
380
  - The rank of any standard integer type shall be greater than the rank
381
  of any extended integer type with the same size.
382
- - The rank of `char` shall equal the rank of `signed` `char` and
383
- `unsigned` `char`.
384
  - The rank of `bool` shall be less than the rank of all other standard
385
  integer types.
386
  - The ranks of `char16_t`, `char32_t`, and `wchar_t` shall equal the
387
  ranks of their underlying types ([[basic.fundamental]]).
388
  - The rank of any extended signed integer type relative to another
@@ -391,46 +470,57 @@ Every integer type has an *integer conversion rank* defined as follows:
391
  determining the integer conversion rank.
392
  - For all integer types `T1`, `T2`, and `T3`, if `T1` has greater rank
393
  than `T2` and `T2` has greater rank than `T3`, then `T1` shall have
394
  greater rank than `T3`.
395
 
396
- The integer conversion rank is used in the definition of the integral
397
- promotions ([[conv.prom]]) and the usual arithmetic conversions
398
- (Clause  [[expr]]).
399
 
400
  <!-- Link reference definitions -->
 
401
  [basic.def.odr]: basic.md#basic.def.odr
402
  [basic.fundamental]: basic.md#basic.fundamental
403
  [basic.lval]: basic.md#basic.lval
404
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
405
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
 
406
  [class.access]: class.md#class.access
407
  [class.bit]: class.md#class.bit
408
  [class.conv]: special.md#class.conv
409
  [class.derived]: class.md#class.derived
 
410
  [class.member.lookup]: class.md#class.member.lookup
411
  [class.mi]: class.md#class.mi
 
 
412
  [conv]: #conv
413
  [conv.array]: #conv.array
414
  [conv.bool]: #conv.bool
415
  [conv.double]: #conv.double
 
416
  [conv.fpint]: #conv.fpint
417
  [conv.fpprom]: #conv.fpprom
418
  [conv.func]: #conv.func
419
  [conv.integral]: #conv.integral
420
  [conv.lval]: #conv.lval
421
  [conv.mem]: #conv.mem
422
  [conv.prom]: #conv.prom
423
  [conv.ptr]: #conv.ptr
424
  [conv.qual]: #conv.qual
425
  [conv.rank]: #conv.rank
 
 
426
  [dcl.enum]: dcl.md#dcl.enum
427
  [dcl.fct]: dcl.md#dcl.fct
428
  [dcl.init]: dcl.md#dcl.init
429
  [dcl.init.ref]: dcl.md#dcl.init.ref
 
 
430
  [dcl.ref]: dcl.md#dcl.ref
431
  [expr]: expr.md#expr
 
432
  [lex.icon]: lex.md#lex.icon
433
  [over.best.ics]: over.md#over.best.ics
434
  [over.over]: over.md#over.over
435
  [stmt.iter]: stmt.md#stmt.iter
436
  [stmt.select]: stmt.md#stmt.select
@@ -438,13 +528,13 @@ promotions ([[conv.prom]]) and the usual arithmetic conversions
438
  [^1]: For historical reasons, this conversion is called the
439
  “lvalue-to-rvalue” conversion, even though that name does not
440
  accurately reflect the taxonomy of expressions described in 
441
  [[basic.lval]].
442
 
443
- [^2]: In C++class prvalues can have cv-qualified types (because they are
444
- objects). This differs from ISO C, in which non-lvalues never have
445
- cv-qualified types.
446
 
447
  [^3]: This conversion never applies to non-static member functions
448
  because an lvalue that refers to a non-static member function cannot
449
  be obtained.
450
 
 
7
 
8
  - Zero or one conversion from the following set: lvalue-to-rvalue
9
  conversion, array-to-pointer conversion, and function-to-pointer
10
  conversion.
11
  - Zero or one conversion from the following set: integral promotions,
12
+ floating-point promotion, integral conversions, floating-point
13
  conversions, floating-integral conversions, pointer conversions,
14
  pointer to member conversions, and boolean conversions.
15
+ - Zero or one function pointer conversion.
16
  - Zero or one qualification conversion.
17
 
18
+ [*Note 1*: A standard conversion sequence can be empty, i.e., it can
19
+ consist of no conversions. *end note*]
 
20
 
21
+ A standard conversion sequence will be applied to an expression if
22
+ necessary to convert it to a required destination type.
23
+
24
+ [*Note 2*:
25
+
26
+ Expressions with a given type will be implicitly converted to other
27
  types in several contexts:
28
 
29
  - When used as operands of operators. The operator’s requirements for
30
  its operands dictate the destination type (Clause  [[expr]]).
31
  - When used in the condition of an `if` statement or iteration
 
37
  includes use as an argument in a function call and use as the
38
  expression in a `return` statement). The type of the entity being
39
  initialized is (generally) the destination type. See  [[dcl.init]], 
40
  [[dcl.init.ref]].
41
 
42
+ — *end note*]
43
+
44
  An expression `e` can be *implicitly converted* to a type `T` if and
45
  only if the declaration `T t=e;` is well-formed, for some invented
46
  temporary variable `t` ([[dcl.init]]).
47
 
48
  Certain language constructs require that an expression be converted to a
 
52
  variable `t` ([[dcl.init]]).
53
 
54
  Certain language constructs require conversion to a value having one of
55
  a specified set of types appropriate to the construct. An expression `e`
56
  of class type `E` appearing in such a context is said to be
57
+ *contextually implicitly converted* to a specified type `T` and is
58
  well-formed if and only if `e` can be implicitly converted to a type `T`
59
+ that is determined as follows: `E` is searched for non-explicit
60
+ conversion functions whose return type is *cv* `T` or reference to *cv*
61
+ `T` such that `T` is allowed by the context. There shall be exactly one
62
+ such `T`.
63
 
64
  The effect of any implicit conversion is the same as performing the
65
  corresponding declaration and initialization and then using the
66
  temporary variable as the result of the conversion. The result is an
67
  lvalue if `T` is an lvalue reference type or an rvalue reference to
68
  function type ([[dcl.ref]]), an xvalue if `T` is an rvalue reference to
69
  object type, and a prvalue otherwise. The expression `e` is used as a
70
  glvalue if and only if the initialization uses it as a glvalue.
71
 
72
+ [*Note 3*: For class types, user-defined conversions are considered as
73
+ well; see  [[class.conv]]. In general, an implicit conversion sequence (
74
  [[over.best.ics]]) consists of a standard conversion sequence followed
75
  by a user-defined conversion followed by another standard conversion
76
+ sequence. — *end note*]
77
 
78
+ [*Note 4*: There are some contexts where certain conversions are
79
+ suppressed. For example, the lvalue-to-rvalue conversion is not done on
80
+ the operand of the unary `&` operator. Specific exceptions are given in
81
+ the descriptions of those operators and contexts. — *end note*]
82
 
83
  ## Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
84
 
85
  A glvalue ([[basic.lval]]) of a non-function, non-array type `T` can be
86
  converted to a prvalue.[^1] If `T` is an incomplete type, a program that
 
96
  the set of potential results of `e`, and `ex` names a variable `x`
97
  that is not odr-used by `ex` ([[basic.def.odr]]),
98
 
99
  the value contained in the referenced object is not accessed.
100
 
101
+ [*Example 1*:
102
+
103
  ``` cpp
104
  struct S { int n; };
105
  auto f() {
106
  S x { 1 };
107
  constexpr S y { 2 };
 
110
  auto g = f();
111
  int m = g(false); // undefined behavior due to access of x.n outside its lifetime
112
  int n = g(true); // OK, does not access y.n
113
  ```
114
 
115
+ *end example*]
 
116
 
117
+ The result of the conversion is determined according to the following
118
+ rules:
119
+
120
+ - If `T` is cv `std::nullptr_t`, the result is a null pointer constant (
121
+ [[conv.ptr]]). \[*Note 1*: Since no value is fetched from memory,
122
+ there is no side effect for a volatile access ([[intro.execution]]),
123
+ and an inactive member of a union ([[class.union]]) may be
124
+ accessed. — *end note*]
125
+ - Otherwise, if `T` has a class type, the conversion copy-initializes
126
+ the result object from the glvalue.
127
  - Otherwise, if the object to which the glvalue refers contains an
128
  invalid pointer value ([[basic.stc.dynamic.deallocation]],
129
+ [[basic.stc.dynamic.safety]]), the behavior is
130
+ *implementation-defined*.
131
  - Otherwise, the value contained in the object indicated by the glvalue
132
  is the prvalue result.
133
 
134
+ [*Note 2*: See also  [[basic.lval]]. — *end note*]
135
 
136
  ## Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
137
 
138
  An lvalue or rvalue of type “array of `N` `T`” or “array of unknown
139
  bound of `T`” can be converted to a prvalue of type “pointer to `T`”.
140
+ The temporary materialization conversion ([[conv.rval]]) is applied.
141
  The result is a pointer to the first element of the array.
142
 
143
  ## Function-to-pointer conversion <a id="conv.func">[[conv.func]]</a>
144
 
145
  An lvalue of function type `T` can be converted to a prvalue of type
146
+ “pointer to `T`”. The result is a pointer to the function.[^3]
147
 
148
+ [*Note 1*: See  [[over.over]] for additional rules for the case where
149
+ the function is overloaded. — *end note*]
150
+
151
+ ## Temporary materialization conversion <a id="conv.rval">[[conv.rval]]</a>
152
+
153
+ A prvalue of type `T` can be converted to an xvalue of type `T`. This
154
+ conversion initializes a temporary object ([[class.temporary]]) of type
155
+ `T` from the prvalue by evaluating the prvalue with the temporary object
156
+ as its result object, and produces an xvalue denoting the temporary
157
+ object. `T` shall be a complete type.
158
+
159
+ [*Note 1*: If `T` is a class type (or array thereof), it must have an
160
+ accessible and non-deleted destructor; see 
161
+ [[class.dtor]]. — *end note*]
162
+
163
+ [*Example 1*:
164
+
165
+ ``` cpp
166
+ struct X { int n; };
167
+ int k = X().n; // OK, X() prvalue is converted to xvalue
168
+ ```
169
+
170
+ — *end example*]
171
 
172
  ## Qualification conversions <a id="conv.qual">[[conv.qual]]</a>
173
 
174
+ A *cv-decomposition* of a type `T` is a sequence of cvᵢ and Pᵢ such that
175
+ `T` is
 
176
 
177
+ where each cvᵢ is a set of cv-qualifiers ([[basic.type.qualifier]]),
178
+ and each Pᵢ is “pointer to” ([[dcl.ptr]]), “pointer to member of class
179
+ Cᵢ of type ([[dcl.mptr]]), “array of Nᵢ”, orarray of unknown bound
180
+ of” ([[dcl.array]]). If Pᵢ designates an array, the cv-qualifiers cvᵢ₊₁
181
+ on the element type are also taken as the cv-qualifiers cvᵢ of the
182
+ array.
183
 
184
+ [*Example 1*: The type denoted by the *type-id* `const int **` has two
185
+ cv-decompositions, taking `U` as “`int`” and as “pointer to
186
+ `const int`”. — *end example*]
187
 
188
+ The n-tuple of cv-qualifiers after the first one in the longest
189
+ cv-decomposition of `T`, that is, cv₁, cv₂, …, cvₙ, is called the
190
+ *cv-qualification signature* of `T`.
191
 
192
+ Two types `T₁` and `T` are *similar* if they have cv-decompositions
193
+ with the same n such that corresponding Pᵢ components are the same and
194
+ the types denoted by `U` are the same.
195
+
196
+ A prvalue expression of type `T₁` can be converted to type `T₂` if the
197
+ following conditions are satisfied, where cvᵢʲ denotes the cv-qualifiers
198
+ in the cv-qualification signature of `Tⱼ`: [^4]
199
+
200
+ - `T₁` and `T₂` are similar.
201
+ - For every i > 0, if `const` is in cvᵢ¹ then `const` is in cvᵢ², and
202
+ similarly for `volatile`.
203
+ - If the cvᵢ¹ and cvᵢ² are different, then `const` is in every cvₖ² for
204
+ 0 < k < i.
205
+
206
+ [*Note 1*:
207
+
208
+ If a program could assign a pointer of type `T**` to a pointer of type
209
+ `const` `T**` (that is, if line \#1 below were allowed), a program could
210
+ inadvertently modify a `const` object (as it is done on line \#2). For
211
+ example,
212
 
213
  ``` cpp
214
  int main() {
215
  const char c = 'c';
216
  char* pc;
 
218
  *pcc = &c;
219
  *pc = 'C'; // #2: modifies a const object
220
  }
221
  ```
222
 
223
+ *end note*]
 
224
 
225
+ [*Note 2*: A prvalue of type pointer to *cv1* `T`” can be converted to
226
+ a prvalue of type “pointer to *cv2* `T`” if “*cv2* `T`” is more
227
+ cv-qualified than “*cv1* `T`”. A prvalue of type “pointer to member of
228
+ `X` of type *cv1* `T`” can be converted to a prvalue of type “pointer to
229
+ member of `X` of type *cv2* `T`” if “*cv2* `T`” is more cv-qualified
230
+ than “*cv1* `T`”. — *end note*]
231
 
232
+ [*Note 3*: Function types (including those used in pointer to member
233
+ function types) are never cv-qualified ([[dcl.fct]]). *end note*]
 
 
 
 
 
 
 
234
 
235
  ## Integral promotions <a id="conv.prom">[[conv.prom]]</a>
236
 
237
  A prvalue of an integer type other than `bool`, `char16_t`, `char32_t`,
238
  or `wchar_t` whose integer conversion rank ([[conv.rank]]) is less than
 
241
  prvalue can be converted to a prvalue of type `unsigned int`.
242
 
243
  A prvalue of type `char16_t`, `char32_t`, or `wchar_t` (
244
  [[basic.fundamental]]) can be converted to a prvalue of the first of the
245
  following types that can represent all the values of its underlying
246
+ type: `int`, `unsigned int`, `long int`, `unsigned long int`,
247
  `long long int`, or `unsigned long long int`. If none of the types in
248
  that list can represent all the values of its underlying type, a prvalue
249
  of type `char16_t`, `char32_t`, or `wchar_t` can be converted to a
250
  prvalue of its underlying type.
251
 
252
  A prvalue of an unscoped enumeration type whose underlying type is not
253
  fixed ([[dcl.enum]]) can be converted to a prvalue of the first of the
254
  following types that can represent all the values of the enumeration
255
  (i.e., the values in the range bₘin to bₘax as described in 
256
+ [[dcl.enum]]): `int`, `unsigned int`, `long int`, `unsigned long int`,
257
+ `long long int`, or `unsigned long long int`. If none of the types in
258
+ that list can represent all the values of the enumeration, a prvalue of
259
+ an unscoped enumeration type can be converted to a prvalue of the
260
+ extended integer type with lowest integer conversion rank (
261
+ [[conv.rank]]) greater than the rank of `long long` in which all the
262
  values of the enumeration can be represented. If there are two such
263
  extended types, the signed one is chosen.
264
 
265
  A prvalue of an unscoped enumeration type whose underlying type is
266
  fixed ([[dcl.enum]]) can be converted to a prvalue of its underlying
 
280
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
281
  with `false` becoming zero and `true` becoming one.
282
 
283
  These conversions are called *integral promotions*.
284
 
285
+ ## Floating-point promotion <a id="conv.fpprom">[[conv.fpprom]]</a>
286
 
287
  A prvalue of type `float` can be converted to a prvalue of type
288
  `double`. The value is unchanged.
289
 
290
+ This conversion is called *floating-point promotion*.
291
 
292
  ## Integral conversions <a id="conv.integral">[[conv.integral]]</a>
293
 
294
  A prvalue of an integer type can be converted to a prvalue of another
295
  integer type. A prvalue of an unscoped enumeration type can be converted
296
  to a prvalue of an integer type.
297
 
298
  If the destination type is unsigned, the resulting value is the least
299
  unsigned integer congruent to the source integer (modulo 2ⁿ where n is
300
+ the number of bits used to represent the unsigned type).
301
+
302
+ [*Note 1*: In a two’s complement representation, this conversion is
303
+ conceptual and there is no change in the bit pattern (if there is no
304
+ truncation). — *end note*]
305
 
306
  If the destination type is signed, the value is unchanged if it can be
307
+ represented in the destination type; otherwise, the value is
308
+ *implementation-defined*.
309
 
310
  If the destination type is `bool`, see  [[conv.bool]]. If the source
311
  type is `bool`, the value `false` is converted to zero and the value
312
  `true` is converted to one.
313
 
314
  The conversions allowed as integral promotions are excluded from the set
315
  of integral conversions.
316
 
317
+ ## Floating-point conversions <a id="conv.double">[[conv.double]]</a>
318
 
319
+ A prvalue of floating-point type can be converted to a prvalue of
320
+ another floating-point type. If the source value can be exactly
321
  represented in the destination type, the result of the conversion is
322
  that exact representation. If the source value is between two adjacent
323
  destination values, the result of the conversion is an
324
  *implementation-defined* choice of either of those values. Otherwise,
325
  the behavior is undefined.
326
 
327
+ The conversions allowed as floating-point promotions are excluded from
328
+ the set of floating-point conversions.
329
 
330
  ## Floating-integral conversions <a id="conv.fpint">[[conv.fpint]]</a>
331
 
332
+ A prvalue of a floating-point type can be converted to a prvalue of an
333
  integer type. The conversion truncates; that is, the fractional part is
334
  discarded. The behavior is undefined if the truncated value cannot be
335
+ represented in the destination type.
336
+
337
+ [*Note 1*: If the destination type is `bool`, see 
338
+ [[conv.bool]]. — *end note*]
339
 
340
  A prvalue of an integer type or of an unscoped enumeration type can be
341
+ converted to a prvalue of a floating-point type. The result is exact if
342
  possible. If the value being converted is in the range of values that
343
  can be represented but the value cannot be represented exactly, it is an
344
  *implementation-defined* choice of either the next lower or higher
345
+ representable value.
346
+
347
+ [*Note 2*: Loss of precision occurs if the integral value cannot be
348
+ represented exactly as a value of the floating type. — *end note*]
349
+
350
+ If the value being converted is outside the range of values that can be
351
  represented, the behavior is undefined. If the source type is `bool`,
352
  the value `false` is converted to zero and the value `true` is converted
353
  to one.
354
 
355
  ## Pointer conversions <a id="conv.ptr">[[conv.ptr]]</a>
 
362
  called a *null pointer conversion*. Two null pointer values of the same
363
  type shall compare equal. The conversion of a null pointer constant to a
364
  pointer to cv-qualified type is a single conversion, and not the
365
  sequence of a pointer conversion followed by a qualification
366
  conversion ([[conv.qual]]). A null pointer constant of integral type
367
+ can be converted to a prvalue of type `std::nullptr_t`.
 
368
 
369
+ [*Note 1*: The resulting prvalue is not a null pointer
370
+ value. — *end note*]
371
+
372
+ A prvalue of type “pointer to *cv* `T`”, where `T` is an object type,
373
  can be converted to a prvalue of type “pointer to *cv* `void`”. The
374
+ pointer value ([[basic.compound]]) is unchanged by this conversion.
 
 
 
375
 
376
  A prvalue of type “pointer to *cv* `D`”, where `D` is a class type, can
377
  be converted to a prvalue of type “pointer to *cv* `B`”, where `B` is a
378
  base class (Clause  [[class.derived]]) of `D`. If `B` is an inaccessible
379
  (Clause  [[class.access]]) or ambiguous ([[class.member.lookup]]) base
 
409
  object is valid. The result is the same as if indirecting through the
410
  pointer to member of `B` with the `B` subobject of `D`. The null member
411
  pointer value is converted to the null member pointer value of the
412
  destination type.[^5]
413
 
414
+ ## Function pointer conversions <a id="conv.fctptr">[[conv.fctptr]]</a>
415
+
416
+ A prvalue of type “pointer to `noexcept` function” can be converted to a
417
+ prvalue of type “pointer to function”. The result is a pointer to the
418
+ function. A prvalue of type “pointer to member of type `noexcept`
419
+ function” can be converted to a prvalue of type “pointer to member of
420
+ type function”. The result points to the member function.
421
+
422
+ [*Example 1*:
423
+
424
+ ``` cpp
425
+ void (*p)();
426
+ void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept function
427
+
428
+ struct S { typedef void (*p)(); operator p(); };
429
+ void (*q)() noexcept = S(); // error: cannot convert to pointer to noexcept function
430
+ ```
431
+
432
+ — *end example*]
433
+
434
  ## Boolean conversions <a id="conv.bool">[[conv.bool]]</a>
435
 
436
  A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to
437
  member type can be converted to a prvalue of type `bool`. A zero value,
438
  null pointer value, or null member pointer value is converted to
 
448
  - No two signed integer types other than `char` and `signed
449
  char` (if `char` is signed) shall have the same rank, even if they
450
  have the same representation.
451
  - The rank of a signed integer type shall be greater than the rank of
452
  any signed integer type with a smaller size.
453
+ - The rank of `long long int` shall be greater than the rank of
454
+ `long int`, which shall be greater than the rank of `int`, which shall
455
+ be greater than the rank of `short int`, which shall be greater than
456
+ the rank of `signed char`.
457
  - The rank of any unsigned integer type shall equal the rank of the
458
  corresponding signed integer type.
459
  - The rank of any standard integer type shall be greater than the rank
460
  of any extended integer type with the same size.
461
+ - The rank of `char` shall equal the rank of `signed char` and
462
+ `unsigned char`.
463
  - The rank of `bool` shall be less than the rank of all other standard
464
  integer types.
465
  - The ranks of `char16_t`, `char32_t`, and `wchar_t` shall equal the
466
  ranks of their underlying types ([[basic.fundamental]]).
467
  - The rank of any extended signed integer type relative to another
 
470
  determining the integer conversion rank.
471
  - For all integer types `T1`, `T2`, and `T3`, if `T1` has greater rank
472
  than `T2` and `T2` has greater rank than `T3`, then `T1` shall have
473
  greater rank than `T3`.
474
 
475
+ [*Note 1*: The integer conversion rank is used in the definition of the
476
+ integral promotions ([[conv.prom]]) and the usual arithmetic
477
+ conversions (Clause  [[expr]]). — *end note*]
478
 
479
  <!-- Link reference definitions -->
480
+ [basic.compound]: basic.md#basic.compound
481
  [basic.def.odr]: basic.md#basic.def.odr
482
  [basic.fundamental]: basic.md#basic.fundamental
483
  [basic.lval]: basic.md#basic.lval
484
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
485
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
486
+ [basic.type.qualifier]: basic.md#basic.type.qualifier
487
  [class.access]: class.md#class.access
488
  [class.bit]: class.md#class.bit
489
  [class.conv]: special.md#class.conv
490
  [class.derived]: class.md#class.derived
491
+ [class.dtor]: special.md#class.dtor
492
  [class.member.lookup]: class.md#class.member.lookup
493
  [class.mi]: class.md#class.mi
494
+ [class.temporary]: special.md#class.temporary
495
+ [class.union]: class.md#class.union
496
  [conv]: #conv
497
  [conv.array]: #conv.array
498
  [conv.bool]: #conv.bool
499
  [conv.double]: #conv.double
500
+ [conv.fctptr]: #conv.fctptr
501
  [conv.fpint]: #conv.fpint
502
  [conv.fpprom]: #conv.fpprom
503
  [conv.func]: #conv.func
504
  [conv.integral]: #conv.integral
505
  [conv.lval]: #conv.lval
506
  [conv.mem]: #conv.mem
507
  [conv.prom]: #conv.prom
508
  [conv.ptr]: #conv.ptr
509
  [conv.qual]: #conv.qual
510
  [conv.rank]: #conv.rank
511
+ [conv.rval]: #conv.rval
512
+ [dcl.array]: dcl.md#dcl.array
513
  [dcl.enum]: dcl.md#dcl.enum
514
  [dcl.fct]: dcl.md#dcl.fct
515
  [dcl.init]: dcl.md#dcl.init
516
  [dcl.init.ref]: dcl.md#dcl.init.ref
517
+ [dcl.mptr]: dcl.md#dcl.mptr
518
+ [dcl.ptr]: dcl.md#dcl.ptr
519
  [dcl.ref]: dcl.md#dcl.ref
520
  [expr]: expr.md#expr
521
+ [intro.execution]: intro.md#intro.execution
522
  [lex.icon]: lex.md#lex.icon
523
  [over.best.ics]: over.md#over.best.ics
524
  [over.over]: over.md#over.over
525
  [stmt.iter]: stmt.md#stmt.iter
526
  [stmt.select]: stmt.md#stmt.select
 
528
  [^1]: For historical reasons, this conversion is called the
529
  “lvalue-to-rvalue” conversion, even though that name does not
530
  accurately reflect the taxonomy of expressions described in 
531
  [[basic.lval]].
532
 
533
+ [^2]: In C++class and array prvalues can have cv-qualified types. This
534
+ differs from ISO C, in which non-lvalues never have cv-qualified
535
+ types.
536
 
537
  [^3]: This conversion never applies to non-static member functions
538
  because an lvalue that refers to a non-static member function cannot
539
  be obtained.
540