diff --git a/example/example_io.cpp b/example/example_io.cpp index e656fc0..1b63194 100644 --- a/example/example_io.cpp +++ b/example/example_io.cpp @@ -66,11 +66,11 @@ my_fopen( char const * name, char const * mode ) if( FILE * f = ::fopen(name,mode) ) return boost::shared_ptr(f,fclose); else - throw fopen_error() << BOOST_ERROR_INFO << + BOOST_THROW_EXCEPTION(fopen_error() << errno_info(errno) << file_name_info(name) << open_mode_info(mode) << - function_info("fopen"); + function_info("fopen")); } void @@ -78,10 +78,10 @@ my_fread( void * buffer, size_t size, size_t count, boost::shared_ptr cons { assert(stream); if( count!=fread(buffer,size,count,stream.get()) || ferror(stream.get()) ) - throw fread_error() << BOOST_ERROR_INFO << + BOOST_THROW_EXCEPTION(fread_error() << function_info("fread") << errno_info(errno) << - file_stream_info(boost::weak_ptr(stream)); + file_stream_info(boost::weak_ptr(stream))); } void @@ -89,10 +89,10 @@ my_fwrite( void const * buffer, size_t size, size_t count, boost::shared_ptr(stream)); + file_stream_info(boost::weak_ptr(stream))); } void diff --git a/example/logging.cpp b/example/logging.cpp index 41295b5..b72b03e 100644 --- a/example/logging.cpp +++ b/example/logging.cpp @@ -20,6 +20,6 @@ g() catch( boost::exception & e ) { - std::cerr << e.diagnostic_information(); + std::cerr << diagnostic_information(e); } } diff --git a/include/boost/exception/detail/error_info_base.hpp b/include/boost/exception/detail/error_info_base.hpp index 7953d13..d6011a8 100644 --- a/include/boost/exception/detail/error_info_base.hpp +++ b/include/boost/exception/detail/error_info_base.hpp @@ -6,7 +6,6 @@ #ifndef UUID_CE6983AC753411DDA764247956D89593 #define UUID_CE6983AC753411DDA764247956D89593 -#include #include namespace @@ -25,10 +24,8 @@ boost protected: -#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) ) -virtual //Disable bogus GCC warning. -#endif - ~error_info_base() + virtual + ~error_info_base() throw() { } }; diff --git a/include/boost/exception/detail/object_hex_dump.hpp b/include/boost/exception/detail/object_hex_dump.hpp index 5b15637..a6221b6 100644 --- a/include/boost/exception/detail/object_hex_dump.hpp +++ b/include/boost/exception/detail/object_hex_dump.hpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp index 9e53d42..8aaee8d 100644 --- a/include/boost/exception/detail/type_info.hpp +++ b/include/boost/exception/detail/type_info.hpp @@ -44,13 +44,6 @@ boost return a.type_==b.type_; } - friend - bool - operator!=( type_info_ const & a, type_info_ const & b ) - { - return !(a==b); - } - friend bool operator<( type_info_ const & a, type_info_ const & b ) @@ -88,13 +81,6 @@ boost return (*a.type_)==(*b.type_); } - friend - bool - operator!=( type_info_ const & a, type_info_ const & b ) - { - return !(a==b); - } - friend bool operator<( type_info_ const & a, type_info_ const & b ) @@ -109,6 +95,13 @@ boost } }; #endif + + inline + bool + operator!=( type_info_ const & a, type_info_ const & b ) + { + return !(a==b); + } } } diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp index 8c5e0d6..26b299c 100644 --- a/include/boost/exception/diagnostic_information.hpp +++ b/include/boost/exception/diagnostic_information.hpp @@ -6,9 +6,9 @@ #ifndef UUID_0552D49838DD11DD90146B8956D89593 #define UUID_0552D49838DD11DD90146B8956D89593 -#include -#include +#include #include +#include #include namespace @@ -17,13 +17,27 @@ boost namespace exception_detail { + char const * + get_diagnostic_information( exception const & x ) + { + if( error_info_container * c=x.data_.get() ) + try + { + return c->diagnostic_information(); + } + catch(...) + { + } + return 0; + } + template std::string std_exception_diagnostic_information( std::exception const * x, T const & ) { if( char const * s=x->what() ) if( *s ) - return std::string("std::exception::what(): ")+s; + return std::string("\nstd::exception::what(): ")+s; return std::string(); } @@ -35,58 +49,32 @@ boost if( std::exception const * x=dynamic_cast(&e) ) return std_exception_diagnostic_information(x,e); else -#endif - return std::string(); - } - - template - std::string - boost_exception_diagnostic_information( boost::exception const * x, T const & ) - { - if( char const * s=x->diagnostic_information() ) - if( *s ) - return std::string("boost::exception::diagnostic_information():\n")+s; - return std::string(); - } - - template - std::string - boost_exception_diagnostic_information( void const *, T const & e ) - { -#ifndef BOOST_NO_RTTI - if( exception const * x=dynamic_cast(&e) ) - return boost_exception_diagnostic_information(x,e); - else #endif return std::string(); } } - template inline std::string - diagnostic_information( T const & x ) + diagnostic_information( exception const & x ) { - std::string di= -#if defined(BOOST_NO_RTTI) || defined(BOOST_NO_TYPEID) - std::string("Static exception type: ")+BOOST_EXCEPTION_STATIC_TYPEID(T) -#else - std::string("Dynamic exception type: ")+BOOST_EXCEPTION_DYNAMIC_TYPEID(x) + std::ostringstream tmp; + tmp << + "boost::exception diagnostic information:" +#if !defined(BOOST_NO_RTTI) && !defined(BOOST_NO_TYPEID) + "\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name() #endif - .name(); - std::string di1=exception_detail::std_exception_diagnostic_information(&x,x); - if( !di1.empty() ) - { - di+='\n'; - di+=di1; - } - std::string di2=exception_detail::boost_exception_diagnostic_information(&x,x); - if( !di2.empty() ) - { - di+='\n'; - di+=di2; - } - return di; + ; + if( boost::shared_ptr f=get_error_info(x) ) + tmp << "\nThrow function: " << *f; + if( boost::shared_ptr f=get_error_info(x) ) + tmp << "\nThrow file name: " << *f; + if( boost::shared_ptr l=get_error_info(x) ) + tmp << "\nThrow file line: " << *l; + if( char const * s=exception_detail::get_diagnostic_information(x) ) + if( *s ) + tmp << "\n" << s; + return tmp.str(); } } diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp index dcc6d43..5cba804 100644 --- a/include/boost/exception/exception.hpp +++ b/include/boost/exception/exception.hpp @@ -9,9 +9,6 @@ namespace boost { - - //////////////////////////////////////////////////////////////////////// - namespace exception_detail { @@ -66,65 +63,77 @@ boost add_ref() { if( px_ ) - intrusive_ptr_add_ref(px_); + px_->add_ref(); } void release() { if( px_ ) - intrusive_ptr_release(px_); + px_->release(); } }; } //////////////////////////////////////////////////////////////////////// - namespace - exception_detail + template + class error_info; + + typedef error_info throw_function; + typedef error_info throw_file; + typedef error_info throw_line; + + template <> + class + error_info { - class - counted_base + public: + typedef char const * value_type; + value_type v_; + explicit + error_info( value_type v ): + v_(v) { - friend - void - intrusive_ptr_add_ref( counted_base const * c ) - { - c->add_ref(); - } + } + }; - friend - void - intrusive_ptr_release( counted_base const * c ) - { - c->release(); - } + template <> + class + error_info + { + public: + typedef char const * value_type; + value_type v_; + explicit + error_info( value_type v ): + v_(v) + { + } + }; - virtual void add_ref() const=0; - virtual void release() const=0; + template <> + class + error_info + { + public: + typedef int value_type; + value_type v_; + explicit + error_info( value_type v ): + v_(v) + { + } + }; - protected: - - virtual - ~counted_base() throw() - { - } - }; - } - - //////////////////////////////////////////////////////////////////////// + template + E const & operator<<( E const &, error_info const & ); class exception; template class shared_ptr; - template - class error_info; - - template - E const & operator<<( E const &, error_info const & ); - namespace exception_detail { @@ -132,62 +141,83 @@ boost struct type_info_; struct - error_info_container: - public exception_detail::counted_base + error_info_container { virtual char const * diagnostic_information() const = 0; virtual shared_ptr get( type_info_ const & ) const = 0; virtual void set( shared_ptr const &, type_info_ const & ) = 0; + virtual void add_ref() const = 0; + virtual void release() const = 0; + + protected: + + virtual + ~error_info_container() throw() + { + } }; - template - shared_ptr get_info( exception const & ); + template + struct get_info; + + char const * get_diagnostic_information( exception const & ); } class exception { - public: - - virtual - char const * - diagnostic_information() const throw() - { - return _diagnostic_information(); - } - protected: - exception() + exception(): + throw_function_(0), + throw_file_(0), + throw_line_(-1) { } - virtual ~exception() throw()=0; - - char const * - _diagnostic_information() const throw() - { - if( exception_detail::error_info_container * c=data_.get() ) - try - { - if( char const * w = c->diagnostic_information() ) - return w; - } - catch(...) - { - } - return ""; - } + virtual ~exception() throw() = 0; private: - template - friend E const & operator<<( E const &, error_info const & ); + template + friend + E const & + operator<<( E const & x, throw_function y ) + { + x.throw_function_=y.v_; + return x; + } - template - friend shared_ptr exception_detail::get_info( exception const & ); + template + friend + E const & + operator<<( E const & x, throw_file y ) + { + x.throw_file_=y.v_; + return x; + } + + template + friend + E const & + operator<<( E const & x, throw_line y ) + { + x.throw_line_=y.v_; + return x; + } + + friend char const * exception_detail::get_diagnostic_information( exception const & ); + + template + friend E const & operator<<( E const &, error_info const & ); + + template + friend struct exception_detail::get_info; mutable exception_detail::refcount_ptr data_; + mutable char const * throw_function_; + mutable char const * throw_file_; + mutable int throw_line_; }; inline @@ -270,14 +300,12 @@ boost virtual clone_base const * clone() const = 0; virtual void rethrow() const = 0; - virtual ~clone_base() throw() = 0; - }; - inline - clone_base:: - ~clone_base() throw() - { - } + virtual + ~clone_base() throw() + { + } + }; inline void @@ -322,7 +350,7 @@ boost void rethrow() const { - throw *this; + throw*this; } }; } @@ -334,9 +362,6 @@ boost { return exception_detail::clone_impl(x); } - - //////////////////////////////////////////////////////////////////////// - } #endif diff --git a/include/boost/exception/get_error_info.hpp b/include/boost/exception/get_error_info.hpp index 477ba5e..70027c4 100644 --- a/include/boost/exception/get_error_info.hpp +++ b/include/boost/exception/get_error_info.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace boost @@ -17,22 +18,106 @@ boost namespace exception_detail { - template - inline - shared_ptr - get_info( exception const & x ) + struct + strwrap { - if( exception_detail::error_info_container * c=x.data_.get() ) - if( shared_ptr eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) ) + char const * str; + strwrap( char const * s ): + str(init(s)) + { + } + ~strwrap() + { + delete[] str; + } + + private: + + strwrap( strwrap const & ); + strwrap & operator=( strwrap const & ); + + static + char const * + init( char const * s ) + { + size_t n=1+strlen(s); + char * str = new char[n]; + (void) memcpy(str,s,n); + return str; + } + }; + + template <> + struct + get_info + { + static + shared_ptr + get( exception const & x ) + { + if( x.throw_function_ ) { -#ifndef BOOST_NO_RTTI - BOOST_ASSERT( 0!=dynamic_cast(eib.get()) ); -#endif - ErrorInfo const * w = static_cast(eib.get()); - return shared_ptr(eib,&w->value()); + shared_ptr s(new strwrap(x.throw_function_)); + return shared_ptr(s,&s->str); } - return shared_ptr(); - } + else + return shared_ptr(); + } + }; + + template <> + struct + get_info + { + static + shared_ptr + get( exception const & x ) + { + if( x.throw_file_ ) + { + shared_ptr s(new strwrap(x.throw_file_)); + return shared_ptr(s,&s->str); + } + else + return shared_ptr(); + } + }; + + template <> + struct + get_info + { + static + shared_ptr + get( exception const & x ) + { + if( x.throw_line_!=-1 ) + return boost::shared_ptr(new int(x.throw_line_)); + else + return shared_ptr(); + } + }; + + template + struct + get_info + { + static + shared_ptr + get( exception const & x ) + { + if( exception_detail::error_info_container * c=x.data_.get() ) + if( shared_ptr eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) ) + { +#ifndef BOOST_NO_RTTI + BOOST_ASSERT( 0!=dynamic_cast(eib.get()) ); +#endif + ErrorInfo const * w = static_cast(eib.get()); + return shared_ptr(eib,&w->value()); + } + return shared_ptr(); + } + }; } #ifdef BOOST_NO_RTTI @@ -41,7 +126,7 @@ boost shared_ptr get_error_info( boost::exception const & x ) { - return exception_detail::get_info(x); + return exception_detail::get_info::get(x); } #else template @@ -50,7 +135,7 @@ boost get_error_info( E const & some_exception ) { if( exception const * x = dynamic_cast(&some_exception) ) - return exception_detail::get_info(*x); + return exception_detail::get_info::get(*x); else return shared_ptr(); } diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index d324986..9be1f6a 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -7,25 +7,14 @@ #define UUID_8D22C4CA9CC811DCAA9133D256D89593 #include -#include #include #include -#include #include #include -#define BOOST_ERROR_INFO\ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ - ::boost::throw_file(__FILE__) <<\ - ::boost::throw_line((int)__LINE__) - namespace boost { - typedef error_info throw_function; - typedef error_info throw_file; - typedef error_info throw_line; - template class error_info: @@ -40,6 +29,10 @@ boost { } + ~error_info() throw() + { + } + value_type const & value() const { @@ -159,7 +152,7 @@ boost if( !(c=x.data_.get()) ) x.data_.adopt(c=new exception_detail::error_info_container_impl); c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t)); - return x; + return x; } } diff --git a/include/boost/exception_ptr.hpp b/include/boost/exception_ptr.hpp index 1842fdb..15f0ea2 100644 --- a/include/boost/exception_ptr.hpp +++ b/include/boost/exception_ptr.hpp @@ -8,161 +8,63 @@ #include #include -#include -#include +#include #include #include namespace boost { - namespace - exception_detail + class exception_ptr; + exception_ptr current_exception(); + void rethrow_exception( exception_ptr const & ); + + class + exception_ptr { - class - counted_clone: - public counted_base - { - public: + typedef bool exception_ptr::*unspecified_bool_type; + friend exception_ptr current_exception(); + friend void rethrow_exception( exception_ptr const & ); - counted_clone(): - count_(0), - clone_(0) - { - } - - void - set( clone_base const * c ) - { - clone_ = c; - BOOST_ASSERT(clone_!=0); - } - - void - rethrow() const - { - if( clone_ ) - clone_->rethrow(); - else - throw enable_current_exception(std::bad_alloc()); - } - - private: - - counted_clone( counted_clone const & ); - counted_clone & operator=( counted_clone const & ); - - mutable detail::atomic_count count_; - clone_base const * clone_; - void (*clone_deleter_)(clone_base const *); - - ~counted_clone() throw() - { - if( clone_ ) - delete clone_; - } - - void - add_ref() const - { - ++count_; - } - - void - release() const - { - if( !--count_ ) - delete this; - } - }; + shared_ptr c_; + bool bad_alloc_; struct bad_alloc_tag { }; - struct - bad_exception_tag + explicit + exception_ptr( bad_alloc_tag ): + bad_alloc_(true) { - }; - } - - class exception_ptr; - void rethrow_exception( exception_ptr const & ); - - class - exception_ptr - { - private: - - friend void rethrow_exception( exception_ptr const & ); - - enum - { - bad_alloc_caught, - clone_failed, - ok - } what_happened_; - - intrusive_ptr c_; - - void - rethrow() const - { - switch( - what_happened_ ) - { - case - bad_alloc_caught: - throw enable_current_exception(std::bad_alloc()); - case - clone_failed: - throw enable_current_exception(std::bad_exception()); - case - ok: - BOOST_ASSERT(c_.get()!=0); - c_->rethrow(); - } - BOOST_ASSERT(0); } - typedef intrusive_ptr exception_ptr::*unspecified_bool_type; + explicit + exception_ptr( shared_ptr const & c ): + c_(c), + bad_alloc_(false) + { + BOOST_ASSERT(c); + } public: - explicit - exception_ptr( exception_detail::bad_alloc_tag ): - what_happened_(bad_alloc_caught) - { - } - - explicit - exception_ptr( exception_detail::bad_exception_tag ): - what_happened_(clone_failed) - { - } - exception_ptr(): - what_happened_(ok) + bad_alloc_(false) { } - explicit - exception_ptr( intrusive_ptr const & c ): - what_happened_(ok), - c_(c) + operator unspecified_bool_type() const { - BOOST_ASSERT(c_.get()!=0); + return (bad_alloc_ || c_) ? &exception_ptr::bad_alloc_ : 0; } friend bool operator==( exception_ptr const & a, exception_ptr const & b ) { - return - a.what_happened_==ok && - b.what_happened_==ok && - a.c_==b.c_; + return a.c_==b.c_ && a.bad_alloc_==b.bad_alloc_; } friend @@ -171,11 +73,6 @@ boost { return !(a==b); } - - operator unspecified_bool_type() const - { - return (what_happened_!=ok || c_) ? &exception_ptr::c_ : 0; - } }; class @@ -211,7 +108,7 @@ boost void rethrow() const { - throw *this; + throw*this; } }; @@ -288,55 +185,42 @@ boost template inline - exception_ptr + shared_ptr current_exception_std_exception( T const & e1 ) { - intrusive_ptr x(new exception_detail::counted_clone); if( boost::exception const * e2 = get_boost_exception(&e1) ) - x->set(new current_exception_std_exception_wrapper(e1,*e2)); + return shared_ptr(new current_exception_std_exception_wrapper(e1,*e2)); else - x->set(new current_exception_std_exception_wrapper(e1)); - return exception_ptr(x); + return shared_ptr(new current_exception_std_exception_wrapper(e1)); } inline - exception_ptr + shared_ptr current_exception_unknown_exception() { - intrusive_ptr x(new exception_detail::counted_clone); - x->set(new unknown_exception()); - return exception_ptr(x); + return shared_ptr(new unknown_exception()); } inline - exception_ptr + shared_ptr + current_exception_unknown_boost_exception( boost::exception const & e ) + { + return shared_ptr(new unknown_exception(e)); + } + + inline + shared_ptr current_exception_unknown_std_exception( std::exception const & e ) { if( boost::exception const * be = get_boost_exception(&e) ) - { - intrusive_ptr x(new exception_detail::counted_clone); - x->set(new unknown_exception(*be)); - return exception_ptr(x); - } + return current_exception_unknown_boost_exception(*be); else return current_exception_unknown_exception(); } inline - exception_ptr - current_exception_unknown_boost_exception( boost::exception const & e ) - { - intrusive_ptr x(new exception_detail::counted_clone); - x->set(new unknown_exception(e)); - return exception_ptr(x); - } - } - - inline - exception_ptr - current_exception() - { - try + shared_ptr + current_exception_impl() { try { @@ -345,9 +229,7 @@ boost catch( exception_detail::clone_base & e ) { - intrusive_ptr x(new exception_detail::counted_clone); - x->set(e.clone()); - return exception_ptr(x); + return shared_ptr(e.clone()); } catch( std::invalid_argument & e ) @@ -402,16 +284,38 @@ boost return exception_detail::current_exception_unknown_exception(); } } + } + + inline + exception_ptr + current_exception() + { + try + { + return exception_ptr(exception_detail::current_exception_impl()); + } catch( std::bad_alloc & ) { - return exception_ptr( exception_detail::bad_alloc_tag() ); } catch( ... ) { - return exception_ptr( exception_detail::bad_exception_tag() ); + try + { + return exception_ptr(exception_detail::current_exception_std_exception(std::bad_exception())); + } + catch( + std::bad_alloc & ) + { + } + catch( + ... ) + { + BOOST_ASSERT(0); + } } + return exception_ptr(exception_ptr::bad_alloc_tag()); } template @@ -423,7 +327,8 @@ boost { throw enable_current_exception(e); } - catch( ... ) + catch( + ... ) { return current_exception(); } @@ -433,7 +338,11 @@ boost void rethrow_exception( exception_ptr const & p ) { - p.rethrow(); + BOOST_ASSERT(p); + if( p.bad_alloc_ ) + throw enable_current_exception(std::bad_alloc()); + else + p.c_->rethrow(); } } diff --git a/include/boost/throw_exception.hpp b/include/boost/throw_exception.hpp index 0834e9d..94536d3 100644 --- a/include/boost/throw_exception.hpp +++ b/include/boost/throw_exception.hpp @@ -38,6 +38,13 @@ #if !defined( BOOST_NO_EXCEPTIONS ) && !defined( BOOST_EXCEPTION_DISABLE ) # include +# include +# define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(::boost::enable_error_info(x) <<\ + ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ + ::boost::throw_file(__FILE__) <<\ + ::boost::throw_line((int)__LINE__)) +#else +# define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x) #endif namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1d6ea16..5c0591f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -23,7 +23,6 @@ run cloning_test.cpp ; run copy_exception_test.cpp ; run unknown_exception_test.cpp ; run exception_test.cpp ; -run boost_error_info_test.cpp ; run enable_error_info_test.cpp helper1.cpp ; run throw_exception_test.cpp helper2.cpp ; run errno_test.cpp ; diff --git a/test/boost_error_info_test.cpp b/test/boost_error_info_test.cpp deleted file mode 100644 index 3b1b4ac..0000000 --- a/test/boost_error_info_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. - -//Distributed under the Boost Software License, Version 1.0. (See accompanying -//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include - -namespace -test - { - class my_exception: public boost::exception { }; - - typedef boost::error_info my_info; - - void - test_boost_error_info() - { - try - { - throw my_exception() << BOOST_ERROR_INFO << my_info(1); - } - catch( - my_exception & x ) - { - BOOST_TEST(1==*boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - } - } - } - -int -main() - { - test::test_boost_error_info(); - return boost::report_errors(); - } diff --git a/test/diagnostic_information_test.cpp b/test/diagnostic_information_test.cpp index 2d1c39b..596fd56 100644 --- a/test/diagnostic_information_test.cpp +++ b/test/diagnostic_information_test.cpp @@ -11,7 +11,8 @@ typedef boost::error_info tag_int; struct error1: - public std::exception + public std::exception, + public boost::exception { char const * what() const throw() @@ -22,18 +23,6 @@ error1: struct error2: - public std::exception, - public boost::exception - { - char const * - what() const throw() - { - return "error2"; - } - }; - -struct -error3: public boost::exception { }; @@ -44,56 +33,17 @@ main() using namespace boost; try { - error1 x; + error1 x; x << tag_int(42); BOOST_TEST(x.what()==std::string("error1")); throw x; } catch( - std::exception & x ) - { - std::string di=boost::diagnostic_information(x); - BOOST_TEST(di.find("type:")!=std::string::npos); - BOOST_TEST(di.find("error1")!=std::string::npos); - } - catch( - ... ) - { - BOOST_TEST(false); - } - try - { - error2 x; x << tag_int(42); - BOOST_TEST(x.what()==std::string("error2")); - throw x; - } - catch( - std::exception & x ) - { - std::string di=boost::diagnostic_information(x); - BOOST_TEST(di.find("type:")!=std::string::npos); - BOOST_TEST(di.find("error2")!=std::string::npos); -#ifndef BOOST_NO_RTTI - BOOST_TEST(di.find("test_tag")!=std::string::npos); -#endif - } - catch( - ... ) - { - BOOST_TEST(false); - } - try - { - error2 x; x << tag_int(42); - BOOST_TEST(x.what()==std::string("error2")); - throw x; - } - catch( boost::exception & x ) { std::string di=boost::diagnostic_information(x); - BOOST_TEST(di.find("type:")!=std::string::npos); #ifndef BOOST_NO_RTTI - BOOST_TEST(di.find("error2")!=std::string::npos); + BOOST_TEST(di.find("type:")!=std::string::npos); + BOOST_TEST(di.find("error1")!=std::string::npos); #endif BOOST_TEST(di.find("test_tag")!=std::string::npos); } @@ -104,7 +54,7 @@ main() } try { - error3 x; + error2 x; x << tag_int(1); throw x; } diff --git a/test/refcount_ptr_test.cpp b/test/refcount_ptr_test.cpp index 58cadd3..68ccaec 100644 --- a/test/refcount_ptr_test.cpp +++ b/test/refcount_ptr_test.cpp @@ -22,19 +22,17 @@ test_type count_=42; } - friend void - intrusive_ptr_add_ref( test_type const * c ) + add_ref() { - ++c->count_; + ++count_; } - friend void - intrusive_ptr_release( test_type const * c ) + release() { - if( !--c->count_ ) - delete c; + if( !--count_ ) + delete this; } private: diff --git a/test/throw_exception_test.cpp b/test/throw_exception_test.cpp index d4b4615..9397509 100644 --- a/test/throw_exception_test.cpp +++ b/test/throw_exception_test.cpp @@ -11,6 +11,66 @@ typedef boost::error_info test_data; +struct +exception1: + std::exception + { + }; + +struct +exception2: + std::exception, + boost::exception + { + }; + +void +boost_throw_exception_test() + { + try + { + BOOST_THROW_EXCEPTION(exception1()); + BOOST_TEST(false); + } + catch( + boost::exception & x ) + { + boost::shared_ptr file=boost::get_error_info(x); + boost::shared_ptr function=boost::get_error_info(x); + boost::shared_ptr line=boost::get_error_info(x); + BOOST_TEST( file && *file ); + BOOST_TEST( function && *function ); + BOOST_TEST( line && *line==32 ); + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + BOOST_THROW_EXCEPTION(exception2() << test_data(42)); + BOOST_TEST(false); + } + catch( + boost::exception & x ) + { + boost::shared_ptr file=boost::get_error_info(x); + boost::shared_ptr function=boost::get_error_info(x); + boost::shared_ptr line=boost::get_error_info(x); + boost::shared_ptr data=boost::get_error_info(x); + BOOST_TEST( file && *file ); + BOOST_TEST( function && *function ); + BOOST_TEST( line && *line==52 ); + BOOST_TEST( data && *data==42 ); + } + catch( + ... ) + { + BOOST_TEST(false); + } + } + void throw_fwd( void (*thrower)(int) ) { @@ -80,6 +140,7 @@ tester() int main() { + boost_throw_exception_test(); tester(); tester(); tester();