🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

g++1.35 evaluates expression twice when destructor is virtual

#82
From: Tom Vijlbrief
Date: Wed, 28 Jun 1989 10:23
56 lines
1963 bytes
G++ evaluates the expression b.delfunc(this) twice.
Discovered when porting ET++


g++ version 1.35.0
 /usr/local/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 doubledel.cc /tmp/cca04906.cpp
GNU CPP version 1.35
 /usr/local/lib/gcc-cc1plus /tmp/cca04906.cpp -quiet -dumpbase doubledel.cc -noreg -version -o /tmp/cca04906.s
GNU C++ version 1.35.0 (68k, MIT syntax) compiled by GNU C version 1.35.
 /usr/local/lib/gcc-as -mc68020 /tmp/cca04906.s -o doubledel.o
 /usr/local/lib/gcc-ld++ -C /usr/local/lib/crt0+.o /lib/Mcrt1.o doubledel.o -lg++ /usr/local/lib/gcc-gnulib -lc

tom@twilight:~/src/CC> a.out

called
called

=================================================
#include <stdio.h>

class del {
public:
  del() {};
  virtual ~del() {};
  virtual void bug();
  virtual del *delfunc(del*);
};

del b;

del *del::delfunc(del*)
{
  del *p= new del;
  fprintf(stderr, "called\n");
  return p;
}

void del::bug()
{
  delete b.delfunc(this);  // b.delfunc(this) is called twice !!!
}


main()
{
  del *a= new del;
  a->bug();
}
===============================================================================
Tom Vijlbrief
TNO Institute for Perception
P.O. Box 23				Phone: +31 34 63 562 11
3769 ZG  Soesterberg			E-mail: tnosoes!tom@mcvax.cwi.nl
The Netherlands				    or:	uunet!mcvax!tnosoes!tom
===============================================================================
Technical Details
Message-ID: <465@tnosoes.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!hp4nl!tnosoes!tom

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!hp4nl!tnosoes!tom
From: tom@tnosoes.UUCP (Tom Vijlbrief)
Newsgroups: gnu.g++.bug
Subject: g++1.35 evaluates expression twice when destructor is virtual
Keywords: delete
Message-ID: <465@tnosoes.UUCP>
Date: 28 Jun 89 10:23:36 GMT
Organization: TNO Institute for Perception, Soesterberg, The Netherlands
Lines: 56