Possible throw bug (egcs-1.1.2)
Chris Yeoh
chris@maptek.com
Fri Apr 2 09:31:00 GMT 1999
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."
More information about the Gcc-bugs
mailing list