chatty%FRLRI61.BITNET@CUNYVM.CUNY.EDU (06/05/89)
In the following example, a class B derives from a class A, and a class D derive
from class B and another class C. It seems that the presence of D confuses g++ 1
when managing simple inheritance of B from A : inherited members are called with
a wrong 'this' address.
% cat bug.cc
class A {
public:
A () {};
void foo () { printf ("this = %x\n", this); }
};
class B : public A {
public:
B () { printf ("this = %x\n", this); }
};
class C {
public:
C ();
};
class D : public C, public B {
public :
D ();
};
main ()
{
B b;
b.foo ();
}
% g++ -v -o bug bug.cc
g++ version 1.35.0+
/usr/local/lib/GNU/cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc6800
0 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Dmc68020 bug.cc /tmp/cca03288
.cpp
GNU CPP version 1.35
/usr/local/lib/GNU/cc1plus /tmp/cca03288.cpp -quiet -dumpbase bug.cc -noreg -ve
rsion -o /tmp/cca03288.s
GNU C++ version 1.35.0+ (68k, MIT syntax) compiled by GNU C version 1.35.
In method void A::foo ():
bug.cc:4: warning: implicit declaration of function `printf'
as -mc68020 /tmp/cca03288.s -o bug.o
/usr/local/lib/GNU/ld++ -o bug -C /usr/local/lib/GNU/crt0+.o /lib/Fcrt1.o bug.o
-lg++ /usr/local/lib/GNU/gnulib -lc
% bug
this = efffa86
this = efffa88
Surprising, ain't it ?
BTW, I would like more infos on the new 'protected virtual' feature. Is it norma
derived class cannot use the virtual functions of its base class ?
Stephane Chatty chatty@frlri61.fr
chatty@lri.lri.frsacco@eileen.samsung.com (Joseph E. Sacco) (06/07/89)
In article <8906051539.AA18913@lri.lri.fr>, chatty%FRLRI61.BITNET@CUNYVM.CUNY.EDU writes: > > In the following example, a class B derives from a class A, and a class D derive > from class B and another class C. It seems that the presence of D confuses g++ 1 > when managing simple inheritance of B from A : inherited members are called with > a wrong 'this' address. > Another aspect of the bug is that not only does its existence depend upon the declaration of D but also upon the order in which the parents of D are specified. If that order is reversed the two values of "this" are seen to be identical. Hmmmm ....................! What gives ? JOE