added some comments and ran clang-format

This commit is contained in:
Jordan Maples 2020-03-06 11:17:58 -08:00
parent 769f01900d
commit b30524088a

View File

@ -36,6 +36,7 @@
// Currently terminate is a no-op in this mode, so we add termination behavior back // Currently terminate is a no-op in this mode, so we add termination behavior back
// //
#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> #include <intrin.h>
#define RANGE_CHECKS_FAILURE 0 #define RANGE_CHECKS_FAILURE 0
@ -43,13 +44,13 @@
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-noreturn" #pragma clang diagnostic ignored "-Winvalid-noreturn"
#endif #endif // defined(__clang__)
#else #else
#include <exception> #include <exception>
#endif #endif // !defined(_MSC_VER) || !defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS
#define GSL_STRINGIFY_DETAIL(x) #x #define GSL_STRINGIFY_DETAIL(x) #x
#define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x) #define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x)
@ -57,10 +58,12 @@
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
#define GSL_LIKELY(x) __builtin_expect(!!(x), 1) #define GSL_LIKELY(x) __builtin_expect(!!(x), 1)
#define GSL_UNLIKELY(x) __builtin_expect(!!(x), 0) #define GSL_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else #else
#define GSL_LIKELY(x) (!!(x)) #define GSL_LIKELY(x) (!!(x))
#define GSL_UNLIKELY(x) (!!(x)) #define GSL_UNLIKELY(x) (!!(x))
#endif #endif // defined(__clang__) || defined(__GNUC__)
// //
// GSL_ASSUME(cond) // GSL_ASSUME(cond)
@ -89,7 +92,9 @@ namespace details
typedef void(__cdecl* terminate_handler)(); typedef void(__cdecl* terminate_handler)();
// clang-format off
GSL_SUPPRESS(f.6) // NO-FORMAT: attribute GSL_SUPPRESS(f.6) // NO-FORMAT: attribute
// clang-format on
[[noreturn]] inline void __cdecl default_terminate_handler() [[noreturn]] inline void __cdecl default_terminate_handler()
{ {
__fastfail(RANGE_CHECKS_FAILURE); __fastfail(RANGE_CHECKS_FAILURE);
@ -101,7 +106,7 @@ namespace details
return handler; return handler;
} }
#endif #endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND)
[[noreturn]] inline void terminate() noexcept [[noreturn]] inline void terminate() noexcept
{ {
@ -109,13 +114,12 @@ namespace details
(*gsl::details::get_terminate_handler())(); (*gsl::details::get_terminate_handler())();
#else #else
std::terminate(); std::terminate();
#endif #endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND)
} }
} // namespace details } // namespace details
} // namespace gsl } // namespace gsl
#define GSL_CONTRACT_CHECK(type, cond) \ #define GSL_CONTRACT_CHECK(type, cond) \
(GSL_LIKELY(cond) ? static_cast<void>(0) : gsl::details::terminate()) (GSL_LIKELY(cond) ? static_cast<void>(0) : gsl::details::terminate())