[clang] Allow struct q{int q;~q();} (#88597) (PR #88673)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 15:37:50 PDT 2024


https://github.com/nabijaczleweli updated https://github.com/llvm/llvm-project/pull/88673

>From 05545c8cc2ef2751128f1906933151fb09e37b65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli at nabijaczleweli.xyz>
Date: Mon, 15 Apr 2024 03:52:50 +0200
Subject: [PATCH 1/2] Allow struct q{int q;~q();} (#88597)

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 --
 clang/lib/Sema/SemaExprCXX.cpp                   | 5 ++---
 clang/test/CXX/class/class.mem/p13.cpp           | 1 -
 clang/test/SemaCXX/GH59446.cpp                   | 1 -
 clang/test/SemaCXX/constructor.cpp               | 5 ++---
 5 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5ec0218aedfe86..c8c3f2de81f82a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2187,8 +2187,6 @@ def err_undeclared_destructor_name : Error<
   "undeclared identifier %0 in destructor name">;
 def err_destructor_name : Error<
   "expected the class name after '~' to name the enclosing class">;
-def err_destructor_name_nontype : Error<
-  "identifier %0 after '~' in destructor name does not name a type">;
 def err_destructor_expr_mismatch : Error<
   "identifier %0 in object destruction expression does not name the type "
   "%1 of the object being destroyed">;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 25f23a3abf1718..69d4a6d51ecafb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -448,9 +448,8 @@ ParsedType Sema::getDestructorName(const IdentifierInfo &II,
       Diag(NameLoc, diag::err_destructor_expr_nontype)
           << &II << MakeFixItHint();
     }
-  } else {
-    Diag(NameLoc, SearchType.isNull() ? diag::err_destructor_name_nontype
-                                      : diag::err_destructor_expr_mismatch)
+  } else if (!SearchType.isNull()) {
+    Diag(NameLoc, diag::err_destructor_expr_mismatch)
         << &II << SearchType << MakeFixItHint();
   }
 
diff --git a/clang/test/CXX/class/class.mem/p13.cpp b/clang/test/CXX/class/class.mem/p13.cpp
index d947586c419400..1a3173ddfa474c 100644
--- a/clang/test/CXX/class/class.mem/p13.cpp
+++ b/clang/test/CXX/class/class.mem/p13.cpp
@@ -112,5 +112,4 @@ template<typename B> struct Dtemplate_with_ctors : B {
 template<typename B> struct CtorDtorName : B {
   using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}} expected-note {{non-type declaration found by destructor name lookup}}
   CtorDtorName();
-  ~CtorDtorName(); // expected-error {{identifier 'CtorDtorName' after '~' in destructor name does not name a type}}
 };
diff --git a/clang/test/SemaCXX/GH59446.cpp b/clang/test/SemaCXX/GH59446.cpp
index b85a57abb9fa57..c0c1c40265f8be 100644
--- a/clang/test/SemaCXX/GH59446.cpp
+++ b/clang/test/SemaCXX/GH59446.cpp
@@ -8,5 +8,4 @@ namespace N {
   }
   void f(X<int> *x) { // expected-error {{no template named 'X'; did you mean 'N::X'}}
     x->N::X<int>::~X(); // expected-error 2 {{implicit instantiation of undefined template 'GH59446::N::X<int>'}}
-                        // expected-error at -1 {{identifier 'X' after '~' in destructor name does not name a type}}
 } // expected-error {{expected '}'}}
diff --git a/clang/test/SemaCXX/constructor.cpp b/clang/test/SemaCXX/constructor.cpp
index abd7dbe18a0e6a..64683675805924 100644
--- a/clang/test/SemaCXX/constructor.cpp
+++ b/clang/test/SemaCXX/constructor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s 
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 typedef int INT;
 
 class Foo {
@@ -14,7 +14,7 @@ class Foo {
   static Foo(short, short); // expected-error{{constructor cannot be declared 'static'}}
   virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
   Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}}
-  
+
   int Foo(int, int); // expected-error{{constructor cannot have a return type}}
 
   volatile Foo(float); // expected-error{{constructor cannot have a return type}}
@@ -94,5 +94,4 @@ namespace PR38286 {
   template<typename> struct B;
   template<typename T> void B<T>::f() {} // expected-error {{out-of-line definition of 'f' from class 'B<type-parameter-0-0>'}}
   template<typename> struct C; // expected-note {{non-type declaration found}}
-  template<typename T> C<T>::~C() {} // expected-error {{identifier 'C' after '~' in destructor name does not name a type}}
 }

>From 0d8b4fe52595db3c43d3fbc4039c7965c05f3ac3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli at nabijaczleweli.xyz>
Date: Wed, 17 Apr 2024 00:37:35 +0200
Subject: [PATCH 2/2] ?

---
 clang/test/CXX/class/class.mem/p13.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CXX/class/class.mem/p13.cpp b/clang/test/CXX/class/class.mem/p13.cpp
index 1a3173ddfa474c..afccdc57114a12 100644
--- a/clang/test/CXX/class/class.mem/p13.cpp
+++ b/clang/test/CXX/class/class.mem/p13.cpp
@@ -110,6 +110,6 @@ template<typename B> struct Dtemplate_with_ctors : B {
 };
 
 template<typename B> struct CtorDtorName : B {
-  using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}} expected-note {{non-type declaration found by destructor name lookup}}
+  using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}}
   CtorDtorName();
 };



More information about the cfe-commits mailing list