From 6fa94b5aa3af06c76ca28e50baf046840747308c Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Sun, 30 Aug 2020 22:16:52 -0700 Subject: [PATCH] Fixed bug in detection of std::uncaught_exceptions --- examples/lua_callback_result.cpp | 19 +++++++++++++++++++ include/boost/leaf.hpp | 6 +++--- include/boost/leaf/detail/config.hpp | 4 +++- include/boost/leaf/detail/print.hpp | 1 - include/boost/leaf/exception.hpp | 1 - test/match_member_test.cpp | 1 - test/match_test.cpp | 1 - test/match_value_test.cpp | 1 - test/multiple_errors_test.cpp | 1 - 9 files changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/lua_callback_result.cpp b/examples/lua_callback_result.cpp index 1d7f457..6c5eb79 100644 --- a/examples/lua_callback_result.cpp +++ b/examples/lua_callback_result.cpp @@ -135,3 +135,22 @@ int main() return 0; } + +#ifdef BOOST_LEAF_NO_EXCEPTIONS + +namespace boost +{ + BOOST_LEAF_NORETURN void throw_exception( std::exception const & e ) + { + std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what(); + std::terminate(); + } + + struct source_location; + BOOST_LEAF_NORETURN void throw_exception( std::exception const & e, boost::source_location const & ) + { + throw_exception(e); + } +} + +#endif diff --git a/include/boost/leaf.hpp b/include/boost/leaf.hpp index df7c67e..965e63e 100644 --- a/include/boost/leaf.hpp +++ b/include/boost/leaf.hpp @@ -532,6 +532,8 @@ namespace boost { namespace leaf { // (C) Copyright Martin Wille 2003. // (C) Copyright Guillaume Melquiond 2003. +#include + #ifndef BOOST_LEAF_ENABLE_WARNINGS # if defined(__clang__) # pragma clang system_header @@ -684,7 +686,7 @@ namespace boost { namespace leaf { //////////////////////////////////////// -#if __cplusplus > 201402L +#if (defined(__cpp_lib_uncaught_exceptions) && __cpp_lib_uncaught_exceptions >= 201411L) || (defined(_MSC_VER) && _MSC_VER >= 1900) # define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 1 #else # define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 0 @@ -867,7 +869,6 @@ namespace boost { namespace leaf { #endif // <<< #include #line 20 "boost/leaf/detail/print.hpp" -#include #include #include @@ -1724,7 +1725,6 @@ namespace boost { namespace leaf { #endif // <<< #include #line 20 "boost/leaf/exception.hpp" -#include #define BOOST_LEAF_EXCEPTION ::boost::leaf::leaf_detail::inject_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception #define BOOST_LEAF_THROW_EXCEPTION ::boost::leaf::leaf_detail::throw_with_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception diff --git a/include/boost/leaf/detail/config.hpp b/include/boost/leaf/detail/config.hpp index 6edac63..4ad7bc3 100644 --- a/include/boost/leaf/detail/config.hpp +++ b/include/boost/leaf/detail/config.hpp @@ -12,6 +12,8 @@ // (C) Copyright Martin Wille 2003. // (C) Copyright Guillaume Melquiond 2003. +#include + #ifndef BOOST_LEAF_ENABLE_WARNINGS # if defined(__clang__) # pragma clang system_header @@ -164,7 +166,7 @@ //////////////////////////////////////// -#if __cplusplus > 201402L +#if (defined(__cpp_lib_uncaught_exceptions) && __cpp_lib_uncaught_exceptions >= 201411L) || (defined(_MSC_VER) && _MSC_VER >= 1900) # define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 1 #else # define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 0 diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index 98954c4..25cbb1c 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -17,7 +17,6 @@ #endif #include -#include #include #include diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index b71f432..b63aed5 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -17,7 +17,6 @@ #endif #include -#include #define BOOST_LEAF_EXCEPTION ::boost::leaf::leaf_detail::inject_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception #define BOOST_LEAF_THROW_EXCEPTION ::boost::leaf::leaf_detail::throw_with_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception diff --git a/test/match_member_test.cpp b/test/match_member_test.cpp index 7563e62..d7d1abf 100644 --- a/test/match_member_test.cpp +++ b/test/match_member_test.cpp @@ -18,7 +18,6 @@ int main() #include #include #include -#include #include "_test_ec.hpp" #include "lightweight_test.hpp" diff --git a/test/match_test.cpp b/test/match_test.cpp index 4835dbc..d05a1c3 100644 --- a/test/match_test.cpp +++ b/test/match_test.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "_test_ec.hpp" #include "lightweight_test.hpp" diff --git a/test/match_value_test.cpp b/test/match_value_test.cpp index cc3cb9b..f5e5452 100644 --- a/test/match_value_test.cpp +++ b/test/match_value_test.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "_test_ec.hpp" #include "lightweight_test.hpp" diff --git a/test/multiple_errors_test.cpp b/test/multiple_errors_test.cpp index 665d487..b36af89 100644 --- a/test/multiple_errors_test.cpp +++ b/test/multiple_errors_test.cpp @@ -7,7 +7,6 @@ #include #include -#include #include "lightweight_test.hpp" namespace leaf = boost::leaf;