Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 32 additions & 0 deletions clang/test/CXX/drs/cwg9xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ struct B : A {
} // namespace example2
} // namespace cwg952

namespace cwg960 { // cwg960: 2.8
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(); // expected-note{{overridden virtual function is here}}
virtual a&& lvalue_vs_rvalue_ref(); // expected-note{{overridden virtual function is here}}
virtual a& rvalue_ref_vs_pointer(); // expected-note{{overridden virtual function is here}}
virtual a* pointer_vs_rvalue_ref(); // expected-note{{overridden virtual function is here}}
virtual a&& lvalue_ref_vs_pointer(); // expected-note{{overridden virtual function is here}}
virtual a* pointer_vs_lvalue_ref(); // expected-note{{overridden virtual function is here}}
#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; // expected-error{{virtual function 'rvalue_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a &')}}
a& lvalue_vs_rvalue_ref() override; // expected-error{{virtual function 'lvalue_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a &&')}}
a* rvalue_ref_vs_pointer() override; // expected-error{{virtual function 'rvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &')}}
a& pointer_vs_rvalue_ref() override; // expected-error{{virtual function 'pointer_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a *')}}
a* lvalue_ref_vs_pointer() override; // expected-error{{virtual function 'lvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &&')}}
a&& pointer_vs_lvalue_ref() override; // expected-error{{virtual function 'pointer_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a *')}}
#endif
};

} // namespace cwg960

namespace cwg974 { // cwg974: yes
#if __cplusplus >= 201103L
void test() {
Expand Down
8 changes: 4 additions & 4 deletions clang/test/SemaCXX/virtual-override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace T6 {
struct a { };

class A {
// Classes.
// Check cv-qualification.
virtual const a* const_vs_unqualified_class();
virtual a* unqualified_vs_const_class(); // expected-note{{overridden virtual function is here}}

Expand All @@ -102,13 +102,13 @@ class A {
virtual const volatile a* const_volatile_vs_unualified_class();
virtual a* unqualified_vs_const_volatile_class(); // expected-note{{overridden virtual function is here}}

// Non Classes.
// Check non class.
virtual const int* const_vs_unqualified_non_class(); // expected-note{{overridden virtual function is here}}
virtual int* unqualified_vs_const_non_class(); // expected-note{{overridden virtual function is here}}
};

class B : A {
// Classes.
// Check cv-qualification.
a* const_vs_unqualified_class() override;
const a* unqualified_vs_const_class() override; // expected-error{{return type of virtual function 'unqualified_vs_const_class' is not covariant with the return type of the function it overrides (class type 'const a *' does not have the same cv-qualification as or less cv-qualification than class type 'a *')}}

Expand All @@ -127,7 +127,7 @@ class B : A {
a* const_volatile_vs_unualified_class() override;
const volatile a* unqualified_vs_const_volatile_class() override; // expected-error{{return type of virtual function 'unqualified_vs_const_volatile_class' is not covariant with the return type of the function it overrides (class type 'const volatile a *' does not have the same cv-qualification as or less cv-qualification than class type 'a *')}}

// Non Classes.
// Check non class.
int* const_vs_unqualified_non_class() override; // expected-error{{virtual function 'const_vs_unqualified_non_class' has a different return type ('int *') than the function it overrides (which has return type 'const int *')}}
const int* unqualified_vs_const_non_class() override; // expected-error{{virtual function 'unqualified_vs_const_non_class' has a different return type ('const int *') than the function it overrides (which has return type 'int *')}}
};
Expand Down
Loading