mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-28 18:32:46 +00:00
Fix sign conversion warnings (#790)
This commit is contained in:
parent
2e95823ef7
commit
c6d9730ddb
@ -199,10 +199,19 @@
|
|||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// An implementation of declval for pre-C++11 compilers such as gcc 4.
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
// An implementation of declval for pre-C++11 compilers such as gcc 4.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::add_rvalue_reference<T>::type declval() FMT_NOEXCEPT;
|
typename std::add_rvalue_reference<T>::type declval() FMT_NOEXCEPT;
|
||||||
|
|
||||||
|
// Casts nonnegative integer to unsigned.
|
||||||
|
template <typename Int>
|
||||||
|
FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
|
||||||
|
FMT_ASSERT(value >= 0, "negative value");
|
||||||
|
return static_cast<typename std::make_unsigned<Int>::type>(value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -749,7 +758,7 @@ class basic_parse_context : private ErrorHandler {
|
|||||||
|
|
||||||
// Advances the begin iterator to ``it``.
|
// Advances the begin iterator to ``it``.
|
||||||
FMT_CONSTEXPR void advance_to(iterator it) {
|
FMT_CONSTEXPR void advance_to(iterator it) {
|
||||||
format_str_.remove_prefix(it - begin());
|
format_str_.remove_prefix(internal::to_unsigned(it - begin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the next argument index.
|
// Returns the next argument index.
|
||||||
@ -1074,7 +1083,7 @@ class basic_format_args {
|
|||||||
format_arg do_get(size_type index) const {
|
format_arg do_get(size_type index) const {
|
||||||
int64_t signed_types = static_cast<int64_t>(types_);
|
int64_t signed_types = static_cast<int64_t>(types_);
|
||||||
if (signed_types < 0) {
|
if (signed_types < 0) {
|
||||||
uint64_t num_args = -signed_types;
|
uint64_t num_args = static_cast<uint64_t>(-signed_types);
|
||||||
return index < num_args ? args_[index] : format_arg();
|
return index < num_args ? args_[index] : format_arg();
|
||||||
}
|
}
|
||||||
format_arg arg;
|
format_arg arg;
|
||||||
|
@ -461,13 +461,6 @@ class format_error : public std::runtime_error {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// Casts nonnegative integer to unsigned.
|
|
||||||
template <typename Int>
|
|
||||||
FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
|
|
||||||
FMT_ASSERT(value >= 0, "negative value");
|
|
||||||
return static_cast<typename std::make_unsigned<Int>::type>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if FMT_SECURE_SCL
|
#if FMT_SECURE_SCL
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct checked { typedef stdext::checked_array_iterator<T*> type; };
|
struct checked { typedef stdext::checked_array_iterator<T*> type; };
|
||||||
@ -1004,7 +997,7 @@ class decimal_formatter {
|
|||||||
uint64_t t = ((1ULL << (32 + a)) / data::POWERS_OF_10_32[n] + 1 - n / 9);
|
uint64_t t = ((1ULL << (32 + a)) / data::POWERS_OF_10_32[n] + 1 - n / 9);
|
||||||
t = ((t * u) >> a) + n / 5 * 4;
|
t = ((t * u) >> a) + n / 5 * 4;
|
||||||
write_pair(0, t >> 32);
|
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<uint32_t>(t);
|
t = 100ULL * static_cast<uint32_t>(t);
|
||||||
write_pair(i, t >> 32);
|
write_pair(i, t >> 32);
|
||||||
}
|
}
|
||||||
@ -1670,7 +1663,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(Iterator &it, ErrorHandler &&eh) {
|
|||||||
value = max_int + 1;
|
value = max_int + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value = value * 10 + (*it - '0');
|
value = value * 10 + unsigned(*it - '0');
|
||||||
// Workaround for MSVC "setup_exception stack overflow" error:
|
// Workaround for MSVC "setup_exception stack overflow" error:
|
||||||
auto next = it;
|
auto next = it;
|
||||||
++next;
|
++next;
|
||||||
@ -1717,7 +1710,7 @@ class width_checker: public function<unsigned long long> {
|
|||||||
is_integer<T>::value, unsigned long long>::type operator()(T value) {
|
is_integer<T>::value, unsigned long long>::type operator()(T value) {
|
||||||
if (is_negative(value))
|
if (is_negative(value))
|
||||||
handler_.on_error("negative width");
|
handler_.on_error("negative width");
|
||||||
return value;
|
return static_cast<unsigned long long>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -1741,7 +1734,7 @@ class precision_checker: public function<unsigned long long> {
|
|||||||
is_integer<T>::value, unsigned long long>::type operator()(T value) {
|
is_integer<T>::value, unsigned long long>::type operator()(T value) {
|
||||||
if (is_negative(value))
|
if (is_negative(value))
|
||||||
handler_.on_error("negative precision");
|
handler_.on_error("negative precision");
|
||||||
return value;
|
return static_cast<unsigned long long>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -1778,7 +1771,7 @@ class specs_setter {
|
|||||||
|
|
||||||
FMT_CONSTEXPR void on_width(unsigned width) { specs_.width_ = width; }
|
FMT_CONSTEXPR void on_width(unsigned width) { specs_.width_ = width; }
|
||||||
FMT_CONSTEXPR void on_precision(unsigned precision) {
|
FMT_CONSTEXPR void on_precision(unsigned precision) {
|
||||||
specs_.precision_ = precision;
|
specs_.precision_ = static_cast<int>(precision);
|
||||||
}
|
}
|
||||||
FMT_CONSTEXPR void end_precision() {}
|
FMT_CONSTEXPR void end_precision() {}
|
||||||
|
|
||||||
@ -1859,7 +1852,7 @@ FMT_CONSTEXPR void set_dynamic_spec(
|
|||||||
unsigned long long big_value = visit(Handler<ErrorHandler>(eh), arg);
|
unsigned long long big_value = visit(Handler<ErrorHandler>(eh), arg);
|
||||||
if (big_value > (std::numeric_limits<int>::max)())
|
if (big_value > (std::numeric_limits<int>::max)())
|
||||||
eh.on_error("number is too big");
|
eh.on_error("number is too big");
|
||||||
value = static_cast<int>(big_value);
|
value = static_cast<T>(big_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct auto_id {};
|
struct auto_id {};
|
||||||
@ -2006,7 +1999,7 @@ FMT_CONSTEXPR Iterator parse_arg_id(Iterator it, IDHandler &&handler) {
|
|||||||
do {
|
do {
|
||||||
c = *++it;
|
c = *++it;
|
||||||
} while (is_name_start(c) || ('0' <= c && c <= '9'));
|
} while (is_name_start(c) || ('0' <= c && c <= '9'));
|
||||||
handler(basic_string_view<char_type>(pointer_from(start), it - start));
|
handler(basic_string_view<char_type>(pointer_from(start), to_unsigned(it - start)));
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2474,8 +2467,8 @@ class basic_writer {
|
|||||||
size = spec.width();
|
size = spec.width();
|
||||||
}
|
}
|
||||||
} else if (spec.precision() > static_cast<int>(num_digits)) {
|
} else if (spec.precision() > static_cast<int>(num_digits)) {
|
||||||
size = prefix.size() + spec.precision();
|
size = prefix.size() + static_cast<std::size_t>(spec.precision());
|
||||||
padding = spec.precision() - num_digits;
|
padding = static_cast<std::size_t>(spec.precision()) - num_digits;
|
||||||
fill = '0';
|
fill = '0';
|
||||||
}
|
}
|
||||||
align_spec as = spec;
|
align_spec as = spec;
|
||||||
@ -3332,7 +3325,7 @@ struct format_handler : internal::error_handler {
|
|||||||
: context(r.begin(), str, format_args) {}
|
: context(r.begin(), str, format_args) {}
|
||||||
|
|
||||||
void on_text(iterator begin, iterator end) {
|
void on_text(iterator begin, iterator end) {
|
||||||
size_t size = end - begin;
|
auto size = internal::to_unsigned(end - begin);
|
||||||
auto out = context.out();
|
auto out = context.out();
|
||||||
auto &&it = internal::reserve(out, size);
|
auto &&it = internal::reserve(out, size);
|
||||||
it = std::copy_n(begin, size, it);
|
it = std::copy_n(begin, size, it);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user