From Jason Turner

[conv]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp15hv_lu4/{from.md → to.md} +73 -53
tmp/tmp15hv_lu4/{from.md → to.md} RENAMED
@@ -19,11 +19,12 @@ following order:
19
 
20
  [*Note 1*: A standard conversion sequence can be empty, i.e., it can
21
  consist of no conversions. — *end note*]
22
 
23
  A standard conversion sequence will be applied to an expression if
24
- necessary to convert it to a required destination type.
 
25
 
26
  [*Note 2*:
27
 
28
  Expressions with a given type will be implicitly converted to other
29
  types in several contexts:
@@ -41,12 +42,12 @@ types in several contexts:
41
  [[dcl.init.ref]].
42
 
43
  — *end note*]
44
 
45
  An expression E can be *implicitly converted* to a type `T` if and only
46
- if the declaration `T t=E;` is well-formed, for some invented temporary
47
- variable `t` [[dcl.init]].
48
 
49
  Certain language constructs require that an expression be converted to a
50
  Boolean value. An expression E appearing in such a context is said to be
51
  *contextually converted to `bool`* and is well-formed if and only if the
52
  declaration `bool t(E);` is well-formed, for some invented temporary
@@ -126,15 +127,30 @@ rules:
126
  `T` is volatile-qualified [[intro.execution]], and the glvalue can
127
  refer to an inactive member of a union [[class.union]]. — *end note*]
128
  - Otherwise, if `T` has a class type, the conversion copy-initializes
129
  the result object from the glvalue.
130
  - Otherwise, if the object to which the glvalue refers contains an
131
- invalid pointer value [[basic.stc.dynamic.deallocation]], the behavior
132
- is *implementation-defined*.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  - Otherwise, the object indicated by the glvalue is read
134
- [[defns.access]], and the value contained in the object is the prvalue
135
- result.
 
136
 
137
  [*Note 2*: See also  [[basic.lval]]. — *end note*]
138
 
139
  ### Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
140
 
@@ -183,14 +199,10 @@ element type are also taken as the cv-qualifiers cvᵢ of the array.
183
  [*Example 1*: The type denoted by the *type-id* `const int **` has
184
  three qualification-decompositions, taking `U` as “`int`”, as “pointer
185
  to `const int`”, and as “pointer to pointer to
186
  `const int`”. — *end example*]
187
 
188
- The n-tuple of cv-qualifiers after the first one in the longest
189
- qualification-decomposition of `T`, that is, cv₁, cv₂, …, cvₙ, is called
190
- the *cv-qualification signature* of `T`.
191
-
192
  Two types `T1` and `T2` are *similar* if they have
193
  qualification-decompositions with the same n such that corresponding Pᵢ
194
  components are either the same or one is “array of Nᵢ” and the other is
195
  “array of unknown bound of”, and the types denoted by `U` are the same.
196
 
@@ -242,24 +254,20 @@ than “*cv1* `T`”. — *end note*]
242
  pointer-to-member-function types) are never cv-qualified
243
  [[dcl.fct]]. — *end note*]
244
 
245
  ### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
246
 
247
- A prvalue of an integer type other than `bool`, `char8_t`, `char16_t`,
248
- `char32_t`, or `wchar_t` whose integer conversion rank [[conv.rank]] is
249
- less than the rank of `int` can be converted to a prvalue of type `int`
250
- if `int` can represent all the values of the source type; otherwise, the
251
- source prvalue can be converted to a prvalue of type `unsigned int`.
252
 
253
- A prvalue of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t`
254
- [[basic.fundamental]] can be converted to a prvalue of the first of the
255
- following types that can represent all the values of its underlying
256
- type: `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 its underlying type, a prvalue
259
- of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t` can be converted
260
- to a prvalue of its underlying type.
261
 
262
  A prvalue of an unscoped enumeration type whose underlying type is not
263
  fixed can be converted to a prvalue of the first of the following types
264
  that can represent all the values of the enumeration [[dcl.enum]]:
265
  `int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
@@ -275,17 +283,25 @@ A prvalue of an unscoped enumeration type whose underlying type is fixed
275
  [[dcl.enum]] can be converted to a prvalue of its underlying type.
276
  Moreover, if integral promotion can be applied to its underlying type, a
277
  prvalue of an unscoped enumeration type whose underlying type is fixed
278
  can also be converted to a prvalue of the promoted underlying type.
279
 
