https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/142975

>From d4294fbb02932ec8b1870ac2960856bbbf299eb5 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Thu, 5 Jun 2025 16:15:33 +0200
Subject: [PATCH 1/4] [Clang] Implement CWG2496

https://cplusplus.github.io/CWG/issues/2496.html

We failed to diagnose the following in C++23 mode

```
struct S {
    virtual void f(); // expected-note {{previous declaration is here}}
};

struct T : S {
    virtual void f() &;
};
```
---
 clang/docs/ReleaseNotes.rst     |  2 ++
 clang/lib/Sema/SemaOverload.cpp |  2 +-
 clang/test/CXX/drs/cwg24xx.cpp  | 20 ++++++++++++++++++++
 clang/www/cxx_dr_status.html    |  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 512071427b65c..d1ee6de66b4ee 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -155,6 +155,8 @@ Resolutions to C++ Defect Reports
 
 - Implemented `CWG3005 Function parameters should never be name-independent 
<https://wg21.link/CWG3005>`_.
 
+- Implemented `CWG2496 ref-qualifiers and virtual overriding 
<https://wg21.link/CWG2496>`_.
+
 C Language Changes
 ------------------
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 66f84fc67b52f..5a19dacdc4d84 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1490,7 +1490,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   auto DiagnoseInconsistentRefQualifiers = [&]() {
-    if (SemaRef.LangOpts.CPlusPlus23)
+    if (SemaRef.LangOpts.CPlusPlus23 && !UseOverrideRules)
       return false;
     if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
       return false;
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9c9a3f14b9e8b..05b9a74e292ab 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -215,3 +215,23 @@ void (*q)() throw() = S();
 // since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() 
throw()'}}
 //   since-cxx17-note@#cwg2486-conv {{candidate function}}
 } // namespace cwg2486
+
+
+namespace cwg2496 { // cwg2496: 21
+#if __cplusplus >= 201102L
+struct S {
+    virtual void f(); // expected-note {{previous declaration is here}}
+    virtual void g() &; // expected-note {{previous declaration is here}}
+    virtual void h(); // expected-note {{previous declaration is here}}
+};
+
+struct T : S {
+    virtual void f() &;
+    // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+    virtual void g();
+    // expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+    virtual void h() &&;
+    // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
+};
+#endif
+}
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 58286db165077..fe9b571b47261 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -14811,7 +14811,7 @@ <h2 id="cxxdr">C++ defect report implementation 
status</h2>
     <td><a 
href="https://cplusplus.github.io/CWG/issues/2496.html";>2496</a></td>
     <td>CD6</td>
     <td><I>ref-qualifier</I>s and virtual overriding</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="unreleased" align="center">Clang 21</td>
   </tr>
   <tr class="open" id="2497">
     <td><a 
href="https://cplusplus.github.io/CWG/issues/2497.html";>2497</a></td>

>From 1f2f57051b5f1d8934e5726e16c99ae6b287d8cf Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Thu, 5 Jun 2025 19:41:54 +0200
Subject: [PATCH 2/4] more tests

---
 clang/test/CXX/drs/cwg24xx.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 05b9a74e292ab..a1821e71ff06a 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -220,18 +220,23 @@ void (*q)() throw() = S();
 namespace cwg2496 { // cwg2496: 21
 #if __cplusplus >= 201102L
 struct S {
-    virtual void f(); // expected-note {{previous declaration is here}}
-    virtual void g() &; // expected-note {{previous declaration is here}}
-    virtual void h(); // expected-note {{previous declaration is here}}
+    virtual void f(); // #cwg2496-f
+    virtual void g() &; // #cwg2496-g
+    virtual void h(); // #cwg2496-h
+    virtual void i(); // #cwg2496-i
 };
 
 struct T : S {
     virtual void f() &;
     // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+    // expected-note@#cwg2496-f {{previous declaration is here}}
     virtual void g();
     // expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+    // expected-note@#cwg2496-g {{previous declaration is here}}
     virtual void h() &&;
     // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
+    // expected-note@#cwg2496-h {{previous declaration is here}}
+    virtual void i();
 };
 #endif
 }

>From 32d10afc7f6128d659a59af18ebc44587eca60cb Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Thu, 5 Jun 2025 19:48:20 +0200
Subject: [PATCH 3/4] more tests

---
 clang/test/CXX/drs/cwg24xx.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index a1821e71ff06a..5c07fc18e1ec2 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -223,7 +223,9 @@ struct S {
     virtual void f(); // #cwg2496-f
     virtual void g() &; // #cwg2496-g
     virtual void h(); // #cwg2496-h
-    virtual void i(); // #cwg2496-i
+    virtual void i();
+    virtual void j() &;
+    virtual void k() &&;
 };
 
 struct T : S {
@@ -237,6 +239,8 @@ struct T : S {
     // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
     // expected-note@#cwg2496-h {{previous declaration is here}}
     virtual void i();
+    virtual void j() &;
+    virtual void k() &;
 };
 #endif
 }

>From 6aee385e6e64244b636bd6b7e1bfa5e5865801f1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinja...@gmail.com>
Date: Mon, 9 Jun 2025 18:04:36 +0200
Subject: [PATCH 4/4] add tests

---
 clang/test/CXX/drs/cwg24xx.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 5c07fc18e1ec2..c499a2dfcccb3 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -226,6 +226,7 @@ struct S {
     virtual void i();
     virtual void j() &;
     virtual void k() &&;
+    virtual void l() &;
 };
 
 struct T : S {
@@ -241,6 +242,7 @@ struct T : S {
     virtual void i();
     virtual void j() &;
     virtual void k() &;
+    virtual void l() &&;
 };
 #endif
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to