Author: Corentin Jabot Date: 2025-06-09T21:16:57+02:00 New Revision: c8009797d388a89346e2116de08e9c0be17e0c2d
URL: https://github.com/llvm/llvm-project/commit/c8009797d388a89346e2116de08e9c0be17e0c2d DIFF: https://github.com/llvm/llvm-project/commit/c8009797d388a89346e2116de08e9c0be17e0c2d.diff LOG: [Clang] Implement CWG2496 (#142975) 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() &; }; ``` Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaOverload.cpp clang/test/CXX/drs/cwg24xx.cpp clang/www/cxx_dr_status.html Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index db427451322a8..beed0da6883d6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -157,6 +157,8 @@ Resolutions to C++ Defect Reports `constraint-expression <https://cplusplus.github.io/CWG/issues/2517.html>`_. - 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..c499a2dfcccb3 100644 --- a/clang/test/CXX/drs/cwg24xx.cpp +++ b/clang/test/CXX/drs/cwg24xx.cpp @@ -215,3 +215,34 @@ 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(); // #cwg2496-f + virtual void g() &; // #cwg2496-g + virtual void h(); // #cwg2496-h + virtual void i(); + virtual void j() &; + virtual void k() &&; + virtual void l() &; +}; + +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(); + virtual void j() &; + virtual void k() &; + virtual void l() &&; +}; +#endif +} diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index d06eb4a0ed23e..ad82d7ab0cec6 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> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits