[cfe-commits] r102260 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/Sema.cpp lib/Sema/SemaCXXCast.cpp lib/Sema/SemaExpr.cpp
Anders Carlsson
andersca at mac.com
Sat Apr 24 12:22:20 PDT 2010
Author: andersca
Date: Sat Apr 24 14:22:20 2010
New Revision: 102260
URL: http://llvm.org/viewvc/llvm-project?rev=102260&view=rev
Log:
Add base paths to CK_UncheckedDerivedToBase and CK_DerivedToBaseMemberPointer.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=102260&r1=102259&r2=102260&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Apr 24 14:22:20 2010
@@ -1659,14 +1659,14 @@
#ifndef NDEBUG
switch (getCastKind()) {
case CK_DerivedToBase:
+ case CK_UncheckedDerivedToBase:
+ case CK_DerivedToBaseMemberPointer:
assert(!BasePath.empty() && "Cast kind should have a base path!");
break;
// FIXME: We should add inheritance paths for these.
case CK_BaseToDerived:
- case CK_UncheckedDerivedToBase:
case CK_BaseToDerivedMemberPointer:
- case CK_DerivedToBaseMemberPointer:
// These should not have an inheritance path.
case CK_Unknown:
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=102260&r1=102259&r2=102260&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Apr 24 14:22:20 2010
@@ -178,8 +178,7 @@
CheckImplicitConversion(Expr, Ty);
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
- if (ImpCast->getCastKind() == Kind) {
- assert(BasePath.empty() && "FIXME: Merge paths!");
+ if (ImpCast->getCastKind() == Kind && BasePath.empty()) {
ImpCast->setType(Ty);
ImpCast->setLvalueCast(isLvalue);
return;
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=102260&r1=102259&r2=102260&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Sat Apr 24 14:22:20 2010
@@ -86,11 +86,13 @@
QualType OrigDestType, unsigned &msg,
CastExpr::CastKind &Kind);
static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr,
- QualType SrcType,
- QualType DestType,bool CStyle,
- const SourceRange &OpRange,
- unsigned &msg,
- CastExpr::CastKind &Kind);
+ QualType SrcType,
+ QualType DestType,bool CStyle,
+ const SourceRange &OpRange,
+ unsigned &msg,
+ CastExpr::CastKind &Kind,
+ CXXBaseSpecifierArray &BasePath);
+
static TryCastResult TryStaticImplicitCast(Sema &Self, Expr *&SrcExpr,
QualType DestType, bool CStyle,
const SourceRange &OpRange,
@@ -550,7 +552,7 @@
// conversion. C++ 5.2.9p9 has additional information.
// DR54's access restrictions apply here also.
tcr = TryStaticMemberPointerUpcast(Self, SrcExpr, SrcType, DestType, CStyle,
- OpRange, msg, Kind);
+ OpRange, msg, Kind, BasePath);
if (tcr != TC_NotApplicable)
return tcr;
@@ -796,7 +798,8 @@
TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType,
QualType DestType, bool CStyle,
const SourceRange &OpRange,
- unsigned &msg, CastExpr::CastKind &Kind) {
+ unsigned &msg, CastExpr::CastKind &Kind,
+ CXXBaseSpecifierArray &BasePath) {
const MemberPointerType *DestMemPtr = DestType->getAs<MemberPointerType>();
if (!DestMemPtr)
return TC_NotApplicable;
@@ -828,7 +831,7 @@
// B base of D
QualType SrcClass(SrcMemPtr->getClass(), 0);
QualType DestClass(DestMemPtr->getClass(), 0);
- CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/!CStyle,
+ CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
/*DetectVirtual=*/true);
if (!Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
return TC_NotApplicable;
@@ -882,6 +885,7 @@
}
}
+ Self.BuildBasePathArray(Paths, BasePath);
Kind = CastExpr::CK_DerivedToBaseMemberPointer;
return TC_Success;
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=102260&r1=102259&r2=102260&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr 24 14:22:20 2010
@@ -1436,14 +1436,15 @@
// type of the object type, in which case we just ignore it.
// Otherwise build the appropriate casts.
if (IsDerivedFrom(FromRecordType, QRecordType)) {
+ CXXBaseSpecifierArray BasePath;
if (CheckDerivedToBaseConversion(FromRecordType, QRecordType,
- FromLoc, FromRange))
+ FromLoc, FromRange, &BasePath))
return true;
if (PointerConversions)
QType = Context.getPointerType(QType);
ImpCastExprToType(From, QType, CastExpr::CK_UncheckedDerivedToBase,
- /*isLvalue=*/!PointerConversions);
+ /*isLvalue=*/!PointerConversions, BasePath);
FromType = QType;
FromRecordType = QRecordType;
@@ -1471,15 +1472,16 @@
// conversion is non-trivial.
if (!Context.hasSameUnqualifiedType(FromRecordType, URecordType)) {
assert(IsDerivedFrom(FromRecordType, URecordType));
+ CXXBaseSpecifierArray BasePath;
if (CheckDerivedToBaseConversion(FromRecordType, URecordType,
- FromLoc, FromRange))
+ FromLoc, FromRange, &BasePath))
return true;
QualType UType = URecordType;
if (PointerConversions)
UType = Context.getPointerType(UType);
ImpCastExprToType(From, UType, CastExpr::CK_UncheckedDerivedToBase,
- /*isLvalue*/ !PointerConversions);
+ /*isLvalue=*/!PointerConversions, BasePath);
FromType = UType;
FromRecordType = URecordType;
}
@@ -1489,15 +1491,14 @@
IgnoreAccess = true;
}
- if (CheckDerivedToBaseConversion(FromRecordType,
- DestRecordType,
- FromLoc,
- FromRange, 0,
+ CXXBaseSpecifierArray BasePath;
+ if (CheckDerivedToBaseConversion(FromRecordType, DestRecordType,
+ FromLoc, FromRange, &BasePath,
IgnoreAccess))
return true;
ImpCastExprToType(From, DestType, CastExpr::CK_UncheckedDerivedToBase,
- /*isLvalue=*/!PointerConversions);
+ /*isLvalue=*/!PointerConversions, BasePath);
return false;
}
More information about the cfe-commits
mailing list