🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

destructor called for object that never was

#2117
From: David Fox
Date: Tue, 02 Jan 1990 21:30
21 lines
914 bytes
I am running the g++ from interviews of December 21
on a sun-4.  The program below constructs an "X" only when
the if condition is satisfied, but it mistakenly destructs
it regardless.  Enclosing the for statment in braces is a
workaround.  Cfront behaves correctly.

#include <stream.h>

class X {
  int a;
public:
  X() : a(123) {}
  X(int n) : a(n) {}
  ~X() {cout << "Deleting " << a << "\n";}
};

main(int ac)
{
  if (ac > 1)
    for (X x(5); ac > 0; ac--);
}
Technical Details
Message-ID: <9001022130.AA26007@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!allegra.tempo.nj.att.com!fox

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!allegra.tempo.nj.att.com!fox
From: fox@allegra.tempo.nj.att.com (David Fox)
Newsgroups: gnu.g++.bug
Subject: destructor called for object that never was
Message-ID: <9001022130.AA26007@life.ai.mit.edu>
Date: 2 Jan 90 21:30:07 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 21