Fix sign conversion warning
This commit is contained in:
parent
1f92f8a9d8
commit
fda7611caf
@ -377,7 +377,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
|||||||
-> decltype(ctx.begin()) {
|
-> decltype(ctx.begin()) {
|
||||||
auto begin = ctx.begin(), end = ctx.end();
|
auto begin = ctx.begin(), end = ctx.end();
|
||||||
end = parse_chrono_format(begin, end, internal::chrono_format_checker());
|
end = parse_chrono_format(begin, end, internal::chrono_format_checker());
|
||||||
format_str = basic_string_view<Char>(&*begin, end - begin);
|
format_str = basic_string_view<Char>(&*begin, static_cast<size_t>(end - begin));
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -246,7 +246,7 @@ struct color_type {
|
|||||||
}
|
}
|
||||||
FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT
|
FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT
|
||||||
: is_rgb(true), value{} {
|
: is_rgb(true), value{} {
|
||||||
value.rgb_color = (rgb_color.r << 16) + (rgb_color.g << 8) + rgb_color.b;
|
value.rgb_color = (static_cast<uint32_t>(rgb_color.r) << 16) | (static_cast<uint32_t>(rgb_color.g) << 8) | rgb_color.b;
|
||||||
}
|
}
|
||||||
FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT
|
FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT
|
||||||
: is_rgb(), value{} {
|
: is_rgb(), value{} {
|
||||||
@ -395,22 +395,22 @@ struct ansi_color_escape {
|
|||||||
// sequence.
|
// sequence.
|
||||||
if (!text_color.is_rgb) {
|
if (!text_color.is_rgb) {
|
||||||
bool is_background = esc == internal::data::BACKGROUND_COLOR;
|
bool is_background = esc == internal::data::BACKGROUND_COLOR;
|
||||||
uint8_t value = text_color.value.term_color;
|
uint32_t value = text_color.value.term_color;
|
||||||
// Background ASCII codes are the same as the foreground ones but with
|
// Background ASCII codes are the same as the foreground ones but with
|
||||||
// 10 more.
|
// 10 more.
|
||||||
if (is_background)
|
if (is_background)
|
||||||
value += 10;
|
value += 10u;
|
||||||
|
|
||||||
std::size_t index = 0;
|
std::size_t index = 0;
|
||||||
buffer[index++] = static_cast<Char>('\x1b');
|
buffer[index++] = static_cast<Char>('\x1b');
|
||||||
buffer[index++] = static_cast<Char>('[');
|
buffer[index++] = static_cast<Char>('[');
|
||||||
|
|
||||||
if (value >= 100) {
|
if (value >= 100u) {
|
||||||
buffer[index++] = static_cast<Char>('1');
|
buffer[index++] = static_cast<Char>('1');
|
||||||
value %= 100;
|
value %= 100u;
|
||||||
}
|
}
|
||||||
buffer[index++] = static_cast<Char>('0' + value / 10);
|
buffer[index++] = static_cast<Char>('0' + value / 10u);
|
||||||
buffer[index++] = static_cast<Char>('0' + value % 10);
|
buffer[index++] = static_cast<Char>('0' + value % 10u);
|
||||||
|
|
||||||
buffer[index++] = static_cast<Char>('m');
|
buffer[index++] = static_cast<Char>('m');
|
||||||
buffer[index++] = static_cast<Char>('\0');
|
buffer[index++] = static_cast<Char>('\0');
|
||||||
@ -452,7 +452,7 @@ struct ansi_color_escape {
|
|||||||
FMT_CONSTEXPR operator const Char *() const FMT_NOEXCEPT { return buffer; }
|
FMT_CONSTEXPR operator const Char *() const FMT_NOEXCEPT { return buffer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Char buffer[7 + 3 * 4 + 1];
|
Char buffer[7u + 3u * 4u + 1u];
|
||||||
|
|
||||||
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out,
|
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out,
|
||||||
char delimiter) FMT_NOEXCEPT {
|
char delimiter) FMT_NOEXCEPT {
|
||||||
|
|||||||
@ -464,14 +464,14 @@ FMT_FUNC fp get_cached_power(int min_exponent, int &pow10_exponent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FMT_FUNC bool grisu2_round(
|
FMT_FUNC bool grisu2_round(
|
||||||
char *buf, ptrdiff_t &size, size_t max_digits, uint64_t delta,
|
char *buf, int &size, int max_digits, uint64_t delta,
|
||||||
uint64_t remainder, uint64_t exp, uint64_t diff, int &exp10) {
|
uint64_t remainder, uint64_t exp, uint64_t diff, int &exp10) {
|
||||||
while (remainder < diff && delta - remainder >= exp &&
|
while (remainder < diff && delta - remainder >= exp &&
|
||||||
(remainder + exp < diff || diff - remainder > remainder + exp - diff)) {
|
(remainder + exp < diff || diff - remainder > remainder + exp - diff)) {
|
||||||
--buf[size - 1];
|
--buf[size - 1];
|
||||||
remainder += exp;
|
remainder += exp;
|
||||||
}
|
}
|
||||||
if (size > static_cast<ptrdiff_t>(max_digits)) {
|
if (size > max_digits) {
|
||||||
--size;
|
--size;
|
||||||
++exp10;
|
++exp10;
|
||||||
if (buf[size] >= '5')
|
if (buf[size] >= '5')
|
||||||
@ -482,8 +482,8 @@ FMT_FUNC bool grisu2_round(
|
|||||||
|
|
||||||
// Generates output using Grisu2 digit-gen algorithm.
|
// Generates output using Grisu2 digit-gen algorithm.
|
||||||
FMT_FUNC bool grisu2_gen_digits(
|
FMT_FUNC bool grisu2_gen_digits(
|
||||||
char *buf, ptrdiff_t &size, uint32_t hi, uint64_t lo, int &exp,
|
char *buf, int &size, uint32_t hi, uint64_t lo, int &exp,
|
||||||
uint64_t delta, const fp &one, const fp &diff, size_t max_digits) {
|
uint64_t delta, const fp &one, const fp &diff, int max_digits) {
|
||||||
// Generate digits for the most significant part (hi).
|
// Generate digits for the most significant part (hi).
|
||||||
while (exp > 0) {
|
while (exp > 0) {
|
||||||
uint32_t digit = 0;
|
uint32_t digit = 0;
|
||||||
@ -507,7 +507,7 @@ FMT_FUNC bool grisu2_gen_digits(
|
|||||||
buf[size++] = static_cast<char>('0' + digit);
|
buf[size++] = static_cast<char>('0' + digit);
|
||||||
--exp;
|
--exp;
|
||||||
uint64_t remainder = (static_cast<uint64_t>(hi) << -one.e) + lo;
|
uint64_t remainder = (static_cast<uint64_t>(hi) << -one.e) + lo;
|
||||||
if (remainder <= delta || size > static_cast<ptrdiff_t>(max_digits)) {
|
if (remainder <= delta || size > max_digits) {
|
||||||
return grisu2_round(
|
return grisu2_round(
|
||||||
buf, size, max_digits, delta, remainder,
|
buf, size, max_digits, delta, remainder,
|
||||||
static_cast<uint64_t>(data::POWERS_OF_10_32[exp]) << -one.e,
|
static_cast<uint64_t>(data::POWERS_OF_10_32[exp]) << -one.e,
|
||||||
@ -523,7 +523,7 @@ FMT_FUNC bool grisu2_gen_digits(
|
|||||||
buf[size++] = static_cast<char>('0' + digit);
|
buf[size++] = static_cast<char>('0' + digit);
|
||||||
lo &= one.f - 1;
|
lo &= one.f - 1;
|
||||||
--exp;
|
--exp;
|
||||||
if (lo < delta || size > static_cast<ptrdiff_t>(max_digits)) {
|
if (lo < delta || size > max_digits) {
|
||||||
return grisu2_round(buf, size, max_digits, delta, lo, one.f,
|
return grisu2_round(buf, size, max_digits, delta, lo, one.f,
|
||||||
diff.f * data::POWERS_OF_10_32[-exp], exp);
|
diff.f * data::POWERS_OF_10_32[-exp], exp);
|
||||||
}
|
}
|
||||||
@ -704,7 +704,7 @@ FMT_FUNC gen_digits_params process_specs(const core_format_specs &specs,
|
|||||||
++num_digits;
|
++num_digits;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
params.num_digits = to_unsigned(num_digits);
|
params.num_digits = num_digits;
|
||||||
char_counter counter{num_digits};
|
char_counter counter{num_digits};
|
||||||
grisu2_prettify(params, params.num_digits, exp - num_digits, counter);
|
grisu2_prettify(params, params.num_digits, exp - num_digits, counter);
|
||||||
buf.resize(to_unsigned(counter.size));
|
buf.resize(to_unsigned(counter.size));
|
||||||
@ -750,7 +750,7 @@ FMT_FUNC typename std::enable_if<sizeof(Double) == sizeof(uint64_t), bool>::type
|
|||||||
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
|
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
|
||||||
// lo = supper % one.
|
// lo = supper % one.
|
||||||
uint64_t lo = upper.f & (one.f - 1);
|
uint64_t lo = upper.f & (one.f - 1);
|
||||||
ptrdiff_t size = 0;
|
int size = 0;
|
||||||
if (!grisu2_gen_digits(buf.data(), size, hi, lo, exp, delta, one, diff,
|
if (!grisu2_gen_digits(buf.data(), size, hi, lo, exp, delta, one, diff,
|
||||||
params.num_digits)) {
|
params.num_digits)) {
|
||||||
buf.clear();
|
buf.clear();
|
||||||
|
|||||||
@ -66,10 +66,6 @@
|
|||||||
// many valid cases.
|
// many valid cases.
|
||||||
# pragma GCC diagnostic ignored "-Wshadow"
|
# pragma GCC diagnostic ignored "-Wshadow"
|
||||||
|
|
||||||
// Disable the warning about implicit conversions that may change the sign of
|
|
||||||
// an integer; silencing it otherwise would require many explicit casts.
|
|
||||||
# pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
||||||
|
|
||||||
// Disable the warning about nonliteral format strings because we construct
|
// Disable the warning about nonliteral format strings because we construct
|
||||||
// them dynamically when falling back to snprintf for FP formatting.
|
// them dynamically when falling back to snprintf for FP formatting.
|
||||||
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||||
@ -956,8 +952,9 @@ inline wchar_t thousands_sep(locale_ref loc) {
|
|||||||
// thousands_sep is a functor that is called after writing each char to
|
// thousands_sep is a functor that is called after writing each char to
|
||||||
// add a thousands separator if necessary.
|
// add a thousands separator if necessary.
|
||||||
template <typename UInt, typename Char, typename ThousandsSep>
|
template <typename UInt, typename Char, typename ThousandsSep>
|
||||||
inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits,
|
inline Char *format_decimal(Char *buffer, UInt value, int num_digits,
|
||||||
ThousandsSep thousands_sep) {
|
ThousandsSep thousands_sep) {
|
||||||
|
FMT_ASSERT(num_digits >= 0, "invalid digit count");
|
||||||
buffer += num_digits;
|
buffer += num_digits;
|
||||||
Char *end = buffer;
|
Char *end = buffer;
|
||||||
while (value >= 100) {
|
while (value >= 100) {
|
||||||
@ -985,7 +982,8 @@ inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits,
|
|||||||
template <typename OutChar, typename UInt, typename Iterator,
|
template <typename OutChar, typename UInt, typename Iterator,
|
||||||
typename ThousandsSep>
|
typename ThousandsSep>
|
||||||
inline Iterator format_decimal(
|
inline Iterator format_decimal(
|
||||||
Iterator out, UInt value, unsigned num_digits, ThousandsSep sep) {
|
Iterator out, UInt value, int num_digits, ThousandsSep sep) {
|
||||||
|
FMT_ASSERT(num_digits >= 0, "invalid digit count");
|
||||||
typedef typename ThousandsSep::char_type char_type;
|
typedef typename ThousandsSep::char_type char_type;
|
||||||
// Buffer should be large enough to hold all digits (<= digits10 + 1).
|
// Buffer should be large enough to hold all digits (<= digits10 + 1).
|
||||||
enum { max_size = std::numeric_limits<UInt>::digits10 + 1 };
|
enum { max_size = std::numeric_limits<UInt>::digits10 + 1 };
|
||||||
@ -996,12 +994,12 @@ inline Iterator format_decimal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename OutChar, typename It, typename UInt>
|
template <typename OutChar, typename It, typename UInt>
|
||||||
inline It format_decimal(It out, UInt value, unsigned num_digits) {
|
inline It format_decimal(It out, UInt value, int num_digits) {
|
||||||
return format_decimal<OutChar>(out, value, num_digits, no_thousands_sep());
|
return format_decimal<OutChar>(out, value, num_digits, no_thousands_sep());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <unsigned BASE_BITS, typename Char, typename UInt>
|
template <unsigned BASE_BITS, typename Char, typename UInt>
|
||||||
inline Char *format_uint(Char *buffer, UInt value, unsigned num_digits,
|
inline Char *format_uint(Char *buffer, UInt value, int num_digits,
|
||||||
bool upper = false) {
|
bool upper = false) {
|
||||||
buffer += num_digits;
|
buffer += num_digits;
|
||||||
Char *end = buffer;
|
Char *end = buffer;
|
||||||
@ -1014,7 +1012,7 @@ inline Char *format_uint(Char *buffer, UInt value, unsigned num_digits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <unsigned BASE_BITS, typename Char, typename It, typename UInt>
|
template <unsigned BASE_BITS, typename Char, typename It, typename UInt>
|
||||||
inline It format_uint(It out, UInt value, unsigned num_digits,
|
inline It format_uint(It out, UInt value, int num_digits,
|
||||||
bool upper = false) {
|
bool upper = false) {
|
||||||
// Buffer should be large enough to hold all digits (digits / BASE_BITS + 1)
|
// Buffer should be large enough to hold all digits (digits / BASE_BITS + 1)
|
||||||
// and null.
|
// and null.
|
||||||
|
|||||||
@ -122,7 +122,7 @@ struct formatter<std::tm, Char> {
|
|||||||
auto end = it;
|
auto end = it;
|
||||||
while (end != ctx.end() && *end != '}')
|
while (end != ctx.end() && *end != '}')
|
||||||
++end;
|
++end;
|
||||||
tm_format.reserve(end - it + 1);
|
tm_format.reserve(static_cast<size_t>(end - it + 1));
|
||||||
tm_format.append(it, end);
|
tm_format.append(it, end);
|
||||||
tm_format.push_back('\0');
|
tm_format.push_back('\0');
|
||||||
return end;
|
return end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user