mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-29 12:32:38 +00:00
Fix warnings
This commit is contained in:
parent
4e99e09bb3
commit
c1e97392be
@ -520,7 +520,7 @@ struct chrono_formatter {
|
|||||||
std::chrono::duration<Rep, Period> d)
|
std::chrono::duration<Rep, Period> d)
|
||||||
: context(ctx), out(o), val(d.count()), negative(false) {
|
: context(ctx), out(o), val(d.count()), negative(false) {
|
||||||
if (d.count() < 0) {
|
if (d.count() < 0) {
|
||||||
val = -val;
|
val = 0 - val;
|
||||||
negative = true;
|
negative = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
|
|||||||
using value_type = format_part<char_type>;
|
using value_type = format_part<char_type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
using type = conditional_t<static_cast<bool>(number_of_format_parts),
|
using type = conditional_t<number_of_format_parts != 0,
|
||||||
format_parts_array<number_of_format_parts>, empty>;
|
format_parts_array<number_of_format_parts>, empty>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1741,11 +1741,14 @@ class arg_formatter_base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void write(const char_type* value) {
|
void write(const char_type* value) {
|
||||||
if (!value) FMT_THROW(format_error("string pointer is null"));
|
if (!value) {
|
||||||
|
FMT_THROW(format_error("string pointer is null"));
|
||||||
|
} else {
|
||||||
auto length = std::char_traits<char_type>::length(value);
|
auto length = std::char_traits<char_type>::length(value);
|
||||||
basic_string_view<char_type> sv(value, length);
|
basic_string_view<char_type> sv(value, length);
|
||||||
specs_ ? writer_.write(sv, *specs_) : writer_.write(sv);
|
specs_ ? writer_.write(sv, *specs_) : writer_.write(sv);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
arg_formatter_base(Range r, format_specs* s, locale_ref loc)
|
arg_formatter_base(Range r, format_specs* s, locale_ref loc)
|
||||||
@ -1851,7 +1854,7 @@ FMT_CONSTEXPR int parse_nonnegative_int(const Char*& begin, const Char* end,
|
|||||||
}
|
}
|
||||||
unsigned value = 0;
|
unsigned value = 0;
|
||||||
// Convert to unsigned to prevent a warning.
|
// Convert to unsigned to prevent a warning.
|
||||||
unsigned max_int = (std::numeric_limits<int>::max)();
|
constexpr unsigned max_int = (std::numeric_limits<int>::max)();
|
||||||
unsigned big = max_int / 10;
|
unsigned big = max_int / 10;
|
||||||
do {
|
do {
|
||||||
// Check for overflow.
|
// Check for overflow.
|
||||||
@ -2054,7 +2057,7 @@ FMT_CONSTEXPR void set_dynamic_spec(T& value, FormatArg arg, ErrorHandler eh) {
|
|||||||
struct auto_id {};
|
struct auto_id {};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
FMT_CONSTEXPR typename Context::format_arg get_arg(Context& ctx, unsigned id) {
|
FMT_CONSTEXPR typename Context::format_arg get_arg(Context& ctx, int id) {
|
||||||
auto arg = ctx.arg(id);
|
auto arg = ctx.arg(id);
|
||||||
if (!arg) ctx.on_error("argument index out of range");
|
if (!arg) ctx.on_error("argument index out of range");
|
||||||
return arg;
|
return arg;
|
||||||
@ -2092,7 +2095,7 @@ class specs_handler : public specs_setter<typename Context::char_type> {
|
|||||||
return internal::get_arg(context_, parse_context_.next_arg_id());
|
return internal::get_arg(context_, parse_context_.next_arg_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_CONSTEXPR format_arg get_arg(unsigned arg_id) {
|
FMT_CONSTEXPR format_arg get_arg(int arg_id) {
|
||||||
parse_context_.check_arg_id(arg_id);
|
parse_context_.check_arg_id(arg_id);
|
||||||
return internal::get_arg(context_, arg_id);
|
return internal::get_arg(context_, arg_id);
|
||||||
}
|
}
|
||||||
@ -2418,7 +2421,7 @@ inline bool find<false, char>(const char* first, const char* last, char value,
|
|||||||
|
|
||||||
template <typename Handler, typename Char> struct id_adapter {
|
template <typename Handler, typename Char> struct id_adapter {
|
||||||
FMT_CONSTEXPR void operator()() { handler.on_arg_id(); }
|
FMT_CONSTEXPR void operator()() { handler.on_arg_id(); }
|
||||||
FMT_CONSTEXPR void operator()(unsigned id) { handler.on_arg_id(id); }
|
FMT_CONSTEXPR void operator()(int id) { handler.on_arg_id(id); }
|
||||||
FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
|
FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
|
||||||
handler.on_arg_id(id);
|
handler.on_arg_id(id);
|
||||||
}
|
}
|
||||||
@ -2511,7 +2514,7 @@ class format_string_checker {
|
|||||||
arg_id_ = context_.next_arg_id();
|
arg_id_ = context_.next_arg_id();
|
||||||
check_arg_id();
|
check_arg_id();
|
||||||
}
|
}
|
||||||
FMT_CONSTEXPR void on_arg_id(unsigned id) {
|
FMT_CONSTEXPR void on_arg_id(int id) {
|
||||||
arg_id_ = id;
|
arg_id_ = id;
|
||||||
context_.check_arg_id(id);
|
context_.check_arg_id(id);
|
||||||
check_arg_id();
|
check_arg_id();
|
||||||
@ -2642,7 +2645,7 @@ class FMT_API system_error : public std::runtime_error {
|
|||||||
protected:
|
protected:
|
||||||
int error_code_;
|
int error_code_;
|
||||||
|
|
||||||
system_error() : std::runtime_error("") {}
|
system_error() : std::runtime_error(""), error_code_(0) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -3156,10 +3159,10 @@ struct format_handler : internal::error_handler {
|
|||||||
context.advance_to(out);
|
context.advance_to(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_arg(unsigned id) { arg = internal::get_arg(context, id); }
|
void get_arg(int id) { arg = internal::get_arg(context, id); }
|
||||||
|
|
||||||
void on_arg_id() { get_arg(parse_context.next_arg_id()); }
|
void on_arg_id() { get_arg(parse_context.next_arg_id()); }
|
||||||
void on_arg_id(unsigned id) {
|
void on_arg_id(int id) {
|
||||||
parse_context.check_arg_id(id);
|
parse_context.check_arg_id(id);
|
||||||
get_arg(id);
|
get_arg(id);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
|||||||
// yes, From always fits in To.
|
// yes, From always fits in To.
|
||||||
} else {
|
} else {
|
||||||
// from may not fit in To, we have to do a dynamic check
|
// from may not fit in To, we have to do a dynamic check
|
||||||
if (from > T::max()) {
|
if (from > static_cast<From>(T::max())) {
|
||||||
ec = 1;
|
ec = 1;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
|
|||||||
// yes, From always fits in To.
|
// yes, From always fits in To.
|
||||||
} else {
|
} else {
|
||||||
// from may not fit in To, we have to do a dynamic check
|
// from may not fit in To, we have to do a dynamic check
|
||||||
if (from > T::max()) {
|
if (from > static_cast<From>(T::max())) {
|
||||||
// outside range.
|
// outside range.
|
||||||
ec = 1;
|
ec = 1;
|
||||||
return {};
|
return {};
|
||||||
|
@ -1461,7 +1461,7 @@ TEST(FormatterTest, PrecisionRounding) {
|
|||||||
// Trigger rounding error in Grisu by a carefully chosen number.
|
// Trigger rounding error in Grisu by a carefully chosen number.
|
||||||
auto n = 3788512123356.985352;
|
auto n = 3788512123356.985352;
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
sprintf(buffer, "%f", n);
|
safe_sprintf(buffer, "%f", n);
|
||||||
EXPECT_EQ(buffer, format("{:f}", n));
|
EXPECT_EQ(buffer, format("{:f}", n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user