------- Comment #6 from mark dot woollard at macrovision dot com  2006-06-07 
23:13 -------
I have come across this issue too. It seems that if the exception being thrown
is passed back across a function call then the rethrow will cause a segfault.
If the catch and rethrow are in the same function as the original throw then
the issue does not reveal itself. Example code that causes the problem is below
and I have tested with this against compilers from 3.4.3 through to 4.1.1. The
same code behaves correctly on all other platforms we work with.

#include <iostream>
#include <string>
#include <exception>

class derived : public std::exception
{
public:
        derived( const std::string &m ) : msg(m) { }
        virtual ~derived() throw() {}

        const char *what() const throw()
        {
                return msg.c_str( );
        }       

private:
        std::string msg;
};

void test( )
{
        derived e("Screwed");
        throw e;
}

int main ( int argc, char * argv[] )
{
        try
        {
                try
                {
                        test( ); 
                        // Switching to the following in place of calling
test() works correctly
                        // derived e("Screwed"); throw e; 
                }
                catch( const std::exception &e )
                {               
                        std::cout << "Inner catch: " << e.what() << std::endl;
                        throw; // Segfaults
                }
        }
        catch( const std::exception & e )
        {
                std::cout << "Outer catch: " << e.what() << std::endl;
        }

        return 0;
}


-- 

mark dot woollard at macrovision dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark dot woollard at
                   |                            |macrovision dot com


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

Reply via email to