public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* delete not called
@ 1998-04-16 23:59 Tudor Hulubei
  1998-04-17  7:07 ` Warner Losh
  0 siblings, 1 reply; 4+ messages in thread
From: Tudor Hulubei @ 1998-04-16 23:59 UTC (permalink / raw)
  To: egcs

Hi there,

I think there is a bug in recent snapshots of egcs.  For the appended
example there is no call to operator delete generated for objects of
type Y, so the output looks like:

new: 0x8049928
new: 0x8049938
delete: 0x8049928

gcc-2.8.1 & gcc-2.7.2.3 (and I believe older snapshots of egcs) do
generate the call.

Is this a known problem?

Thanks,
Tudor

P.S.  The version I use is:
Reading specs from /home/tudor/usr/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.22/specs
gcc version egcs-2.91.22 980404 (gcc2 ss-980401 experimental)

#include <new>
#include <iostream.h>
#include <stdlib.h>

void *operator new(size_t size)
{
    if (void *ptr = malloc(size)) {
	cerr << "new: " << ptr << endl;
	return ptr;
    }
}

void operator delete(void *ptr)
{
    if (ptr) {
	cerr << "delete: " << ptr << endl;
	free(ptr);
    }
}

class X { public: ~X() {} };
class Y : public X {};

int
main()
{
    X *x = new X();
    Y *y = new Y();

    delete x;
    delete y;
}

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

* Re: delete not called
  1998-04-16 23:59 delete not called Tudor Hulubei
@ 1998-04-17  7:07 ` Warner Losh
  1998-04-17 14:42   ` Tudor Hulubei
  1998-04-17 14:49   ` Tudor Hulubei
  0 siblings, 2 replies; 4+ messages in thread
From: Warner Losh @ 1998-04-17  7:07 UTC (permalink / raw)
  To: Tudor Hulubei; +Cc: egcs

In message < 13622.59339.352264.243086@hal2.dyn.ml.org > Tudor Hulubei writes:
: Is this a known problem?

It is doing the right thing.

: class X { public: ~X() {} };
: class Y : public X {};

You need to make ~X virtual.

Warner

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

* Re: delete not called
  1998-04-17  7:07 ` Warner Losh
@ 1998-04-17 14:42   ` Tudor Hulubei
  1998-04-17 14:49   ` Tudor Hulubei
  1 sibling, 0 replies; 4+ messages in thread
From: Tudor Hulubei @ 1998-04-17 14:42 UTC (permalink / raw)
  To: Warner Losh; +Cc: egcs

  On Fri, 17 April 1998, Warner Losh wrote:
  > In message < 13622.59339.352264.243086@hal2.dyn.ml.org > Tudor Hulubei writes:
  > : Is this a known problem?
  > 
  > It is doing the right thing.

I don't think so.  Do you mean that the space for Y is never
deallocated?  What does the fact that ~X is virtual has anything to do 
with deallocation?

  > 
  > : class X { public: ~X() {} };
  > : class Y : public X {};
  > 
  > You need to make ~X virtual.

I already tried that, before reporting the bug.  In fact, in my code
~X() _was_ virtual when I noticed the leak.  Try to make ~X() virtual
and you'll see that you still get 2 calls to new and one call to
delete.  Again, gcc-2.8.1 is working fine as do older versions of egcs
(I tried egcs 1.0 and it used to work with older snapshots).

Regards,
Tudor

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

* Re: delete not called
  1998-04-17  7:07 ` Warner Losh
  1998-04-17 14:42   ` Tudor Hulubei
@ 1998-04-17 14:49   ` Tudor Hulubei
  1 sibling, 0 replies; 4+ messages in thread
From: Tudor Hulubei @ 1998-04-17 14:49 UTC (permalink / raw)
  To: egcs

  On Fri, 17 April 1998, Warner Losh wrote:
  > In message < 13622.59339.352264.243086@hal2.dyn.ml.org > Tudor Hulubei writes:
  > : Is this a known problem?
  > 
  > It is doing the right thing.
  > 
  > : class X { public: ~X() {} };
  > : class Y : public X {};
  > 
  > You need to make ~X virtual.

I have updated my CVS tree and managed to compile the latest version
on Linux (now that the compilation failure has been fixed) and the
problem is gone.  Both calls to delete are now correctly generated.

I am running in some other compiler failures, but this time they are
internal compiler errors.  I couln't reproduce it in a smaller
example, but I'll keep trying :-)

/home/tudor/usr/include/g++/stl_deque.h: In method `void deque<CSPConstraint *,__default_alloc_template<true,0>,0>::clear<CSPConstraint *, alloc, 0>()':
/home/tudor/usr/include/g++/stl_deque.h:769: Internal compiler error.
/home/tudor/usr/include/g++/stl_deque.h:769: Please submit a full bug report to `egcs-bugs@cygnus.com'.
make: *** [CSPac3.o] Error 1

I haven't had this problem with 980406.

Regards,
Tudor

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

end of thread, other threads:[~1998-04-17 14:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-16 23:59 delete not called Tudor Hulubei
1998-04-17  7:07 ` Warner Losh
1998-04-17 14:42   ` Tudor Hulubei
1998-04-17 14:49   ` Tudor Hulubei

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).