diff --git a/include/gsl/byte b/include/gsl/byte index f92a91c..a721dc6 100644 --- a/include/gsl/byte +++ b/include/gsl/byte @@ -174,26 +174,15 @@ constexpr IntegerType to_integer(byte b) noexcept #endif // GSL_USE_STD_BYTE -template -constexpr byte to_byte_impl(T t) noexcept -{ - static_assert( - E, "gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. " - "If you are calling to_byte with an integer contant use: gsl::to_byte() version."); - return static_cast(t); -} -template <> +template // NOTE: need suppression since c++14 does not allow "return {t}" // GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: suppression does not work -constexpr byte to_byte_impl(unsigned char t) noexcept -{ - return byte(t); -} - -template constexpr byte to_byte(T t) noexcept { - return to_byte_impl::value, T>(t); + static_assert(std::is_same::value, + "gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. " + "If you are calling to_byte with an integer contant use: gsl::to_byte() version."); + return byte(t); } template diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index 4432fc9..fbef36f 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -61,6 +61,12 @@ TEST(byte_tests, construction) EXPECT_TRUE(static_cast(b) == 14); } #endif + +#ifdef CONFIRM_COMPILATION_ERRORS + to_byte(char{}); + to_byte(3); + to_byte(3u); +#endif } TEST(byte_tests, bitwise_operations)