This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Covariant returns?
- To: gcc at gcc dot gnu dot org
- Subject: Re: Covariant returns?
- From: Chris Heath <cheath at umich dot edu>
- Date: Mon, 6 Mar 2000 22:46:58 -0500 (EST)
> I'm wondering if covariant returns are going to be implemented anytime
> soon... I looked on the known bugs page, but I didn't see anything
> about it.
>
> [code snipped]
>
> The result:
> x.cpp:7: sorry, not implemented: adjusting pointers for covariant returns
Worse, in the multiple inheritance case, the compiler doesn't produce any
error message, but produces incorrect code. Here's an example:
#include <stdio.h>
struct A {
virtual A* This() {return this;}
};
struct B {
virtual B* This() {return this;}
};
struct C : A, B {
virtual C* This() {return this;}
};
main () {
C cl;
C* c=&cl;
B* b=&cl;
A* a=&cl;
printf("%p %p %p\n", c, b, a);
printf("%p %p %p\n", c->This(), b->This(), a->This());
}
This compiles without errors with gcc 2.95.2, but its output is (on my
SPARC)
effff9b0 effff9b4 effff9b0
effff9b0 effff9b0 effff9b0
In other words, b->This() is returning a pointer to an object that is not
of type B.
Chris