More -Wconversion fixes for GCC 10 and below

This commit is contained in:
Peter Dimov 2023-05-31 19:54:43 +03:00
parent 266fbe6449
commit 7ab05d5de0
6 changed files with 8 additions and 8 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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 );
@ -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 );

View File

@ -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 );
@ -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 );