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 compiler warnings in public header files #1856

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ template <typename T> class buffer {
size_(sz),
capacity_(cap) {}

~buffer() = default;
virtual ~buffer() = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is intentional.

Copy link
Author

Choose a reason for hiding this comment

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

Is the idea behind that to keep the vtable as small as possible? If that's the case maybe by using CRTP we could get rid of the vtable at all and satisfy my compiler ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual. CRTP is not needed here, I suggest suppressing the useless warning.


/** Sets the buffer data and capacity. */
void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT {
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
char digits[40];
format_decimal(digits, abs_value, num_digits);
basic_memory_buffer<Char> buffer;
size += prefix_size;
size += static_cast<int>(prefix_size);
const auto usize = to_unsigned(size);
buffer.resize(usize);
basic_string_view<Char> s(&sep, sep_size);
Expand Down Expand Up @@ -3493,7 +3493,7 @@ inline std::string to_string(T value) {
// The buffer should be large enough to store the number including the sign or
// "false" for bool.
constexpr int max_size = detail::digits10<T>() + 2;
char buffer[max_size > 5 ? max_size : 5];
char buffer[max_size > 5 ? static_cast<size_t>(max_size) : 5];
Copy link
Contributor

Choose a reason for hiding this comment

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

static_cast -> to_unsigned

char* begin = buffer;
return std::string(begin, detail::write<char>(begin, value));
}
Expand Down