280
- A prvalue for an integral bit-field [[class.bit]] can be converted to a
281
- prvalue of type `int` if `int` can represent all the values of the
282
- bit-field; otherwise, it can be converted to `unsigned int` if
283
- `unsigned int` can represent all the values of the bit-field. If the
284
- bit-field is larger yet, no integral promotion applies to it. If the
285
- bit-field has enumeration type, it is treated as any other value of that
286
- type for promotion purposes.
 
 
 
 
 
 
 
 
287
 
288
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
289
  with `false` becoming zero and `true` becoming one.
290
 
291
  These conversions are called *integral promotions*.
@@ -361,60 +377,64 @@ to one.
361
  A *null pointer constant* is an integer literal [[lex.icon]] with value
362
  zero or a prvalue of type `std::nullptr_t`. A null pointer constant can
363
  be converted to a pointer type; the result is the null pointer value of
364
  that type [[basic.compound]] and is distinguishable from every other
365
  value of object pointer or function pointer type. Such a conversion is
366
- called a *null pointer conversion*. Two null pointer values of the same
367
- type shall compare equal. The conversion of a null pointer constant to a
368
- pointer to cv-qualified type is a single conversion, and not the
369
- sequence of a pointer conversion followed by a qualification conversion
370
- [[conv.qual]]. A null pointer constant of integral type can be converted
371
- to a prvalue of type `std::nullptr_t`.
372
 
373
  [*Note 1*: The resulting prvalue is not a null pointer
374
  value. — *end note*]
375
 
376
  A prvalue of type “pointer to cv `T`”, where `T` is an object type, can
377
  be converted to a prvalue of type “pointer to cv `void`”. The pointer
378
  value [[basic.compound]] is unchanged by this conversion.
379
 
380
- A prvalue of type “pointer to cv `D`”, where `D` is a complete class
381
  type, can be converted to a prvalue of type “pointer to cv `B`”, where
382
  `B` is a base class [[class.derived]] of `D`. If `B` is an inaccessible
383
  [[class.access]] or ambiguous [[class.member.lookup]] base class of `D`,
384
- a program that necessitates this conversion is ill-formed. The result of
385
- the conversion is a pointer to the base class subobject of the derived
386
- class object. The null pointer value is converted to the null pointer
387
- value of the destination type.
 
 
 
388
 
389
  ### Pointer-to-member conversions <a id="conv.mem">[[conv.mem]]</a>
390
 
391
  A null pointer constant [[conv.ptr]] can be converted to a
392
  pointer-to-member type; the result is the *null member pointer value* of
393
  that type and is distinguishable from any pointer to member not created
394
  from a null pointer constant. Such a conversion is called a *null member
395
- pointer conversion*. Two null member pointer values of the same type
396
- shall compare equal. The conversion of a null pointer constant to a
397
  pointer to member of cv-qualified type is a single conversion, and not
398
  the sequence of a pointer-to-member conversion followed by a
399
  qualification conversion [[conv.qual]].
400
 
401
  A prvalue of type “pointer to member of `B` of type cv `T`”, where `B`
402
  is a class type, can be converted to a prvalue of type “pointer to
403
  member of `D` of type cv `T`”, where `D` is a complete class derived
404
  [[class.derived]] from `B`. If `B` is an inaccessible [[class.access]],
405
  ambiguous [[class.member.lookup]], or virtual [[class.mi]] base class of
406
  `D`, or a base class of a virtual base class of `D`, a program that
407
- necessitates this conversion is ill-formed. The result of the conversion
408
- refers to the same member as the pointer to member before the conversion
409
- took place, but it refers to the base class member as if it were a
410
- member of the derived class. The result refers to the member in `D`’s
411
- instance of `B`. Since the result has type “pointer to member of `D` of
412
- type cv `T`”, indirection through it with a `D` object is valid. The
413
- result is the same as if indirecting through the pointer to member of
414
- `B` with the `B` subobject of `D`. The null member pointer value is
415
- converted to the null member pointer value of the destination type.[^8]
 
 
 
416
 
417
  ### Function pointer conversions <a id="conv.fctptr">[[conv.fctptr]]</a>
418
 
419
  A prvalue of type “pointer to `noexcept` function” can be converted to a
420
  prvalue of type “pointer to function”. The result is a pointer to the
 
19
 
20
  [*Note 1*: A standard conversion sequence can be empty, i.e., it can
21
  consist of no conversions. — *end note*]
22
 
23
  A standard conversion sequence will be applied to an expression if
24
+ necessary to convert it to an expression having a required destination
25
+ type and value category.
26
 
