O_o
Never use `std::uncaught_exception' in any production code. Ever. It is guaranteed to fail eventually, and a few compilers are designed for `std::uncaught_exception' to return false in any case.
Am I mistaken, or is this a bug with GCC?
*shrug*
It doesn't matter, but a guess says that the environmental copy of the `fatal' instance you catch is being destroyed correctly after the `catch' block which then throws another exception.
[Edit]
Try this slight change to see what I'm saying.
[/Edit]
Soma
Code:
#include <iostream>
#include <stdexcept>
struct fatal
{
fatal()
{
std::cout << "fatal()" << '\n';
}
fatal(const fatal &)
{
std::cout << "fatal(const fatal &)" << '\n';
}
fatal & operator = (const fatal &)
{
std::cout << "fatal & operator = (const fatal &)" << '\n';
return *this;
}
~fatal( void )
{
std::cout << "~fatal( void )" << '\n';
if( !std::uncaught_exception( ) )
throw *this;
}
};
int main( void )
{
try
{
fatal( );
}
catch( fatal const& )
{
std::cout << "Exception caught!" << std::endl;
}
std::cout << "Success!" << std::endl;
}