This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Possible throw bug (egcs-1.1.2)



When I run the following bit of code, I get some unexpected behaviour.
It seems to be running the destructor for `foo' one too many times
(and with a corrupt `this' pointer). The output I get from egcs is:

constructing foo0x7ffedda0
copying foo0x100072d0
destructing foo0x7ffedd98
destructing foo0x7ffedda0
caught
destructing foo0x100072d0

This happens on the version of egcs I have compiled on linux 2.2.3 as
well as Irix 5.3.

but using an older version (gcc 2.7.2.3) or SGI CC, it works as
expected (two constructions, two destructions). 

#include <iostream.h>
class foo 
{
public:
  foo() { cout << "constructing foo" << this << endl; };
  foo(const foo& Original) { cout << "copying foo" << this << endl; };
  ~foo() { cout << "destructing foo" << this << endl; };
};

const foo &bar(const foo &theFoo)
{
  return theFoo;
}

int main()
{
  try
  {
    throw bar(foo());
  }
  catch (...)
  {
    cout << "caught" << endl;
  }
}


--
chris@maptek.com
"Before criticizing someone, walk a mile in their shoes. Then when you
do criticize them, you will be a mile away and have their shoes."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]