[clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)
Qiu Chaofan via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 9 01:43:33 PST 2023
================
@@ -289,3 +289,29 @@ namespace PR8168 {
static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}}
};
}
+
+namespace T13 {
+ class A {
+ public:
+ virtual const int* foo(); // expected-note{{overridden virtual function is here}}
+ };
+
+ class B: public A {
+ public:
+ virtual int* foo(); // expected-error{{return type of virtual function 'foo' is not covariant with the return type of the function it overrides ('int *' has different qualifiers than 'const int *')}}
+ };
+}
+
+namespace T14 {
+ struct a {};
+
+ class A {
+ public:
+ virtual const a* foo(); // expected-note{{overridden virtual function is here}}
+ };
+
+ class B: public A {
+ public:
+ virtual volatile a* foo(); // expected-error{{return type of virtual function 'foo' is not covariant with the return type of the function it overrides (class type 'volatile a *' is more qualified than class type 'const a *')}}
----------------
ecnelises wrote:
Hmm, right, we can't say `volatile` is more qualified than `const` or not. But `virtual volatile a* foo(); ... virtual a* foo() override;` is acceptable as long as `a` is a class-type, so saying `has different qualifiers` also looks inaccurate.
https://github.com/llvm/llvm-project/pull/71696
More information about the cfe-commits
mailing list