diff --git a/include/boost/decimal/decimal128.hpp b/include/boost/decimal/decimal128.hpp index b2a0dc60a..669020b8d 100644 --- a/include/boost/decimal/decimal128.hpp +++ b/include/boost/decimal/decimal128.hpp @@ -960,10 +960,8 @@ template #else template , bool>> #endif -constexpr decimal128::decimal128(Integer val) noexcept // NOLINT : Incorrect parameter is never used +constexpr decimal128::decimal128(Integer val) noexcept : decimal128{val, 0} { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal128{static_cast(val), 0}; } template diff --git a/include/boost/decimal/decimal128_fast.hpp b/include/boost/decimal/decimal128_fast.hpp index 4d8d80ee6..520c53ac0 100644 --- a/include/boost/decimal/decimal128_fast.hpp +++ b/include/boost/decimal/decimal128_fast.hpp @@ -412,10 +412,8 @@ template #else template , bool>> #endif -constexpr decimal128_fast::decimal128_fast(Integer val) noexcept +constexpr decimal128_fast::decimal128_fast(Integer val) noexcept : decimal128_fast{val, 0} { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal128_fast{static_cast(val), 0, false}; } #if defined(__clang__) diff --git a/include/boost/decimal/decimal32.hpp b/include/boost/decimal/decimal32.hpp index d60044ea5..22d355136 100644 --- a/include/boost/decimal/decimal32.hpp +++ b/include/boost/decimal/decimal32.hpp @@ -590,6 +590,7 @@ BOOST_DECIMAL_EXPORT class decimal32 final // NOLINT(cppcoreguidelines-special-m #if defined(__GNUC__) && __GNUC__ >= 6 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wduplicated-branches" +# pragma GCC diagnostic ignored "-Wbool-compare" #endif #ifdef BOOST_DECIMAL_HAS_CONCEPTS @@ -609,11 +610,21 @@ constexpr decimal32::decimal32(T coeff, T2 exp, bool sign) noexcept // NOLINT(re Unsigned_Integer unsigned_coeff {detail::make_positive_unsigned(coeff)}; BOOST_DECIMAL_IF_CONSTEXPR (detail::is_signed_v) { + // This branch will never be taken by bool but it throws a warning prior to C++17 + #ifdef _MSC_VER + # pragma warning(push) + # pragma warning(disable : 4804) + #endif + if (coeff < 0 || sign) { bits_ |= detail::d32_sign_mask; isneg = true; } + + #ifdef _MSC_VER + # pragma warning(pop) + #endif } else { @@ -1535,10 +1546,8 @@ template #else template , bool>> #endif -constexpr decimal32::decimal32(Integer val) noexcept // NOLINT : Incorrect parameter is never used +constexpr decimal32::decimal32(Integer val) noexcept : decimal32{val, 0}// NOLINT : Incorrect parameter is never used { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal32{static_cast(val), 0}; } template diff --git a/include/boost/decimal/decimal32_fast.hpp b/include/boost/decimal/decimal32_fast.hpp index 937e45080..ac47b76e8 100644 --- a/include/boost/decimal/decimal32_fast.hpp +++ b/include/boost/decimal/decimal32_fast.hpp @@ -393,10 +393,8 @@ constexpr decimal32_fast::decimal32_fast(T1 coeff, T2 exp, bool sign) noexcept } template , bool>> -constexpr decimal32_fast::decimal32_fast(Integer val) noexcept +constexpr decimal32_fast::decimal32_fast(Integer val) noexcept : decimal32_fast{val, 0} { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal32_fast{static_cast(val), 0, false}; } #if defined(__clang__) diff --git a/include/boost/decimal/decimal64.hpp b/include/boost/decimal/decimal64.hpp index 6f484caa5..19e089921 100644 --- a/include/boost/decimal/decimal64.hpp +++ b/include/boost/decimal/decimal64.hpp @@ -327,13 +327,6 @@ BOOST_DECIMAL_EXPORT class decimal64 final #endif constexpr decimal64(T1 coeff, T2 exp, bool sign = false) noexcept; - #ifdef BOOST_DECIMAL_HAS_CONCEPTS - template - #else - template , bool> = true> - #endif - constexpr decimal64(bool coeff, T exp, bool sign = false) noexcept; - // cmath functions that are easier as friends friend constexpr auto signbit BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal64 rhs) noexcept -> bool; friend constexpr auto isnan BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal64 rhs) noexcept -> bool; @@ -610,6 +603,7 @@ constexpr auto to_bits(decimal64 rhs) noexcept -> std::uint64_t #if defined(__GNUC__) && __GNUC__ >= 6 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wduplicated-branches" +# pragma GCC diagnostic ignored "-Wbool-compare" #endif // 3.2.5 initialization from coefficient and exponent: @@ -627,11 +621,21 @@ constexpr decimal64::decimal64(T1 coeff, T2 exp, bool sign) noexcept Unsigned_Integer unsigned_coeff {detail::make_positive_unsigned(coeff)}; BOOST_DECIMAL_IF_CONSTEXPR (detail::is_signed_v) { + // This branch will never be taken by bool but it throws a warning prior to C++17 + #ifdef _MSC_VER + # pragma warning(push) + # pragma warning(disable : 4804) + #endif + if (coeff < 0 || sign) { bits_ |= detail::d64_sign_mask; isneg = true; } + + #ifdef _MSC_VER + # pragma warning(pop) + #endif } else { @@ -860,10 +864,8 @@ template #else template , bool>> #endif -constexpr decimal64::decimal64(Integer val) noexcept // NOLINT : Incorrect parameter is never used +constexpr decimal64::decimal64(Integer val) noexcept : decimal64{val, 0} { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal64{static_cast(val), 0}; } template @@ -875,16 +877,6 @@ constexpr auto decimal64::operator=(const Integer& val) noexcept return *this; } -#ifdef BOOST_DECIMAL_HAS_CONCEPTS -template -#else -template , bool>> -#endif -constexpr decimal64::decimal64(bool coeff, T exp, bool sign) noexcept -{ - *this = decimal64(static_cast(coeff), exp, sign); -} - constexpr decimal64::operator bool() const noexcept { constexpr decimal64 zero {0, 0}; diff --git a/include/boost/decimal/decimal64_fast.hpp b/include/boost/decimal/decimal64_fast.hpp index ed7ec5711..ca9cf77ad 100644 --- a/include/boost/decimal/decimal64_fast.hpp +++ b/include/boost/decimal/decimal64_fast.hpp @@ -407,10 +407,8 @@ template #else template , bool>> #endif -constexpr decimal64_fast::decimal64_fast(Integer val) noexcept +constexpr decimal64_fast::decimal64_fast(Integer val) noexcept : decimal64_fast{val, 0} { - using ConversionType = std::conditional_t::value, std::int32_t, Integer>; - *this = decimal64_fast{static_cast(val), 0, false}; } #if defined(__clang__) diff --git a/include/boost/decimal/detail/type_traits.hpp b/include/boost/decimal/detail/type_traits.hpp index 0fd70f211..06a32846f 100644 --- a/include/boost/decimal/detail/type_traits.hpp +++ b/include/boost/decimal/detail/type_traits.hpp @@ -49,6 +49,9 @@ constexpr bool is_unsigned_v = !is_signed_v; template struct make_unsigned { using type = std::make_unsigned_t; }; +template <> +struct make_unsigned { using type = std::uint8_t; }; + template <> struct make_unsigned { using type = uint128; };