Path: utzoo!telly!ddsw1!mcdchg!rutgers!ukma!tut.cis.ohio-state.edu!cs.utexas.edu!sm.unisys.com!ucla-cs!casey From: casey@CS.UCLA.EDU Newsgroups: gnu.g++.bug Subject: GNU C++ 1.27 does not call destructors for temporaries Keywords: compiler temporaries, constructors, destructors Message-ID: <16551@shemp.CS.UCLA.EDU> Date: 6 Oct 88 00:21:43 GMT Sender: news@CS.UCLA.EDU Reply-To: casey@CS.UCLA.EDU (Casey Leedom) Distribution: gnu Organization: UCLA Lines: 73 VERSION: GNU CC 1.27 GNU C++ 1.27 GNU LIBG++ 1.25 CLIENT MACHINE: VAX 8350 CLIENT OPERATING SYSTEM: ULTRIX 2.2 - no patches installed SYNOPSIS: The GNU C++ compiler automatically allocates temporaries for expression evaluation. It properly calls constructors for the class of the temporaries, but doesn't call destructors for them. REPEAT-BY: The following program demonstrates the problem. No fix yet, but we'll start looking immediately because we can't proceed with our work until this is fixed. If anyone comes up with a fix please mail us a copy. Thanks! ----- char *malloc(unsigned int); /* * CLASS FOO */ class foo { int *store; public: foo(int); ~foo(void); friend foo operator+(foo &, foo&); }; inline foo::foo(int n) /* FOO CONSTRUCTOR */ { puts("foo constructor"); store = (int *)malloc(sizeof(*store)); if (store) *store = n; else perror("malloc"); } inline foo::~foo(void) /* FOO DESTRUCTOR */ { puts("foo destructor"); if (store) free(store); } inline foo operator+(foo &a, foo &b) /* FOO OPERATOR + */ { return(*a.store + *b.store); } /* * Trivial main program. * * GNU C++ generates a temporary of type foo to handle the expression to * compute the value of s. A constructor for the temporary is properly * called, but a destructor for it is never called. This is a bug. */ main() { foo a(1), b(2), c(5); foo s = a + b + c; }