Article View: gnu.g++.bug
Article #3Yet another MI bug in g++ 2.2.2
From: Alexander Klaiber
Date: Tue, 27 Oct 1992 19:37
Date: Tue, 27 Oct 1992 19:37
75 lines
2371 bytes
2371 bytes
Compiler: gcc-2.2.2
Compiled with: gcc-2.2.2
Platform: most likely *platform-independent*
(observed on decstation/ultrix and Sun4/SunOS-4.1)
Summary: Incorrect search for methods when using multiple inheritance.
In the code below, obviously B::foo should be called from {main}; gcc-2.2.2
instead calls D::foo which has been overridden!!
If B is made to inherit from D only ("class B : public D"), the right thing
happens (i.e. B::foo gets called).
Similarly, if {foo} is made into a virtual function, the right thing happens.
Clearly, this is a bug in the code that searches for members in the
inheritance graph; it apparently hasn't been properly generalized for
multiple inheritance.
As a side note: I first reported this bug around the time gdb-4.4 came out,
that's quite a while ago... it would be nice if someone could get around to
fixing this code, even if I understand multiple inheritance is not a top
priority...
Anyway, here's the code, compile with gcc-2.2.2
#include <stdio.h>
/* Class hierarchy:
C D::foo
\ /
\ /
B::foo
|
|
Test
*/
class C { public: C(); };
class D {
public:
D();
void foo();
};
class B : public C, public D {
public:
B();
void foo();
};
class Test : public B {
public:
Test();
};
//----------------------------------------------------------------------
C::C() {}
B::B() {}
D::D() {}
Test::Test() {}
void B::foo() { printf("B::foo\n"); }
void D::foo() { printf("D::foo\n"); }
//======================================================================
main() {
Test t;
t.foo(); // should call B::foo, but calls D::foo instead. BOGUS!
}
Technical Details
Message-ID:
<1992Oct27.193747.10982@beaver.cs.washington.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!june.cs.washington.edu!klaiberReferences:
<9210251332.AA29843@gjetost.cs.wisc.edu>Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!june.cs.washington.edu!klaiber From: klaiber@june.cs.washington.edu (Alexander Klaiber) Subject: Yet another MI bug in g++ 2.2.2 Message-ID: <1992Oct27.193747.10982@beaver.cs.washington.edu> Sender: gnulists@ai.mit.edu Organization: Computer Science & Engineering, U. of Washington, Seattle References: <9210251332.AA29843@gjetost.cs.wisc.edu> Distribution: gnu Date: Tue, 27 Oct 1992 19:37:47 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 76