From 941754ed239de94d484ab4286d4d1a4ab89ec48d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 26 Jan 2022 01:07:46 +0200 Subject: [PATCH 1/3] Add exception_ptr_test2.cpp --- test/Jamfile.v2 | 1 + test/exception_ptr_test2.cpp | 107 +++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 test/exception_ptr_test2.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 90345bb..683b14b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -41,6 +41,7 @@ run no_exceptions_test.cpp : : : off ; run errinfos_test.cpp : : : on ; run exception_ptr_test.cpp/BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR ../../thread/src/tss_null.cpp /boost/exception /boost//thread : : : multi on : non_intrusive_exception_ptr_test ; run exception_ptr_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : multi on ; +run exception_ptr_test2.cpp ; lib visibility_test_lib : visibility_test_lib.cpp : hidden on ; run visibility_test.cpp visibility_test_lib/shared : : : hidden on ; diff --git a/test/exception_ptr_test2.cpp b/test/exception_ptr_test2.cpp new file mode 100644 index 0000000..6001d7e --- /dev/null +++ b/test/exception_ptr_test2.cpp @@ -0,0 +1,107 @@ +// Copyright 2022 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +#if defined(BOOST_NO_CXX11_HDR_EXCEPTION) + +#include +BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_EXCEPTION is defined" ) + +int main() {} + +#else + +#include +#include +#include +#include +#include +#include + +class my_exception +{ +}; + +class my_exception2: public std::exception +{ +}; + +class my_exception3: public std::bad_alloc +{ +}; + +class my_exception4: public std::exception, public boost::exception +{ +}; + +class my_exception5: public std::logic_error, public virtual boost::exception +{ +public: + + my_exception5(): std::logic_error( "" ) {} +}; + +int main() +{ + try + { + throw my_exception(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception ); + } + + try + { + throw my_exception2(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::exception ); + } + + try + { + throw my_exception3(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception3 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::bad_alloc ); + } + + try + { + throw my_exception4(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception4 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::exception ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + try + { + throw my_exception5(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception5 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::logic_error ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + return boost::report_errors(); +} + +#endif From eafe6dbd5c5b18f39a77b758f83f44a304b828ed Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 26 Jan 2022 01:12:54 +0200 Subject: [PATCH 2/3] Prefer using std::current_exception when available (refs #42) --- include/boost/exception/detail/exception_ptr.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index c3b97b9..53e3793 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -385,6 +385,9 @@ boost { return exception_ptr(shared_ptr(e.clone())); } + +#ifdef BOOST_NO_CXX11_HDR_EXCEPTION + catch( std::domain_error & e ) { @@ -457,19 +460,19 @@ boost { return exception_detail::current_exception_std_exception(e); } -#ifdef BOOST_NO_CXX11_HDR_EXCEPTION - // this case can be handled losslesly with std::current_exception() (see below) catch( std::exception & e ) { return exception_detail::current_exception_unknown_std_exception(e); } -#endif catch( boost::exception & e ) { return exception_detail::current_exception_unknown_boost_exception(e); } + +#endif // #ifdef BOOST_NO_CXX11_HDR_EXCEPTION + catch( ... ) { From 9259706f08995f964cffb17c6c0692bff1aec5e9 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 26 Jan 2022 01:49:45 +0200 Subject: [PATCH 3/3] Disable exception_ptr_test2 when exceptions aren't enabled --- test/exception_ptr_test2.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/exception_ptr_test2.cpp b/test/exception_ptr_test2.cpp index 6001d7e..143b917 100644 --- a/test/exception_ptr_test2.cpp +++ b/test/exception_ptr_test2.cpp @@ -4,7 +4,14 @@ #include -#if defined(BOOST_NO_CXX11_HDR_EXCEPTION) +#if defined(BOOST_NO_EXCEPTIONS) + +#include +BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_EXCEPTIONS is defined" ) + +int main() {} + +#elif defined(BOOST_NO_CXX11_HDR_EXCEPTION) #include BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_EXCEPTION is defined" )