Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings under MSVC #679

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,9 @@ class basic_format_args {

unsigned max_size() const {
int64_t signed_types = static_cast<int64_t>(types_);
return signed_types < 0 ?
-signed_types : static_cast<int64_t>(internal::max_packed_args);
return static_cast<unsigned>(signed_types < 0
? -signed_types
: static_cast<int64_t>(internal::max_packed_args));
}
};

Expand Down
12 changes: 6 additions & 6 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ class arg_formatter_base {

void operator()(const char_type *value) {
internal::handle_cstring_type_spec(
specs_.type_, cstring_spec_handler(*this, value));
static_cast<char>(specs_.type_), cstring_spec_handler(*this, value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to make character type a template parameter of handle_cstring_type_spec instead, because otherwise an invalid type specifier can be transformed into a valid one by a narrowing cast which is undesirable.

Same in similar places below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you just did that, I was grepping through the code and couldn't find those casts anymore.. :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries =)

}

void operator()(basic_string_view<char_type> value) {
Expand All @@ -1461,7 +1461,7 @@ class arg_formatter_base {
}

void operator()(const void *value) {
check_pointer_type_spec(specs_.type_, internal::error_handler());
check_pointer_type_spec(static_cast<char>(specs_.type_), internal::error_handler());
write_pointer(value);
}
};
Expand Down Expand Up @@ -2394,7 +2394,7 @@ class basic_writer {
void on_hex() {
if (spec.flag(HASH_FLAG)) {
prefix[prefix_size++] = '0';
prefix[prefix_size++] = spec.type();
prefix[prefix_size++] = static_cast<char>(spec.type());
}
unsigned num_digits = count_digits<4>();
writer.write_int(num_digits, get_prefix(), spec,
Expand All @@ -2415,7 +2415,7 @@ class basic_writer {
void on_bin() {
if (spec.flag(HASH_FLAG)) {
prefix[prefix_size++] = '0';
prefix[prefix_size++] = spec.type();
prefix[prefix_size++] = static_cast<char>(spec.type());
}
unsigned num_digits = count_digits<1>();
writer.write_int(num_digits, get_prefix(), spec,
Expand Down Expand Up @@ -2465,7 +2465,7 @@ class basic_writer {
// Writes a formatted integer.
template <typename T, typename Spec>
void write_int(T value, const Spec &spec) {
internal::handle_int_type_spec(spec.type(),
internal::handle_int_type_spec(static_cast<char>(spec.type()),
int_writer<T, Spec>(*this, value, spec));
}

Expand Down Expand Up @@ -2698,7 +2698,7 @@ template <typename T>
void basic_writer<Range>::write_double(T value, const format_specs &spec) {
// Check type.
float_spec_handler<char_type> handler(spec.type());
internal::handle_float_type_spec(spec.type(), handler);
internal::handle_float_type_spec(static_cast<char>(spec.type()), handler);

char sign = 0;
// Use isnegative instead of value < 0 because the latter is always
Expand Down