Bogus error message? (covariant return types)

Joe Buck jbuck@synopsys.com
Thu Dec 18 15:29:00 GMT 1997


> Now to the potential bug. If I compile the following code with egcs-1.0
> (plus H.J. patches for RedHat 5.0) I get an error message saying:
> 
> covariant-bug1.cc:26: sorry, not implemented:
> adjusting pointers for covariant returns   

Sigh.  Any message beginning "sorry, not implemented" means that while you
have written correct C++, the compiler cannot handle the code.  The
compiler is even apologizing for you.  Given how polite the compiler is
being to you, it seems rather impolite to complain about a "bogus error
message".

> However, if I change the order of the base classes the code compiles and
> runs perfectly. 

That's because if you change the order of the baseclasses, the offset
becomes zero and the compiler doesn't need to adjust the pointer returned
by C::who.  That is, with

class C: public A, public B

Then we can convert a C* to an A* with no code, but converting a C* to
a B* requires adding an offset to the address of the pointer.  This is
what is not implemnted.

Right now, covariant return types work for single inheritance, and in
some multiple inheritance cases.  You aren't telling the maintainers
anything they don't know.

> Here is the workaround:

Sorry, that kind of workaround won't help people who cannot change their
inheritance structure for other reasons.  But it will work for some
people.




More information about the Gcc mailing list