diff --git a/doc/changelog.qbk b/doc/changelog.qbk index 303f163..bd93db4 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -17,6 +17,7 @@ Not yet released * Fixed move-only type support in constraints * Added support for dereferencing in mock::equal * Added support for movable objects in mock::retrieve +* Fixed deprecation warning about std::uncaught_exception in c++17 for msvc [endsect] diff --git a/include/turtle/config.hpp b/include/turtle/config.hpp index 5d2f78e..96a11c8 100644 --- a/include/turtle/config.hpp +++ b/include/turtle/config.hpp @@ -94,4 +94,11 @@ # endif #endif +#if defined(__cplusplus) && (__cplusplus >= 201703L) || \ + defined(_MSC_VER) && (_MSC_VER >= 1900) +# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS +# define MOCK_UNCAUGHT_EXCEPTIONS +# endif +#endif + #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/include/turtle/detail/function.hpp b/include/turtle/detail/function.hpp index 837b169..a631310 100644 --- a/include/turtle/detail/function.hpp +++ b/include/turtle/detail/function.hpp @@ -86,6 +86,15 @@ namespace detail E* e_; }; + + inline int uncaught_exceptions() + { +#ifdef MOCK_UNCAUGHT_EXCEPTIONS + return std::uncaught_exceptions(); +#else + return std::uncaught_exception() ? 1 : 0; +#endif + } } } // mock diff --git a/include/turtle/detail/function_impl_template.hpp b/include/turtle/detail/function_impl_template.hpp index 044195f..2a8d74a 100644 --- a/include/turtle/detail/function_impl_template.hpp +++ b/include/turtle/detail/function_impl_template.hpp @@ -44,10 +44,11 @@ namespace detail : context_( 0 ) , valid_( true ) , mutex_( boost::make_shared< mutex >() ) + , exceptions_( uncaught_exceptions() ) {} virtual ~function_impl() { - if( valid_ && ! std::uncaught_exception() ) + if( valid_ && exceptions_ >= uncaught_exceptions() ) for( expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it ) if( ! it->verify() ) @@ -300,6 +301,7 @@ namespace detail expectations_type expectations_; context* context_; mutable bool valid_; + const int exceptions_; const boost::shared_ptr< mutex > mutex_; }; }