From Jason Turner

[expr.cast]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2azbra4r/{from.md → to.md} +15 -5
tmp/tmp2azbra4r/{from.md → to.md} RENAMED
@@ -48,12 +48,13 @@ conversion is valid even if the base class is inaccessible:
48
  of a derived class type, respectively.
49
 
50
  If a conversion can be interpreted in more than one of the ways listed
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 { };
@@ -61,10 +62,19 @@ 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
@@ -74,9 +84,9 @@ 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
 
 
48
  of a derived class type, respectively.
49
 
50
  If a conversion can be interpreted in more than one of the ways listed
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
+ `static_cast` followed by a `const_cast` is used and the conversion can
54
+ be interpreted in more than one way as such, the conversion is
55
+ ill-formed.
56
 
57
  [*Example 1*:
58
 
59
  ``` cpp
60
  struct A { };
 
62
  struct I2 : A { };
63
  struct D : I1, I2 { };
64
  A* foo( D* p ) {
65
  return (A*)( p ); // ill-formed static_cast interpretation
66
  }
67
+
68
+ int*** ptr = 0;
69
+ auto t = (int const*const*const*)ptr; // OK, const_cast interpretation
70
+
71
+ struct S {
72
+ operator const int*();
73
+ operator volatile int*();
74
+ };
75
+ int *p = (int*)S(); // error: two possible interpretations using static_cast followed by const_cast
76
  ```
77
 
78
  — *end example*]
79
 
80
  The operand of a cast using the cast notation can be a prvalue of type
 
84
  incomplete, it is unspecified whether the `static_cast` or the
85
  `reinterpret_cast` interpretation is used, even if there is an
86
  inheritance relationship between the two classes.
87
 
88
  [*Note 2*: For example, if the classes were defined later in the
89
+ translation unit, a multi-pass compiler could validly interpret a cast
90
+ between pointers to the classes as if the class types were complete at
91
+ the point of the cast. — *end note*]
92