public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/6878: Multiple inheritance structure causes segfault on delete. <synopsis of the problem (one line)>
@ 2002-05-30 22:36 Doug Johnson
  0 siblings, 0 replies; 2+ messages in thread
From: Doug Johnson @ 2002-05-30 22:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/6878; it has been noted by GNATS.

From: Doug Johnson <doug@centibyte.org>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/6878: Multiple inheritance structure causes segfault on
	delete. <synopsis of the problem (one line)>
Date: 30 May 2002 18:20:27 -0700

 --=-1sq+X6uMR94ZvBsJ7+LS
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 
 I apologise, but an email I sent several weeks ago has been sitting in
 my mail server and just got accidently re-sent.  The 'bug' has already
 been resolved (it was my error), and I would ask you to ignore my last
 message.  Sorry.
 
 
    Doug
 
 
 On Thu, 2002-05-30 at 18:16, gcc-gnats@gcc.gnu.org wrote:
 
     Thank you very much for your problem report.
     It has the internal identification `c++/6878'.
     The individual assigned to look at your
     report is: unassigned. 
     
     >Category:       c++
     >Responsible:    unassigned
     >Synopsis:       Multiple inheritance structure causes segfault on delete.
     >Arrival-Date:   Thu May 30 18:16:00 PDT 2002
     
 
 --=-1sq+X6uMR94ZvBsJ7+LS
 Content-Type: text/html; charset=utf-8
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
 <HTML>
 <HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
   <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.2">
 </HEAD>
 <BODY>
 I apologise, but an email I sent several weeks ago has been sitting in my mail server and just got accidently re-sent.&nbsp; The 'bug' has already been resolved (it was my error), and I would ask you to ignore my last message.&nbsp; Sorry.
 <BR>
 
 <BR>
 
 <BR>
 &nbsp;&nbsp; Doug
 <BR>
 
 <BR>
 
 <BR>
 On Thu, 2002-05-30 at 18:16, gcc-gnats@gcc.gnu.org wrote:
     <BLOCKQUOTE>
 <PRE><FONT COLOR="#737373"><FONT SIZE="3"><I>Thank you very much for your problem report.</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>It has the internal identification `c++/6878'.</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>The individual assigned to look at your</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>report is: unassigned. </FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>&gt;Category:       c++</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>&gt;Responsible:    unassigned</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>&gt;Synopsis:       Multiple inheritance structure causes segfault on delete.</FONT></FONT></I>
 <FONT COLOR="#737373"><FONT SIZE="3"><I>&gt;Arrival-Date:&nbsp;&nbsp; Thu May 30 18:16:00 PDT 2002</FONT></FONT></I>
 </PRE>
     </BLOCKQUOTE>
 </BODY>
 </HTML>
 
 --=-1sq+X6uMR94ZvBsJ7+LS--
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/6878: Multiple inheritance structure causes segfault on delete. <synopsis of the problem (one line)>
@ 2002-05-30 18:26 doug
  0 siblings, 0 replies; 2+ messages in thread
From: doug @ 2002-05-30 18:26 UTC (permalink / raw)
  To: gcc-gnats; +Cc: xternal


>Number:         6878
>Category:       c++
>Synopsis:       Multiple inheritance structure causes segfault on delete.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu May 30 18:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Doug Johnson
>Release:        3.2 20020411 (experimental)
>Organization:
>Environment:
System: Linux shimmer 2.4.18 #6 Fri Mar 22 22:12:55 CST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/opt/gcc --program-suffix=-cvs --enable-languages=c,c++
>Description:
	A simple 5-element multiple inheritance structure can cause the output program to segfault
	if an object of the class is deleted by means of a pointer to a specific element of the
	inheritance structure.

	The class must have two superclasses.  Each superclass must itself have a superclass.
	If a pointer to the *second* of the initial two superclasses is deleted, the program
	will segfault.  The problem goes away if that superclass is given a virtual destructor.
	
	
>How-To-Repeat:
	
	Compile the following program with the command
	
		g++ -o delete-bug delete-bug.cc -g -Wall -Werror
	
	The program will segfault on the 'delete object;' line.

	I've commented out the output statements so that the program doesn't include
	any other files.  However, they may be useful to demonstrate where the problem
	occurs after determining that the problem is in fact in this file.
	
	I've tested this process with gcc 2.95, 3.0 and the CVS version as of April 11, 2002.
	I get the same results with each versions.
	
*** begin file ***
	//#include <iostream>
	//#include <string>

	using namespace std;

	class GrandParent { 
	public:
		// Adding a virtual destructor to the grandparent on the right side 
		// fixes the problem
		//virtual ~GrandParent() {}

		// potential workaround: 
		// adding a pure virtual function to handle deleting the object fixes the problem
		virtual void deleteMe()=0;
	};

	class LeftParent: public GrandParent {
	public:
		// a virtual destructor in the left parent doesn't help
		//virtual ~LeftParent() {}
	};

	class RightParent : public GrandParent {
	public:
		// a virtual destructor on the right parent also fixes the problem
		//virtual ~RightParent() {}
	};

	class Child: public LeftParent, public RightParent {
	public:
		void deleteMe() {
			delete this;
		}
	};
																

	int main(int argc, char **argv) {
	
		// Declaring object to be a pointer to RightParent will cause a
		// segfault when it is deleted.  Declaring it a pointer to LeftParent
		// or Child produces the desired (non-segfaulting) behavior.
		RightParent *object = new Child();
		//LeftParent *object = new Child();
		//Child *object = new Child();
														
		//cout << __FILE__ << ": trying to delete object " << object << ": " << endl;
	
		// comment out the 'delete object' line and uncomment this next line
		// to try the virtual function workaround.  It works, but is clunky.
		//object->deleteMe();
	
		delete object;
	
		//cout << __FILE__ << ": success! " << endl;
																									
		return 0;
	}
*** end file ***
	
	
>Fix:
	Give the top level classes virtual destructors.
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-31  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-30 22:36 c++/6878: Multiple inheritance structure causes segfault on delete. <synopsis of the problem (one line)> Doug Johnson
  -- strict thread matches above, loose matches on Subject: below --
2002-05-30 18:26 doug

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).