From 769f01900dbf58ffa96b987e37cd169e371d005b Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Tue, 3 Mar 2020 17:04:46 -0800 Subject: [PATCH 1/4] moving exception include --- include/gsl/gsl_assert | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert index 7a9e8ad..ac87ef4 100644 --- a/include/gsl/gsl_assert +++ b/include/gsl/gsl_assert @@ -17,8 +17,6 @@ #ifndef GSL_CONTRACTS_H #define GSL_CONTRACTS_H -#include - // // make suppress attributes parse for some compilers // Hopefully temporary until suppression standardization occurs @@ -47,6 +45,10 @@ #pragma clang diagnostic ignored "-Winvalid-noreturn" #endif +#else + +#include + #endif #define GSL_STRINGIFY_DETAIL(x) #x @@ -110,14 +112,6 @@ namespace details #endif } - 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 From b30524088a8d3454b95c2a94f300caf26ba92fe2 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Fri, 6 Mar 2020 11:17:58 -0800 Subject: [PATCH 2/4] added some comments and ran clang-format --- include/gsl/gsl_assert | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert index ac87ef4..e8f3f66 100644 --- a/include/gsl/gsl_assert +++ b/include/gsl/gsl_assert @@ -36,6 +36,7 @@ // 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 @@ -43,13 +44,13 @@ #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-noreturn" -#endif +#endif // defined(__clang__) #else #include -#endif +#endif // !defined(_MSC_VER) || !defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS #define GSL_STRINGIFY_DETAIL(x) #x #define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x) @@ -57,10 +58,12 @@ #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) @@ -87,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); @@ -101,7 +106,7 @@ namespace details return handler; } -#endif +#endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) [[noreturn]] inline void terminate() noexcept { @@ -109,13 +114,12 @@ namespace details (*gsl::details::get_terminate_handler())(); #else std::terminate(); -#endif +#endif // defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) } } // namespace details } // namespace gsl - #define GSL_CONTRACT_CHECK(type, cond) \ (GSL_LIKELY(cond) ? static_cast(0) : gsl::details::terminate()) From ce4d689f4f5af11ce97e1c2f05c26b91de164493 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Fri, 6 Mar 2020 11:22:09 -0800 Subject: [PATCH 3/4] shuffle around code to bring includes to top. --- include/gsl/gsl_assert | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert index e8f3f66..7efa84e 100644 --- a/include/gsl/gsl_assert +++ b/include/gsl/gsl_assert @@ -17,20 +17,6 @@ #ifndef GSL_CONTRACTS_H #define GSL_CONTRACTS_H -// -// make suppress attributes parse for some compilers -// Hopefully temporary until suppression standardization occurs -// -#if defined(__clang__) -#define GSL_SUPPRESS(x) [[gsl::suppress("x")]] -#else -#if defined(_MSC_VER) -#define GSL_SUPPRESS(x) [[gsl::suppress(x)]] -#else -#define GSL_SUPPRESS(x) -#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 @@ -45,13 +31,24 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-noreturn" #endif // defined(__clang__) - #else - #include - #endif // !defined(_MSC_VER) || !defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS +// +// make suppress attributes parse for some compilers +// Hopefully temporary until suppression standardization occurs +// +#if defined(__clang__) +#define GSL_SUPPRESS(x) [[gsl::suppress("x")]] +#else +#if defined(_MSC_VER) +#define GSL_SUPPRESS(x) [[gsl::suppress(x)]] +#else +#define GSL_SUPPRESS(x) +#endif // _MSC_VER +#endif // __clang__ + #define GSL_STRINGIFY_DETAIL(x) #x #define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x) From 06adf557e925ba4010b0964cb216efb9f2370ed6 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Thu, 12 Mar 2020 12:32:32 -0700 Subject: [PATCH 4/4] update kernel mode detection macro --- include/gsl/gsl_assert | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert index 7efa84e..96eaada 100644 --- a/include/gsl/gsl_assert +++ b/include/gsl/gsl_assert @@ -21,7 +21,7 @@ // 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 +#if defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) #define GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND #include @@ -31,9 +31,12 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-noreturn" #endif // defined(__clang__) -#else + +#else // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) + #include -#endif // !defined(_MSC_VER) || !defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS + +#endif // defined(_MSC_VER) && (defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)) // // make suppress attributes parse for some compilers