Skip to content

Commit 44d5ebe

Browse files
committed
[clang] Unify the new covariant tests, remove T13 and add the new tests into T2 and T6.
In T2, we check that return types that are pointers to different non-class types fail. In T6, we check that unlike class return types, non-class return types do not allow to change qualifiers at all (add or remove).
1 parent d5cf39d commit 44d5ebe

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

clang/test/SemaCXX/virtual-override.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ struct b { };
1919

2020
class A {
2121
virtual a* f(); // expected-note{{overridden virtual function is here}}
22+
virtual int *g(); // expected-note{{overridden virtual function is here}}
2223
};
2324

2425
class B : A {
2526
virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides ('b *' is not derived from 'a *')}}
27+
virtual char *g(); // expected-error{{virtual function 'g' has a different return type ('char *') than the function it overrides (which has return type 'int *')}}
2628
};
2729

2830
}
@@ -83,11 +85,15 @@ struct a { };
8385
class A {
8486
virtual const a* f();
8587
virtual a* g(); // expected-note{{overridden virtual function is here}}
88+
virtual const int* h(); // expected-note{{overridden virtual function is here}}
89+
virtual int* i(); // expected-note{{overridden virtual function is here}}
8690
};
8791

8892
class B : A {
8993
virtual a* f();
9094
virtual const a* g(); // expected-error{{return type of virtual function 'g' is not covariant with the return type of the function it overrides (class type 'const a *' is more qualified than class type 'a *'}}
95+
virtual int* h(); // expected-error{{virtual function 'h' has a different return type ('int *') than the function it overrides (which has return type 'const int *')}}
96+
virtual const int* i(); // expected-error{{virtual function 'i' has a different return type ('const int *') than the function it overrides (which has return type 'int *')}}
9197
};
9298

9399
}
@@ -289,13 +295,3 @@ namespace PR8168 {
289295
static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}}
290296
};
291297
}
292-
293-
namespace T13 {
294-
struct A {
295-
virtual const int *f() const; // expected-note{{overridden virtual function is here}}
296-
};
297-
298-
struct B : A {
299-
int *f() const override; // expected-error{{virtual function 'f' has a different return type ('int *') than the function it overrides (which has return type 'const int *')}}
300-
};
301-
}

0 commit comments

Comments
 (0)