🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by James Clark Thu, 27 Apr 1989 19:12
fix for operator delete bug
#1925
Author: James Clark
Date: Thu, 27 Apr 1989 19:12
69 lines
2399 bytes
The following patch seems to fix the problem that I reported with
objects' getting deleted twice.

*** cplus-init.c.distrib	Thu Apr 27 18:37:26 1989
--- cplus-init.c	Thu Apr 27 19:09:11 1989
***************
*** 2607,2613 ****
        if (TREE_GETS_DELETE (type))
  	{
  	  parent_auto_delete = integer_zero_node;
! 	  expr = build_opfncall (DELETE_EXPR, addr, addr);
  	  if (expr == error_mark_node)
  	    return error_mark_node;
  	  exprstmt = build_tree_list (NULL_TREE, expr);
--- 2607,2617 ----
        if (TREE_GETS_DELETE (type))
  	{
  	  parent_auto_delete = integer_zero_node;
! 	  expr = build (COND_EXPR, void_type_node,
! 			build (NE_EXPR, integer_type_node, auto_delete, integer_zero_node),
! 			build_opfncall (DELETE_EXPR, addr, addr),
! 			build (NOP_EXPR, void_type_node, integer_zero_node));
! 
  	  if (expr == error_mark_node)
  	    return error_mark_node;
  	  exprstmt = build_tree_list (NULL_TREE, expr);

Here's an illustration of the problem:

Script started on Thu Apr 27 19:06:18 1989
jclark% cat delete.c
#include <stdio.h>


struct A {
  virtual ~A() {}
  operator delete(void *p) { fprintf(stderr, "A::operator delete(%d)\n", p); }
};

struct B : A {
};

struct C : B {
  ~C() {}
};


main()
{
  A *a = new C;
  delete a;
}
jclark% g++ -g -v delete.c
g++ version 1.34.1
 /usr/local/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ delete.c /tmp/cca03921.cpp
GNU CPP version 1.34
 /usr/local/lib/gcc-c++ /tmp/cca03921.cpp -quiet -dumpbase delete.c -g -version -o /tmp/cca03921.s
GNU C++ version 1.34.1 (sparc) compiled by GNU C version 1.34.
 as /tmp/cca03921.s -o delete.o
 /usr/local/lib/gcc-ld++ -C -e start -dc -dp -Bstatic /usr/local/lib/crt0+.o delete.o -lg++ /usr/local/lib/gcc-gnulib -lg -lc
jclark% a.out
A::operator delete(43048)
A::operator delete(43048)
jclark% exit
jclark% 
script done on Thu Apr 27 19:07:04 1989

James Clark
jjc@jclark.uucp
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads