diff --git a/include/fmt/core.h b/include/fmt/core.h index c61738a2837d6..e6a6bb5afff77 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -749,7 +749,7 @@ class basic_parse_context : private ErrorHandler { // Advances the begin iterator to ``it``. FMT_CONSTEXPR void advance_to(iterator it) { - format_str_.remove_prefix(it - begin()); + format_str_.remove_prefix(to_unsigned(it - begin())); } // Returns the next argument index. @@ -1074,7 +1074,7 @@ class basic_format_args { format_arg do_get(size_type index) const { int64_t signed_types = static_cast(types_); if (signed_types < 0) { - uint64_t num_args = -signed_types; + uint64_t num_args = static_cast(-signed_types); return index < num_args ? args_[index] : format_arg(); } format_arg arg; diff --git a/include/fmt/format.h b/include/fmt/format.h index 07d7a0661e9aa..ede2014b157a2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1004,7 +1004,7 @@ class decimal_formatter { uint64_t t = ((1ULL << (32 + a)) / data::POWERS_OF_10_32[n] + 1 - n / 9); t = ((t * u) >> a) + n / 5 * 4; write_pair(0, t >> 32); - for (int i = 2; i < N; i += 2) { + for (unsigned i = 2; i < N; i += 2) { t = 100ULL * static_cast(t); write_pair(i, t >> 32); } @@ -1670,7 +1670,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(Iterator &it, ErrorHandler &&eh) { value = max_int + 1; break; } - value = value * 10 + (*it - '0'); + value = value * 10 + unsigned(*it - '0'); // Workaround for MSVC "setup_exception stack overflow" error: auto next = it; ++next; @@ -1717,7 +1717,7 @@ class width_checker: public function { is_integer::value, unsigned long long>::type operator()(T value) { if (is_negative(value)) handler_.on_error("negative width"); - return value; + return static_cast(value); } template @@ -1741,7 +1741,7 @@ class precision_checker: public function { is_integer::value, unsigned long long>::type operator()(T value) { if (is_negative(value)) handler_.on_error("negative precision"); - return value; + return static_cast(value); } template @@ -1778,7 +1778,7 @@ class specs_setter { FMT_CONSTEXPR void on_width(unsigned width) { specs_.width_ = width; } FMT_CONSTEXPR void on_precision(unsigned precision) { - specs_.precision_ = precision; + specs_.precision_ = static_cast(precision); } FMT_CONSTEXPR void end_precision() {} @@ -1859,7 +1859,7 @@ FMT_CONSTEXPR void set_dynamic_spec( unsigned long long big_value = visit(Handler(eh), arg); if (big_value > (std::numeric_limits::max)()) eh.on_error("number is too big"); - value = static_cast(big_value); + value = static_cast(big_value); } struct auto_id {}; @@ -2006,7 +2006,7 @@ FMT_CONSTEXPR Iterator parse_arg_id(Iterator it, IDHandler &&handler) { do { c = *++it; } while (is_name_start(c) || ('0' <= c && c <= '9')); - handler(basic_string_view(pointer_from(start), it - start)); + handler(basic_string_view(pointer_from(start), to_unsigned(it - start))); return it; } @@ -2474,8 +2474,8 @@ class basic_writer { size = spec.width(); } } else if (spec.precision() > static_cast(num_digits)) { - size = prefix.size() + spec.precision(); - padding = spec.precision() - num_digits; + size = prefix.size() + static_cast(spec.precision()); + padding = static_cast(spec.precision()) - num_digits; fill = '0'; } align_spec as = spec; @@ -3332,8 +3332,8 @@ struct format_handler : internal::error_handler { : context(r.begin(), str, format_args) {} void on_text(iterator begin, iterator end) { - size_t size = end - begin; - auto out = context.out(); + auto size = to_unsigned(end - begin); + auto out = context.begin(); auto &&it = internal::reserve(out, size); it = std::copy_n(begin, size, it); context.advance_to(out);