diff options
author | John McCall <rjmccall@apple.com> | 2010-02-12 06:15:07 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-02-12 06:15:07 +0000 |
commit | 96058953c72355efb266abe8e333db4f5715dbd2 (patch) | |
tree | 2054438a657bb67ad063a3b59b3c009166138a9c /lib/CodeGen/CGVtable.cpp | |
parent | a301ac3f4b5c36593e84a4db78e66445232c949b (diff) |
Fix a bug causing an assertion when a covariant return type differed from
an overriden type only by reduced qualification.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGVtable.cpp')
-rw-r--r-- | lib/CodeGen/CGVtable.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 1c5384767e..e2ea4736d3 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -64,8 +64,8 @@ static bool TypeConversionRequiresAdjustment(ASTContext &Ctx, QualType DerivedType, QualType BaseType) { // Canonicalize the types. - QualType CanDerivedType = Ctx.getCanonicalType(DerivedType); - QualType CanBaseType = Ctx.getCanonicalType(BaseType); + CanQualType CanDerivedType = Ctx.getCanonicalType(DerivedType); + CanQualType CanBaseType = Ctx.getCanonicalType(BaseType); assert(CanDerivedType->getTypeClass() == CanBaseType->getTypeClass() && "Types must have same type class!"); @@ -75,26 +75,29 @@ TypeConversionRequiresAdjustment(ASTContext &Ctx, return false; } - if (const ReferenceType *RT = CanDerivedType->getAs<ReferenceType>()) { - CanDerivedType = RT->getPointeeType(); + if (isa<ReferenceType>(CanDerivedType)) { + CanDerivedType = CanDerivedType->getAs<ReferenceType>()->getPointeeType(); CanBaseType = CanBaseType->getAs<ReferenceType>()->getPointeeType(); - } else if (const PointerType *PT = CanDerivedType->getAs<PointerType>()) { - CanDerivedType = PT->getPointeeType(); + } else if (isa<PointerType>(CanDerivedType)) { + CanDerivedType = CanDerivedType->getAs<PointerType>()->getPointeeType(); CanBaseType = CanBaseType->getAs<PointerType>()->getPointeeType(); } else { assert(false && "Unexpected return type!"); } - if (CanDerivedType == CanBaseType) { + // We need to compare unqualified types here; consider + // const T *Base::foo(); + // T *Derived::foo(); + if (CanDerivedType.getUnqualifiedType() == CanBaseType.getUnqualifiedType()) { // No adjustment needed. return false; } const CXXRecordDecl *DerivedDecl = - cast<CXXRecordDecl>(CanDerivedType->getAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(cast<RecordType>(CanDerivedType)->getDecl()); const CXXRecordDecl *BaseDecl = - cast<CXXRecordDecl>(CanBaseType->getAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(cast<RecordType>(CanBaseType)->getDecl()); return TypeConversionRequiresAdjustment(Ctx, DerivedDecl, BaseDecl); } |