From 1b8f499ee1e269d75e47d5b57ebf36fe6da3254a Mon Sep 17 00:00:00 2001 From: Jonathan Gopel Date: Wed, 11 Nov 2020 08:56:59 -0700 Subject: [PATCH] :wrench: Silence useless cast warnings (#2008) Problem: - gcc-10 is generating the following warning at all standards: test/format-test.cc: In member function 'virtual void UtilTest_BitCast_Test::TestBody()': test/format-test.cc:108:42: error: useless cast to type 'uint64_t' {aka 'long long unsigned int'} [-Werror=useless-cast] 108 | s = fmt::detail::bit_cast(uint64_t(~0ull)); | ^~~~~~~~~~~~~~~ - gcc-8 is generating the following warning at all standards: test/format-test.cc: In member function 'virtual void UtilTest_BitCast_Test::TestBody()': test/format-test.cc:108:56: error: useless cast to type 'uint64_t' {aka 'long long unsigned int'} [-Werror=useless-cast] s = fmt::detail::bit_cast(uint64_t(~0ull)); ^ Solution: - Cast 0 to a 64 unsigned bit int and then invert. Co-authored-by: Jonathan Gopel --- test/format-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/format-test.cc b/test/format-test.cc index 77a6ded6..ac1a96bb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -105,7 +105,7 @@ struct uint32_pair { TEST(UtilTest, BitCast) { auto s = fmt::detail::bit_cast(uint64_t{42}); EXPECT_EQ(fmt::detail::bit_cast(s), 42ull); - s = fmt::detail::bit_cast(uint64_t(~0ull)); + s = fmt::detail::bit_cast(~uint64_t{0}); EXPECT_EQ(fmt::detail::bit_cast(s), ~0ull); }