27
  [*Note 2*:
28
 
29
  Expressions with a given type will be implicitly converted to other
30
  types in several contexts:
 
42
  [[dcl.init.ref]].
43
 
44
  — *end note*]
45
 
46
  An expression E can be *implicitly converted* to a type `T` if and only
47
+ if the declaration `T t = E;` is well-formed, for some invented
48
+ temporary variable `t` [[dcl.init]].
49
 
50
  Certain language constructs require that an expression be converted to a
51
  Boolean value. An expression E appearing in such a context is said to be
52
  *contextually converted to `bool`* and is well-formed if and only if the
53
  declaration `bool t(E);` is well-formed, for some invented temporary
 
127
  `T` is volatile-qualified [[intro.execution]], and the glvalue can
128
  refer to an inactive member of a union [[class.union]]. — *end note*]
129
  - Otherwise, if `T` has a class type, the conversion copy-initializes
130
  the result object from the glvalue.
131
  - Otherwise, if the object to which the glvalue refers contains an
132
+ invalid pointer value [[basic.compound]], the behavior is
133
+ *implementation-defined*.
134
+ - Otherwise, if the bits in the value representation of the object to
135
+ which the glvalue refers are not valid for the object’s type, the
136
+ behavior is undefined.
137
+ \[*Example 2*:
138
+ ``` cpp
139
+ bool f() {
140
+ bool b = true;
141
+ char c = 42;
142
+ memcpy(&b, &c, 1);
143
+ return b; // undefined behavior if 42 is not a valid value representation for bool
144
+ }
145
+ ```
146
+
147
+ — *end example*]
148
  - Otherwise, the object indicated by the glvalue is read
149
+ [[defns.access]]. Let `V` be the value contained in the object. If `T`
150
+ is an integer type, the prvalue result is the value of type `T`
151
+ congruent [[basic.fundamental]] to `V`, and `V` otherwise.
152
 
153
  [*Note 2*: See also  [[basic.lval]]. — *end note*]
154
 
155
  ### Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
156
 
 
199
  [*Example 1*: The type denoted by the *type-id* `const int **` has
200
  three qualification-decompositions, taking `U` as “`int`”, as “pointer
201
  to `const int`”, and as “pointer to pointer to
202
  `const int`”. — *end example*]
203
 
 
 
 
 
204
  Two types `T1` and `T2` are *similar* if they have
205
  qualification-decompositions with the same n such that corresponding Pᵢ
206
  components are either the same or one is “array of Nᵢ” and the other is
207
  “array of unknown bound of”, and the types denoted by `U` are the same.
208
 
 
254
  pointer-to-member-function types) are never cv-qualified
255
  [[dcl.fct]]. — *end note*]
256
 
257
  ### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
258
 
259
+ For the purposes of [[conv.prom]], a *converted bit-field* is a prvalue
260
+ that is the result of an lvalue-to-rvalue conversion [[conv.lval]]
261
+ applied to a bit-field [[class.bit]].
 
 
262
 
263
+ A prvalue that is not a converted bit-field and has an integer type
264
+ other than `bool`, `char8_t`, `char16_t`, `char32_t`, or `wchar_t` whose
265
+ integer conversion rank [[conv.rank]] is less than the rank of `int` can
266
+ be converted to a prvalue of type `int` if `int` can represent all the
267
+ values of the source type; otherwise, the source prvalue can be
268
+ converted to a prvalue of type `unsigned int`.
 
 
269
 
270
  A prvalue of an unscoped enumeration type whose underlying type is not
271
  fixed can be converted to a prvalue of the first of the following types
272
  that can represent all the values of the enumeration [[dcl.enum]]:
273
  `int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
 
283
  [[dcl.enum]] can be converted to a prvalue of its underlying type.
284
  Moreover, if integral promotion can be applied to its underlying type, a
285
  prvalue of an unscoped enumeration type whose underlying type is fixed
286
  can also be converted to a prvalue of the promoted underlying type.
287
 
288
+ [*Note 1*: A converted bit-field of enumeration type is treated as any
289
+ other value of that type for promotion purposes. *end note*]
290
+
291
+ A converted bit-field of integral type can be converted to a prvalue of
292
+ type `int` if `int` can represent all the values of the bit-field;
293
+ otherwise, it can be converted to `unsigned int` if `unsigned int` can
294
+ represent all the values of the bit-field.
295
+
296
+ A prvalue of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t`
297
+ [[basic.fundamental]] (including a converted bit-field that was not
298
+ already promoted to `int` or `unsigned int` according to the rules
299
+ above) can be converted to a prvalue of the first of the following types
300
+ that can represent all the values of its underlying type: `int`,
301
+ `unsigned int`, `long int`, `unsigned long int`, `long long int`,
302
+ `unsigned long long int`, or its underlying type.
303
 
