🔧 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<uint32_pair>(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<uint32_pair>(uint64_t(~0ull));
                                                        ^
Solution:
- Cast 0 to a 64 unsigned bit int and then invert.

Co-authored-by: Jonathan Gopel <jgopel@quantlab.com>
This commit is contained in:
Jonathan Gopel 2020-11-11 08:56:59 -07:00 committed by GitHub
parent f428d286a1
commit 1b8f499ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,7 +105,7 @@ struct uint32_pair {
TEST(UtilTest, BitCast) {
auto s = fmt::detail::bit_cast<uint32_pair>(uint64_t{42});
EXPECT_EQ(fmt::detail::bit_cast<uint64_t>(s), 42ull);
s = fmt::detail::bit_cast<uint32_pair>(uint64_t(~0ull));
s = fmt::detail::bit_cast<uint32_pair>(~uint64_t{0});
EXPECT_EQ(fmt::detail::bit_cast<uint64_t>(s), ~0ull);
}