🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Bug with multible inheritance and virtual member functions.

#787
From: Aksnes Knut-Havard
Date: Thu, 13 Aug 1992 11:18
71 lines
2257 bytes
The following skeleton pinpoints a bug in g++2.2.2 with the gdb-4.6
patch. I am using sparc with sunos 4.1.2. 

The TimedObject class maintains a static array of pointers to all
TimedObjects, th TicTock class sometimes calls the timeout functions
via these pointers. The problem being that the wrong timeout function
is used: The function in defined in StateMachine is called for MS
objects, this happens even when the timeout function in StateMachine
is removed then causing a branch to never-never land. The debuger
tells me that the vtable ptr is faulty.

The problem dissapears when TimedObject is made a derived class of
PrintableObject, and the multiple inheritance for StateMachine is
removed.

class TimedObject // This class maintains a static timer queue
{
	.
	.
	.
	virtual void timeout() = 0;
	.
	.
	
	void Static::TicTock();
// This function increments timer then it calls timeout for objects in
// queue with their timer expired.
};

class PrintableObject
{
	// This class exists to avoid having to define a 
	// ostream& operator<<(ostream&, const <clasname>&);
	// for all classes that can print itself out.
	
public:
	virtual void printon(ostream&) = 0;
};


class StateMachine: public PrintableObject, public TimedObject
{
public:
	.
	.
	.
	// Not necesary 
	virtual void timeout();	// added to isolate bug
	.
	.
	.
};

class MS: public StateMachine, public ...
{
	.
	.
	.
	virtual void timout();
	.
	.
	.
};


--

-------------------------------------------------------------------------------
Name:	Knut-Hevard Aksnes (ECMA 94) or		Knut-Haavard Aksnes (ASCII)
Ericsson signature: HI/ETN/U/IT KNA		Phone: +47 41 19481
Email: etnkna@etn.ericsson.se (internet)  ETN.ETNKNA (memo)
Technical Details
Message-ID: <ETNKNA.92Aug13131547@hisoy2.etn.ericsson.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!hisoy2.etn.ericsson.SE!etnkna

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!hisoy2.etn.ericsson.SE!etnkna
From: etnkna@hisoy2.etn.ericsson.SE (Aksnes Knut-Havard)
Subject: Bug with multible inheritance and virtual member functions.
Message-ID: <ETNKNA.92Aug13131547@hisoy2.etn.ericsson.se>
Sender: gnulists@ai.mit.edu
Organization: Ericsson Telecom AS
Distribution: gnu
Date: Thu, 13 Aug 1992 11:18:45 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 73