304
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
305
  with `false` becoming zero and `true` becoming one.
306
 
307
  These conversions are called *integral promotions*.
 
377
  A *null pointer constant* is an integer literal [[lex.icon]] with value
378
  zero or a prvalue of type `std::nullptr_t`. A null pointer constant can
379
  be converted to a pointer type; the result is the null pointer value of
380
  that type [[basic.compound]] and is distinguishable from every other
381
  value of object pointer or function pointer type. Such a conversion is
382
+ called a *null pointer conversion*. The conversion of a null pointer
383
+ constant to a pointer to cv-qualified type is a single conversion, and
384
+ not the sequence of a pointer conversion followed by a qualification
385
+ conversion [[conv.qual]]. A null pointer constant of integral type can
386
+ be converted to a prvalue of type `std::nullptr_t`.
 
387
 
388
  [*Note 1*: The resulting prvalue is not a null pointer
389
  value. — *end note*]
390
 
391
  A prvalue of type “pointer to cv `T`”, where `T` is an object type, can
392
  be converted to a prvalue of type “pointer to cv `void`”. The pointer
393
  value [[basic.compound]] is unchanged by this conversion.
394
 
395
+ A prvalue `v` of type “pointer to cv `D`”, where `D` is a complete class
396
  type, can be converted to a prvalue of type “pointer to cv `B`”, where
397
  `B` is a base class [[class.derived]] of `D`. If `B` is an inaccessible
398
  [[class.access]] or ambiguous [[class.member.lookup]] base class of `D`,
399
+ a program that necessitates this conversion is ill-formed. If `v` is a
400
+ null pointer value, the result is a null pointer value. Otherwise, if
401
+ `B` is a virtual base class of `D` and `v` does not point to an object
402
+ whose type is similar [[conv.qual]] to `D` and that is within its
403
+ lifetime or within its period of construction or destruction
404
+ [[class.cdtor]], the behavior is undefined. Otherwise, the result is a
405
+ pointer to the base class subobject of the derived class object.
406
 
407
  ### Pointer-to-member conversions <a id="conv.mem">[[conv.mem]]</a>
408
 
409
  A null pointer constant [[conv.ptr]] can be converted to a
410
  pointer-to-member type; the result is the *null member pointer value* of
411
  that type and is distinguishable from any pointer to member not created
412
  from a null pointer constant. Such a conversion is called a *null member
413
+ pointer conversion*. The conversion of a null pointer constant to a
 
414
  pointer to member of cv-qualified type is a single conversion, and not
415
  the sequence of a pointer-to-member conversion followed by a
416
  qualification conversion [[conv.qual]].
417
 
418
  A prvalue of type “pointer to member of `B` of type cv `T`”, where `B`
419
  is a class type, can be converted to a prvalue of type “pointer to
420
  member of `D` of type cv `T`”, where `D` is a complete class derived
421
  [[class.derived]] from `B`. If `B` is an inaccessible [[class.access]],
422
  ambiguous [[class.member.lookup]], or virtual [[class.mi]] base class of
423
  `D`, or a base class of a virtual base class of `D`, a program that
424
+ necessitates this conversion is ill-formed. If class `D` does not
425
+ contain the original member and is not a base class of the class
426
+ containing the original member, the behavior is undefined. Otherwise,
427
+ the result of the conversion refers to the same member as the pointer to
428
+ member before the conversion took place, but it refers to the base class
429
+ member as if it were a member of the derived class. The result refers to
430
+ the member in `D`’s instance of `B`. Since the result has type “pointer
431
+ to member of `D` of type cv `T`”, indirection through it with a `D`
432
+ object is valid. The result is the same as if indirecting through the
433
+ pointer to member of `B` with the `B` subobject of `D`. The null member
434
+ pointer value is converted to the null member pointer value of the
435
+ destination type.[^8]
436
 
437
  ### Function pointer conversions <a id="conv.fctptr">[[conv.fctptr]]</a>
438
 
439
  A prvalue of type “pointer to `noexcept` function” can be converted to a
440
  prvalue of type “pointer to function”. The result is a pointer to the