Fix crash-on-invalid when trying to recover from a function template

being deleted on its second or subsequent declaration.
This commit is contained in:
Richard Smith 2020-03-10 16:33:42 -07:00
parent d07f9e7309
commit 4cba668ac1
2 changed files with 21 additions and 2 deletions

View File

@ -16349,9 +16349,16 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) {
Diag(Prev->getLocation().isInvalid() ? DelLoc : Prev->getLocation(),
Prev->isImplicit() ? diag::note_previous_implicit_declaration
: diag::note_previous_declaration);
// We can't recover from this; the declaration might have already
// been used.
Fn->setInvalidDecl();
return;
}
// If the declaration wasn't the first, we delete the function anyway for
// recovery.
// To maintain the invariant that functions are only deleted on their first
// declaration, mark the implicitly-instantiated declaration of the
// explicitly-specialized function as deleted instead of marking the
// instantiated redeclaration.
Fn = Fn->getCanonicalDecl();
}

View File

@ -199,3 +199,15 @@ S::S() __attribute((pure)) = default;
using size_t = decltype(sizeof(0));
void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
// FIXME: Diagnosing the call as "no matching function" due to substitution
// failure is not ideal.
template<typename T> void delete_template_too_late(); // expected-note {{previous}}
template<typename T> void delete_template_too_late() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}
void use_template_deleted_too_late() { delete_template_too_late<int>(); } // expected-error {{no matching function}}
struct DeletedMemberTemplateTooLate {
template<typename T> static void f(); // expected-note {{previous}}
};
template<typename T> void DeletedMemberTemplateTooLate::f() = delete; // expected-error {{must be first decl}} expected-note {{substitution failure}}
void use_member_template_deleted_too_late() { DeletedMemberTemplateTooLate::f<int>(); } // expected-error {{no matching function}}