From 7ab05d5de02ff6fbd0f00d60bfc5d854e61856ea Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 31 May 2023 19:54:43 +0300 Subject: [PATCH] More -Wconversion fixes for GCC 10 and below --- test/bit_ceil_test.cpp | 2 +- test/bit_countl_test.cpp | 2 +- test/bit_countr_test.cpp | 2 +- test/bit_popcount_test.cpp | 2 +- test/bit_width_test.cpp | 4 ++-- test/has_single_bit_test.cpp | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/bit_ceil_test.cpp b/test/bit_ceil_test.cpp index 2cde75b..fbb81d4 100644 --- a/test/bit_ceil_test.cpp +++ b/test/bit_ceil_test.cpp @@ -14,7 +14,7 @@ template void test_bit_ceil( T x ) { if( !boost::core::has_single_bit( x ) ) { - x >>= 1; + x = static_cast( x >> 1 ); } T y = boost::core::bit_ceil( x ); diff --git a/test/bit_countl_test.cpp b/test/bit_countl_test.cpp index c25423e..fe6e3b5 100644 --- a/test/bit_countl_test.cpp +++ b/test/bit_countl_test.cpp @@ -14,7 +14,7 @@ template void test_countl( T x ) { x |= static_cast( 1 ) << ( std::numeric_limits::digits - 1 ); - for( int i = 0; i <= std::numeric_limits::digits; ++i, x >>= 1 ) + for( int i = 0; i <= std::numeric_limits::digits; ++i, x = static_cast( x >> 1 ) ) { BOOST_TEST_EQ( boost::core::countl_zero( x ), i ); BOOST_TEST_EQ( boost::core::countl_one( static_cast( ~x ) ), i ); diff --git a/test/bit_countr_test.cpp b/test/bit_countr_test.cpp index a3b0c96..ab9bd06 100644 --- a/test/bit_countr_test.cpp +++ b/test/bit_countr_test.cpp @@ -14,7 +14,7 @@ template void test_countr( T x ) { x |= 1; - for( int i = 0; i <= std::numeric_limits::digits; ++i, x <<= 1 ) + for( int i = 0; i <= std::numeric_limits::digits; ++i, x = static_cast( x << 1 ) ) { BOOST_TEST_EQ( boost::core::countr_zero( x ), i ); BOOST_TEST_EQ( boost::core::countr_one( static_cast( ~x ) ), i ); diff --git a/test/bit_popcount_test.cpp b/test/bit_popcount_test.cpp index f2f8aa2..cf8ee87 100644 --- a/test/bit_popcount_test.cpp +++ b/test/bit_popcount_test.cpp @@ -14,7 +14,7 @@ template void test_popcount( T x ) { int k = 0; - for( T y = x; y; y &= y - 1, ++k ); + for( T y = x; y; y = static_cast( y & (y - 1) ), ++k ); BOOST_TEST_EQ( boost::core::popcount( x ), k ) || ( std::cerr << "x: " << +x << std::endl ); } diff --git a/test/bit_width_test.cpp b/test/bit_width_test.cpp index 15ac76d..8f84ac5 100644 --- a/test/bit_width_test.cpp +++ b/test/bit_width_test.cpp @@ -24,7 +24,7 @@ int main() x = 1; - for( int i = 0; i < 8; ++i, x <<= 1 ) + for( int i = 0; i < 8; ++i, x = static_cast( x << 1 ) ) { BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 ); BOOST_TEST_EQ( boost::core::bit_width( static_cast( x | ( x >> 1 ) ) ), i+1 ); @@ -39,7 +39,7 @@ int main() x = 1; - for( int i = 0; i < 16; ++i, x <<= 1 ) + for( int i = 0; i < 16; ++i, x = static_cast( x << 1 ) ) { BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 ); BOOST_TEST_EQ( boost::core::bit_width( static_cast( x | ( x >> 1 ) ) ), i+1 ); diff --git a/test/has_single_bit_test.cpp b/test/has_single_bit_test.cpp index 1e0fe39..221f8c7 100644 --- a/test/has_single_bit_test.cpp +++ b/test/has_single_bit_test.cpp @@ -28,7 +28,7 @@ int main() x = 2; - for( int i = 1; i < 8; ++i, x <<= 1 ) + for( int i = 1; i < 8; ++i, x = static_cast( x << 1 ) ) { BOOST_TEST_EQ( boost::core::has_single_bit( x ), true ); BOOST_TEST_EQ( boost::core::has_single_bit( static_cast( x | ( x >> 1 ) ) ), false ); @@ -47,7 +47,7 @@ int main() x = 2; - for( int i = 1; i < 16; ++i, x <<= 1 ) + for( int i = 1; i < 16; ++i, x = static_cast( x << 1 ) ) { BOOST_TEST_EQ( boost::core::has_single_bit( x ), true ); BOOST_TEST_EQ( boost::core::has_single_bit( static_cast( x | ( x >> 1 ) ) ), false );