An example where one is overriding POD return type without const
in the derived class:
struct B1{ virtual const int* f();};struct D1 : B1{ int* f() override;};
Compilers like Clang and GCC raise a warning:
invalid covariant return type for 'virtual int* D1::f()'
When same scenario is applied but return type is some struct/class, no warning is raised:
struct S{};struct B2{ virtual const S* f();};struct D2 : B2{ S* f() override;};
I compiled this on different compilers and versions (Clang and GCC).I would have expected similar warning when struct/class pointer is returned in the derived class when not using const
declaration.