Skip to content

Commit 1dfdbf7

Browse files
authored
[clang] Add covariance tests that make sure we return an error when return value is different in pointer / lvalue ref / rvalue ref (#112853)
Per https://cplusplus.github.io/CWG/issues/960.html.
1 parent bd861d0 commit 1dfdbf7

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

clang/test/CXX/drs/cwg9xx.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,56 @@ struct B : A {
9393
} // namespace example2
9494
} // namespace cwg952
9595

96+
namespace cwg960 { // cwg960: 3.0
97+
struct a {};
98+
class A {
99+
#if __cplusplus >= 201103L
100+
// Check lvalue ref vs rvalue ref vs pointer.
101+
virtual a& rvalue_ref();
102+
virtual a&& lvalue_ref();
103+
virtual a& rvalue_vs_lvalue_ref(); // #cwg960-A-rvalue_vs_lvalue_ref
104+
virtual a&& lvalue_vs_rvalue_ref(); // #cwg960-A-lvalue_vs_rvalue_ref
105+
virtual a& rvalue_ref_vs_pointer(); // #cwg960-A-rvalue_ref_vs_pointer
106+
virtual a* pointer_vs_rvalue_ref(); // #cwg960-A-pointer_vs_rvalue_ref
107+
virtual a&& lvalue_ref_vs_pointer(); // #cwg960-A-lvalue_ref_vs_pointer
108+
virtual a* pointer_vs_lvalue_ref(); // #cwg960-A-pointer_vs_lvalue_ref
109+
#endif
110+
};
111+
112+
class B : A {
113+
#if __cplusplus >= 201103L
114+
// Check lvalue ref vs rvalue ref vs pointer.
115+
a& rvalue_ref() override;
116+
a&& lvalue_ref() override;
117+
118+
a&& rvalue_vs_lvalue_ref() override;
119+
// since-cxx11-error@-1 {{virtual function 'rvalue_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a &')}}
120+
// since-cxx11-note@#cwg960-A-rvalue_vs_lvalue_ref {{overridden virtual function is here}}
121+
122+
a& lvalue_vs_rvalue_ref() override;
123+
// since-cxx11-error@-1 {{virtual function 'lvalue_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a &&')}}
124+
// since-cxx11-note@#cwg960-A-lvalue_vs_rvalue_ref {{overridden virtual function is here}}
125+
126+
a* rvalue_ref_vs_pointer() override;
127+
// since-cxx11-error@-1 {{virtual function 'rvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &')}}
128+
// since-cxx11-note@#cwg960-A-rvalue_ref_vs_pointer {{overridden virtual function is here}}
129+
130+
a& pointer_vs_rvalue_ref() override;
131+
// since-cxx11-error@-1 {{virtual function 'pointer_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a *')}}
132+
// since-cxx11-note@#cwg960-A-pointer_vs_rvalue_ref {{overridden virtual function is here}}
133+
134+
a* lvalue_ref_vs_pointer() override;
135+
// since-cxx11-error@-1 {{virtual function 'lvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &&')}}
136+
// since-cxx11-note@#cwg960-A-lvalue_ref_vs_pointer {{overridden virtual function is here}}
137+
138+
a&& pointer_vs_lvalue_ref() override;
139+
// since-cxx11-error@-1 {{virtual function 'pointer_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a *')}}
140+
// since-cxx11-note@#cwg960-A-pointer_vs_lvalue_ref {{overridden virtual function is here}}
141+
#endif
142+
};
143+
144+
} // namespace cwg960
145+
96146
namespace cwg974 { // cwg974: yes
97147
#if __cplusplus >= 201103L
98148
void test() {

clang/www/cxx_dr_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5579,7 +5579,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
55795579
<td><a href="https://cplusplus.github.io/CWG/issues/960.html">960</a></td>
55805580
<td>CD2</td>
55815581
<td>Covariant functions and lvalue/rvalue references</td>
5582-
<td class="unknown" align="center">Unknown</td>
5582+
<td class="full" align="center">Clang 3.0</td>
55835583
</tr>
55845584
<tr id="961">
55855585
<td><a href="https://cplusplus.github.io/CWG/issues/961.html">961</a></td>

0 commit comments

Comments
 (0)