From Jason Turner

[expr.reinterpret.cast]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp33mny7_p/{from.md → to.md} +31 -37
tmp/tmp33mny7_p/{from.md → to.md} RENAMED
@@ -1,29 +1,30 @@
1
- ### Reinterpret cast <a id="expr.reinterpret.cast">[[expr.reinterpret.cast]]</a>
2
 
3
  The result of the expression `reinterpret_cast<T>(v)` is the result of
4
  converting the expression `v` to type `T`. If `T` is an lvalue reference
5
  type or an rvalue reference to function type, the result is an lvalue;
6
  if `T` is an rvalue reference to object type, the result is an xvalue;
7
- otherwise, the result is a prvalue and the lvalue-to-rvalue (
8
- [[conv.lval]]), array-to-pointer ([[conv.array]]), and
9
- function-to-pointer ([[conv.func]]) standard conversions are performed
10
- on the expression `v`. Conversions that can be performed explicitly
11
- using `reinterpret_cast` are listed below. No other conversion can be
12
- performed explicitly using `reinterpret_cast`.
13
 
14
- The `reinterpret_cast` operator shall not cast away constness (
15
- [[expr.const.cast]]). An expression of integral, enumeration, pointer,
16
- or pointer-to-member type can be explicitly converted to its own type;
17
- such a cast yields the value of its operand.
18
 
19
  [*Note 1*: The mapping performed by `reinterpret_cast` might, or might
20
  not, produce a representation different from the original
21
  value. — *end note*]
22
 
23
  A pointer can be explicitly converted to any integral type large enough
24
- to hold it. The mapping function is *implementation-defined*.
 
25
 
26
  [*Note 2*: It is intended to be unsurprising to those who know the
27
  addressing structure of the underlying machine. — *end note*]
28
 
29
  A value of type `std::nullptr_t` can be converted to an integral type;
@@ -45,23 +46,23 @@ value. — *end note*]
45
 
46
  A function pointer can be explicitly converted to a function pointer of
47
  a different type.
48
 
49
  [*Note 5*: The effect of calling a function through a pointer to a
50
- function type ([[dcl.fct]]) that is not the same as the type used in
51
- the definition of the function is undefined. — *end note*]
52
 
53
  Except that converting a prvalue of type “pointer to `T1`” to the type
54
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
55
  its original type yields the original pointer value, the result of such
56
  a pointer conversion is unspecified.
57
 
58
  [*Note 6*: See also  [[conv.ptr]] for more details of pointer
59
  conversions. — *end note*]
60
 
61
  An object pointer can be explicitly converted to an object pointer of a
62
- different type.[^12] When a prvalue `v` of object pointer type is
63
  converted to the object pointer type “pointer to cv `T`”, the result is
64
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
65
 
