Skip to content
28 changes: 24 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,23 @@ 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 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}}

// 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 +137,17 @@ 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 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 *')}}

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