diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp index 0a092d3..8c4e1bb 100644 --- a/include/boost/integer/integer_mask.hpp +++ b/include/boost/integer/integer_mask.hpp @@ -70,6 +70,11 @@ struct low_bits_mask_t BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ } +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch +#endif + BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); #if USHRT_MAX > UCHAR_MAX @@ -84,6 +89,10 @@ BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); #endif +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + #undef BOOST_LOW_BITS_MASK_SPECIALIZE diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp index 96b3526..8011618 100644 --- a/include/boost/integer_traits.hpp +++ b/include/boost/integer_traits.hpp @@ -27,6 +27,17 @@ #include #endif +// +// We simply cannot include this header on gcc without getting copious warnings of the kind: +// +// ../../../boost/integer_traits.hpp:164:66: warning: use of C99 long long integer constant +// +// And yet there is no other reasonable implementation, so we declare this a system header +// to suppress these warnings. +// +#if defined(__GNUC__) && (__GNUC__ >= 4) +#pragma GCC system_header +#endif namespace boost { template diff --git a/test/integer_mask_test.cpp b/test/integer_mask_test.cpp index 38f5211..8e0c11a 100644 --- a/test/integer_mask_test.cpp +++ b/test/integer_mask_test.cpp @@ -17,6 +17,9 @@ #include // for std::cout (std::endl indirectly) +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif #define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \ (v) >::high_bit == (1ul << (v)) ); @@ -25,10 +28,20 @@ #define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) -#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits == ((1ul << (v)) - 1) ); -#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \ - (v) >::sig_bits_fast == ((1ul << (v)) - 1) ); +#define PRIVATE_LOW_BITS_SLOW_TEST(v) \ + do{ \ + unsigned long mask = 0;\ + if(v > 0)\ + { mask = ((1ul << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_CHECK( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \ + }while(false); +#define PRIVATE_LOW_BITS_FAST_TEST(v) \ + do{ \ + unsigned long mask = 0;\ + if(v > 0)\ + { mask = ((1ul << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_CHECK( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\ + }while(false); #define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) @@ -73,7 +86,7 @@ int test_main( int, char*[] ) PRIVATE_HIGH_BIT_TEST( 0 ); cout << "Doing low_bits_mask_t tests." << endl; - PRIVATE_LOW_BITS_TEST( 32 ); // Undefined behavior? Whoops! + PRIVATE_LOW_BITS_TEST( 32 ); PRIVATE_LOW_BITS_TEST( 31 ); PRIVATE_LOW_BITS_TEST( 30 ); PRIVATE_LOW_BITS_TEST( 29 ); diff --git a/test/integer_test.cpp b/test/integer_test.cpp index 6bfff11..ba6a4bb 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -22,6 +22,10 @@ #include // for std::cout (std::endl indirectly) #include // for std::type_info +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif + // Control if the names of the types for each version // of the integer templates will be printed.