Great g++ bug! Local destructor isn't called!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux