diff --git a/cppformat/format.cc b/cppformat/format.cc index 0857965e..908a5156 100644 --- a/cppformat/format.cc +++ b/cppformat/format.cc @@ -257,7 +257,7 @@ class WidthHandler : public fmt::internal::ArgVisitor { template unsigned visit_any_int(T value) { typedef typename fmt::internal::IntTraits::MainType UnsignedType; - UnsignedType width = value; + UnsignedType width = static_cast(value); if (fmt::internal::is_negative(value)) { spec_.align_ = fmt::ALIGN_LEFT; width = 0 - width; @@ -336,7 +336,7 @@ class ArgConverter : public fmt::internal::ArgVisitor, void> { // glibc's printf doesn't sign extend arguments of smaller types: // std::printf("%lld", -42); // prints "4294967254" // but we don't have to do the same because it's a UB. - arg_.long_long_value = value; + arg_.long_long_value = static_cast(value); } else { arg_.type = Arg::ULONG_LONG; arg_.ulong_long_value = @@ -786,7 +786,7 @@ void fmt::internal::PrintfFormatter::format( if (*s == '.') { ++s; if ('0' <= *s && *s <= '9') { - spec.precision_ = parse_nonnegative_int(s); + spec.precision_ = static_cast(parse_nonnegative_int(s)); } else if (*s == '*') { ++s; spec.precision_ = PrecisionHandler().visit(get_arg(s)); @@ -795,7 +795,7 @@ void fmt::internal::PrintfFormatter::format( Arg arg = get_arg(s, arg_index); if (spec.flag(HASH_FLAG) && IsZeroInt().visit(arg)) - spec.flags_ &= ~HASH_FLAG; + spec.flags_ &= ~to_unsigned(HASH_FLAG); if (spec.fill_ == '0') { if (arg.type <= Arg::LAST_NUMERIC_TYPE) spec.align_ = ALIGN_NUMERIC; diff --git a/cppformat/format.h b/cppformat/format.h index 9f81bb4a..22be015b 100644 --- a/cppformat/format.h +++ b/cppformat/format.h @@ -1832,7 +1832,7 @@ class FormatterBase { // Returns the next argument. Arg next_arg(const char *&error) { if (next_arg_index_ >= 0) - return do_get_arg(static_cast(next_arg_index_++), error); + return do_get_arg(internal::to_unsigned(next_arg_index_++), error); error = "cannot switch from manual to automatic argument indexing"; return Arg(); } @@ -2245,7 +2245,8 @@ class BasicWriter { // Writes a decimal integer. template void write_decimal(Int value) { - typename internal::IntTraits::MainType abs_value = value; + typedef typename internal::IntTraits::MainType MainType; + MainType abs_value = static_cast(value); if (internal::is_negative(value)) { abs_value = 0 - abs_value; *write_unsigned_decimal(abs_value, 1) = '-'; @@ -2548,7 +2549,8 @@ typename BasicWriter::CharPtr // is specified. if (prefix_size > 0 && prefix[prefix_size - 1] == '0') --prefix_size; - unsigned number_size = prefix_size + spec.precision(); + unsigned number_size = + prefix_size + internal::to_unsigned(spec.precision()); AlignSpec subspec(number_size, '0', ALIGN_NUMERIC); if (number_size >= width) return prepare_int_buffer(num_digits, subspec, prefix, prefix_size); @@ -3430,7 +3432,7 @@ inline bool is_name_start(Char c) { // Parses an unsigned integer advancing s to the end of the parsed input. // This function assumes that the first character of s is a digit. template -int parse_nonnegative_int(const Char *&s) { +unsigned parse_nonnegative_int(const Char *&s) { assert('0' <= *s && *s <= '9'); unsigned value = 0; do {