From 0cebd7efbf49a14b343a7e62406a83c2eb15bf60 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Thu, 18 Feb 2010 05:58:00 +0000 Subject: [PATCH] Fixing problems found by the vacpp test. [SVN r59743] --- .../exception/detail/is_output_streamable.hpp | 17 +++- include/boost/exception/exception.hpp | 84 ++++++++++--------- include/boost/exception/info.hpp | 31 +++++-- include/boost/throw_exception.hpp | 24 +++++- test/is_output_streamable_test.cpp | 18 ++-- 5 files changed, 115 insertions(+), 59 deletions(-) diff --git a/include/boost/exception/detail/is_output_streamable.hpp b/include/boost/exception/detail/is_output_streamable.hpp index 5eb1695..743313c 100644 --- a/include/boost/exception/detail/is_output_streamable.hpp +++ b/include/boost/exception/detail/is_output_streamable.hpp @@ -20,8 +20,21 @@ boost namespace to_string_detail { - template - char operator<<( std::basic_ostream &, T const & ); + struct + partial_ordering_helper1 + { + template + partial_ordering_helper1( std::basic_ostream & ); + }; + + struct + partial_ordering_helper2 + { + template + partial_ordering_helper2( T const & ); + }; + + char operator<<( partial_ordering_helper1, partial_ordering_helper2 ); template struct diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp index bd86b76..82ff23a 100644 --- a/include/boost/exception/exception.hpp +++ b/include/boost/exception/exception.hpp @@ -132,18 +132,6 @@ boost } }; - template - E const & operator<<( E const &, error_info const & ); - - template - E const & operator<<( E const &, throw_function const & ); - - template - E const & operator<<( E const &, throw_file const & ); - - template - E const & operator<<( E const &, throw_line const & ); - class exception; template @@ -187,6 +175,18 @@ boost char const * get_diagnostic_information( exception const &, char const * ); void copy_boost_exception( exception *, exception const * ); + + template + E const & set_info( E const &, error_info const & ); + + template + E const & set_info( E const &, throw_function const & ); + + template + E const & set_info( E const &, throw_file const & ); + + template + E const & set_info( E const &, throw_line const & ); } class @@ -225,18 +225,18 @@ boost private: template - friend E const & operator<<( E const &, throw_function const & ); + friend E const & exception_detail::set_info( E const &, throw_function const & ); template - friend E const & operator<<( E const &, throw_file const & ); + friend E const & exception_detail::set_info( E const &, throw_file const & ); template - friend E const & operator<<( E const &, throw_line const & ); - - friend char const * exception_detail::get_diagnostic_information( exception const &, char const * ); + friend E const & exception_detail::set_info( E const &, throw_line const & ); template - friend E const & operator<<( E const &, error_info const & ); + friend E const & exception_detail::set_info( E const &, error_info const & ); + + friend char const * exception_detail::get_diagnostic_information( exception const &, char const * ); template friend struct exception_detail::get_info; @@ -257,28 +257,32 @@ boost { } - template - E const & - operator<<( E const & x, throw_function const & y ) + namespace + exception_detail { - x.throw_function_=y.v_; - return x; - } + template + E const & + set_info( E const & x, throw_function const & y ) + { + x.throw_function_=y.v_; + return x; + } - template - E const & - operator<<( E const & x, throw_file const & y ) - { - x.throw_file_=y.v_; - return x; - } + template + E const & + set_info( E const & x, throw_file const & y ) + { + x.throw_file_=y.v_; + return x; + } - template - E const & - operator<<( E const & x, throw_line const & y ) - { - x.throw_line_=y.v_; - return x; + template + E const & + set_info( E const & x, throw_line const & y ) + { + x.throw_line_=y.v_; + return x; + } } //////////////////////////////////////////////////////////////////////// @@ -304,10 +308,10 @@ boost }; struct large_size { char c[256]; }; - large_size dispatch( exception * ); + large_size dispatch_boost_exception( exception const * ); struct small_size { }; - small_size dispatch( void * ); + small_size dispatch_boost_exception( void const * ); template struct enable_error_info_helper; @@ -330,7 +334,7 @@ boost struct enable_error_info_return_type { - typedef typename enable_error_info_helper::type type; + typedef typename enable_error_info_helper::type type; }; } diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index 8c393a6..7aeeee5 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -157,20 +157,35 @@ boost return p; } }; + + template + inline + E const & + set_info( E const & x, error_info const & v ) + { + typedef error_info error_info_tag_t; + shared_ptr p( new error_info_tag_t(v) ); + exception_detail::error_info_container * c=x.data_.get(); + if( !c ) + x.data_.adopt(c=new exception_detail::error_info_container_impl); + c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t)); + return x; + } + + template + struct + derives_boost_exception + { + enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) }; + }; } template inline - E const & + typename enable_if,E const &>::type operator<<( E const & x, error_info const & v ) { - typedef error_info error_info_tag_t; - shared_ptr p( new error_info_tag_t(v) ); - exception_detail::error_info_container * c=x.data_.get(); - if( !c ) - 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 exception_detail::set_info(x,v); } } diff --git a/include/boost/throw_exception.hpp b/include/boost/throw_exception.hpp index 656b8de..1d018c5 100644 --- a/include/boost/throw_exception.hpp +++ b/include/boost/throw_exception.hpp @@ -36,16 +36,32 @@ #if !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(__LINE__)) +# define BOOST_THROW_EXCEPTION(x) ::boost::exception_detail::throw_exception_(x,BOOST_CURRENT_FUNCTION,__FILE__,__LINE__) #else # define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x) #endif namespace boost { +#if !defined( BOOST_EXCEPTION_DISABLE ) + namespace + exception_detail + { + template + void + throw_exception_( E const & x, char const * current_function, char const * file, int line ) + { + throw_exception( + set_info( + set_info( + set_info( + enable_error_info(x), + throw_function(current_function)), + throw_file(file)), + throw_line(line))); + } + } +#endif #ifdef BOOST_NO_EXCEPTIONS diff --git a/test/is_output_streamable_test.cpp b/test/is_output_streamable_test.cpp index cb030b7..b0fe2c4 100644 --- a/test/is_output_streamable_test.cpp +++ b/test/is_output_streamable_test.cpp @@ -4,7 +4,6 @@ //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include namespace n1 @@ -31,11 +30,20 @@ n2 } } +template +struct test; + +template <> +struct +test + { + }; + int main() { - BOOST_TEST( !boost::is_output_streamable::value ); - BOOST_TEST( boost::is_output_streamable::value ); - BOOST_TEST( boost::is_output_streamable::value ); - return boost::report_errors(); + test::value>(); + test::value>(); + test::value>(); + return 0; }