Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22199

No compiler warning for 'const' pointers of non POD types when overriding a method

$
0
0

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.


Viewing all articles
Browse latest Browse all 22199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>