From af4de75bacaf607b0f8cc970cd9bc096f57bc687 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 18 Aug 2014 14:58:41 +0100 Subject: [PATCH 1/4] Add metadata file. --- meta/libraries.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 meta/libraries.json diff --git a/meta/libraries.json b/meta/libraries.json new file mode 100644 index 0000000..a7dd283 --- /dev/null +++ b/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "exception", + "name": "Exception", + "authors": [ + "Emil Dotchevski" + ], + "description": "The Boost Exception library supports transporting of arbitrary data in exception objects, and transporting of exceptions between threads.", + "documentation": "doc/boost-exception.html", + "category": [ + "Emulation" + ], + "maintainers": [ + "Emil Dotchevski " + ] +} From 5a040eedf54691d202e3099033d6d1c5c88a736e Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 24 Mar 2015 15:44:28 -0700 Subject: [PATCH 2/4] rvalue references support in error_info --- .../exception/detail/error_info_impl.hpp | 15 ++- include/boost/exception/info.hpp | 111 ++++++++++++++++ test/Jamfile.v2 | 1 + test/error_info_rv_test.cpp | 122 ++++++++++++++++++ 4 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 test/error_info_rv_test.cpp diff --git a/include/boost/exception/detail/error_info_impl.hpp b/include/boost/exception/detail/error_info_impl.hpp index 12e601b..dbe0afd 100644 --- a/include/boost/exception/detail/error_info_impl.hpp +++ b/include/boost/exception/detail/error_info_impl.hpp @@ -12,6 +12,8 @@ #pragma warning(push,1) #endif +#include +#include #include namespace @@ -41,11 +43,16 @@ boost error_info: public exception_detail::error_info_base { - public: + public: typedef T value_type; error_info( value_type const & value ); +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + error_info( error_info const & ); + error_info( value_type && value ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(value)))); + error_info( error_info && x ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(x.value_)))); +#endif ~error_info() throw(); value_type const & @@ -60,7 +67,11 @@ boost return value_; } - private: + private: + error_info & operator=( error_info const & ); +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + error_info & operator=( error_info && x ); +#endif std::string name_value_string() const; diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index 762a950..b362f48 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -46,6 +46,30 @@ boost { } +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + template + inline + error_info:: + error_info( error_info const & x ): + value_(x.value_) + { + } + template + inline + error_info:: + error_info( value_type && value ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(value)))): + value_(std::move(value)) + { + } + template + inline + error_info:: + error_info( error_info && x ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(x.value_)))): + value_(std::move(x.value_)) + { + } +#endif + template inline error_info:: @@ -175,6 +199,83 @@ boost return x; } +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + template + E const & set_info( E const &, error_info && ); + template + class + set_info_rv > + { + template + friend E const & set_info( E const &, error_info && ); + template + static + E const & + set( E const & x, error_info && v ) + { + typedef error_info error_info_tag_t; + shared_ptr p( new error_info_tag_t(std::move(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 <> + class + set_info_rv + { + template + friend E const & set_info( E const &, error_info && ); + template + static + E const & + set( E const & x, throw_function && y ) + { + x.throw_function_=y.v_; + return x; + } + }; + template <> + class + set_info_rv + { + template + friend E const & set_info( E const &, error_info && ); + template + static + E const & + set( E const & x, throw_file && y ) + { + x.throw_file_=y.v_; + return x; + } + }; + template <> + class + set_info_rv + { + template + friend E const & set_info( E const &, error_info && ); + template + static + E const & + set( E const & x, throw_line && y ) + { + x.throw_line_=y.v_; + return x; + } + }; + template + inline + E const & + set_info( E const & x, error_info && v ) + { + return set_info_rv >::template set(x,std::move(v)); + } +#endif + template struct derives_boost_exception @@ -190,6 +291,16 @@ boost { return exception_detail::set_info(x,v); } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + template + inline + typename enable_if,E const &>::type + operator<<( E const & x, error_info && v ) + { + return exception_detail::set_info(x,std::move(v)); + } +#endif } #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d2dfcd6..dceba8e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -35,6 +35,7 @@ run enable_error_info_test.cpp helper1.cpp ; run throw_exception_test.cpp helper2.cpp ; run errno_test.cpp ; run error_info_test.cpp ; +run error_info_rv_test.cpp ; run diagnostic_information_test.cpp ; run refcount_ptr_test.cpp ; run current_exception_cast_test.cpp ; diff --git a/test/error_info_rv_test.cpp b/test/error_info_rv_test.cpp new file mode 100644 index 0000000..40f975f --- /dev/null +++ b/test/error_info_rv_test.cpp @@ -0,0 +1,122 @@ +//Copyright (c) 2006-2009 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 +#include + +#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES +int +main() + { + BOOST_FAIL("Platform does not support rvalue references."); + return 1; + } +#else +struct move_only; +typedef boost::error_info test1; +struct +test_exception: + boost::exception + { + }; +struct +move_only + { + explicit move_only(int x) : x_(x) { } + move_only( move_only && other ) : x_(other.x_) { } + int x_; + private: + move_only( move_only const & ); + }; +void +throw_test1() + { + throw test_exception() << test1(move_only(7)); + } +void +throw_test_throw_file_rv() + { + throw test_exception() << std::move(boost::throw_file("throw_file")); + } +void +throw_test_throw_function_rv() + { + throw test_exception() << std::move(boost::throw_function("throw_function")); + } +void +throw_test_throw_line_rv() + { + throw test_exception() << std::move(boost::throw_line(42)); + } +int +main() + { + try + { + throw_test1(); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(boost::get_error_info(x)); + BOOST_TEST(boost::get_error_info(x)->x_ == 7); + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + throw_test_throw_function_rv(); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(boost::get_error_info(x) && !strcmp(*boost::get_error_info(x),"throw_function")); + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + throw_test_throw_file_rv(); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(boost::get_error_info(x) && !strcmp(*boost::get_error_info(x),"throw_file")); + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + throw_test_throw_line_rv(); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(boost::get_error_info(x) && *boost::get_error_info(x)==42); + } + catch( + ... ) + { + BOOST_TEST(false); + } + return boost::report_errors(); + } +#endif From c57eefbf4252aa98a76ea5653640010a8a4c6f67 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Wed, 25 Mar 2015 14:28:54 -0700 Subject: [PATCH 3/4] More complete error_info testing --- test/Jamfile.v2 | 4 +- test/error_info_lv_const_test.cpp | 13 ++ test/error_info_lv_test.cpp | 13 ++ test/error_info_rv_const_test.cpp | 28 +++++ test/error_info_rv_test.cpp | 118 ++---------------- ...rror_info_test.cpp => error_info_test.hpp} | 30 ++--- 6 files changed, 81 insertions(+), 125 deletions(-) create mode 100644 test/error_info_lv_const_test.cpp create mode 100644 test/error_info_lv_test.cpp create mode 100644 test/error_info_rv_const_test.cpp rename test/{error_info_test.cpp => error_info_test.hpp} (88%) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dceba8e..e7cf00d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -34,8 +34,10 @@ run exception_test.cpp ; run enable_error_info_test.cpp helper1.cpp ; run throw_exception_test.cpp helper2.cpp ; run errno_test.cpp ; -run error_info_test.cpp ; +run error_info_lv_test.cpp ; +run error_info_lv_const_test.cpp ; run error_info_rv_test.cpp ; +run error_info_rv_const_test.cpp ; run diagnostic_information_test.cpp ; run refcount_ptr_test.cpp ; run current_exception_cast_test.cpp ; diff --git a/test/error_info_lv_const_test.cpp b/test/error_info_lv_const_test.cpp new file mode 100644 index 0000000..c79f97a --- /dev/null +++ b/test/error_info_lv_const_test.cpp @@ -0,0 +1,13 @@ +//Copyright (c) 2006-2015 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 "boost/exception/info.hpp" +template +E const & +add_info( E const & e, I const & i ) + { + return e << i; + } +#include "error_info_test.hpp" diff --git a/test/error_info_lv_test.cpp b/test/error_info_lv_test.cpp new file mode 100644 index 0000000..994b941 --- /dev/null +++ b/test/error_info_lv_test.cpp @@ -0,0 +1,13 @@ +//Copyright (c) 2006-2015 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 "boost/exception/info.hpp" +template +E const & +add_info( E const & e, I i ) + { + return e << i; + } +#include "error_info_test.hpp" diff --git a/test/error_info_rv_const_test.cpp b/test/error_info_rv_const_test.cpp new file mode 100644 index 0000000..2906061 --- /dev/null +++ b/test/error_info_rv_const_test.cpp @@ -0,0 +1,28 @@ +//Copyright (c) 2006-2015 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 "boost/exception/info.hpp" + +#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES +int +main() + { + return 0; + } +#else +template +I const +rv_const( I i ) + { + return i; + } +template +E const & +add_info( E const & e, I i ) + { + return e << rv_const(i); + } +#include "error_info_test.hpp" +#endif diff --git a/test/error_info_rv_test.cpp b/test/error_info_rv_test.cpp index 40f975f..433be92 100644 --- a/test/error_info_rv_test.cpp +++ b/test/error_info_rv_test.cpp @@ -1,122 +1,22 @@ -//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. +//Copyright (c) 2006-2015 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 -#include +#include "boost/exception/info.hpp" #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES int main() - { - BOOST_FAIL("Platform does not support rvalue references."); - return 1; + { + return 0; } #else -struct move_only; -typedef boost::error_info test1; -struct -test_exception: - boost::exception - { - }; -struct -move_only - { - explicit move_only(int x) : x_(x) { } - move_only( move_only && other ) : x_(other.x_) { } - int x_; - private: - move_only( move_only const & ); - }; -void -throw_test1() - { - throw test_exception() << test1(move_only(7)); - } -void -throw_test_throw_file_rv() +template +E const & +add_info( E const & e, I i ) { - throw test_exception() << std::move(boost::throw_file("throw_file")); + return e << std::move(i); } -void -throw_test_throw_function_rv() - { - throw test_exception() << std::move(boost::throw_function("throw_function")); - } -void -throw_test_throw_line_rv() - { - throw test_exception() << std::move(boost::throw_line(42)); - } -int -main() - { - try - { - throw_test1(); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)->x_ == 7); - } - catch( - ... ) - { - BOOST_TEST(false); - } - try - { - throw_test_throw_function_rv(); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(boost::get_error_info(x) && !strcmp(*boost::get_error_info(x),"throw_function")); - } - catch( - ... ) - { - BOOST_TEST(false); - } - try - { - throw_test_throw_file_rv(); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(boost::get_error_info(x) && !strcmp(*boost::get_error_info(x),"throw_file")); - } - catch( - ... ) - { - BOOST_TEST(false); - } - try - { - throw_test_throw_line_rv(); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(boost::get_error_info(x) && *boost::get_error_info(x)==42); - } - catch( - ... ) - { - BOOST_TEST(false); - } - return boost::report_errors(); - } +#include "error_info_test.hpp" #endif diff --git a/test/error_info_test.cpp b/test/error_info_test.hpp similarity index 88% rename from test/error_info_test.cpp rename to test/error_info_test.hpp index f3dda1a..8648362 100644 --- a/test/error_info_test.cpp +++ b/test/error_info_test.hpp @@ -1,4 +1,4 @@ -//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. +//Copyright (c) 2006-2015 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) @@ -69,7 +69,7 @@ basic_test() try { test_exception x; - x << test_1(1) << test_2(2u) << test_3(3.14159f); + add_info(add_info(add_info(x,test_1(1)),test_2(2u)),test_3(3.14159f)); throw x; } catch( @@ -86,7 +86,7 @@ basic_test() try { test_exception x; - x << test_1(1) << test_2(2u) << test_3(3.14159f); + add_info(add_info(add_info(x,test_1(1)),test_2(2u)),test_3(3.14159f)); throw x; } catch( @@ -105,7 +105,7 @@ exception_safety_test() test_exception x; try { - x << test_4(throws_on_copy()); + add_info(x,test_4(throws_on_copy())); BOOST_TEST(false); } catch( @@ -124,13 +124,13 @@ throw_empty() void throw_test_1( char const * value ) { - throw test_exception() << test_5(std::string(value)); + throw add_info(test_exception(),test_5(std::string(value))); } void throw_test_2() { - throw test_exception() << test_6(non_printable()); + throw add_info(test_exception(),test_6(non_printable())); } void @@ -144,7 +144,7 @@ throw_catch_add_file_name( char const * name ) catch( boost::exception & x ) { - x << test_5(std::string(name)); + add_info(x,test_5(std::string(name))); throw; } } @@ -256,10 +256,10 @@ test_add_tuple() typedef boost::tuple tuple_test_1235; try { - throw test_exception() << tuple_test_(); + throw add_info(test_exception(),tuple_test_()); } catch( - test_exception & x ) + test_exception & ) { } catch( @@ -269,7 +269,7 @@ test_add_tuple() } try { - throw test_exception() << tuple_test_1(42); + throw add_info(test_exception(),tuple_test_1(42)); } catch( test_exception & x ) @@ -283,7 +283,7 @@ test_add_tuple() } try { - throw test_exception() << tuple_test_12(42,42u); + throw add_info(test_exception(),tuple_test_12(42,42u)); } catch( test_exception & x ) @@ -298,7 +298,7 @@ test_add_tuple() } try { - throw test_exception() << tuple_test_123(42,42u,42.0f); + throw add_info(test_exception(),tuple_test_123(42,42u,42.0f)); } catch( test_exception & x ) @@ -314,7 +314,7 @@ test_add_tuple() } try { - throw test_exception() << tuple_test_1235(42,42u,42.0f,std::string("42")); + throw add_info(test_exception(),tuple_test_1235(42,42u,42.0f,std::string("42"))); } catch( test_exception & x ) @@ -337,7 +337,7 @@ test_lifetime1() int count=0; try { - throw test_exception() << test_7(user_data(count)); + throw add_info(test_exception(),test_7(user_data(count))); } catch( boost::exception & x ) @@ -359,7 +359,7 @@ test_lifetime2() int count=0; { boost::exception_ptr ep; - test_exception e; e<0); } From 1afb7e0372359d26df813280f6448180ff0dac24 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 31 May 2016 14:46:13 -0700 Subject: [PATCH 4/4] Ticket #12230 --- include/boost/exception/errinfo_errno.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/exception/errinfo_errno.hpp b/include/boost/exception/errinfo_errno.hpp index 2cf7cab..612ae5e 100644 --- a/include/boost/exception/errinfo_errno.hpp +++ b/include/boost/exception/errinfo_errno.hpp @@ -10,6 +10,7 @@ #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma warning(push,1) +#pragma warning(disable:4996) #endif #include "boost/exception/info.hpp"