66
  [*Note 7*: Converting a prvalue of type “pointer to `T1`” to the type
67
  “pointer to `T2`” (where `T1` and `T2` are object types and where the
@@ -74,44 +75,37 @@ conditionally-supported. The meaning of such a conversion is
74
  *implementation-defined*, except that if an implementation supports
75
  conversions in both directions, converting a prvalue of one type to the
76
  other type and back, possibly with different cv-qualification, shall
77
  yield the original pointer value.
78
 
79
- The null pointer value ([[conv.ptr]]) is converted to the null pointer
80
- value of the destination type.
81
 
82
  [*Note 8*: A null pointer constant of type `std::nullptr_t` cannot be
83
  converted to a pointer type, and a null pointer constant of integral
84
  type is not necessarily converted to a null pointer
85
  value. — *end note*]
86
 
87
  A prvalue of type “pointer to member of `X` of type `T1`” can be
88
  explicitly converted to a prvalue of a different type “pointer to member
89
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
90
- object types.[^13] The null member pointer value ([[conv.mem]]) is
91
  converted to the null member pointer value of the destination type. The
92
  result of this conversion is unspecified, except in the following cases:
93
 
94
- - converting a prvalue of type “pointer to member function” to a
95
- different pointer to member function type and back to its original
96
- type yields the original pointer to member value.
97
- - converting a prvalue of type “pointer to data member of `X` of type
98
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
99
  the alignment requirements of `T2` are no stricter than those of `T1`)
100
- and back to its original type yields the original pointer to member
101
  value.
102
 
103
- A glvalue expression of type `T1` can be cast to the type “reference to
104
- `T2`” if an expression of type “pointer to `T1`” can be explicitly
105
- converted to the type “pointer to `T2`” using a `reinterpret_cast`. The
106
- result refers to the same object as the source glvalue, but with the
107
- specified type.
108
-
109
- [*Note 9*: That is, for lvalues, a reference cast
110
- `reinterpret_cast<T&>(x)` has the same effect as the conversion
111
- `*reinterpret_cast<T*>(&x)` with the built-in `&` and `*` operators (and
112
- similarly for `reinterpret_cast<T&&>(x)`). — *end note*]
113
-
114
- No temporary is created, no copy is made, and constructors (
115
- [[class.ctor]]) or conversion functions ([[class.conv]]) are not
116
- called.[^14]
117
 
 
1
+ #### Reinterpret cast <a id="expr.reinterpret.cast">[[expr.reinterpret.cast]]</a>
2
 
3
  The result of the expression `reinterpret_cast<T>(v)` is the result of
4
  converting the expression `v` to type `T`. If `T` is an lvalue reference
5
  type or an rvalue reference to function type, the result is an lvalue;
6
  if `T` is an rvalue reference to object type, the result is an xvalue;
7
+ otherwise, the result is a prvalue and the lvalue-to-rvalue
8
+ [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
9
+ [[conv.func]] standard conversions are performed on the expression `v`.
10
+ Conversions that can be performed explicitly using `reinterpret_cast`
11
+ are listed below. No other conversion can be performed explicitly using
12
+ `reinterpret_cast`.
13
 
14
+ The `reinterpret_cast` operator shall not cast away constness
15
+ [[expr.const.cast]]. An expression of integral, enumeration, pointer, or
16
+ pointer-to-member type can be explicitly converted to its own type; such
17
+ a cast yields the value of its operand.
18
 
19
  [*Note 1*: The mapping performed by `reinterpret_cast` might, or might
20
  not, produce a representation different from the original
21
  value. — *end note*]
22
 
23
  A pointer can be explicitly converted to any integral type large enough
24
+ to hold all values of its type. The mapping function is
25
+ *implementation-defined*.
26
 
27
  [*Note 2*: It is intended to be unsurprising to those who know the
28
  addressing structure of the underlying machine. — *end note*]
29
 
30
  A value of type `std::nullptr_t` can be converted to an integral type;
 
46
 
47
  A function pointer can be explicitly converted to a function pointer of
48
  a different type.
49
 
50
  [*Note 5*: The effect of calling a function through a pointer to a
51
+ function type [[dcl.fct]] that is not the same as the type used in the
52
+ definition of the function is undefined [[expr.call]]. — *end note*]
53
 
54
  Except that converting a prvalue of type “pointer to `T1`” to the type
55
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
56
  its original type yields the original pointer value, the result of such
57
  a pointer conversion is unspecified.
58
 
59
  [*Note 6*: See also  [[conv.ptr]] for more details of pointer
60
  conversions. — *end note*]
61
 
62
  An object pointer can be explicitly converted to an object pointer of a
63
+ different type.[^17] When a prvalue `v` of object pointer type is
64
  converted to the object pointer type “pointer to cv `T`”, the result is
65
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
66
 
67
  [*Note 7*: Converting a prvalue of type “pointer to `T1`” to the type
68
  “pointer to `T2`” (where `T1` and `T2` are object types and where the
 
75
  *implementation-defined*, except that if an implementation supports
76
  conversions in both directions, converting a prvalue of one type to the
77
  other type and back, possibly with different cv-qualification, shall
78
  yield the original pointer value.
79
 
80
+ The null pointer value [[basic.compound]] is converted to the null
81
+ pointer value of the destination type.
82
 
83
  [*Note 8*: A null pointer constant of type `std::nullptr_t` cannot be
84
  converted to a pointer type, and a null pointer constant of integral
85
  type is not necessarily converted to a null pointer
86
  value. — *end note*]
87
 
88
  A prvalue of type “pointer to member of `X` of type `T1`” can be
89
  explicitly converted to a prvalue of a different type “pointer to member
90
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
91
+ object types.[^18] The null member pointer value [[conv.mem]] is
92
  converted to the null member pointer value of the destination type. The
93
  result of this conversion is unspecified, except in the following cases:
94
 
95
+ - Converting a prvalue of type “pointer to member function” to a
96
+ different pointer-to-member-function type and back to its original
97
+ type yields the original pointer-to-member value.
98
+ - Converting a prvalue of type “pointer to data member of `X` of type
99
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
100
  the alignment requirements of `T2` are no stricter than those of `T1`)
101
+ and back to its original type yields the original pointer-to-member
102
  value.
103
 
104
+ A glvalue of type `T1`, designating an object *x*, can be cast to the
105
+ type “reference to `T2`” if an expression of type “pointer to `T1`” can
106
+ be explicitly converted to the type “pointer to `T2`” using a
107
+ `reinterpret_cast`. The result is that of `*reinterpret_cast<T2 *>(p)`
108
+ where `p` is a pointer to *x* of type “pointer to `T1`”. No temporary is
109
+ created, no copy is made, and no constructors [[class.ctor]] or
110
+ conversion functions [[class.conv]] are called. [^19]
 
 
 
 
 
 
 
111