The result is an lvalue if T is an lvalue
reference type or an rvalue reference to function type and an xvalue if T
is an rvalue reference to object type; otherwise the result is a prvalue.
An explicit type conversion can be expressed using functional
notation ([expr.type.conv]), a type conversion operator
(dynamic_cast, static_cast, reinterpret_cast,
const_cast), or the cast notation.
can be performed using the cast notation of explicit type conversion.
The same semantic restrictions and behaviors apply, with the exception
that in performing a static_cast in the following situations the
conversion is valid even if the base class is inaccessible:
a pointer to an object of derived class type or an lvalue or
rvalue of derived class type may be explicitly converted to a pointer or
reference to an unambiguous base class type, respectively;
a pointer to an object of an unambiguous non-virtual base class
type, a glvalue of an unambiguous non-virtual base class type,
or a pointer to member of an unambiguous non-virtual base class type may
be explicitly converted to a pointer, a reference, or a pointer to
member of a derived class type, respectively.
If a conversion can be interpreted in more than one of the ways listed
above, the interpretation that appears first in the list is used, even
if a cast resulting from that interpretation is ill-formed.
If a
static_cast followed by a const_cast is used and
the conversion can be interpreted in more than one way as such,
the conversion is
ill-formed.
[Example 1: struct A {};
struct I1 : A {};
struct I2 : A {};
struct D : I1, I2 {};
A* foo( D* p ){return(A*)( p ); // ill-formed static_cast interpretation}int*** ptr =0;
auto t =(intconst*const*const*)ptr; // OK, const_cast interpretationstruct S {operatorconstint*();
operatorvolatileint*();
};
int*p =(int*)S(); // error: two possible interpretations using static_cast followed by const_cast — end example]
The operand of a cast using the cast notation can be a prvalue of type
“pointer to incomplete class type”.
The destination type of a cast
using the cast notation can be “pointer to incomplete class type”.
If
both the operand and destination types are class types and one or both
are incomplete, it is unspecified whether the static_cast or the
reinterpret_cast interpretation is used, even if there is an
inheritance relationship between the two classes.
For example, if the classes were defined later in the translation unit,
a multi-pass compiler could validly interpret a cast between
pointers to the classes as if the class types were complete at the point
of the cast.