From 7d71fac5cb07b0bd41e5119f8f1441b63cfaadca Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 13 Feb 2023 09:39:07 -0800 Subject: [PATCH] Avoid signed/unsigned conversion warnings --- include/boost/charconv/from_chars.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/boost/charconv/from_chars.hpp b/include/boost/charconv/from_chars.hpp index 8505cc7..2ef7a18 100644 --- a/include/boost/charconv/from_chars.hpp +++ b/include/boost/charconv/from_chars.hpp @@ -87,10 +87,13 @@ BOOST_CXX14_CONSTEXPR from_chars_result from_chars_integer_impl(const char* firs return {first, EINVAL}; } + Unsigned_Integer unsigned_base = static_cast(base); + // Strip sign if the type is signed // Negative sign will be appended at the end of parsing BOOST_ATTRIBUTE_UNUSED bool is_negative = false; auto next = first; + #ifdef BOOST_CHARCONV_HAS_INT128 BOOST_IF_CONSTEXPR (std::is_same::value || std::is_signed::value) #else @@ -157,8 +160,8 @@ BOOST_CXX14_CONSTEXPR from_chars_result from_chars_integer_impl(const char* firs } } - overflow_value /= static_cast(base); - max_digit %= base; + overflow_value /= unsigned_base; + max_digit %= unsigned_base; // If the only character was a sign abort now if (next == last) @@ -169,16 +172,16 @@ BOOST_CXX14_CONSTEXPR from_chars_result from_chars_integer_impl(const char* firs bool overflowed = false; while (next != last) { - auto current_digit = digit_from_char(*next); + const unsigned char current_digit = digit_from_char(*next); - if (current_digit >= base) + if (current_digit >= unsigned_base) { break; } if (result < overflow_value || (result == overflow_value && current_digit <= max_digit)) { - result = static_cast(result * base + current_digit); + result = static_cast(result * unsigned_base + current_digit); } else {