Author: Richard Smith Date: 2020-03-10T16:34:27-07:00 New Revision: 4cba668ac13433ce295ee101a920365fba6f20de
URL: https://github.com/llvm/llvm-project/commit/4cba668ac13433ce295ee101a920365fba6f20de DIFF: https://github.com/llvm/llvm-project/commit/4cba668ac13433ce295ee101a920365fba6f20de.diff LOG: Fix crash-on-invalid when trying to recover from a function template being deleted on its second or subsequent declaration. Added: Modified: clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 7331c3369744..2dfefa386e65 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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(); } diff --git a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp index 7a581fd519a9..1ec484ab1e5e 100644 --- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp +++ b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp @@ -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}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits