From ad991370daccc087f4dca8c239df413c45e5ec2f Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Sat, 17 Sep 2016 09:16:15 +0200 Subject: [PATCH 1/2] Add tests for to_integer(): they fail --- tests/byte_tests.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index 59ff0cd..3bbf382 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -96,6 +96,24 @@ SUITE(byte_tests) a >>= 4; CHECK(a == to_byte<0x0F>()); } + + TEST(to_integer) + { + byte b = to_byte<0x12>(); + + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + CHECK(0x12 == gsl::to_integer(b)); + +// CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error +// CHECK(0x12 == gsl::to_integer(b)); // expect compile-time error + } } } From 6cf154e067550440e9580cad0744afd12e1ccafd Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Sat, 17 Sep 2016 09:24:34 +0200 Subject: [PATCH 2/2] Fix to_integer() --- gsl/gsl_byte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsl/gsl_byte b/gsl/gsl_byte index ab5e4e3..9962ab4 100644 --- a/gsl/gsl_byte +++ b/gsl/gsl_byte @@ -103,7 +103,7 @@ inline constexpr byte operator~(byte b) noexcept { return byte(~static_cast::value>> inline constexpr IntegerType to_integer(byte b) noexcept { - return {b}; + return static_cast(b); } template