Skip to content

Commit c800979

Browse files
authored
[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() &; }; ```
1 parent 8380a55 commit c800979

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Resolutions to C++ Defect Reports
157157
`constraint-expression <https://cplusplus.github.io/CWG/issues/2517.html>`_.
158158
- Implemented `CWG3005 Function parameters should never be name-independent <https://wg21.link/CWG3005>`_.
159159

160+
- Implemented `CWG2496 ref-qualifiers and virtual overriding <https://wg21.link/CWG2496>`_.
161+
160162
C Language Changes
161163
------------------
162164

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
14901490
// If the function is a class member, its signature includes the
14911491
// cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
14921492
auto DiagnoseInconsistentRefQualifiers = [&]() {
1493-
if (SemaRef.LangOpts.CPlusPlus23)
1493+
if (SemaRef.LangOpts.CPlusPlus23 && !UseOverrideRules)
14941494
return false;
14951495
if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
14961496
return false;

clang/test/CXX/drs/cwg24xx.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,34 @@ void (*q)() throw() = S();
215215
// since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() throw()'}}
216216
// since-cxx17-note@#cwg2486-conv {{candidate function}}
217217
} // namespace cwg2486
218+
219+
220+
namespace cwg2496 { // cwg2496: 21
221+
#if __cplusplus >= 201102L
222+
struct S {
223+
virtual void f(); // #cwg2496-f
224+
virtual void g() &; // #cwg2496-g
225+
virtual void h(); // #cwg2496-h
226+
virtual void i();
227+
virtual void j() &;
228+
virtual void k() &&;
229+
virtual void l() &;
230+
};
231+
232+
struct T : S {
233+
virtual void f() &;
234+
// expected-error@-1 {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}}
235+
// expected-note@#cwg2496-f {{previous declaration is here}}
236+
virtual void g();
237+
// expected-error@-1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}}
238+
// expected-note@#cwg2496-g {{previous declaration is here}}
239+
virtual void h() &&;
240+
// expected-error@-1 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
241+
// expected-note@#cwg2496-h {{previous declaration is here}}
242+
virtual void i();
243+
virtual void j() &;
244+
virtual void k() &;
245+
virtual void l() &&;
246+
};
247+
#endif
248+
}

clang/www/cxx_dr_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14811,7 +14811,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
1481114811
<td><a href="https://cplusplus.github.io/CWG/issues/2496.html">2496</a></td>
1481214812
<td>CD6</td>
1481314813
<td><I>ref-qualifier</I>s and virtual overriding</td>
14814-
<td class="unknown" align="center">Unknown</td>
14814+
<td class="unreleased" align="center">Clang 21</td>
1481514815
</tr>
1481614816
<tr class="open" id="2497">
1481714817
<td><a href="https://cplusplus.github.io/CWG/issues/2497.html">2497</a></td>

0 commit comments

Comments
 (0)