From: ghawkins@unix1.tcd.ie (George C. Hawkins)
Subject: multiple inheritance bug isolated in g++ (gcc-2.2.2)
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 23 Jul 1992 21:25:13 GMT

I sent you a bug report a few days ago. I included the code that
I was writing that resulted in the bug occuring. As this was rather
bulky I have written a very short (37 lines) program that demonstrates
exactly under what circumstances the bug arises. It is included
below with comments and gdb output.

If this is a known bug, with a fix or planned fix could you inform
me as I will need to buy an alternative product if it can not be
fixed soon (which I'd rather not do - given my funding :-)
Thank you for your time (and products), yours,


George.

[------------------------------------------------------------------------------]

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();
}

[------------------------------------------------------------------------------]

Explanation of ocde:

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

Newsgroups: gnu.g++.bug