This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Possible throw bug (egcs-1.1.2)
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: Possible throw bug (egcs-1.1.2)
- From: Chris Yeoh <chris at maptek dot com>
- Date: Fri, 02 Apr 1999 10:31:22 -0700
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."