Article View: gnu.g++.bug
Article #149Multiple inheritance is a non-starter due to bug in g++.
From: George C. Hawkins
Date: Thu, 23 Jul 1992 19:11
Date: Thu, 23 Jul 1992 19:11
137 lines
4454 bytes
4454 bytes
The following very short and simple piece of code demonstrates
multiple inheritance. It compiles and runs as expected when using
AT&T's cfront but when compiled with g++ (gcc-2.2.2) it results in
an abort() call being made at runtime:
[------------------------------------------------------------------------------]
class A {
public:
A() {}
};
class B {
public:
virtual void memFunc() = 0;
};
class C : public A, public B {
public:
virtual void memFunc() {}
//^^^^^ do I need to respecify virtual?
};
class D : public C {
public:
void memFunc()
{
C::memFunc();
// do something more if we ever got to this point
}
};
int main(int,char*)
{
D test;
test.memFunc();
}
[------------------------------------------------------------------------------]
1. First I define too classes A and B, B contains a pure virtual
function memFunc().
2. Then class C is defined, it inherits from both A and B. C defines
memFunc().
3. Finally class D is defined, it inherits from C and redefines
memFunc(), within it's definition of memFunc() there is a call to
C::memFunc.
It is when this call is made that things go wrong, the setup for
the call results in abort() being called.
I have compiled and run this code using a Sun supplied AT&T cfront
based compiler on a Sparc IPC. I have compiled and failed to run
successfully this code using gcc-2.2.2 on a Sparc IPC and a MIPS
Magnum system.
Below is a typescript showing the program being run under gdb-4.5
(I have yet to try gdb-4.6) unfortunetly gcc-2.2.2 was not compiled
using the '-g' flag so little can be seen at the actual point of
failure.
[------------------------------------------------------------------------------]
Script started on Thu Jul 23 19:49:47 1992
orange(ghawkins)[101]: ls -l /usr/local/bin/g*
-rwxr-xr-x 1 root 1410 Jun 24 23:16 /usr/local/bin/g++*
-rwxr-xr-x 2 root 57344 Jun 24 23:16 /usr/local/bin/gcc*
-rwxr-xr-x 2 root 57344 Jun 24 23:16 /usr/local/bin/gcc-sparc-sun-sunos4.1*
-rwxr-xr-x 1 root 909312 Jul 3 18:06 /usr/local/bin/gdb*
orange(ghawkins)[102]: g++ -g -o example example.c
orange(ghawkins)[103]: gdb example
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.5, Copyright 1992 Free Software Foundation, Inc...
(gdb) list 25
20 class D : public C {
21 public:
22 void memFunc()
23 {
24 C::memFunc();
25 // do something more if we ever got to this point
26 }
27 };
28
29
(gdb) break 24
Breakpoint 1 at 0x22f8: file example.c, line 24.
(gdb) run
Starting program: /home/ghawkins/example
C::memFunc() called.
Breakpoint 1, D::memFunc (this=0xf7fff810) at example.c:24
24 C::memFunc();
(gdb) stepi
0x22fc 24 C::memFunc();
(gdb)
0x2300 24 C::memFunc();
(gdb)
0x2304 24 C::memFunc();
(gdb)
0x10090 in _DYNAMIC ()
(gdb)
0x10094 in _DYNAMIC ()
(gdb)
0x10098 in _DYNAMIC ()
(gdb)
0x10060 in _DYNAMIC ()
(gdb)
0x10064 in _DYNAMIC ()
(gdb)
0x10068 in _DYNAMIC ()
(gdb)
0xf77e0070 in _locales ()
(gdb) step
Current function has no line number information.
Single stepping until function exit.
Program received signal 6, Abort
0xf775c008 in kill ()
(gdb) cont
Continuing.
Program terminated with signal 6, Abort
The inferior process no longer exists.
(gdb) quit
orange(ghawkins)[104]: exit
script done on Thu Jul 23 19:51:18 1992
--
george lives at:
___________________________________________________________________________
| ghawkins@unix1.tcd.ie (mostly) | ghawkins@vax1.tcd.ie (sometimes) |
---------------------------------------------------------------------------
Technical Details
Message-ID:
<ghawkins.711918699@unix1.tcd.ie>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!unix1.tcd.ie!ghawkinsShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!unix1.tcd.ie!ghawkins From: ghawkins@unix1.tcd.ie (George C. Hawkins) Subject: Multiple inheritance is a non-starter due to bug in g++. Message-ID: <ghawkins.711918699@unix1.tcd.ie> Summary: multiple inheritance doesn't even work in a simple example. Keywords: multiple inheritance bug Sender: gnulists@ai.mit.edu Organization: Trinity College, Dublin Distribution: gnu Date: Thu, 23 Jul 1992 19:11:39 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 138