forked from OSchip/llvm-project
Sema: Taking the address of a dtor is illegal per C++ [class.dtor]p2.
Emit a proper error instead of crashing in CodeGen. PR16892. llvm-svn: 192345
This commit is contained in:
parent
569f69dace
commit
915d169c6a
|
@ -4483,6 +4483,8 @@ def ext_typecheck_addrof_temporary : ExtWarn<
|
|||
InGroup<DiagGroup<"address-of-temporary">>, DefaultError;
|
||||
def err_typecheck_addrof_temporary : Error<
|
||||
"taking the address of a temporary object of type %0">;
|
||||
def err_typecheck_addrof_dtor : Error<
|
||||
"taking the address of a destructor">;
|
||||
def err_typecheck_unary_expr : Error<
|
||||
"invalid argument type %0 to unary expression">;
|
||||
def err_typecheck_indirection_requires_pointer : Error<
|
||||
|
|
|
@ -8709,6 +8709,10 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) {
|
|||
}
|
||||
}
|
||||
|
||||
// Taking the address of a dtor is illegal per C++ [class.dtor]p2.
|
||||
if (isa<CXXDestructorDecl>(MD))
|
||||
Diag(OpLoc, diag::err_typecheck_addrof_dtor) << op->getSourceRange();
|
||||
|
||||
return Context.getMemberPointerType(op->getType(),
|
||||
Context.getTypeDeclType(MD->getParent()).getTypePtr());
|
||||
} else if (lval != Expr::LV_Valid && lval != Expr::LV_IncompleteVoidType) {
|
||||
|
|
|
@ -363,3 +363,7 @@ namespace PR7900 {
|
|||
(&b)->~A(); // expected-error{{destructor type 'PR7900::A' in object destruction expression does not match the type 'PR7900::B' of the object being destroyed}}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PR16892 {
|
||||
auto p = &A::~A; // expected-error{{taking the address of a destructor}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue