g++ bug on Linux/Alpha: incorrect this pointer in virtual inheritance
Sai-Lai Lo
S.Lo@orl.co.uk
Tue Aug 25 03:19:00 GMT 1998
The following test case illustrate the problem.
Compiler: egcs-980802
No optimisation.
On x86 Linux, the behaviour is correct, the 'this' pointer are the same in
all cases.
% ./bug2
0xbffff87c
0xbffff87c
0xbffff87c
%
On alpha linux, the behaviour is incorrect, the 'this' pointer is *wrong*
in the virtual function that returns a struct.
% ./bug2
0x11ffff210
0x11ffff230 <------------- Wrong 'this' pointer
0x11ffff210
%
By the way, is there someone looks after egcs on alpha {linux,digital
unix}? I CC this mail to Jeffrey Law because I guess he is the coordinator
for egcs-1.1 release.
Regards,
Sai-Lai Lo
------------------ cut here -----------------------
#include <iostream.h>
struct X {
long x1;
long x2;
float x3;
float x4;
};
class Abase {
private:
long b1;
long b2;
};
class AAbase {
};
class AAA : public virtual Abase, public virtual AAbase {
public:
virtual X f1() = 0;
virtual long f2() = 0;
};
class A : public virtual AAA {
public:
X f1();
long f2();
};
X A::f1() {
X x;
x.x1 = x.x2 = 0;
x.x3 = x.x4 = 0.1;
cerr << this << endl; // Wrong this pointer.
return x;
}
long A::f2() {
cerr << this << endl; // this pointer is correct
return 0;
}
int
main(int,char**)
{
A a;
X x;
AAA* ap = &a;
cerr << (void*) &a << endl; // correct pointer
x = ap->f1();
long y;
y = ap->f2();
return 0;
}
More information about the Gcc-bugs
mailing list