diff --git a/include/boost/exception/enable_current_exception.hpp b/include/boost/exception/enable_current_exception.hpp index 976a881..c00a23a 100644 --- a/include/boost/exception/enable_current_exception.hpp +++ b/include/boost/exception/enable_current_exception.hpp @@ -64,6 +64,9 @@ boost clone_impl( T const & x ): T(x) { + if( boost::exception * be1=dynamic_cast(this) ) + if( boost::exception const * be2=dynamic_cast(&x) ) + *be1 = *be2; } private: @@ -88,6 +91,9 @@ boost T(x), count_(0) { + if( boost::exception * be1=dynamic_cast(this) ) + if( boost::exception const * be2=dynamic_cast(&x) ) + *be1 = *be2; } private: diff --git a/test/helper2.cpp b/test/helper2.cpp index 7fce317..258b6aa 100644 --- a/test/helper2.cpp +++ b/test/helper2.cpp @@ -13,41 +13,60 @@ boost exception_test { inline - some_boost_exception:: - some_boost_exception( int x ): + derives_boost_exception:: + derives_boost_exception( int x ): x_(x) { } - some_boost_exception:: - ~some_boost_exception() throw() + derives_boost_exception:: + ~derives_boost_exception() throw() { } inline - some_std_exception:: - some_std_exception( int x ): + derives_boost_exception_virtually:: + derives_boost_exception_virtually( int x ): x_(x) { } - some_std_exception:: - ~some_std_exception() throw() + derives_boost_exception_virtually:: + ~derives_boost_exception_virtually() throw() + { + } + + inline + derives_std_exception:: + derives_std_exception( int x ): + x_(x) + { + } + + derives_std_exception:: + ~derives_std_exception() throw() { } template <> void - throw_test_exception( int x ) + throw_test_exception( int x ) { - boost::throw_exception( some_boost_exception(x) ); + boost::throw_exception( derives_boost_exception(x) ); } template <> void - throw_test_exception( int x ) + throw_test_exception( int x ) { - boost::throw_exception( some_std_exception(x) ); + boost::throw_exception( derives_boost_exception_virtually(x) ); + } + + template <> + void + throw_test_exception( int x ) + { + boost::throw_exception( derives_std_exception(x) ); } } } diff --git a/test/helper2.hpp b/test/helper2.hpp index 2f5e38d..df36fd9 100644 --- a/test/helper2.hpp +++ b/test/helper2.hpp @@ -16,21 +16,31 @@ boost exception_test { struct - some_boost_exception: + derives_boost_exception: public boost::exception, public std::exception { - explicit some_boost_exception( int x ); - virtual ~some_boost_exception() throw(); + explicit derives_boost_exception( int x ); + virtual ~derives_boost_exception() throw(); int x_; }; struct - some_std_exception: + derives_boost_exception_virtually: + public virtual boost::exception, public std::exception { - explicit some_std_exception( int x ); - virtual ~some_std_exception() throw(); + explicit derives_boost_exception_virtually( int x ); + 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_; }; @@ -38,10 +48,13 @@ boost void throw_test_exception( int ); template <> - void throw_test_exception( int ); + void throw_test_exception( int ); template <> - void throw_test_exception( int ); + void throw_test_exception( int ); + + template <> + void throw_test_exception( int ); } } diff --git a/test/throw_exception_test.cpp b/test/throw_exception_test.cpp index a20a88f..247575d 100644 --- a/test/throw_exception_test.cpp +++ b/test/throw_exception_test.cpp @@ -8,7 +8,7 @@ #include #include -typedef boost::error_info test_int; +typedef boost::error_info test_data; void throw_fwd( void (*thrower)(int) ) @@ -20,7 +20,7 @@ throw_fwd( void (*thrower)(int) ) catch( boost::exception & x ) { - x << test_int(42); + x << test_data(42); throw; } } @@ -46,7 +46,9 @@ tester() catch( T & y ) { - BOOST_TEST(*boost::get_error_info(y)==42); + BOOST_TEST(boost::get_error_info(y)); + if( boost::shared_ptr d=boost::get_error_info(y) ) + BOOST_TEST(*d==42); BOOST_TEST(y.x_==42); } catch( @@ -60,7 +62,8 @@ tester() int main() { - tester(); - tester(); + tester(); + tester(); + tester(); return boost::report_errors(); }