diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index e774704d..2bf7c44d 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -34,8 +34,6 @@ namespace leaf_detail #else -#include - namespace boost { namespace leaf { namespace leaf_detail @@ -45,19 +43,6 @@ namespace leaf_detail { throw std::move(e); } - - class exception_id_bump - { - std::shared_ptr auto_id_bump_; - protected: - - exception_id_bump(): - auto_id_bump_(nullptr, [](void const *) { (void) new_id(); }) - { - } - - ~exception_id_bump() noexcept { } - }; } } } @@ -98,9 +83,6 @@ namespace leaf_detail public Ex, public exception_base, public error_id -#ifndef BOOST_LEAF_NO_EXCEPTIONS - ,exception_id_bump -#endif { error_id get_error_id() const noexcept final override { @@ -117,7 +99,14 @@ namespace leaf_detail public: exception( exception const & ) = default; - exception( exception && ) = default; + + exception( exception && other ) noexcept: + Ex(std::move(other)), + exception_base(std::move(other)), + error_id(std::move(other)) + { + static_cast(other) = error_id(); + } exception( error_id id, Ex const & ex ) noexcept: Ex(ex), @@ -138,6 +127,12 @@ namespace leaf_detail { enforce_std_exception(*this); } + + ~exception() noexcept + { + if( current_error() == *this ) + tls::write_uint(0); + } }; template diff --git a/test/diagnostics_test1.cpp b/test/diagnostics_test1.cpp index 32f2fca6..c9e99088 100644 --- a/test/diagnostics_test1.cpp +++ b/test/diagnostics_test1.cpp @@ -458,7 +458,7 @@ int main() std::cout << s << std::endl; if( BOOST_LEAF_CFG_DIAGNOSTICS ) BOOST_TEST(cmp(s, - "Error serial #7\n" + "Error serial #6\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -472,7 +472,7 @@ int main() )); else BOOST_TEST(cmp(s, - "Error serial #7\n" + "Error serial #6\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -517,7 +517,7 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #9\n" + "Error serial #7\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -534,7 +534,7 @@ int main() )); else BOOST_TEST(cmp(s, - "Error serial #9\n" + "Error serial #7\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -549,7 +549,7 @@ int main() )); else BOOST_TEST(cmp(s, - "Error serial #9\n" + "Error serial #7\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -584,7 +584,7 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #11\n" + "Error serial #8\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what\n" @@ -601,7 +601,7 @@ int main() )); else BOOST_TEST(cmp(s, - "Error serial #11\n" + "Error serial #8\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" @@ -609,7 +609,7 @@ int main() )); else BOOST_TEST(cmp(s, - "Error serial #11\n" + "Error serial #8\n" "Caught C++ exception:" "\n\tType: " "\n\tstd::exception::what(): my_exception what" diff --git a/test/on_error_preload_exception_test.cpp b/test/on_error_preload_exception_test.cpp index 84f4cdf0..355d01d2 100644 --- a/test/on_error_preload_exception_test.cpp +++ b/test/on_error_preload_exception_test.cpp @@ -97,7 +97,7 @@ int main() }, []( leaf::error_info const & err, info<2>, info<3> ) { - BOOST_TEST_EQ(err.error().value(), 13); + BOOST_TEST_EQ(err.error().value(), 9); return 2; }, []( info<1>, info<2> ) @@ -114,7 +114,7 @@ int main() }, []( leaf::error_info const & err, info<1> ) { - BOOST_TEST_EQ(err.error().value(), 21); + BOOST_TEST_EQ(err.error().value(), 13); return 1; }, []( info<2> ) @@ -139,7 +139,7 @@ int main() }, []( leaf::error_info const & err, info<2>, info<3> ) { - BOOST_TEST_EQ(err.error().value(), 25); + BOOST_TEST_EQ(err.error().value(), 17); return 2; }, []( info<1>, info<2> )