This is the mail archive of the
egcs-bugs@egcs.cygnus.com
mailing list for the EGCS project.
Re: Wrong delete being called.
- To: khaley@bigfoot.com
- Subject: Re: Wrong delete being called.
- From: "Martin v. Loewis" <martin@mira.isdn.cs.tu-berlin.de>
- Date: Fri, 16 Jul 1999 09:49:06 +0200
- CC: khan@xraylith.wisc.edu, egcs-bugs@egcs.cygnus.com
- References: <4.1.19990714001252.009455a0@pop.mail.yahoo.com>
> I have a base class with operator delete declared private. The destructor
> of a derived class tries to delete a pointer held by the base class but it
> can't. The compiler reports that operator delete is private which is true,
> however it is not the delete that should be called.
Thanks for your bug report. Please note that the compiler also reports
the error if you write
~TPointer() {}
The problem is not deleting P, but deleting a TPointer instance. To
delete a TPointer instance, the appropriate delete operator must be
found. Since the base class has a delete operator, it is the one to
use. Unfortunately, the delete operator is private, so it can't be
used.
This shows up in the TPointer destructor, because in g++, the
deallocation functions are called in the destructor (to correctly
support virtual destructors).
There is a slight bug in g++ here: It should complain only when
somebody allocates or deletes instances of TPointerBase or
TPointer. This does not happen here, so it shouldn't complain.
As a work-around, it seems that you'll have to remove the private
operator delete when compiling with g++.
Regards,
Martin