[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() &;
};
```
This commit is contained in:
Corentin Jabot 2025-06-09 21:16:57 +02:00 committed by GitHub
parent 8380a5500b
commit c8009797d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 2 deletions

View File

@ -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
------------------

View File

@ -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;

View File

@ -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
}

View File

@ -14811,7 +14811,7 @@ and <I>POD class</I></td>
<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>