From: Anders Carlsson Date: Thu, 12 Nov 2009 16:53:16 +0000 (+0000) Subject: Set CK_BaseToDerived in TryStaticDowncast. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95c5d8ac29ba3423e735a0732713907e484b800d;p=clang Set CK_BaseToDerived in TryStaticDowncast. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86996 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index eb931f33a2..269329543e 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -70,16 +70,19 @@ static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, static TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg); + unsigned &msg, + CastExpr::CastKind &Kind); static TryCastResult TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg); + unsigned &msg, + CastExpr::CastKind &Kind); static TryCastResult TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, QualType OrigSrcType, - QualType OrigDestType, unsigned &msg); + QualType OrigDestType, unsigned &msg, + CastExpr::CastKind &Kind); static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType,bool CStyle, const SourceRange &OpRange, @@ -427,7 +430,8 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr, // C++ 5.2.9p5, reference downcast. // See the function for details. // DR 427 specifies that this is to be applied before paragraph 2. - tcr = TryStaticReferenceDowncast(Self, SrcExpr, DestType, CStyle,OpRange,msg); + tcr = TryStaticReferenceDowncast(Self, SrcExpr, DestType, CStyle, OpRange, + msg, Kind); if (tcr != TC_NotApplicable) return tcr; @@ -473,7 +477,8 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr, // Reverse pointer upcast. C++ 4.10p3 specifies pointer upcast. // C++ 5.2.9p8 additionally disallows a cast path through virtual inheritance. - tcr = TryStaticPointerDowncast(Self, SrcType, DestType, CStyle, OpRange, msg); + tcr = TryStaticPointerDowncast(Self, SrcType, DestType, CStyle, OpRange, msg, + Kind); if (tcr != TC_NotApplicable) return tcr; @@ -544,7 +549,7 @@ TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType, TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg) { + unsigned &msg, CastExpr::CastKind &Kind) { // C++ 5.2.9p5: An lvalue of type "cv1 B", where B is a class type, can be // cast to type "reference to cv2 D", where D is a class derived from B, // if a valid standard conversion from "pointer to D" to "pointer to B" @@ -568,14 +573,14 @@ TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, QualType DestPointee = DestReference->getPointeeType(); return TryStaticDowncast(Self, SrcExpr->getType(), DestPointee, CStyle, - OpRange, SrcExpr->getType(), DestType, msg); + OpRange, SrcExpr->getType(), DestType, msg, Kind); } /// Tests whether a conversion according to C++ 5.2.9p8 is valid. TryCastResult TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, - unsigned &msg) { + unsigned &msg, CastExpr::CastKind &Kind) { // C++ 5.2.9p8: An rvalue of type "pointer to cv1 B", where B is a class // type, can be converted to an rvalue of type "pointer to cv2 D", where D // is a class derived from B, if a valid standard conversion from "pointer @@ -597,7 +602,7 @@ TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, return TryStaticDowncast(Self, SrcPointer->getPointeeType(), DestPointer->getPointeeType(), CStyle, - OpRange, SrcType, DestType, msg); + OpRange, SrcType, DestType, msg, Kind); } /// TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and @@ -606,7 +611,8 @@ TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, TryCastResult TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, QualType OrigSrcType, - QualType OrigDestType, unsigned &msg) { + QualType OrigDestType, unsigned &msg, + CastExpr::CastKind &Kind) { // We can only work with complete types. But don't complain if it doesn't work if (Self.RequireCompleteType(OpRange.getBegin(), SrcType, PDiag(0)) || Self.RequireCompleteType(OpRange.getBegin(), DestType, PDiag(0))) @@ -695,6 +701,7 @@ TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType, return TC_Failed; } + Kind = CastExpr::CK_BaseToDerived; return TC_Success; }