diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11496,17 +11496,12 @@ CXXRecordDecl *Record = Destructor->getParent(); QualType ClassType = Context.getTypeDeclType(Record); - // FIXME: Shouldn't we be able to perform this check even when the class - // type is dependent? Both gcc and edg can handle that. - if (!ClassType->isDependentType()) { - DeclarationName Name - = Context.DeclarationNames.getCXXDestructorName( - Context.getCanonicalType(ClassType)); - if (NewFD->getDeclName() != Name) { - Diag(NewFD->getLocation(), diag::err_destructor_name); - NewFD->setInvalidDecl(); - return Redeclaration; - } + DeclarationName Name = Context.DeclarationNames.getCXXDestructorName( + Context.getCanonicalType(ClassType)); + if (NewFD->getDeclName() != Name) { + Diag(NewFD->getLocation(), diag::err_destructor_name); + NewFD->setInvalidDecl(); + return Redeclaration; } } else if (auto *Guide = dyn_cast(NewFD)) { if (auto *TD = Guide->getDescribedFunctionTemplate()) diff --git a/clang/test/SemaCXX/member-class-11.cpp b/clang/test/SemaCXX/member-class-11.cpp --- a/clang/test/SemaCXX/member-class-11.cpp +++ b/clang/test/SemaCXX/member-class-11.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s struct rdar9677163 { struct Y { ~Y(); }; @@ -6,3 +8,22 @@ Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a qualified name}} ~Z(); // expected-error{{expected the class name after '~' to name the enclosing class}} }; + +namespace GH56772 { + +template +struct A { + ~A(); +}; +#if __cplusplus > 202002L +// expected-error@-2 {{expected the class name after '~' to name the enclosing class}} +#endif + +struct B; + +template +struct C { + ~B(); // expected-error {{expected the class name after '~' to name the enclosing class}} +}; + +} \ No newline at end of file