Fixed exception info bug when boost::exception is derived virtually.

[SVN r46333]
This commit is contained in:
Emil Dotchevski
2008-06-11 18:24:10 +00:00
parent 3b2a6a2711
commit 421a059421
4 changed files with 66 additions and 25 deletions

View File

@ -64,6 +64,9 @@ boost
clone_impl( T const & x ): clone_impl( T const & x ):
T(x) T(x)
{ {
if( boost::exception * be1=dynamic_cast<boost::exception *>(this) )
if( boost::exception const * be2=dynamic_cast<T const *>(&x) )
*be1 = *be2;
} }
private: private:
@ -88,6 +91,9 @@ boost
T(x), T(x),
count_(0) count_(0)
{ {
if( boost::exception * be1=dynamic_cast<boost::exception *>(this) )
if( boost::exception const * be2=dynamic_cast<T const *>(&x) )
*be1 = *be2;
} }
private: private:

View File

@ -13,41 +13,60 @@ boost
exception_test exception_test
{ {
inline inline
some_boost_exception:: derives_boost_exception::
some_boost_exception( int x ): derives_boost_exception( int x ):
x_(x) x_(x)
{ {
} }
some_boost_exception:: derives_boost_exception::
~some_boost_exception() throw() ~derives_boost_exception() throw()
{ {
} }
inline inline
some_std_exception:: derives_boost_exception_virtually::
some_std_exception( int x ): derives_boost_exception_virtually( int x ):
x_(x) x_(x)
{ {
} }
some_std_exception:: derives_boost_exception_virtually::
~some_std_exception() throw() ~derives_boost_exception_virtually() throw()
{
}
inline
derives_std_exception::
derives_std_exception( int x ):
x_(x)
{
}
derives_std_exception::
~derives_std_exception() throw()
{ {
} }
template <> template <>
void void
throw_test_exception<some_boost_exception>( int x ) throw_test_exception<derives_boost_exception>( int x )
{ {
boost::throw_exception( some_boost_exception(x) ); boost::throw_exception( derives_boost_exception(x) );
} }
template <> template <>
void void
throw_test_exception<some_std_exception>( int x ) throw_test_exception<derives_boost_exception_virtually>( int x )
{ {
boost::throw_exception( some_std_exception(x) ); boost::throw_exception( derives_boost_exception_virtually(x) );
}
template <>
void
throw_test_exception<derives_std_exception>( int x )
{
boost::throw_exception( derives_std_exception(x) );
} }
} }
} }

View File

@ -16,21 +16,31 @@ boost
exception_test exception_test
{ {
struct struct
some_boost_exception: derives_boost_exception:
public boost::exception, public boost::exception,
public std::exception public std::exception
{ {
explicit some_boost_exception( int x ); explicit derives_boost_exception( int x );
virtual ~some_boost_exception() throw(); virtual ~derives_boost_exception() throw();
int x_; int x_;
}; };
struct struct
some_std_exception: derives_boost_exception_virtually:
public virtual boost::exception,
public std::exception public std::exception
{ {
explicit some_std_exception( int x ); explicit derives_boost_exception_virtually( int x );
virtual ~some_std_exception() throw(); virtual ~derives_boost_exception_virtually() throw();
int x_;
};
struct
derives_std_exception:
public std::exception
{
explicit derives_std_exception( int x );
virtual ~derives_std_exception() throw();
int x_; int x_;
}; };
@ -38,10 +48,13 @@ boost
void throw_test_exception( int ); void throw_test_exception( int );
template <> template <>
void throw_test_exception<some_boost_exception>( int ); void throw_test_exception<derives_boost_exception>( int );
template <> template <>
void throw_test_exception<some_std_exception>( int ); void throw_test_exception<derives_boost_exception_virtually>( int );
template <>
void throw_test_exception<derives_std_exception>( int );
} }
} }

View File

@ -8,7 +8,7 @@
#include <boost/exception_ptr.hpp> #include <boost/exception_ptr.hpp>
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag_test_int,int> test_int; typedef boost::error_info<struct tag_test_int,int> test_data;
void void
throw_fwd( void (*thrower)(int) ) throw_fwd( void (*thrower)(int) )
@ -20,7 +20,7 @@ throw_fwd( void (*thrower)(int) )
catch( catch(
boost::exception & x ) boost::exception & x )
{ {
x << test_int(42); x << test_data(42);
throw; throw;
} }
} }
@ -46,7 +46,9 @@ tester()
catch( catch(
T & y ) T & y )
{ {
BOOST_TEST(*boost::get_error_info<test_int>(y)==42); BOOST_TEST(boost::get_error_info<test_data>(y));
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
BOOST_TEST(*d==42);
BOOST_TEST(y.x_==42); BOOST_TEST(y.x_==42);
} }
catch( catch(
@ -60,7 +62,8 @@ tester()
int int
main() main()
{ {
tester<boost::exception_test::some_boost_exception>(); tester<boost::exception_test::derives_boost_exception>();
tester<boost::exception_test::some_std_exception>(); tester<boost::exception_test::derives_boost_exception_virtually>();
tester<boost::exception_test::derives_std_exception>();
return boost::report_errors(); return boost::report_errors();
} }