const SourceRange &OpRange);
static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
const SourceRange &OpRange,
- const SourceRange &DestRange);
+ const SourceRange &DestRange,
+ CastExpr::CastKind &Kind);
static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType);
return Owned(new (Context) CXXConstCastExpr(DestType.getNonReferenceType(),
Ex, DestType, OpLoc));
- case tok::kw_dynamic_cast:
+ case tok::kw_dynamic_cast: {
+ CastExpr::CastKind Kind = CastExpr::CK_Unknown;
if (!TypeDependent)
- CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
+ CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange, Kind);
return Owned(new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(),
- CastExpr::CK_Unknown, Ex,
- DestType, OpLoc));
-
+ Kind, Ex, DestType, OpLoc));
+ }
case tok::kw_reinterpret_cast:
if (!TypeDependent)
CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
/// CheckDynamicCast - Check that a dynamic_cast\<DestType\>(SrcExpr) is valid.
/// Refer to C++ 5.2.7 for details. Dynamic casts are used mostly for runtime-
/// checked downcasts in class hierarchies.
-void
+static void
CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
const SourceRange &OpRange,
- const SourceRange &DestRange)
+ const SourceRange &DestRange, CastExpr::CastKind &Kind)
{
QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType();
DestType = Self.Context.getCanonicalType(DestType);
if (DestRecord && Self.IsDerivedFrom(SrcPointee, DestPointee)) {
Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
OpRange.getBegin(), OpRange);
+ Kind = CastExpr::CK_DerivedToBase;
// Diagnostic already emitted on error.
return;
}
}
// Done. Everything else is run-time checks.
+ Kind = CastExpr::CK_Dynamic;
}
/// CheckConstCast - Check that a const_cast\<DestType\>(SrcExpr) is valid.