From 7bf2e838cc3b4cf0d1b31dab081ecffb1d527e81 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 31 May 2015 09:18:23 +0100 Subject: [PATCH] Fix MSVC analyzer warnings. --- .../boost/multiprecision/cpp_bin_float.hpp | 20 ++++++++++++++++--- .../boost/multiprecision/cpp_bin_float/io.hpp | 10 +++++----- .../boost/multiprecision/cpp_dec_float.hpp | 9 +++++++++ include/boost/multiprecision/cpp_int.hpp | 18 ++++++++--------- .../multiprecision/cpp_int/serialize.hpp | 2 +- .../multiprecision/detail/functions/pow.hpp | 8 ++++++++ .../multiprecision/detail/functions/trig.hpp | 20 +++++++++++++------ .../detail/generic_interconvert.hpp | 2 +- .../multiprecision/detail/number_base.hpp | 12 ++++++++++- include/boost/multiprecision/number.hpp | 2 +- .../cpp_bin_float_include_test.cpp | 5 ++++- .../cpp_dec_float_include_test.cpp | 5 ++++- test/include_test/cpp_int_include_test.cpp | 13 +++++++----- test/include_test/gmp_include_test.cpp | 9 ++++++--- test/include_test/mpfr_include_test.cpp | 5 ++++- test/include_test/tommath_include_test.cpp | 5 ++++- 16 files changed, 106 insertions(+), 39 deletions(-) diff --git a/include/boost/multiprecision/cpp_bin_float.hpp b/include/boost/multiprecision/cpp_bin_float.hpp index f14d765e..ec37bd38 100644 --- a/include/boost/multiprecision/cpp_bin_float.hpp +++ b/include/boost/multiprecision/cpp_bin_float.hpp @@ -21,7 +21,7 @@ enum digit_base_type #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable:4522) // multiple assignment operators specified +#pragma warning(disable:4522 6326) // multiple assignment operators specified, comparison of two constants #endif namespace detail{ @@ -37,7 +37,7 @@ template ::value ? bit_count : 0, bit_count, is_void::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> rep_type; typedef cpp_int_backend::value ? 2 * bit_count : 0, 2 * bit_count, is_void::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> double_rep_type; @@ -773,6 +773,10 @@ inline typename enable_if_c::value>::type eval_multiply(cpp_bin_flo template inline void eval_divide(cpp_bin_float &res, const cpp_bin_float &u, const cpp_bin_float &v) { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif using default_ops::eval_subtract; using default_ops::eval_qr; using default_ops::eval_bit_test; @@ -882,7 +886,7 @@ inline void eval_divide(cpp_bin_float::bit_count - 1)); - static const unsigned lshift = cpp_bin_float::bit_count < limb_bits ? 2 : limb_bits; + static const unsigned lshift = (cpp_bin_float::bit_count < limb_bits) ? 2 : limb_bits; eval_left_shift(q, lshift); res.exponent() -= lshift; eval_left_shift(r, 1u); @@ -893,6 +897,9 @@ inline void eval_divide(cpp_bin_float(1u) << (lshift - 1)) + static_cast(1u); } copy_and_round(res, q); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template @@ -904,6 +911,10 @@ inline void eval_divide(cpp_bin_float inline typename enable_if_c::value>::type eval_divide(cpp_bin_float &res, const cpp_bin_float &u, const U &v) { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif using default_ops::eval_subtract; using default_ops::eval_qr; using default_ops::eval_bit_test; @@ -1000,6 +1011,9 @@ inline typename enable_if_c::value>::type eval_divide(cpp_bin_flo q.limbs()[0] |= (static_cast(1u) << (lshift - 1)) + static_cast(1u); } copy_and_round(res, q); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template diff --git a/include/boost/multiprecision/cpp_bin_float/io.hpp b/include/boost/multiprecision/cpp_bin_float/io.hpp index ae3ab38e..88d5ddd0 100644 --- a/include/boost/multiprecision/cpp_bin_float/io.hpp +++ b/include/boost/multiprecision/cpp_bin_float/io.hpp @@ -282,7 +282,7 @@ cpp_bin_float& cpp_bin_float #ifdef BOOST_MP_STRESS_IO boost::intmax_t max_bits = cpp_bin_float::bit_count + 32; #else - boost::intmax_t max_bits = cpp_bin_float::bit_count + (cpp_bin_float::bit_count % limb_bits ? limb_bits - cpp_bin_float::bit_count % limb_bits : 0) + limb_bits; + boost::intmax_t max_bits = cpp_bin_float::bit_count + ((cpp_bin_float::bit_count % limb_bits) ? (limb_bits - cpp_bin_float::bit_count % limb_bits) : 0) + limb_bits; #endif boost::int64_t error = 0; boost::intmax_t calc_exp = 0; @@ -384,9 +384,9 @@ cpp_bin_float& cpp_bin_float { // Too many bits in q and the bits in q indicate a tie, but we can break that using r, // note that the radius of error in r is error/2 * q: - int shift = gb - (int)cpp_bin_float::bit_count + 1; - q >>= shift; - final_exponent += static_cast(shift); + int lshift = gb - (int)cpp_bin_float::bit_count + 1; + q >>= lshift; + final_exponent += static_cast(lshift); BOOST_ASSERT((msb(q) >= cpp_bin_float::bit_count - 1)); if(error && (r < (error / 2) * q)) roundup = -1; @@ -525,7 +525,7 @@ std::string cpp_bin_float::s #ifdef BOOST_MP_STRESS_IO boost::intmax_t max_bits = cpp_bin_float::bit_count + 32; #else - boost::intmax_t max_bits = cpp_bin_float::bit_count + (cpp_bin_float::bit_count % limb_bits ? limb_bits - cpp_bin_float::bit_count % limb_bits : 0) + limb_bits; + boost::intmax_t max_bits = cpp_bin_float::bit_count + ((cpp_bin_float::bit_count % limb_bits) ? (limb_bits - cpp_bin_float::bit_count % limb_bits) : 0) + limb_bits; if(power10) max_bits += (msb(boost::multiprecision::detail::abs(power10)) / 8) * limb_bits; #endif diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp index ba0800bb..0dd0a40e 100644 --- a/include/boost/multiprecision/cpp_dec_float.hpp +++ b/include/boost/multiprecision/cpp_dec_float.hpp @@ -34,6 +34,11 @@ // #include +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif + namespace boost{ namespace multiprecision{ namespace backends{ @@ -3078,4 +3083,8 @@ struct precision< boost::multiprecision::number >::type > @@ -181,8 +181,8 @@ public: BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1)); BOOST_STATIC_CONSTANT(unsigned, internal_limb_count = MinBits - ? MinBits / limb_bits + (MinBits % limb_bits ? 1 : 0) - : sizeof(limb_data) / sizeof(limb_type)); + ? (MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0)) + : (sizeof(limb_data) / sizeof(limb_type))); BOOST_STATIC_CONSTANT(bool, variable = true); private: @@ -243,7 +243,7 @@ public: } void resize(unsigned new_size, unsigned min_size) { - static const unsigned max_limbs = MaxBits / (CHAR_BIT * sizeof(limb_type)) + (MaxBits % (CHAR_BIT * sizeof(limb_type)) ? 1 : 0); + static const unsigned max_limbs = MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0); // We never resize beyond MaxSize: if(new_size > max_limbs) new_size = max_limbs; @@ -402,9 +402,9 @@ public: BOOST_STATIC_CONSTANT(unsigned, limb_bits = sizeof(limb_type) * CHAR_BIT); BOOST_STATIC_CONSTANT(limb_type, max_limb_value = ~static_cast(0u)); BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1)); - BOOST_STATIC_CONSTANT(unsigned, internal_limb_count = MinBits / limb_bits + (MinBits % limb_bits ? 1 : 0)); + BOOST_STATIC_CONSTANT(unsigned, internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0)); BOOST_STATIC_CONSTANT(bool, variable = false); - BOOST_STATIC_CONSTANT(limb_type, upper_limb_mask = MinBits % limb_bits ? (limb_type(1) << (MinBits % limb_bits)) -1 : (~limb_type(0))); + BOOST_STATIC_CONSTANT(limb_type, upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) -1 : (~limb_type(0))); BOOST_STATIC_ASSERT_MSG(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs"); private: @@ -554,9 +554,9 @@ public: BOOST_STATIC_CONSTANT(unsigned, limb_bits = sizeof(limb_type) * CHAR_BIT); BOOST_STATIC_CONSTANT(limb_type, max_limb_value = ~static_cast(0u)); BOOST_STATIC_CONSTANT(limb_type, sign_bit_mask = 1u << (limb_bits - 1)); - BOOST_STATIC_CONSTANT(unsigned, internal_limb_count = MinBits / limb_bits + (MinBits % limb_bits ? 1 : 0)); + BOOST_STATIC_CONSTANT(unsigned, internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0)); BOOST_STATIC_CONSTANT(bool, variable = false); - BOOST_STATIC_CONSTANT(limb_type, upper_limb_mask = MinBits % limb_bits ? (limb_type(1) << (MinBits % limb_bits)) -1 : (~limb_type(0))); + BOOST_STATIC_CONSTANT(limb_type, upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) -1 : (~limb_type(0))); BOOST_STATIC_ASSERT_MSG(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs"); private: @@ -1555,7 +1555,7 @@ private: limb_type shift = base == 8 ? 3 : 4; limb_type mask = static_cast((1u << shift) - 1); cpp_int_backend t(*this); - result.assign(Bits / shift + (Bits % shift ? 1 : 0), '0'); + result.assign(Bits / shift + ((Bits % shift) ? 1 : 0), '0'); std::string::difference_type pos = result.size() - 1; for(unsigned i = 0; i < Bits / shift; ++i) { diff --git a/include/boost/multiprecision/cpp_int/serialize.hpp b/include/boost/multiprecision/cpp_int/serialize.hpp index bdf4758a..042a9f89 100644 --- a/include/boost/multiprecision/cpp_int/serialize.hpp +++ b/include/boost/multiprecision/cpp_int/serialize.hpp @@ -49,7 +49,7 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::false_ const&, std::size_t limb_count; std::size_t byte_count; ar & byte_count; - limb_count = byte_count / sizeof(limb_type) + (byte_count % sizeof(limb_type) ? 1 : 0); + limb_count = byte_count / sizeof(limb_type) + ((byte_count % sizeof(limb_type)) ? 1 : 0); val.resize(limb_count, limb_count); limb_type* pl = val.limbs(); for(std::size_t i = 0; i < limb_count; ++i) diff --git a/include/boost/multiprecision/detail/functions/pow.hpp b/include/boost/multiprecision/detail/functions/pow.hpp index 5b54a1a9..44c0b38e 100644 --- a/include/boost/multiprecision/detail/functions/pow.hpp +++ b/include/boost/multiprecision/detail/functions/pow.hpp @@ -12,6 +12,11 @@ // This file has no include guards or namespaces - it's expanded inline inside default_ops.hpp // +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif + namespace detail{ template @@ -692,3 +697,6 @@ inline void eval_tanh(T& result, const T& x) eval_divide(result, c); } +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif diff --git a/include/boost/multiprecision/detail/functions/trig.hpp b/include/boost/multiprecision/detail/functions/trig.hpp index baa42be3..5d4e2639 100644 --- a/include/boost/multiprecision/detail/functions/trig.hpp +++ b/include/boost/multiprecision/detail/functions/trig.hpp @@ -12,6 +12,11 @@ // This file has no include guards or namespaces - it's expanded inline inside default_ops.hpp // +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif + template void hyp0F1(T& result, const T& b, const T& x) { @@ -494,12 +499,12 @@ void eval_asin(T& result, const T& x) // Newton-Raphson iteration while(current_digits < target_precision) { - T s, c; - eval_sin(s, result); - eval_cos(c, result); - eval_subtract(s, xx); - eval_divide(s, c); - eval_subtract(result, s); + T sine, cosine; + eval_sin(sine, result); + eval_cos(cosine, result); + eval_subtract(sine, xx); + eval_divide(sine, cosine); + eval_subtract(result, sine); current_digits *= 2; /* @@ -770,3 +775,6 @@ inline typename enable_if, void>::type eval_atan2(T& result, co eval_atan2(result, c, a); } +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif diff --git a/include/boost/multiprecision/detail/generic_interconvert.hpp b/include/boost/multiprecision/detail/generic_interconvert.hpp index 69f939fe..d1fa028d 100644 --- a/include/boost/multiprecision/detail/generic_interconvert.hpp +++ b/include/boost/multiprecision/detail/generic_interconvert.hpp @@ -10,7 +10,7 @@ #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable:4127) +#pragma warning(disable:4127 6326) #endif namespace boost{ namespace multiprecision{ namespace detail{ diff --git a/include/boost/multiprecision/detail/number_base.hpp b/include/boost/multiprecision/detail/number_base.hpp index ca1e4021..e8cb5c76 100644 --- a/include/boost/multiprecision/detail/number_base.hpp +++ b/include/boost/multiprecision/detail/number_base.hpp @@ -25,7 +25,13 @@ # define BOOST_MP_FORCEINLINE inline #endif -namespace boost{ namespace multiprecision{ +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable:6326) +#endif + +namespace boost{ + namespace multiprecision{ enum expression_template_option { @@ -975,6 +981,10 @@ namespace constants{ }} +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + #endif // BOOST_MATH_BIG_NUM_BASE_HPP diff --git a/include/boost/multiprecision/number.hpp b/include/boost/multiprecision/number.hpp index f5f0aced..adf09b1f 100644 --- a/include/boost/multiprecision/number.hpp +++ b/include/boost/multiprecision/number.hpp @@ -32,7 +32,7 @@ namespace boost{ namespace multiprecision{ // warning C4127: conditional expression is constant // warning C4714: function marked as __forceinline not inlined #pragma warning(push) -#pragma warning(disable:4127 4714) +#pragma warning(disable:4127 4714 6326) #endif template diff --git a/test/include_test/cpp_bin_float_include_test.cpp b/test/include_test/cpp_bin_float_include_test.cpp index b36c89e1..96862e87 100644 --- a/test/include_test/cpp_bin_float_include_test.cpp +++ b/test/include_test/cpp_bin_float_include_test.cpp @@ -7,6 +7,9 @@ using namespace boost::multiprecision; -cpp_bin_float<50> a; +int main() +{ + cpp_bin_float<50> a; +} diff --git a/test/include_test/cpp_dec_float_include_test.cpp b/test/include_test/cpp_dec_float_include_test.cpp index bdf09e83..1a721fcb 100644 --- a/test/include_test/cpp_dec_float_include_test.cpp +++ b/test/include_test/cpp_dec_float_include_test.cpp @@ -7,6 +7,9 @@ using namespace boost::multiprecision; -cpp_dec_float<50> a; +int main() +{ + cpp_dec_float<50> a; +} diff --git a/test/include_test/cpp_int_include_test.cpp b/test/include_test/cpp_int_include_test.cpp index e3742612..b7ad8285 100644 --- a/test/include_test/cpp_int_include_test.cpp +++ b/test/include_test/cpp_int_include_test.cpp @@ -7,10 +7,13 @@ using namespace boost::multiprecision; -number > a; -number, et_off> b; -number, et_off> c; -number, et_off> d; -number, et_off> e; +int main() +{ + number > a; + number, et_off> b; + number, et_off> c; + number, et_off> d; + number, et_off> e; +} diff --git a/test/include_test/gmp_include_test.cpp b/test/include_test/gmp_include_test.cpp index 4b07266f..7065ebd1 100644 --- a/test/include_test/gmp_include_test.cpp +++ b/test/include_test/gmp_include_test.cpp @@ -7,8 +7,11 @@ using namespace boost::multiprecision; -mpf_float a; -mpz_int b; -mpq_rational c; +int main() +{ + mpf_float a; + mpz_int b; + mpq_rational c; +} diff --git a/test/include_test/mpfr_include_test.cpp b/test/include_test/mpfr_include_test.cpp index f84cbb95..c49f24fc 100644 --- a/test/include_test/mpfr_include_test.cpp +++ b/test/include_test/mpfr_include_test.cpp @@ -7,6 +7,9 @@ using namespace boost::multiprecision; -mpfr_float a; +int main() +{ + mpfr_float a; +} diff --git a/test/include_test/tommath_include_test.cpp b/test/include_test/tommath_include_test.cpp index bc000fef..9f146dbf 100644 --- a/test/include_test/tommath_include_test.cpp +++ b/test/include_test/tommath_include_test.cpp @@ -7,6 +7,9 @@ using namespace boost::multiprecision; -tom_int a; +int main() +{ + tom_int a; +}