[clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 08:24:59 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 *')}}
----------------
Fznamznon wrote:

I guess technically volatile is not more qualified than const https://eel.is/c++draft/tab:basic.type.qualifier.rel, should we also emit `has different qualifiers` phrase here instead?

https://github.com/llvm/llvm-project/pull/71696


More information about the cfe-commits mailing list