From Jason Turner

[conv]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpraxi8jc5/{from.md → to.md} +86 -51
tmp/tmpraxi8jc5/{from.md → to.md} RENAMED
@@ -34,25 +34,37 @@ types in several contexts:
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]]). Certain language constructs
40
- require that an expression be converted to a Boolean value. An
41
- expression `e` appearing in such a context is said to be *contextually
42
- converted to `bool`* and is well-formed if and only if the declaration
43
- `bool t(e);` is well-formed, for some invented temporary variable `t` (
44
- [[dcl.init]]). The effect of either implicit conversion is the same as
45
- performing the declaration and initialization and then using the
 
 
 
 
 
 
 
 
 
 
 
 
46
  temporary variable as the result of the conversion. The result is an
47
  lvalue if `T` is an lvalue reference type or an rvalue reference to
48
  function type ([[dcl.ref]]), an xvalue if `T` is an rvalue reference to
49
  object type, and a prvalue otherwise. The expression `e` is used as a
50
  glvalue if and only if the initialization uses it as a glvalue.
51
 
52
- For user-defined types, user-defined conversions are considered as well;
53
- see  [[class.conv]]. In general, an implicit conversion sequence (
54
  [[over.best.ics]]) consists of a standard conversion sequence followed
55
  by a user-defined conversion followed by another standard conversion
56
  sequence.
57
 
58
  There are some contexts where certain conversions are suppressed. For
@@ -62,26 +74,49 @@ descriptions of those operators and contexts.
62
 
63
  ## Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
64
 
65
  A glvalue ([[basic.lval]]) of a non-function, non-array type `T` can be
66
  converted to a prvalue.[^1] If `T` is an incomplete type, a program that
67
- necessitates this conversion is ill-formed. If the object to which the
68
- glvalue refers is not an object of type `T` and is not an object of a
69
- type derived from `T`, or if the object is uninitialized, a program that
70
- necessitates this conversion has undefined behavior. If `T` is a
71
- non-class type, the type of the prvalue is the cv-unqualified version of
72
- `T`. Otherwise, the type of the prvalue is `T`.[^2]
73
 
74
- When an lvalue-to-rvalue conversion occurs in an unevaluated operand or
75
- a subexpression thereof (Clause  [[expr]]) the value contained in the
76
- referenced object is not accessed. Otherwise, if the glvalue has a class
77
- type, the conversion copy-initializes a temporary of type `T` from the
78
- glvalue and the result of the conversion is a prvalue for the temporary.
79
- Otherwise, if the glvalue has (possibly cv-qualified) type
80
- `std::nullptr_t`, the prvalue result is a null pointer constant (
81
- [[conv.ptr]]). Otherwise, the value contained in the object indicated by
82
- the glvalue is the prvalue result.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  See also  [[basic.lval]].
85
 
86
  ## Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
87
 
@@ -257,32 +292,29 @@ represented, the behavior is undefined. If the source type is `bool`,
257
  the value `false` is converted to zero and the value `true` is converted
258
  to one.
259
 
260
  ## Pointer conversions <a id="conv.ptr">[[conv.ptr]]</a>
261
 
262
- A *null pointer constant* is an integral constant expression (
263
- [[expr.const]]) prvalue of integer type that evaluates to zero or a
264
- prvalue of type `std::nullptr_t`. A null pointer constant can be
265
- converted to a pointer type; the result is the *null pointer value* of
266
- that type and is distinguishable from every other value of object
267
- pointer or function pointer type. Such a conversion is called a *null
268
- pointer conversion*. Two null pointer values of the same type shall
269
- compare equal. The conversion of a null pointer constant to a pointer to
270
- cv-qualified type is a single conversion, and not the sequence of a
271
- pointer conversion followed by a qualification conversion (
272
- [[conv.qual]]). A null pointer constant of integral type can be
273
- converted to a prvalue of type `std::nullptr_t`. The resulting prvalue
274
- is not a null pointer value.
275
 
276
  A prvalue of type “pointer to *cv* `T`,” where `T` is an object type,
277
  can be converted to a prvalue of type “pointer to *cv* `void`”. The
278
- result of converting a pointer to *cv* `T`” to a pointer to *cv*
279
- `void`” points to the start of the storage location where the object of
280
- type `T` resides, as if the object is a most derived object (
281
- [[intro.object]]) of type `T` (that is, not a base class subobject). The
282
- null pointer value is converted to the null pointer value of the
283
- destination type.
284
 
285
  A prvalue of type “pointer to *cv* `D`”, where `D` is a class type, can
286
  be converted to a prvalue of type “pointer to *cv* `B`”, where `B` is a
