Add a new routine Sema::LookupDestructor and make all destructor-lookup calls use that routine

llvm-svn: 107444
This commit is contained in:
Douglas Gregor 2010-07-01 22:47:18 +00:00
parent 504055ce9e
commit e71eddac59
6 changed files with 27 additions and 18 deletions

View File

@ -1476,6 +1476,7 @@ public:
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
QualType T1, QualType T2,
UnresolvedSetImpl &Functions);
CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
void ArgumentDependentLookup(DeclarationName Name, bool Operator,
Expr **Args, unsigned NumArgs,
@ -1485,7 +1486,7 @@ public:
VisibleDeclConsumer &Consumer);
void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
VisibleDeclConsumer &Consumer);
/// \brief The context in which typo-correction occurs.
///
/// The typo-correction context affects which keywords (if any) are

View File

@ -5951,7 +5951,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) {
case CXXDestructor:
if (RD->hasUserDeclaredDestructor()) {
SourceLocation DtorLoc = RD->getDestructor()->getLocation();
SourceLocation DtorLoc = LookupDestructor(RD)->getLocation();
Diag(DtorLoc, diag::note_nontrivial_user_defined) << QT << member;
return;
}

View File

@ -2230,7 +2230,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
if (FieldClassDecl->hasTrivialDestructor())
continue;
CXXDestructorDecl *Dtor = FieldClassDecl->getDestructor();
CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
CheckDestructorAccess(Field->getLocation(), Dtor,
PDiag(diag::err_access_dtor_field)
<< Field->getDeclName()
@ -2256,7 +2256,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
if (BaseClassDecl->hasTrivialDestructor())
continue;
CXXDestructorDecl *Dtor = BaseClassDecl->getDestructor();
CXXDestructorDecl *Dtor = LookupDestructor(BaseClassDecl);
// FIXME: caret should be on the start of the class name
CheckDestructorAccess(Base->getSourceRange().getBegin(), Dtor,
@ -2283,7 +2283,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
if (BaseClassDecl->hasTrivialDestructor())
continue;
CXXDestructorDecl *Dtor = BaseClassDecl->getDestructor();
CXXDestructorDecl *Dtor = LookupDestructor(BaseClassDecl);
CheckDestructorAccess(ClassDecl->getLocation(), Dtor,
PDiag(diag::err_access_dtor_vbase)
<< VBase->getType());
@ -4256,7 +4256,7 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(Scope *S,
if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
ExceptSpec.CalledDecl(
cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
LookupDestructor(cast<CXXRecordDecl>(BaseType->getDecl())));
}
// Virtual base-class destructors.
@ -4265,7 +4265,7 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(Scope *S,
B != BEnd; ++B) {
if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
ExceptSpec.CalledDecl(
cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
LookupDestructor(cast<CXXRecordDecl>(BaseType->getDecl())));
}
// Field destructors.
@ -4275,7 +4275,7 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(Scope *S,
if (const RecordType *RecordTy
= Context.getBaseElementType(F->getType())->getAs<RecordType>())
ExceptSpec.CalledDecl(
cast<CXXRecordDecl>(RecordTy->getDecl())->getDestructor());
LookupDestructor(cast<CXXRecordDecl>(RecordTy->getDecl())));
}
QualType Ty = Context.getFunctionType(Context.VoidTy,
@ -5214,7 +5214,7 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Record->getDecl());
if (!ClassDecl->isInvalidDecl() && !VD->isInvalidDecl() &&
!ClassDecl->hasTrivialDestructor() && !ClassDecl->isDependentContext()) {
CXXDestructorDecl *Destructor = ClassDecl->getDestructor();
CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
MarkDeclarationReferenced(VD->getLocation(), Destructor);
CheckDestructorAccess(VD->getLocation(), Destructor,
PDiag(diag::err_access_dtor_var)
@ -6685,8 +6685,7 @@ void Sema::SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation) {
= Context.getBaseElementType(Field->getType())
->getAs<RecordType>()) {
CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
if (CXXDestructorDecl *Destructor
= const_cast<CXXDestructorDecl*>(RD->getDestructor())) {
if (CXXDestructorDecl *Destructor = LookupDestructor(RD)) {
MarkDeclarationReferenced(Field->getLocation(), Destructor);
CheckDestructorAccess(Field->getLocation(), Destructor,
PDiag(diag::err_access_dtor_ivar)

View File

@ -474,7 +474,7 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
return false;
CXXDestructorDecl *Destructor
= const_cast<CXXDestructorDecl*>(RD->getDestructor());
= const_cast<CXXDestructorDecl*>(LookupDestructor(RD));
if (!Destructor)
return false;
@ -1475,7 +1475,7 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
return ExprError();
if (!RD->hasTrivialDestructor())
if (const CXXDestructorDecl *Dtor = RD->getDestructor())
if (const CXXDestructorDecl *Dtor = LookupDestructor(RD))
MarkDeclarationReferenced(StartLoc,
const_cast<CXXDestructorDecl*>(Dtor));
}
@ -2639,10 +2639,9 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) {
if (RD->hasTrivialDestructor())
return Owned(E);
CXXTemporary *Temp = CXXTemporary::Create(Context, RD->getDestructor());
CXXTemporary *Temp = CXXTemporary::Create(Context, LookupDestructor(RD));
ExprTemporaries.push_back(Temp);
if (CXXDestructorDecl *Destructor =
const_cast<CXXDestructorDecl*>(RD->getDestructor())) {
if (CXXDestructorDecl *Destructor = LookupDestructor(RD)) {
MarkDeclarationReferenced(E->getExprLoc(), Destructor);
CheckDestructorAccess(E->getExprLoc(), Destructor,
PDiag(diag::err_access_dtor_temp)

View File

@ -3708,8 +3708,8 @@ InitializationSequence::Perform(Sema &S,
CurInitExpr = static_cast<Expr *>(CurInit.get());
QualType T = CurInitExpr->getType();
if (const RecordType *Record = T->getAs<RecordType>()) {
CXXDestructorDecl *Destructor
= cast<CXXRecordDecl>(Record->getDecl())->getDestructor();
CXXDestructorDecl *Destructor
= S.LookupDestructor(cast<CXXRecordDecl>(Record->getDecl()));
S.CheckDestructorAccess(CurInitExpr->getLocStart(), Destructor,
S.PDiag(diag::err_access_dtor_temp) << T);
S.MarkDeclarationReferenced(CurInitExpr->getLocStart(), Destructor);

View File

@ -1897,6 +1897,16 @@ void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
}
}
/// \brief Look for the destructor of the given class.
///
/// During semantic analysis, this routine should be used in lieu of
/// CXXRecordDecl::getDestructor().
///
/// \returns The destructor for this class.
CXXDestructorDecl *Sema::LookupDestructor(CXXRecordDecl *Class) {
return Class->getDestructor();
}
void ADLResult::insert(NamedDecl *New) {
NamedDecl *&Old = Decls[cast<NamedDecl>(New->getCanonicalDecl())];