🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

bug in operator delete

#1811
From: Michael Tiemann
Date: Sun, 02 Apr 1989 09:58
54 lines
2447 bytes
   This appears in g++ 1.34.1 for an Encore and also a Sun-3/60 w/SunOS4.0.1.
   
   I have a class (Message) that declares
   
       void operator delete(void *);
   
   and class Task uses this when deleting items. However, g++ gives me a
   message " `this' has no member function named delete". Other classes with
   `operator delete' work with no problems.
   
   When I run c++ using gdb, I find that this message is from cplus-class.c,
   line 2512:
	 if (field == NULL_TREE)
	   {
	     error ("`this' has no member named `%s'", err_name);
   
   If this is indeed a bug, I'd appreciate a patch if one is available.
   
Here's what is happening: GNU C++ thinks that operator delete is like
a member function.  Hence, when you call it, it takes a this pointer
in addition to the pointer which is being deleted.  When called from a
destructor, the address being deleted and the this pointer are the
same.  When called from other than a member function, they may be
different.  In the case you have here, GNU C++ is trying to call

	this->Task::operator delete (msg);

which is not at all what you want.  You can fix this is one of three ways:

	(1) msg->operator delete (msg);
	(2) define a destructor for class Message
	(3) fix GNU C++:

Change this code in cplus-method.c:

      rval = build_method_call (xarg1,
				get_identifier ("op$delete_expr"),
				build_tree_list (NULL_TREE, xarg2), 1, 1);
      /* This happens when the user mis-declares `operator delete'.  */

to this:

      rval = build_method_call (xarg2,
				get_identifier ("op$delete_expr"),
				build_tree_list (NULL_TREE, xarg2), 1, 1);
      /* This happens when the user mis-declares `operator delete'.  */

I guess that since operator delete is really a static member function
(and hence does not take a this parameter, the right fix is to modify
GNU C++ as I have shown for the time being, and I will fix it right
for 1.34.2.

Michael
Technical Details
Message-ID: <8904020958.AA02166@yahi.stanford.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!mdt
References: <8903221910.AA15968@flute.cs.uiuc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!mdt
From: mdt@YAHI.STANFORD.EDU (Michael Tiemann)
Newsgroups: gnu.g++.bug
Subject: bug in operator delete
Message-ID: <8904020958.AA02166@yahi.stanford.edu>
Date: 2 Apr 89 09:58:42 GMT
References: <8903221910.AA15968@flute.cs.uiuc.edu>
Sender: daemon@tut.cis.ohio-state.edu
Reply-To: tiemann@lurch.stanford.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 54