Skip to content

[clang] Add covariance tests that make sure we return an error when return value is different in pointer / lvalue ref / rvalue ref #112853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions clang/test/CXX/drs/cwg9xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,56 @@ struct B : A {
} // namespace example2
} // namespace cwg952

namespace cwg960 { // cwg960: 3.0
struct a {};
class A {
#if __cplusplus >= 201103L
// Check lvalue ref vs rvalue ref vs pointer.
virtual a& rvalue_ref();
virtual a&& lvalue_ref();
virtual a& rvalue_vs_lvalue_ref(); // #cwg960-A-rvalue_vs_lvalue_ref
virtual a&& lvalue_vs_rvalue_ref(); // #cwg960-A-lvalue_vs_rvalue_ref
virtual a& rvalue_ref_vs_pointer(); // #cwg960-A-rvalue_ref_vs_pointer
virtual a* pointer_vs_rvalue_ref(); // #cwg960-A-pointer_vs_rvalue_ref
virtual a&& lvalue_ref_vs_pointer(); // #cwg960-A-lvalue_ref_vs_pointer
virtual a* pointer_vs_lvalue_ref(); // #cwg960-A-pointer_vs_lvalue_ref
#endif
};

class B : A {
#if __cplusplus >= 201103L
// Check lvalue ref vs rvalue ref vs pointer.
a& rvalue_ref() override;
a&& lvalue_ref() override;

a&& rvalue_vs_lvalue_ref() override;
// 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 &')}}
// since-cxx11-note@#cwg960-A-rvalue_vs_lvalue_ref {{overridden virtual function is here}}

a& lvalue_vs_rvalue_ref() override;
// 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 &&')}}
// since-cxx11-note@#cwg960-A-lvalue_vs_rvalue_ref {{overridden virtual function is here}}

a* rvalue_ref_vs_pointer() override;
// 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 &')}}
// since-cxx11-note@#cwg960-A-rvalue_ref_vs_pointer {{overridden virtual function is here}}

a& pointer_vs_rvalue_ref() override;
// 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 *')}}
// since-cxx11-note@#cwg960-A-pointer_vs_rvalue_ref {{overridden virtual function is here}}

a* lvalue_ref_vs_pointer() override;
// 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 &&')}}
// since-cxx11-note@#cwg960-A-lvalue_ref_vs_pointer {{overridden virtual function is here}}

a&& pointer_vs_lvalue_ref() override;
// 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 *')}}
// since-cxx11-note@#cwg960-A-pointer_vs_lvalue_ref {{overridden virtual function is here}}
#endif
};

} // namespace cwg960

namespace cwg974 { // cwg974: yes
#if __cplusplus >= 201103L
void test() {
Expand Down
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -5579,7 +5579,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/960.html">960</a></td>
<td>CD2</td>
<td>Covariant functions and lvalue/rvalue references</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 3.0</td>
</tr>
<tr id="961">
<td><a href="https://cplusplus.github.io/CWG/issues/961.html">961</a></td>
Expand Down
Loading