🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #2069

bug caused by multiple inheritance

#2069
From: chatty%FRLRI61.BITNET
Date: Mon, 05 Jun 1989 15:39
62 lines
2036 bytes
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.fr
Technical Details
Message-ID: <8906051539.AA18913@lri.lri.fr>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CUNYVM.CUNY.EDU!chatty%FRLRI61.BITNET

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CUNYVM.CUNY.EDU!chatty%FRLRI61.BITNET
From: chatty%FRLRI61.BITNET@CUNYVM.CUNY.EDU
Newsgroups: gnu.g++.bug
Subject: bug caused by multiple inheritance
Message-ID: <8906051539.AA18913@lri.lri.fr>
Date: 5 Jun 89 15:39:17 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 62