forked from OSchip/llvm-project
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:
parent
6ea5949a93
commit
8e36d53e34
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue