forked from OSchip/llvm-project
Add base paths to CK_UncheckedDerivedToBase and CK_DerivedToBaseMemberPointer.
llvm-svn: 102260
This commit is contained in:
parent
a70cff624e
commit
b78fecaf6f
|
@ -1659,14 +1659,14 @@ private:
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
switch (getCastKind()) {
|
switch (getCastKind()) {
|
||||||
case CK_DerivedToBase:
|
case CK_DerivedToBase:
|
||||||
|
case CK_UncheckedDerivedToBase:
|
||||||
|
case CK_DerivedToBaseMemberPointer:
|
||||||
assert(!BasePath.empty() && "Cast kind should have a base path!");
|
assert(!BasePath.empty() && "Cast kind should have a base path!");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// FIXME: We should add inheritance paths for these.
|
// FIXME: We should add inheritance paths for these.
|
||||||
case CK_BaseToDerived:
|
case CK_BaseToDerived:
|
||||||
case CK_UncheckedDerivedToBase:
|
|
||||||
case CK_BaseToDerivedMemberPointer:
|
case CK_BaseToDerivedMemberPointer:
|
||||||
case CK_DerivedToBaseMemberPointer:
|
|
||||||
|
|
||||||
// These should not have an inheritance path.
|
// These should not have an inheritance path.
|
||||||
case CK_Unknown:
|
case CK_Unknown:
|
||||||
|
|
|
@ -178,8 +178,7 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
|
||||||
CheckImplicitConversion(Expr, Ty);
|
CheckImplicitConversion(Expr, Ty);
|
||||||
|
|
||||||
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
|
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
|
||||||
if (ImpCast->getCastKind() == Kind) {
|
if (ImpCast->getCastKind() == Kind && BasePath.empty()) {
|
||||||
assert(BasePath.empty() && "FIXME: Merge paths!");
|
|
||||||
ImpCast->setType(Ty);
|
ImpCast->setType(Ty);
|
||||||
ImpCast->setLvalueCast(isLvalue);
|
ImpCast->setLvalueCast(isLvalue);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -86,11 +86,13 @@ static TryCastResult TryStaticDowncast(Sema &Self, CanQualType SrcType,
|
||||||
QualType OrigDestType, unsigned &msg,
|
QualType OrigDestType, unsigned &msg,
|
||||||
CastExpr::CastKind &Kind);
|
CastExpr::CastKind &Kind);
|
||||||
static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr,
|
static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr,
|
||||||
QualType SrcType,
|
QualType SrcType,
|
||||||
QualType DestType,bool CStyle,
|
QualType DestType,bool CStyle,
|
||||||
const SourceRange &OpRange,
|
const SourceRange &OpRange,
|
||||||
unsigned &msg,
|
unsigned &msg,
|
||||||
CastExpr::CastKind &Kind);
|
CastExpr::CastKind &Kind,
|
||||||
|
CXXBaseSpecifierArray &BasePath);
|
||||||
|
|
||||||
static TryCastResult TryStaticImplicitCast(Sema &Self, Expr *&SrcExpr,
|
static TryCastResult TryStaticImplicitCast(Sema &Self, Expr *&SrcExpr,
|
||||||
QualType DestType, bool CStyle,
|
QualType DestType, bool CStyle,
|
||||||
const SourceRange &OpRange,
|
const SourceRange &OpRange,
|
||||||
|
@ -550,7 +552,7 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr,
|
||||||
// conversion. C++ 5.2.9p9 has additional information.
|
// conversion. C++ 5.2.9p9 has additional information.
|
||||||
// DR54's access restrictions apply here also.
|
// DR54's access restrictions apply here also.
|
||||||
tcr = TryStaticMemberPointerUpcast(Self, SrcExpr, SrcType, DestType, CStyle,
|
tcr = TryStaticMemberPointerUpcast(Self, SrcExpr, SrcType, DestType, CStyle,
|
||||||
OpRange, msg, Kind);
|
OpRange, msg, Kind, BasePath);
|
||||||
if (tcr != TC_NotApplicable)
|
if (tcr != TC_NotApplicable)
|
||||||
return tcr;
|
return tcr;
|
||||||
|
|
||||||
|
@ -796,7 +798,8 @@ TryCastResult
|
||||||
TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType,
|
TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType,
|
||||||
QualType DestType, bool CStyle,
|
QualType DestType, bool CStyle,
|
||||||
const SourceRange &OpRange,
|
const SourceRange &OpRange,
|
||||||
unsigned &msg, CastExpr::CastKind &Kind) {
|
unsigned &msg, CastExpr::CastKind &Kind,
|
||||||
|
CXXBaseSpecifierArray &BasePath) {
|
||||||
const MemberPointerType *DestMemPtr = DestType->getAs<MemberPointerType>();
|
const MemberPointerType *DestMemPtr = DestType->getAs<MemberPointerType>();
|
||||||
if (!DestMemPtr)
|
if (!DestMemPtr)
|
||||||
return TC_NotApplicable;
|
return TC_NotApplicable;
|
||||||
|
@ -828,7 +831,7 @@ TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType,
|
||||||
// B base of D
|
// B base of D
|
||||||
QualType SrcClass(SrcMemPtr->getClass(), 0);
|
QualType SrcClass(SrcMemPtr->getClass(), 0);
|
||||||
QualType DestClass(DestMemPtr->getClass(), 0);
|
QualType DestClass(DestMemPtr->getClass(), 0);
|
||||||
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/!CStyle,
|
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
|
||||||
/*DetectVirtual=*/true);
|
/*DetectVirtual=*/true);
|
||||||
if (!Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
|
if (!Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
|
||||||
return TC_NotApplicable;
|
return TC_NotApplicable;
|
||||||
|
@ -882,6 +885,7 @@ TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Self.BuildBasePathArray(Paths, BasePath);
|
||||||
Kind = CastExpr::CK_DerivedToBaseMemberPointer;
|
Kind = CastExpr::CK_DerivedToBaseMemberPointer;
|
||||||
return TC_Success;
|
return TC_Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1436,14 +1436,15 @@ Sema::PerformObjectMemberConversion(Expr *&From,
|
||||||
// type of the object type, in which case we just ignore it.
|
// type of the object type, in which case we just ignore it.
|
||||||
// Otherwise build the appropriate casts.
|
// Otherwise build the appropriate casts.
|
||||||
if (IsDerivedFrom(FromRecordType, QRecordType)) {
|
if (IsDerivedFrom(FromRecordType, QRecordType)) {
|
||||||
|
CXXBaseSpecifierArray BasePath;
|
||||||
if (CheckDerivedToBaseConversion(FromRecordType, QRecordType,
|
if (CheckDerivedToBaseConversion(FromRecordType, QRecordType,
|
||||||
FromLoc, FromRange))
|
FromLoc, FromRange, &BasePath))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (PointerConversions)
|
if (PointerConversions)
|
||||||
QType = Context.getPointerType(QType);
|
QType = Context.getPointerType(QType);
|
||||||
ImpCastExprToType(From, QType, CastExpr::CK_UncheckedDerivedToBase,
|
ImpCastExprToType(From, QType, CastExpr::CK_UncheckedDerivedToBase,
|
||||||
/*isLvalue=*/!PointerConversions);
|
/*isLvalue=*/!PointerConversions, BasePath);
|
||||||
|
|
||||||
FromType = QType;
|
FromType = QType;
|
||||||
FromRecordType = QRecordType;
|
FromRecordType = QRecordType;
|
||||||
|
@ -1471,15 +1472,16 @@ Sema::PerformObjectMemberConversion(Expr *&From,
|
||||||
// conversion is non-trivial.
|
// conversion is non-trivial.
|
||||||
if (!Context.hasSameUnqualifiedType(FromRecordType, URecordType)) {
|
if (!Context.hasSameUnqualifiedType(FromRecordType, URecordType)) {
|
||||||
assert(IsDerivedFrom(FromRecordType, URecordType));
|
assert(IsDerivedFrom(FromRecordType, URecordType));
|
||||||
|
CXXBaseSpecifierArray BasePath;
|
||||||
if (CheckDerivedToBaseConversion(FromRecordType, URecordType,
|
if (CheckDerivedToBaseConversion(FromRecordType, URecordType,
|
||||||
FromLoc, FromRange))
|
FromLoc, FromRange, &BasePath))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
QualType UType = URecordType;
|
QualType UType = URecordType;
|
||||||
if (PointerConversions)
|
if (PointerConversions)
|
||||||
UType = Context.getPointerType(UType);
|
UType = Context.getPointerType(UType);
|
||||||
ImpCastExprToType(From, UType, CastExpr::CK_UncheckedDerivedToBase,
|
ImpCastExprToType(From, UType, CastExpr::CK_UncheckedDerivedToBase,
|
||||||
/*isLvalue*/ !PointerConversions);
|
/*isLvalue=*/!PointerConversions, BasePath);
|
||||||
FromType = UType;
|
FromType = UType;
|
||||||
FromRecordType = URecordType;
|
FromRecordType = URecordType;
|
||||||
}
|
}
|
||||||
|
@ -1489,15 +1491,14 @@ Sema::PerformObjectMemberConversion(Expr *&From,
|
||||||
IgnoreAccess = true;
|
IgnoreAccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckDerivedToBaseConversion(FromRecordType,
|
CXXBaseSpecifierArray BasePath;
|
||||||
DestRecordType,
|
if (CheckDerivedToBaseConversion(FromRecordType, DestRecordType,
|
||||||
FromLoc,
|
FromLoc, FromRange, &BasePath,
|
||||||
FromRange, 0,
|
|
||||||
IgnoreAccess))
|
IgnoreAccess))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ImpCastExprToType(From, DestType, CastExpr::CK_UncheckedDerivedToBase,
|
ImpCastExprToType(From, DestType, CastExpr::CK_UncheckedDerivedToBase,
|
||||||
/*isLvalue=*/!PointerConversions);
|
/*isLvalue=*/!PointerConversions, BasePath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue