Commit 230b2494 authored by Victor Zverovich's avatar Victor Zverovich

Fix sign conversion warnings

parent cadd92d6
...@@ -447,13 +447,13 @@ class basic_parse_context : private ErrorHandler { ...@@ -447,13 +447,13 @@ class basic_parse_context : private ErrorHandler {
} }
// Returns the next argument index. // Returns the next argument index.
FMT_CONSTEXPR unsigned next_arg_id() { FMT_CONSTEXPR int next_arg_id() {
if (next_arg_id_ >= 0) return internal::to_unsigned(next_arg_id_++); if (next_arg_id_ >= 0) return next_arg_id_++;
on_error("cannot switch from manual to automatic argument indexing"); on_error("cannot switch from manual to automatic argument indexing");
return 0; return 0;
} }
FMT_CONSTEXPR bool check_arg_id(unsigned) { FMT_CONSTEXPR bool check_arg_id(int) {
if (next_arg_id_ > 0) { if (next_arg_id_ > 0) {
on_error("cannot switch from automatic to manual argument indexing"); on_error("cannot switch from automatic to manual argument indexing");
return false; return false;
...@@ -1051,7 +1051,7 @@ template <typename OutputIt, typename Char> class basic_format_context { ...@@ -1051,7 +1051,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
internal::locale_ref loc = internal::locale_ref()) internal::locale_ref loc = internal::locale_ref())
: out_(out), args_(ctx_args), loc_(loc) {} : out_(out), args_(ctx_args), loc_(loc) {}
format_arg arg(unsigned id) const { return args_.get(id); } format_arg arg(int id) const { return args_.get(id); }
// Checks if manual indexing is used and returns the argument with the // Checks if manual indexing is used and returns the argument with the
// specified name. // specified name.
...@@ -1123,7 +1123,7 @@ inline format_arg_store<Context, Args...> make_format_args( ...@@ -1123,7 +1123,7 @@ inline format_arg_store<Context, Args...> make_format_args(
/** Formatting arguments. */ /** Formatting arguments. */
template <typename Context> class basic_format_args { template <typename Context> class basic_format_args {
public: public:
using size_type = unsigned; using size_type = int;
using format_arg = basic_format_arg<Context>; using format_arg = basic_format_arg<Context>;
private: private:
...@@ -1142,8 +1142,8 @@ template <typename Context> class basic_format_args { ...@@ -1142,8 +1142,8 @@ template <typename Context> class basic_format_args {
bool is_packed() const { return (types_ & internal::is_unpacked_bit) == 0; } bool is_packed() const { return (types_ & internal::is_unpacked_bit) == 0; }
internal::type type(unsigned index) const { internal::type type(int index) const {
unsigned shift = index * 4; int shift = index * 4;
return static_cast<internal::type>((types_ & (0xfull << shift)) >> shift); return static_cast<internal::type>((types_ & (0xfull << shift)) >> shift);
} }
...@@ -1152,7 +1152,7 @@ template <typename Context> class basic_format_args { ...@@ -1152,7 +1152,7 @@ template <typename Context> class basic_format_args {
void set_data(const internal::value<Context>* values) { values_ = values; } void set_data(const internal::value<Context>* values) { values_ = values; }
void set_data(const format_arg* args) { args_ = args; } void set_data(const format_arg* args) { args_ = args; }
format_arg do_get(size_type index) const { format_arg do_get(int index) const {
format_arg arg; format_arg arg;
if (!is_packed()) { if (!is_packed()) {
auto num_args = max_size(); auto num_args = max_size();
...@@ -1192,14 +1192,14 @@ template <typename Context> class basic_format_args { ...@@ -1192,14 +1192,14 @@ template <typename Context> class basic_format_args {
} }
/** Returns the argument at specified index. */ /** Returns the argument at specified index. */
format_arg get(size_type index) const { format_arg get(int index) const {
format_arg arg = do_get(index); format_arg arg = do_get(index);
if (arg.type_ == internal::named_arg_type) if (arg.type_ == internal::named_arg_type)
arg = arg.value_.named_arg->template deserialize<Context>(); arg = arg.value_.named_arg->template deserialize<Context>();
return arg; return arg;
} }
size_type max_size() const { int max_size() const {
unsigned long long max_packed = internal::max_packed_args; unsigned long long max_packed = internal::max_packed_args;
return static_cast<size_type>( return static_cast<size_type>(
is_packed() ? max_packed : types_ & ~internal::is_unpacked_bit); is_packed() ? max_packed : types_ & ~internal::is_unpacked_bit);
......
...@@ -1254,13 +1254,13 @@ void arg_map<Context>::init(const basic_format_args<Context>& args) { ...@@ -1254,13 +1254,13 @@ void arg_map<Context>::init(const basic_format_args<Context>& args) {
if (map_) return; if (map_) return;
map_ = new entry[args.max_size()]; map_ = new entry[args.max_size()];
if (args.is_packed()) { if (args.is_packed()) {
for (unsigned i = 0;; ++i) { for (int i = 0;; ++i) {
internal::type arg_type = args.type(i); internal::type arg_type = args.type(i);
if (arg_type == internal::none_type) return; if (arg_type == internal::none_type) return;
if (arg_type == internal::named_arg_type) push_back(args.values_[i]); if (arg_type == internal::named_arg_type) push_back(args.values_[i]);
} }
} }
for (unsigned i = 0;; ++i) { for (int i = 0;; ++i) {
auto type = args.args_[i].type_; auto type = args.args_[i].type_;
if (type == internal::none_type) return; if (type == internal::none_type) return;
if (type == internal::named_arg_type) push_back(args.args_[i].value_); if (type == internal::named_arg_type) push_back(args.args_[i].value_);
...@@ -1312,9 +1312,10 @@ template <typename Range> class basic_writer { ...@@ -1312,9 +1312,10 @@ template <typename Range> class basic_writer {
char_type fill = specs.fill[0]; char_type fill = specs.fill[0];
std::size_t padding = 0; std::size_t padding = 0;
if (specs.align == align::numeric) { if (specs.align == align::numeric) {
if (internal::to_unsigned(specs.width) > size) { auto unsiged_width = internal::to_unsigned(specs.width);
padding = specs.width - size; if (unsiged_width > size) {
size = specs.width; padding = unsiged_width - size;
size = unsiged_width;
} }
} else if (specs.precision > num_digits) { } else if (specs.precision > num_digits) {
size = prefix.size() + internal::to_unsigned(specs.precision); size = prefix.size() + internal::to_unsigned(specs.precision);
...@@ -1563,7 +1564,7 @@ template <typename Range> class basic_writer { ...@@ -1563,7 +1564,7 @@ template <typename Range> class basic_writer {
UIntPtr value; UIntPtr value;
int num_digits; int num_digits;
size_t size() const { return num_digits + 2; } size_t size() const { return to_unsigned(num_digits) + 2; }
size_t width() const { return size(); } size_t width() const { return size(); }
template <typename It> void operator()(It&& it) const { template <typename It> void operator()(It&& it) const {
...@@ -1585,7 +1586,8 @@ template <typename Range> class basic_writer { ...@@ -1585,7 +1586,8 @@ template <typename Range> class basic_writer {
// <left-padding><value><right-padding> // <left-padding><value><right-padding>
// where <value> is written by f(it). // where <value> is written by f(it).
template <typename F> void write_padded(const format_specs& specs, F&& f) { template <typename F> void write_padded(const format_specs& specs, F&& f) {
unsigned width = specs.width; // User-perceived width (in code points). // User-perceived width (in code points).
unsigned width = to_unsigned(specs.width);
size_t size = f.size(); // The number of code units. size_t size = f.size(); // The number of code units.
size_t num_code_points = width != 0 ? f.width() : size; size_t num_code_points = width != 0 ? f.width() : size;
if (width <= num_code_points) return f(reserve(size)); if (width <= num_code_points) return f(reserve(size));
...@@ -1686,7 +1688,7 @@ template <typename Range> class basic_writer { ...@@ -1686,7 +1688,7 @@ template <typename Range> class basic_writer {
void write_pointer(UIntPtr value, const format_specs* specs) { void write_pointer(UIntPtr value, const format_specs* specs) {
int num_digits = internal::count_digits<4>(value); int num_digits = internal::count_digits<4>(value);
auto pw = pointer_writer<UIntPtr>{value, num_digits}; auto pw = pointer_writer<UIntPtr>{value, num_digits};
if (!specs) return pw(reserve(num_digits + 2)); if (!specs) return pw(reserve(to_unsigned(num_digits) + 2));
format_specs specs_copy = *specs; format_specs specs_copy = *specs;
if (specs_copy.align == align::none) specs_copy.align = align::right; if (specs_copy.align == align::none) specs_copy.align = align::right;
write_padded(specs_copy, pw); write_padded(specs_copy, pw);
...@@ -1840,8 +1842,7 @@ template <typename Char> FMT_CONSTEXPR bool is_name_start(Char c) { ...@@ -1840,8 +1842,7 @@ template <typename Char> FMT_CONSTEXPR bool is_name_start(Char c) {
// Parses the range [begin, end) as an unsigned integer. This function assumes // Parses the range [begin, end) as an unsigned integer. This function assumes
// that the range is non-empty and the first character is a digit. // that the range is non-empty and the first character is a digit.
template <typename Char, typename ErrorHandler> template <typename Char, typename ErrorHandler>
FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin, FMT_CONSTEXPR int parse_nonnegative_int(const Char*& begin, const Char* end,
const Char* end,
ErrorHandler&& eh) { ErrorHandler&& eh) {
assert(begin != end && '0' <= *begin && *begin <= '9'); assert(begin != end && '0' <= *begin && *begin <= '9');
if (*begin == '0') { if (*begin == '0') {
...@@ -1862,7 +1863,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin, ...@@ -1862,7 +1863,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin,
++begin; ++begin;
} while (begin != end && '0' <= *begin && *begin <= '9'); } while (begin != end && '0' <= *begin && *begin <= '9');
if (value > max_int) eh.on_error("number is too big"); if (value > max_int) eh.on_error("number is too big");
return value; return static_cast<int>(value);
} }
template <typename Context> class custom_formatter { template <typename Context> class custom_formatter {
...@@ -1952,9 +1953,9 @@ template <typename Char> class specs_setter { ...@@ -1952,9 +1953,9 @@ template <typename Char> class specs_setter {
specs_.fill[0] = Char('0'); specs_.fill[0] = Char('0');
} }
FMT_CONSTEXPR void on_width(unsigned width) { specs_.width = width; } FMT_CONSTEXPR void on_width(int width) { specs_.width = width; }
FMT_CONSTEXPR void on_precision(unsigned precision) { FMT_CONSTEXPR void on_precision(int precision) {
specs_.precision = static_cast<int>(precision); specs_.precision = precision;
} }
FMT_CONSTEXPR void end_precision() {} FMT_CONSTEXPR void end_precision() {}
...@@ -2110,7 +2111,7 @@ struct string_view_metadata { ...@@ -2110,7 +2111,7 @@ struct string_view_metadata {
template <typename Char> template <typename Char>
FMT_CONSTEXPR string_view_metadata(basic_string_view<Char> primary_string, FMT_CONSTEXPR string_view_metadata(basic_string_view<Char> primary_string,
basic_string_view<Char> view) basic_string_view<Char> view)
: offset_(view.data() - primary_string.data()), size_(view.size()) {} : offset_(to_unsigned(view.data() - primary_string.data())), size_(view.size()) {}
FMT_CONSTEXPR string_view_metadata(std::size_t offset, std::size_t size) FMT_CONSTEXPR string_view_metadata(std::size_t offset, std::size_t size)
: offset_(offset), size_(size) {} : offset_(offset), size_(size) {}
template <typename Char> template <typename Char>
...@@ -2127,12 +2128,12 @@ enum class arg_id_kind { none, index, name }; ...@@ -2127,12 +2128,12 @@ enum class arg_id_kind { none, index, name };
// An argument reference. // An argument reference.
template <typename Char> struct arg_ref { template <typename Char> struct arg_ref {
FMT_CONSTEXPR arg_ref() : kind(arg_id_kind::none), val() {} FMT_CONSTEXPR arg_ref() : kind(arg_id_kind::none), val() {}
FMT_CONSTEXPR explicit arg_ref(unsigned index) FMT_CONSTEXPR explicit arg_ref(int index)
: kind(arg_id_kind::index), val(index) {} : kind(arg_id_kind::index), val(index) {}
FMT_CONSTEXPR explicit arg_ref(string_view_metadata name) FMT_CONSTEXPR explicit arg_ref(string_view_metadata name)
: kind(arg_id_kind::name), val(name) {} : kind(arg_id_kind::name), val(name) {}
FMT_CONSTEXPR arg_ref& operator=(unsigned idx) { FMT_CONSTEXPR arg_ref& operator=(int idx) {
kind = arg_id_kind::index; kind = arg_id_kind::index;
val.index = idx; val.index = idx;
return *this; return *this;
...@@ -2141,10 +2142,10 @@ template <typename Char> struct arg_ref { ...@@ -2141,10 +2142,10 @@ template <typename Char> struct arg_ref {
arg_id_kind kind; arg_id_kind kind;
union value { union value {
FMT_CONSTEXPR value() : index(0u) {} FMT_CONSTEXPR value() : index(0u) {}
FMT_CONSTEXPR value(unsigned id) : index(id) {} FMT_CONSTEXPR value(int id) : index(id) {}
FMT_CONSTEXPR value(string_view_metadata n) : name(n) {} FMT_CONSTEXPR value(string_view_metadata n) : name(n) {}
unsigned index; int index;
string_view_metadata name; string_view_metadata name;
} val; } val;
}; };
...@@ -2190,7 +2191,7 @@ class dynamic_specs_handler ...@@ -2190,7 +2191,7 @@ class dynamic_specs_handler
private: private:
using arg_ref_type = arg_ref<char_type>; using arg_ref_type = arg_ref<char_type>;
FMT_CONSTEXPR arg_ref_type make_arg_ref(unsigned arg_id) { FMT_CONSTEXPR arg_ref_type make_arg_ref(int arg_id) {
context_.check_arg_id(arg_id); context_.check_arg_id(arg_id);
return arg_ref_type(arg_id); return arg_ref_type(arg_id);
} }
...@@ -2202,7 +2203,7 @@ class dynamic_specs_handler ...@@ -2202,7 +2203,7 @@ class dynamic_specs_handler
FMT_CONSTEXPR arg_ref_type make_arg_ref(basic_string_view<char_type> arg_id) { FMT_CONSTEXPR arg_ref_type make_arg_ref(basic_string_view<char_type> arg_id) {
context_.check_arg_id(arg_id); context_.check_arg_id(arg_id);
basic_string_view<char_type> format_str(context_.begin(), basic_string_view<char_type> format_str(context_.begin(),
context_.end() - context_.begin()); to_unsigned(context_.end() - context_.begin()));
const auto id_metadata = string_view_metadata(format_str, arg_id); const auto id_metadata = string_view_metadata(format_str, arg_id);
return arg_ref_type(id_metadata); return arg_ref_type(id_metadata);
} }
...@@ -2218,7 +2219,7 @@ FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end, ...@@ -2218,7 +2219,7 @@ FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end,
Char c = *begin; Char c = *begin;
if (c == '}' || c == ':') return handler(), begin; if (c == '}' || c == ':') return handler(), begin;
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
unsigned index = parse_nonnegative_int(begin, end, handler); int index = parse_nonnegative_int(begin, end, handler);
if (begin == end || (*begin != '}' && *begin != ':')) if (begin == end || (*begin != '}' && *begin != ':'))
return handler.on_error("invalid format string"), begin; return handler.on_error("invalid format string"), begin;
handler(index); handler(index);
...@@ -2239,7 +2240,7 @@ template <typename SpecHandler, typename Char> struct width_adapter { ...@@ -2239,7 +2240,7 @@ template <typename SpecHandler, typename Char> struct width_adapter {
explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {} explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {}
FMT_CONSTEXPR void operator()() { handler.on_dynamic_width(auto_id()); } FMT_CONSTEXPR void operator()() { handler.on_dynamic_width(auto_id()); }
FMT_CONSTEXPR void operator()(unsigned id) { handler.on_dynamic_width(id); } FMT_CONSTEXPR void operator()(int id) { handler.on_dynamic_width(id); }
FMT_CONSTEXPR void operator()(basic_string_view<Char> id) { FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
handler.on_dynamic_width(id); handler.on_dynamic_width(id);
} }
...@@ -2256,7 +2257,7 @@ template <typename SpecHandler, typename Char> struct precision_adapter { ...@@ -2256,7 +2257,7 @@ template <typename SpecHandler, typename Char> struct precision_adapter {
explicit FMT_CONSTEXPR precision_adapter(SpecHandler& h) : handler(h) {} explicit FMT_CONSTEXPR precision_adapter(SpecHandler& h) : handler(h) {}
FMT_CONSTEXPR void operator()() { handler.on_dynamic_precision(auto_id()); } FMT_CONSTEXPR void operator()() { handler.on_dynamic_precision(auto_id()); }
FMT_CONSTEXPR void operator()(unsigned id) { FMT_CONSTEXPR void operator()(int id) {
handler.on_dynamic_precision(id); handler.on_dynamic_precision(id);
} }
FMT_CONSTEXPR void operator()(basic_string_view<Char> id) { FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment