From 266fbe6449fcc5e9676dff327d6e649956c7a17d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 31 May 2023 18:53:35 +0300 Subject: [PATCH] Fix -Wconversion warnings --- include/boost/core/bit.hpp | 8 ++++---- test/bit_rotate_test.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index a165c8d..70376ff 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -626,7 +626,7 @@ BOOST_CXX14_CONSTEXPR T rotl( T x, int s ) BOOST_NOEXCEPT BOOST_STATIC_ASSERT( std::numeric_limits::is_integer && !std::numeric_limits::is_signed ); unsigned const mask = std::numeric_limits::digits - 1; - return x << (s & mask) | x >> ((-s) & mask); + return static_cast( x << (static_cast( s ) & mask) | x >> (static_cast( -s ) & mask) ); } template @@ -635,7 +635,7 @@ BOOST_CXX14_CONSTEXPR T rotr( T x, int s ) BOOST_NOEXCEPT BOOST_STATIC_ASSERT( std::numeric_limits::is_integer && !std::numeric_limits::is_signed ); unsigned const mask = std::numeric_limits::digits - 1; - return x >> (s & mask) | x << ((-s) & mask); + return static_cast( x >> (static_cast( s ) & mask) | x << (static_cast( -s ) & mask) ); } // integral powers of 2 @@ -664,7 +664,7 @@ BOOST_CONSTEXPR T bit_floor( T x ) BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( std::numeric_limits::is_integer && !std::numeric_limits::is_signed ); - return x == 0? 0: T(1) << ( boost::core::bit_width( x ) - 1 ); + return x == 0? 0: static_cast( T(1) << ( boost::core::bit_width( x ) - 1 ) ); } namespace detail @@ -805,7 +805,7 @@ BOOST_CONSTEXPR inline boost::uint8_t byteswap_impl( boost::uint8_t x ) BOOST_NO BOOST_CONSTEXPR inline boost::uint16_t byteswap_impl( boost::uint16_t x ) BOOST_NOEXCEPT { - return (x << 8) | (x >> 8); + return static_cast( x << 8 | x >> 8 ); } #if defined(__GNUC__) || defined(__clang__) diff --git a/test/bit_rotate_test.cpp b/test/bit_rotate_test.cpp index d37569e..d31c5e9 100644 --- a/test/bit_rotate_test.cpp +++ b/test/bit_rotate_test.cpp @@ -20,7 +20,7 @@ template void test_rotate( T x ) BOOST_TEST_EQ( +boost::core::rotl( x, -i ), +boost::core::rotr( x, i ) ); unsigned const width = std::numeric_limits::digits; - unsigned r = i & ( width - 1 ); + unsigned r = static_cast( i ) & ( width - 1 ); if( r == 0 ) {