diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert index 7a9e8ad..96eaada 100644 --- a/include/gsl/gsl_assert +++ b/include/gsl/gsl_assert @@ -17,8 +17,27 @@ #ifndef GSL_CONTRACTS_H #define GSL_CONTRACTS_H +// +// Temporary until MSVC STL supports no-exceptions mode. +// Currently terminate is a no-op in this mode, so we add termination behavior back +// +#if defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) + +#define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND +#include +#define RANGE_CHECKS_FAILURE 0 + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winvalid-noreturn" +#endif // defined(__clang__) + +#else // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) + #include +#endif // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) + // // make suppress attributes parse for some compilers // Hopefully temporary until suppression standardization occurs @@ -33,32 +52,18 @@ #endif // _MSC_VER #endif // __clang__ -// -// Temporary until MSVC STL supports no-exceptions mode. -// Currently terminate is a no-op in this mode, so we add termination behavior back -// -#if defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS -#define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND -#include -#define RANGE_CHECKS_FAILURE 0 - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winvalid-noreturn" -#endif - -#endif - #define GSL_STRINGIFY_DETAIL(x) #x #define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x) #if defined(__clang__) || defined(__GNUC__) #define GSL_LIKELY(x) __builtin_expect(!!(x), 1) #define GSL_UNLIKELY(x) __builtin_expect(!!(x), 0) + #else + #define GSL_LIKELY(x) (!!(x)) #define GSL_UNLIKELY(x) (!!(x)) -#endif +#endif // defined(__clang__) || defined(__GNUC__) // // GSL_ASSUME(cond) @@ -85,9 +90,11 @@ namespace details { #if defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) - typedef void (__cdecl *terminate_handler)(); + typedef void(__cdecl* terminate_handler)(); + // clang-format off GSL_SUPPRESS(f.6) // NO-FORMAT: attribute + // clang-format on [[noreturn]] inline void __cdecl default_terminate_handler() { __fastfail(RANGE_CHECKS_FAILURE); @@ -99,7 +106,7 @@ namespace details return handler; } -#endif +#endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) [[noreturn]] inline void terminate() noexcept { @@ -107,21 +114,12 @@ namespace details (*gsl::details::get_terminate_handler())(); #else std::terminate(); -#endif +#endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) } - template - [[deprecated("GSL no longer supports throwing for contract violations. Use gsl::details::terminate() instead.")]] - [[noreturn]] void throw_exception(Exception&&) noexcept - { - gsl::details::terminate(); - } - - } // namespace details } // namespace gsl - #define GSL_CONTRACT_CHECK(type, cond) \ (GSL_LIKELY(cond) ? static_cast(0) : gsl::details::terminate())