diff --git a/include/boost/throw_exception.hpp b/include/boost/throw_exception.hpp index 6a68a1b..1699a61 100644 --- a/include/boost/throw_exception.hpp +++ b/include/boost/throw_exception.hpp @@ -20,6 +20,7 @@ // http://www.boost.org/libs/throw_exception // +#include #include #include #include @@ -32,29 +33,12 @@ namespace boost { -// All boost exceptions are required to derive from std::exception, -// to ensure compatibility with BOOST_NO_EXCEPTIONS. - -inline void throw_exception_assert_compatibility( std::exception const & ) {} - -} // namespace boost - #if defined( BOOST_NO_EXCEPTIONS ) -namespace boost -{ - BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined BOOST_NORETURN void throw_exception( std::exception const & e, boost::source_location const & loc ); // user defined -} // namespace boost - -#else // !defined( BOOST_NO_EXCEPTIONS ) - -#include - -namespace boost -{ +#endif // boost::wrapexcept @@ -134,17 +118,29 @@ public: virtual void rethrow() const BOOST_OVERRIDE { +#if defined( BOOST_NO_EXCEPTIONS ) + + boost::throw_exception( *this ); + +#else + throw *this; + +#endif } }; -} // namespace boost +// All boost exceptions are required to derive from std::exception, +// to ensure compatibility with BOOST_NO_EXCEPTIONS. + +inline void throw_exception_assert_compatibility( std::exception const & ) {} + +// boost::throw_exception + +#if !defined( BOOST_NO_EXCEPTIONS ) #if defined( BOOST_EXCEPTION_DISABLE ) -namespace boost -{ - template BOOST_NORETURN void throw_exception( E const & e ) { throw_exception_assert_compatibility( e ); @@ -157,13 +153,7 @@ template BOOST_NORETURN void throw_exception( E const & e, boost::sourc throw e; } -} // namespace boost - -#else // !defined( BOOST_EXCEPTION_DISABLE ) - -namespace boost -{ -// boost::throw_exception +#else // defined( BOOST_EXCEPTION_DISABLE ) template BOOST_NORETURN void throw_exception( E const & e ) { @@ -177,12 +167,12 @@ template BOOST_NORETURN void throw_exception( E const & e, boost::sourc throw wrapexcept( e, loc ); } +#endif // defined( BOOST_EXCEPTION_DISABLE ) + +#endif // !defined( BOOST_NO_EXCEPTIONS ) + } // namespace boost -#endif // # if defined( BOOST_EXCEPTION_DISABLE ) - -#endif // # if defined( BOOST_NO_EXCEPTIONS ) - // BOOST_THROW_EXCEPTION #define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ce0523b..99f2963 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -37,6 +37,10 @@ run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw : : : sha run throw_exception_nx_test.cpp : : : off ; run throw_exception_nx_test2.cpp : : : off ; +run throw_exception_nx_test3.cpp : : : off ; run make_exception_ptr_test.cpp ; run make_exception_ptr_test2.cpp ; + +run make_exception_ptr_nx_test.cpp : : : off ; +run make_exception_ptr_nx_test2.cpp : : : off ; diff --git a/test/make_exception_ptr_nx_test.cpp b/test/make_exception_ptr_nx_test.cpp new file mode 100644 index 0000000..e612013 --- /dev/null +++ b/test/make_exception_ptr_nx_test.cpp @@ -0,0 +1,40 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#if defined(_MSC_VER) +# pragma warning(disable: 4702) // unreachable code +# pragma warning(disable: 4577) // noexcept used without /EHsc +#endif + +//#include + +#include +#include +#include +#include + +typedef boost::shared_ptr exception_ptr; + +template exception_ptr make_exception_ptr( E const& e ) +{ + return boost::make_shared< boost::wrapexcept >( e ); +} + +class my_exception: public std::exception {}; + +int main() +{ + ::make_exception_ptr( my_exception() ); +} + +namespace boost +{ + +// shared_ptr needs this +void throw_exception( std::exception const & ) +{ + std::exit( 1 ); +} + +} // namespace boost diff --git a/test/make_exception_ptr_nx_test2.cpp b/test/make_exception_ptr_nx_test2.cpp new file mode 100644 index 0000000..09927f8 --- /dev/null +++ b/test/make_exception_ptr_nx_test2.cpp @@ -0,0 +1,42 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#if defined(_MSC_VER) +# pragma warning(disable: 4702) // unreachable code +# pragma warning(disable: 4577) // noexcept used without /EHsc +#endif + +#define BOOST_EXCEPTION_DISABLE + +//#include + +#include +#include +#include +#include + +typedef boost::shared_ptr exception_ptr; + +template exception_ptr make_exception_ptr( E const& e ) +{ + return boost::make_shared< boost::wrapexcept >( e ); +} + +class my_exception: public std::exception {}; + +int main() +{ + ::make_exception_ptr( my_exception() ); +} + +namespace boost +{ + +// shared_ptr needs this +void throw_exception( std::exception const & ) +{ + std::exit( 1 ); +} + +} // namespace boost diff --git a/test/throw_exception_nx_test3.cpp b/test/throw_exception_nx_test3.cpp new file mode 100644 index 0000000..ce8aa6d --- /dev/null +++ b/test/throw_exception_nx_test3.cpp @@ -0,0 +1,17 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#if defined(_MSC_VER) +# pragma warning(disable: 4702) // unreachable code +# pragma warning(disable: 4577) // noexcept used without /EHsc +#endif + +// Make sure that simple inclusion does not +// require boost::throw_exception to be defined + +#include + +int main() +{ +}