diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index b37b90a..ca94a9b 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -131,40 +131,46 @@ TEST(byte_tests, aliasing) EXPECT_TRUE(res == i); } -// These are regressions, should be fixed. +#if __cplusplus >= 201703l +using std::void_t; +#else // __cplusplus >= 201703l +template +using void_t = void; +#endif // __cplusplus < 201703l + template static constexpr bool LShiftCompilesFor = false; template static constexpr bool LShiftCompilesFor< - U, std::void_t(declval(), declval()))>> = true; + U, void_t(declval(), declval()))>> = true; static_assert(!LShiftCompilesFor, "!LShiftCompilesFor"); template static constexpr bool RShiftCompilesFor = false; template static constexpr bool RShiftCompilesFor< - U, std::void_t> (declval(), declval()))>> = true; + U, void_t> (declval(), declval()))>> = true; static_assert(!RShiftCompilesFor, "!RShiftCompilesFor"); template static constexpr bool LShiftAssignCompilesFor = false; template static constexpr bool LShiftAssignCompilesFor< - U, std::void_t(declval(), declval()))>> = true; + U, void_t(declval(), declval()))>> = true; static_assert(!LShiftAssignCompilesFor, "!LShiftAssignCompilesFor"); template static constexpr bool RShiftAssignCompilesFor = false; template static constexpr bool RShiftAssignCompilesFor< - U, std::void_t>= (declval(), declval()))>> = true; + U, void_t>= (declval(), declval()))>> = true; static_assert(!RShiftAssignCompilesFor, "!RShiftAssignCompilesFor"); template static constexpr bool ToIntegerCompilesFor = false; template static constexpr bool - ToIntegerCompilesFor(gsl::byte{}))>> = true; + ToIntegerCompilesFor(gsl::byte{}))>> = true; static_assert(!ToIntegerCompilesFor, "!ToIntegerCompilesFor"); } // namespace diff --git a/tests/pointers_tests.cpp b/tests/pointers_tests.cpp index a88d209..673e184 100644 --- a/tests/pointers_tests.cpp +++ b/tests/pointers_tests.cpp @@ -8,6 +8,19 @@ namespace { +// Custom pointer type that can be used for gsl::not_null, but for which these cannot be swapped. +struct NotMoveAssignableCustomPtr +{ + NotMoveAssignableCustomPtr() = default; + NotMoveAssignableCustomPtr(const NotMoveAssignableCustomPtr&) = default; + NotMoveAssignableCustomPtr& operator=(const NotMoveAssignableCustomPtr&) = default; + NotMoveAssignableCustomPtr(NotMoveAssignableCustomPtr&&) = default; + NotMoveAssignableCustomPtr& operator=(NotMoveAssignableCustomPtr&&) = delete; + + bool operator!=(std::nullptr_t) const { return true; } + + int dummy{}; // Without this clang warns, that NotMoveAssignableCustomPtr() is unneeded +}; TEST(pointers_test, swap) { @@ -22,21 +35,28 @@ TEST(pointers_test, swap) EXPECT_TRUE(*a == 1); EXPECT_TRUE(*b == 0); + + // Make sure our custom ptr can be used with not_null. The shared_pr is to prevent "unused" + // compiler warnings. + const auto shared_custom_ptr{std::make_shared()}; + gsl::not_null c{*shared_custom_ptr}; + EXPECT_TRUE(c.get() != nullptr); } -// These are regressions, should be fixed. -struct NotMovable -{ - NotMovable(NotMovable&&) = delete; - NotMovable& operator=(NotMovable&&) = delete; -}; +#if __cplusplus >= 201703l +using std::void_t; +#else // __cplusplus >= 201703l +template +using void_t = void; +#endif // __cplusplus < 201703l + template static constexpr bool SwapCompilesFor = false; template static constexpr bool - SwapCompilesFor(std::declval&>(), - std::declval&>()))>> = - true; -static_assert(!SwapCompilesFor, "!SwapCompilesFor"); + SwapCompilesFor(std::declval&>(), + std::declval&>()))>> = true; +static_assert(!SwapCompilesFor, + "!SwapCompilesFor"); } // namespace diff --git a/tests/span_compatibility_tests.cpp b/tests/span_compatibility_tests.cpp index c6e4b02..3aad961 100644 --- a/tests/span_compatibility_tests.cpp +++ b/tests/span_compatibility_tests.cpp @@ -1005,12 +1005,18 @@ static_assert(std::is_convertible&, gsl::span&, gsl::span>"); #if __cplusplus >= 201703l +using std::void_t; +#else // __cplusplus >= 201703l +template +using void_t = void; +#endif // __cplusplus < 201703l + template static constexpr bool AsWritableBytesCompilesFor = false; template static constexpr bool - AsWritableBytesCompilesFor()))>> = true; + AsWritableBytesCompilesFor()))>> = true; static_assert(AsWritableBytesCompilesFor>, "AsWritableBytesCompilesFor>"); @@ -1020,4 +1026,3 @@ static_assert(!AsWritableBytesCompilesFor>, "!AsWritableBytesCompilesFor>"); static_assert(!AsWritableBytesCompilesFor>, "!AsWritableBytesCompilesFor>"); -#endif // __cplusplus >= 201703l