Check access for the implicit calls to destructors that occur when we

have a temporary object in C++.

Also fix a tag mismatch that Doug noticed.

llvm-svn: 100593
This commit is contained in:
John McCall 2010-04-07 00:41:46 +00:00
parent 6ea5949a93
commit 8e36d53e34
4 changed files with 21 additions and 2 deletions

View File

@ -462,6 +462,9 @@ def err_access_dtor_vbase :
Error<"inherited virtual base class %0 has "
"%select{private|protected}1 destructor">,
NoSFINAE;
def err_access_dtor_temp :
Error<"temporary of type %0 has %select{private|protected}1 destructor">,
NoSFINAE;
def err_access_dtor_field :
Error<"field of type %1 has %select{private|protected}2 destructor">,
NoSFINAE;

View File

@ -168,7 +168,7 @@ struct AccessTarget : public Sema::AccessedEntity {
}
private:
friend class AccessTarget;
friend struct AccessTarget;
explicit SavedInstanceContext(AccessTarget &Target)
: Target(Target), Has(Target.HasInstanceContext) {}
AccessTarget &Target;

View File

@ -2450,8 +2450,12 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) {
RD->getDestructor(Context));
ExprTemporaries.push_back(Temp);
if (CXXDestructorDecl *Destructor =
const_cast<CXXDestructorDecl*>(RD->getDestructor(Context)))
const_cast<CXXDestructorDecl*>(RD->getDestructor(Context))) {
MarkDeclarationReferenced(E->getExprLoc(), Destructor);
CheckDestructorAccess(E->getExprLoc(), Destructor,
PDiag(diag::err_access_dtor_temp)
<< E->getType());
}
// FIXME: Add the temporary to the temporaries vector.
return Owned(CXXBindTemporaryExpr::Create(Context, Temp, E));
}

View File

@ -327,3 +327,15 @@ namespace test13 {
(void) d->x;
}
}
// Destructors for temporaries.
namespace test14 {
class A {
private: ~A(); // expected-note {{declared private here}}
};
A foo();
void test() {
foo(); // expected-error {{temporary of type 'test14::A' has private destructor}}
}
}