[PATCH] D130936: [SemaCXX] Validate destructor is valid for dependent classes

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 14:44:38 PDT 2022


royjacobson created this revision.
Herald added a project: All.
royjacobson updated this revision to Diff 449130.
royjacobson added a comment.
royjacobson retitled this revision from "[SemaCXX] Fix destructor name accepts-invalid bug." to "[SemaCXX] Validate destructor is valid for dependent classes".
royjacobson edited the summary of this revision.
royjacobson added reviewers: erichkeane, shafik.
royjacobson published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix the C++20 check


We didn't check that a destructor's name matches the directly enclosing class if the class was dependent.
I enabled the check we already had for non-dependent types, which seems to work. Added appropriate tests.

Fixes GitHub issue #56772


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130936

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/member-class-11.cpp


Index: clang/test/SemaCXX/member-class-11.cpp
===================================================================
--- clang/test/SemaCXX/member-class-11.cpp
+++ 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<class T>
+struct A {
+  ~A<T>();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template<class T>
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
+
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ 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<CXXDeductionGuideDecl>(NewFD)) {
       if (auto *TD = Guide->getDescribedFunctionTemplate())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130936.449130.patch
Type: text/x-patch
Size: 2269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220801/4224c5c7/attachment.bin>


More information about the cfe-commits mailing list