Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!UUNET.UU.NET!naib!dsamperi From: naib!dsamperi@UUNET.UU.NET (Dominick Samperi) Newsgroups: gnu.g++.bug Subject: g++ bug Message-ID: <8908210205.AA12004@naib.com> Date: 21 Aug 89 02:05:46 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 47 The C++ program below illustrate a g++ bug. The function getx() is called twice, once when x.f() is invoked. When compiled under Zortek C++ getx() is called only once, as I would expect. Please let me know if this is a known problem, to be fixed, etc. Thanks! Dominick Samperi Citicorp, NAIB uunet!naib!samperi /* * g++bug.c -- Illustrates a g++ bug. The function getx() below is called * twice, once incorrectly when x.f() is executed. * * Dominick Samperi, Citicorp, NAIB * uunet!naib!samperi */ #include class xclass { public: void f() {cout << "(xclass.f)\n";} }; xclass& getx() { xclass& q = *(new xclass); cout << "(getx)\n"; return q; } main () { xclass& x = getx(); x.f(); /* * Output is: * * (getx) * (getx) * (xclass.f) * * Looks like getx() is being called again when x.f() is executed. */ }