Merge branch 'master' into hunterization

This commit is contained in:
Stefan Reinhold 2018-08-03 00:53:40 +02:00
commit 73022d1103
2 changed files with 28 additions and 1 deletions

View File

@ -26,6 +26,8 @@
// //
#if defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS #if defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
#define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND #define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND
#include <intrin.h>
#define RANGE_CHECKS_FAILURE 0
#endif #endif
// //
@ -82,10 +84,15 @@ namespace details
#if defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) #if defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND)
typedef void (__cdecl *terminate_handler)(); typedef void (__cdecl *terminate_handler)();
[[noreturn]] inline void __cdecl default_terminate_handler()
{
__fastfail(RANGE_CHECKS_FAILURE);
}
inline gsl::details::terminate_handler& get_terminate_handler() noexcept inline gsl::details::terminate_handler& get_terminate_handler() noexcept
{ {
static terminate_handler handler = &abort; static terminate_handler handler = &default_terminate_handler;
return handler; return handler;
} }
@ -103,6 +110,10 @@ namespace details
#if defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION) #if defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION)
template <typename Exception> template <typename Exception>
#if defined(__clang__) || defined(__GNUC__)
#else
[[gsl::suppress(f.6)]]
#endif
[[noreturn]] void throw_exception(Exception&&) [[noreturn]] void throw_exception(Exception&&)
{ {
gsl::details::terminate(); gsl::details::terminate();

View File

@ -88,6 +88,10 @@ final_action<F> finally(F&& f) noexcept
// narrow_cast(): a searchable way to do narrowing casts of values // narrow_cast(): a searchable way to do narrowing casts of values
template <class T, class U> template <class T, class U>
#if defined(__clang__) || defined(__GNUC__)
#else
[[gsl::suppress(type.1)]]
#endif
constexpr T narrow_cast(U&& u) noexcept constexpr T narrow_cast(U&& u) noexcept
{ {
return static_cast<T>(std::forward<U>(u)); return static_cast<T>(std::forward<U>(u));
@ -108,6 +112,10 @@ namespace details
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value // narrow() : a checked version of narrow_cast() that throws if the cast changed the value
template <class T, class U> template <class T, class U>
#if defined(__clang__) || defined(__GNUC__)
#else
[[gsl::suppress(type.1)]]
#endif
T narrow(U u) T narrow(U u)
{ {
T t = narrow_cast<T>(u); T t = narrow_cast<T>(u);
@ -121,6 +129,10 @@ T narrow(U u)
// at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector // at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector
// //
template <class T, std::size_t N> template <class T, std::size_t N>
#if defined(__clang__) || defined(__GNUC__)
#else
[[gsl::suppress(type.1,bounds.2,bounds.4)]]
#endif
constexpr T& at(T (&arr)[N], const index i) constexpr T& at(T (&arr)[N], const index i)
{ {
Expects(i >= 0 && i < narrow_cast<index>(N)); Expects(i >= 0 && i < narrow_cast<index>(N));
@ -128,6 +140,10 @@ constexpr T& at(T (&arr)[N], const index i)
} }
template <class Cont> template <class Cont>
#if defined(__clang__) || defined(__GNUC__)
#else
[[gsl::suppress(type.1,bounds.4)]]
#endif
constexpr auto at(Cont& cont, const index i) -> decltype(cont[cont.size()]) constexpr auto at(Cont& cont, const index i) -> decltype(cont[cont.size()])
{ {
Expects(i >= 0 && i < narrow_cast<index>(cont.size())); Expects(i >= 0 && i < narrow_cast<index>(cont.size()));