This is the mail archive of the egcs-bugs@egcs.cygnus.com mailing list for the EGCS project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Wrong delete being called.


> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]