287
  base class (Clause  [[class.derived]]) of `D`. If `B` is an inaccessible
288
  (Clause  [[class.access]]) or ambiguous ([[class.member.lookup]]) base
@@ -312,22 +344,23 @@ member of `D` of type *cv* `T`”, where `D` is a derived class (Clause 
312
  of `D`, a program that necessitates this conversion is ill-formed. The
313
  result of the conversion refers to the same member as the pointer to
314
  member before the conversion took place, but it refers to the base class
315
  member as if it were a member of the derived class. The result refers to
316
  the member in `D`’s instance of `B`. Since the result has type “pointer
317
- to member of `D` of type *cv* `T`”, it can be dereferenced with a `D`
318
- object. The result is the same as if the pointer to member of `B` were
319
- dereferenced with the `B` subobject of `D`. The null member pointer
320
- value is converted to the null member pointer value of the destination
321
- type.[^5]
322
 
323
  ## Boolean conversions <a id="conv.bool">[[conv.bool]]</a>
324
 
325
  A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to
326
  member type can be converted to a prvalue of type `bool`. A zero value,
327
  null pointer value, or null member pointer value is converted to
328
- `false`; any other value is converted to `true`. A prvalue of type
 
329
  `std::nullptr_t` can be converted to a prvalue of type `bool`; the
330
  resulting value is `false`.
331
 
332
  ## Integer conversion rank <a id="conv.rank">[[conv.rank]]</a>
333
 
@@ -363,12 +396,15 @@ Every integer type has an *integer conversion rank* defined as follows:
363
  The integer conversion rank is used in the definition of the integral
364
  promotions ([[conv.prom]]) and the usual arithmetic conversions
365
  (Clause  [[expr]]).
366
 
367
  <!-- Link reference definitions -->
 
368
  [basic.fundamental]: basic.md#basic.fundamental
369
  [basic.lval]: basic.md#basic.lval
 
 
370
  [class.access]: class.md#class.access
371
  [class.bit]: class.md#class.bit
372
  [class.conv]: special.md#class.conv
373
  [class.derived]: class.md#class.derived
374
  [class.member.lookup]: class.md#class.member.lookup
@@ -391,12 +427,11 @@ promotions ([[conv.prom]]) and the usual arithmetic conversions
391
  [dcl.fct]: dcl.md#dcl.fct
392
  [dcl.init]: dcl.md#dcl.init
393
  [dcl.init.ref]: dcl.md#dcl.init.ref
394
  [dcl.ref]: dcl.md#dcl.ref
395
  [expr]: expr.md#expr
396
- [expr.const]: expr.md#expr.const
397
- [intro.object]: intro.md#intro.object
398
  [over.best.ics]: over.md#over.best.ics
399
  [over.over]: over.md#over.over
400
  [stmt.iter]: stmt.md#stmt.iter
401
  [stmt.select]: stmt.md#stmt.select
402
 
 
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
42
+ Boolean value. An expression `e` appearing in such a context is said to
43
+ be *contextually converted to `bool`* and is well-formed if and only if
44
+ 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
 
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
79
+ necessitates this conversion is ill-formed. If `T` is a non-class type,
80
+ the type of the prvalue is the cv-unqualified version of `T`. Otherwise,
81
+ the type of the prvalue is `T`.[^2]
 
 
 
82
 
83
+ When an lvalue-to-rvalue conversion is applied to an expression `e`, and
84
+ either
85
+
86
+ - `e` is not potentially evaluated, or
87
+ - the evaluation of `e` results in the evaluation of a member `ex` of
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 };
98
+ return [&](bool b) { return (b ? y : x).n; };
99
+ }
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
 
 
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>
296
 
297
+ A *null pointer constant* is an integer literal ([[lex.icon]]) with
298
+ value zero or a prvalue of type `std::nullptr_t`. A null pointer
299
+ constant can be converted to a pointer type; the result is the *null
300
+ pointer value* of that type and is distinguishable from every other
301
+ 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
 
344
  of `D`, a program that necessitates this conversion is ill-formed. The
345
  result of the conversion refers to the same member as the pointer to
346
  member before the conversion took place, but it refers to the base class
347
  member as if it were a member of the derived class. The result refers to
348
  the member in `D`’s instance of `B`. Since the result has type “pointer
349
+ 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
360
+ `false`; any other value is converted to `true`. For
361
+ direct-initialization ([[dcl.init]]), a prvalue of type
362
  `std::nullptr_t` can be converted to a prvalue of type `bool`; the
363
  resulting value is `false`.
364
 
365
  ## Integer conversion rank <a id="conv.rank">[[conv.rank]]</a>
366
 
 
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
 
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
437