tmp/tmpf0ebevih/{from.md → to.md}
RENAMED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
## Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
|
| 2 |
|
| 3 |
The result of the expression `(T)` *cast-expression* is of type `T`. The
|
| 4 |
result is an lvalue if `T` is an lvalue reference type or an rvalue
|
| 5 |
reference to function type and an xvalue if `T` is an rvalue reference
|
| 6 |
-
to object type; otherwise the result is a prvalue.
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
An explicit type conversion can be expressed using functional notation (
|
| 11 |
[[expr.type.conv]]), a type conversion operator (`dynamic_cast`,
|
| 12 |
`static_cast`, `reinterpret_cast`, `const_cast`), or the *cast*
|
| 13 |
notation.
|
|
@@ -49,26 +51,32 @@ If a conversion can be interpreted in more than one of the ways listed
|
|
| 49 |
above, the interpretation that appears first in the list is used, even
|
| 50 |
if a cast resulting from that interpretation is ill-formed. If a
|
| 51 |
conversion can be interpreted in more than one way as a `static_cast`
|
| 52 |
followed by a `const_cast`, the conversion is ill-formed.
|
| 53 |
|
|
|
|
|
|
|
| 54 |
``` cpp
|
| 55 |
struct A { };
|
| 56 |
struct I1 : A { };
|
| 57 |
struct I2 : A { };
|
| 58 |
struct D : I1, I2 { };
|
| 59 |
A* foo( D* p ) {
|
| 60 |
return (A*)( p ); // ill-formed static_cast interpretation
|
| 61 |
}
|
| 62 |
```
|
| 63 |
|
|
|
|
|
|
|
| 64 |
The operand of a cast using the cast notation can be a prvalue of type
|
| 65 |
“pointer to incomplete class type”. The destination type of a cast using
|
| 66 |
the cast notation can be “pointer to incomplete class type”. If both the
|
| 67 |
operand and destination types are class types and one or both are
|
| 68 |
incomplete, it is unspecified whether the `static_cast` or the
|
| 69 |
`reinterpret_cast` interpretation is used, even if there is an
|
| 70 |
-
inheritance relationship between the two classes.
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
|
|
|
| 1 |
## Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
|
| 2 |
|
| 3 |
The result of the expression `(T)` *cast-expression* is of type `T`. The
|
| 4 |
result is an lvalue if `T` is an lvalue reference type or an rvalue
|
| 5 |
reference to function type and an xvalue if `T` is an rvalue reference
|
| 6 |
+
to object type; otherwise the result is a prvalue.
|
| 7 |
+
|
| 8 |
+
[*Note 1*: If `T` is a non-class type that is cv-qualified, the
|
| 9 |
+
*cv-qualifier*s are discarded when determining the type of the resulting
|
| 10 |
+
prvalue; see Clause [[expr]]. — *end note*]
|
| 11 |
|
| 12 |
An explicit type conversion can be expressed using functional notation (
|
| 13 |
[[expr.type.conv]]), a type conversion operator (`dynamic_cast`,
|
| 14 |
`static_cast`, `reinterpret_cast`, `const_cast`), or the *cast*
|
| 15 |
notation.
|
|
|
|
| 51 |
above, the interpretation that appears first in the list is used, even
|
| 52 |
if a cast resulting from that interpretation is ill-formed. If a
|
| 53 |
conversion can be interpreted in more than one way as a `static_cast`
|
| 54 |
followed by a `const_cast`, the conversion is ill-formed.
|
| 55 |
|
| 56 |
+
[*Example 1*:
|
| 57 |
+
|
| 58 |
``` cpp
|
| 59 |
struct A { };
|
| 60 |
struct I1 : A { };
|
| 61 |
struct I2 : A { };
|
| 62 |
struct D : I1, I2 { };
|
| 63 |
A* foo( D* p ) {
|
| 64 |
return (A*)( p ); // ill-formed static_cast interpretation
|
| 65 |
}
|
| 66 |
```
|
| 67 |
|
| 68 |
+
— *end example*]
|
| 69 |
+
|
| 70 |
The operand of a cast using the cast notation can be a prvalue of type
|
| 71 |
“pointer to incomplete class type”. The destination type of a cast using
|
| 72 |
the cast notation can be “pointer to incomplete class type”. If both the
|
| 73 |
operand and destination types are class types and one or both are
|
| 74 |
incomplete, it is unspecified whether the `static_cast` or the
|
| 75 |
`reinterpret_cast` interpretation is used, even if there is an
|
| 76 |
+
inheritance relationship between the two classes.
|
| 77 |
+
|
| 78 |
+
[*Note 2*: For example, if the classes were defined later in the
|
| 79 |
+
translation unit, a multi-pass compiler would be permitted to interpret
|
| 80 |
+
a cast between pointers to the classes as if the class types were
|
| 81 |
+
complete at the point of the cast. — *end note*]
|
| 82 |
|