Great g++ bug! Local destructor isn't called!
Assinovsky, Lev
LAssinovsky@algorithm.aelita.com
Wed Mar 10 14:52:00 GMT 2004
Hi folks!
In the example bellow the destructor of Object isn't called when exception
was raised from Run() method! That happens only with option -O1, -O2, -O3.
-O0 works fine.
Tested with gcc 3.2 and 3.3.1 in Solaris 8 Intel and HP-UX 11.00.
================== cut here =====================
#include <iostream>
class Raiser
{
public:
Raiser() throw( int )
{
throw 1;
};
};
class Object
{
public:
~Object()
{
std::cout << "~Object()" << std::endl;
};
};
class Base
{
public:
virtual ~Base(){};
virtual void Run(){};
};
class FromBase : public Base
{
public:
virtual ~FromBase(){};
virtual void Run()
{
std::cout << "Derived Run" << std::endl;
{
Object a;
std::cout << "Raise!" << std::endl;
Raiser riser;
}
std::cout << "Unreachable code" << std::endl;
};
};
int main()
{
FromBase a;
Base& b = static_cast<Base&>(a);
try
{
b.Run();
std::cout << "Unreach 2" << std::endl;
}
catch ( int )
{
std::cout << "Exception handler" << std::endl;
}
std::cout << "Exit Main" << std::endl;
return 0;
}
================ cut here =======================
Also we discovered calling a free function throwing an exception leads to same bug appears with -O3 only.
In general this bug coming when and only when class methods or free functions have exception specification!
Any help will be greatly appreciated!
----
Lev Assinovsky
Aelita Software Corporation
O&S InTrust Framework Division
More information about the Gcc-help
mailing list