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

Warning removals in test code #2399

Merged
merged 2 commits into from
Jul 9, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ TEST(buffer_test, indestructible) {
template <typename T> struct mock_buffer final : buffer<T> {
MOCK_METHOD1(do_grow, size_t(size_t capacity));

void grow(size_t capacity) { this->set(this->data(), do_grow(capacity)); }
void grow(size_t capacity) override {
this->set(this->data(), do_grow(capacity));
}

mock_buffer(T* data = nullptr, size_t buf_capacity = 0) {
this->set(data, buf_capacity);
Expand Down Expand Up @@ -452,7 +454,7 @@ struct check_custom {
struct test_buffer final : fmt::detail::buffer<char> {
char data[10];
test_buffer() : fmt::detail::buffer<char>(data, 0, 10) {}
void grow(size_t) {}
void grow(size_t) override {}
} buffer;
auto parse_ctx = fmt::format_parse_context("");
auto ctx = fmt::format_context(fmt::detail::buffer_appender<char>(buffer),
Expand Down
1 change: 1 addition & 0 deletions test/gtest-extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class suppress_assert {
~suppress_assert() {
_set_invalid_parameter_handler(original_handler_);
_CrtSetReportMode(_CRT_ASSERT, original_report_mode_);
(void)original_report_mode_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use function ignore_unused

template <class T> void ignore_unused(const T&) {}
to suppress warning?

Example:

fmt/include/fmt/core.h

Lines 2746 to 2748 in 785908e

FMT_CONSTEXPR bool invalid_format =
(parse_format_string<true>(s, checker(s, {})), true);
ignore_unused(invalid_format);

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please.

}
};

Expand Down
28 changes: 14 additions & 14 deletions test/os-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ TEST(util_test, utf16_to_utf8_empty_string) {
}

template <typename Converter, typename Char>
void check_utf_conversion_error(
const char* message,
fmt::basic_string_view<Char> str = fmt::basic_string_view<Char>(0, 1)) {
void check_utf_conversion_error(const char* message,
fmt::basic_string_view<Char> str =
fmt::basic_string_view<Char>(nullptr, 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be = {nullptr, 1}?

fmt::memory_buffer out;
fmt::detail::format_windows_error(out, ERROR_INVALID_PARAMETER, message);
auto error = std::system_error(std::error_code());
Expand All @@ -63,7 +63,7 @@ TEST(util_test, utf16_to_utf8_error) {

TEST(util_test, utf16_to_utf8_convert) {
fmt::detail::utf16_to_utf8 u;
EXPECT_EQ(ERROR_INVALID_PARAMETER, u.convert(wstring_view(0, 1)));
EXPECT_EQ(ERROR_INVALID_PARAMETER, u.convert(wstring_view(nullptr, 1)));
EXPECT_EQ(ERROR_INVALID_PARAMETER,
u.convert(wstring_view(L"foo", INT_MAX + 1u)));
}
Expand All @@ -81,12 +81,12 @@ TEST(os_test, format_std_error_code) {
}

TEST(os_test, format_windows_error) {
LPWSTR message = 0;
LPWSTR message = nullptr;
auto result = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
0, ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, 0);
nullptr, ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, nullptr);
fmt::detail::utf16_to_utf8 utf8_message(wstring_view(message, result - 2));
LocalFree(message);
fmt::memory_buffer actual_message;
Expand All @@ -97,17 +97,17 @@ TEST(os_test, format_windows_error) {
}

TEST(os_test, format_long_windows_error) {
LPWSTR message = 0;
LPWSTR message = nullptr;
// this error code is not available on all Windows platforms and
// Windows SDKs, so do not fail the test if the error string cannot
// be retrieved.
int provisioning_not_allowed = 0x80284013L; // TBS_E_PROVISIONING_NOT_ALLOWED
auto result = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
0, static_cast<DWORD>(provisioning_not_allowed),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, 0);
auto result = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, static_cast<DWORD>(provisioning_not_allowed),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&message), 0, nullptr);
if (result == 0) {
LocalFree(message);
return;
Expand Down
4 changes: 2 additions & 2 deletions test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ TEST(ostream_test, write_to_ostream_max_size) {
struct test_buffer final : fmt::detail::buffer<char> {
explicit test_buffer(size_t size)
: fmt::detail::buffer<char>(nullptr, size, size) {}
void grow(size_t) {}
void grow(size_t) override {}
} buffer(max_size);

struct mock_streambuf : std::streambuf {
MOCK_METHOD2(xsputn, std::streamsize(const void* s, std::streamsize n));
std::streamsize xsputn(const char* s, std::streamsize n) {
std::streamsize xsputn(const char* s, std::streamsize n) override {
const void* v = s;
return xsputn(v, n);
}
Expand Down
2 changes: 1 addition & 1 deletion test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fmt::buffered_file open_buffered_file(FILE** fp = nullptr);
inline FILE* safe_fopen(const char* filename, const char* mode) {
#if defined(_WIN32) && !defined(__MINGW32__)
// Fix MSVC warning about "unsafe" fopen.
FILE* f = 0;
FILE* f = nullptr;
errno = fopen_s(&f, filename, mode);
return f;
#else
Expand Down