From 8ff5190d35c0e44f1ae36beb20b975bea66a59b0 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Tue, 18 Aug 2020 09:16:46 +0100 Subject: [PATCH] fix warnings fixes: -Wconversion, -Wsign-conversion, -Wshadow, -Wnon-virtual-dtor --- include/fmt/core.h | 2 +- include/fmt/format.h | 4 ++-- include/fmt/os.h | 4 ++-- src/os.cc | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 2b474e36..e16f23f8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -669,7 +669,7 @@ template class buffer { size_(sz), capacity_(cap) {} - ~buffer() = default; + virtual ~buffer() = default; /** Sets the buffer data and capacity. */ void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT { diff --git a/include/fmt/format.h b/include/fmt/format.h index 7dbe90c2..272e25f4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1609,7 +1609,7 @@ template struct int_writer { char digits[40]; format_decimal(digits, abs_value, num_digits); basic_memory_buffer buffer; - size += prefix_size; + size += static_cast(prefix_size); const auto usize = to_unsigned(size); buffer.resize(usize); basic_string_view s(&sep, sep_size); @@ -3482,7 +3482,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() + 2; - char buffer[max_size > 5 ? max_size : 5]; + char buffer[static_cast(max_size > 5 ? max_size : 5)]; char* begin = buffer; return std::string(begin, detail::write(begin, value)); } diff --git a/include/fmt/os.h b/include/fmt/os.h index 7796260a..702a30da 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -361,8 +361,8 @@ struct ostream_params { ostream_params() {} template - ostream_params(T... params, int oflag) : ostream_params(params...) { - this->oflag = oflag; + ostream_params(T... params, int _oflag) : ostream_params(params...) { + this->oflag = _oflag; } template diff --git a/src/os.cc b/src/os.cc index ae89b9c0..b7b89309 100644 --- a/src/os.cc +++ b/src/os.cc @@ -92,11 +92,11 @@ int detail::utf16_to_utf8::convert(wstring_view s) { int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, nullptr, 0, nullptr, nullptr); - if (length == 0) return GetLastError(); - buffer_.resize(length + 1); + if (length == 0) return static_cast(GetLastError()); + buffer_.resize(static_cast(length + 1)); length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, nullptr, nullptr); - if (length == 0) return GetLastError(); + if (length == 0) return static_cast(GetLastError()); buffer_[length] = 0; return 0; } @@ -117,10 +117,10 @@ void detail::format_windows_error(detail::buffer& out, int error_code, buf.resize(inline_buffer_size); for (;;) { wchar_t* system_message = &buf[0]; - int result = FormatMessageW( + int result = static_cast(FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, - error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message, - static_cast(buf.size()), nullptr); + static_cast(error_code), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message, + static_cast(buf.size()), nullptr)); if (result != 0) { utf16_to_utf8 utf8_message; if (utf8_message.convert(system_message) == ERROR_SUCCESS) { @@ -212,10 +212,10 @@ long long file::size() const { if (size_lower == INVALID_FILE_SIZE) { DWORD error = GetLastError(); if (error != NO_ERROR) - FMT_THROW(windows_error(GetLastError(), "cannot get file size")); + FMT_THROW(windows_error(static_cast(GetLastError()), "cannot get file size")); } unsigned long long long_size = size_upper; - return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; + return static_cast((long_size << sizeof(DWORD) * CHAR_BIT) | size_lower); # else using Stat = struct stat; Stat file_stat = Stat(); @@ -306,7 +306,7 @@ long getpagesize() { # ifdef _WIN32 SYSTEM_INFO si; GetSystemInfo(&si); - return si.dwPageSize; + return static_cast(si.dwPageSize); # else long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE)); if (size < 0) FMT_THROW(system_error(errno, "cannot get memory page size"));