Skip to content

Commit

Permalink
More -Wconversion fixes for GCC 10 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed May 31, 2023
1 parent 266fbe6 commit 7ab05d5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/bit_ceil_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template<class T> void test_bit_ceil( T x )
{
if( !boost::core::has_single_bit( x ) )
{
x >>= 1;
x = static_cast<T>( x >> 1 );
}

T y = boost::core::bit_ceil( x );
Expand Down
2 changes: 1 addition & 1 deletion test/bit_countl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template<class T> void test_countl( T x )
{
x |= static_cast<T>( 1 ) << ( std::numeric_limits<T>::digits - 1 );

for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x >>= 1 )
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x = static_cast<T>( x >> 1 ) )
{
BOOST_TEST_EQ( boost::core::countl_zero( x ), i );
BOOST_TEST_EQ( boost::core::countl_one( static_cast<T>( ~x ) ), i );
Expand Down
2 changes: 1 addition & 1 deletion test/bit_countr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template<class T> void test_countr( T x )
{
x |= 1;

for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x <<= 1 )
for( int i = 0; i <= std::numeric_limits<T>::digits; ++i, x = static_cast<T>( x << 1 ) )
{
BOOST_TEST_EQ( boost::core::countr_zero( x ), i );
BOOST_TEST_EQ( boost::core::countr_one( static_cast<T>( ~x ) ), i );
Expand Down
2 changes: 1 addition & 1 deletion test/bit_popcount_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
template<class T> 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<T>( y & (y - 1) ), ++k );

BOOST_TEST_EQ( boost::core::popcount( x ), k ) || ( std::cerr << "x: " << +x << std::endl );
}
Expand Down
4 changes: 2 additions & 2 deletions test/bit_width_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::uint8_t>( x << 1 ) )
{
BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 );
BOOST_TEST_EQ( boost::core::bit_width( static_cast<boost::uint8_t>( x | ( x >> 1 ) ) ), i+1 );
Expand All @@ -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<boost::uint16_t>( x << 1 ) )
{
BOOST_TEST_EQ( boost::core::bit_width( x ), i+1 );
BOOST_TEST_EQ( boost::core::bit_width( static_cast<boost::uint16_t>( x | ( x >> 1 ) ) ), i+1 );
Expand Down
4 changes: 2 additions & 2 deletions test/has_single_bit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::uint8_t>( x << 1 ) )
{
BOOST_TEST_EQ( boost::core::has_single_bit( x ), true );
BOOST_TEST_EQ( boost::core::has_single_bit( static_cast<boost::uint8_t>( x | ( x >> 1 ) ) ), false );
Expand All @@ -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<boost::uint16_t>( x << 1 ) )
{
BOOST_TEST_EQ( boost::core::has_single_bit( x ), true );
BOOST_TEST_EQ( boost::core::has_single_bit( static_cast<boost::uint16_t>( x | ( x >> 1 ) ) ), false );
Expand Down

0 comments on commit 7ab05d5

Please sign in to comment.