[Bug optimization/14535] New: exception throwing in virtual function doesn't turn on the local destructors

lassinovsky at algorithm dot aelita dot com gcc-bugzilla@gcc.gnu.org
Thu Mar 11 14:30:00 GMT 2004


The following conditions do cause the bug:
1. Optimized compilation (-O1,-O2, -O3)
2. Overriding virtual function is called through the base class pointer or 
    reference
3. Overriding virtual function calls any object method, which has exception 
specification and throws an exception.
4. Overriding virtual function doesn't have an exception specification.

My configuration:
uname -a:
SunOS dog 5.8 Generic_108529-09 i86pc i386 i86pc

gcc -v
Reading specs from /opt/AESgcc/lib/gcc-lib/i386-pc-solaris2.8/3.2/specs
Configured with: /export/home/Ext/Archive/gcc-3.2/configure --
prefix=/opt/AESgcc --disable-multilib --enable-threads=posix --enable-
languages=c,c++ --with-gnu-ld --with-ld=/usr/local/bin/ld --with-gnu-as -with-
as=/usr/local/bin/as
Thread model: posix
gcc version 3.2

Test case:
======= Test case starts
#include <iostream>

class Raiser
{
public:
    Raiser()  throw( int )
    {
        throw 1;
    };
};

class Object
{
public:
    virtual ~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;
}

======= Test case end
Compilation:
gcc -O1 -o tst tst.cpp

Due to the bug the string "~Object()" will not be printed.

-- 
           Summary: exception throwing in virtual function doesn't turn on
                    the local destructors
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lassinovsky at algorithm dot aelita dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14535



More information about the Gcc-bugs mailing list