Fixed deprecation warning about std::uncaught_exception in c++17 for msvc

This commit is contained in:
Mathieu Champlon 2018-03-23 18:18:23 +01:00
parent 61d5cf5634
commit c42b708950
4 changed files with 20 additions and 1 deletions

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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_;
};
}