[clang] [clang] When checking for covariant return types, make sure the pointers or references are to *classes* (PR #111856)

Boaz Brickner via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 11 07:48:51 PDT 2024


================
@@ -289,3 +289,13 @@ namespace PR8168 {
     static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}}
   };
 }
+
+namespace T13 {
+  struct A {
+    virtual const int *f() const; // expected-note{{overridden virtual function is here}}
+  };
+
+  struct B : A {
+    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 *')}}
+  };
+}
----------------
bricknerb wrote:

Do you mean that base return type A (`void*`, `int*` or some class type) and derived returns type B != A (`void*`, `int*` or some class type)?
Or do you mean they both return the same type but it's qualified differently?

For different types we have T1 and T2.
For different qualification of class types, we have T6.
Let me know what use case you think is uncovered.

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


More information about the cfe-commits mailing list