From 8d7bc04b1473c922350d54452b7c891366ade8dc Mon Sep 17 00:00:00 2001 From: Bart Siwek Date: Fri, 16 Oct 2020 01:04:45 +0200 Subject: [PATCH] Make classes derived from buffer final to silence the virtual destructor warning. --- include/fmt/core.h | 8 ++++---- include/fmt/format.h | 2 +- include/fmt/os.h | 2 +- test/core-test.cc | 4 ++-- test/format-test.cc | 8 ++------ test/ostream-test.cc | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 2e1ae4b65e0d..ee98ea94ee1b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -761,7 +761,7 @@ class fixed_buffer_traits { // A buffer that writes to an output iterator when flushed. template -class iterator_buffer : public Traits, public buffer { +class iterator_buffer final : public Traits, public buffer { private: OutputIt out_; enum { buffer_size = 256 }; @@ -787,7 +787,7 @@ class iterator_buffer : public Traits, public buffer { size_t count() const { return Traits::count() + this->size(); } }; -template class iterator_buffer : public buffer { +template class iterator_buffer final : public buffer { protected: void grow(size_t) final FMT_OVERRIDE {} @@ -801,7 +801,7 @@ template class iterator_buffer : public buffer { template class iterator_buffer, enable_if_t::value, - typename Container::value_type>> + typename Container::value_type>> final : public buffer { private: Container& container_; @@ -823,7 +823,7 @@ class iterator_buffer, }; // A buffer that counts the number of code units written discarding the output. -template class counting_buffer : public buffer { +template class counting_buffer final : public buffer { private: enum { buffer_size = 256 }; T data_[buffer_size]; diff --git a/include/fmt/format.h b/include/fmt/format.h index eb9e216a5c32..6dbd12d6c3d9 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -651,7 +651,7 @@ enum { inline_buffer_size = 500 }; */ template > -class basic_memory_buffer : public detail::buffer { +class basic_memory_buffer final : public detail::buffer { private: T store_[SIZE]; diff --git a/include/fmt/os.h b/include/fmt/os.h index 66e666781fc3..881510065a5e 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -378,7 +378,7 @@ struct ostream_params { static constexpr detail::buffer_size buffer_size; // A fast output stream which is not thread-safe. -class ostream : private detail::buffer { +class ostream final : private detail::buffer { private: file file_; diff --git a/test/core-test.cc b/test/core-test.cc index 78d54bb1c89b..9d88070d614f 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -78,7 +78,7 @@ TEST(BufferTest, Indestructible) { "buffer's destructor is protected"); } -template struct mock_buffer : buffer { +template struct mock_buffer final : buffer { MOCK_METHOD1(do_grow, size_t(size_t capacity)); void grow(size_t capacity) { this->set(this->data(), do_grow(capacity)); } @@ -368,7 +368,7 @@ TEST(ArgTest, PointerArg) { struct check_custom { test_result operator()( fmt::basic_format_arg::handle h) const { - struct test_buffer : fmt::detail::buffer { + struct test_buffer final : fmt::detail::buffer { char data[10]; test_buffer() : fmt::detail::buffer(data, 0, 10) {} void grow(size_t) {} diff --git a/test/format-test.cc b/test/format-test.cc index bf563e17aae1..a3c925b05b0f 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -293,12 +293,8 @@ TEST(MemoryBufferTest, MoveAssignment) { TEST(MemoryBufferTest, Grow) { typedef allocator_ref> Allocator; - typedef basic_memory_buffer Base; mock_allocator alloc; - struct TestMemoryBuffer : Base { - TestMemoryBuffer(Allocator alloc) : Base(alloc) {} - using Base::grow; - } buffer((Allocator(&alloc))); + basic_memory_buffer buffer((Allocator(&alloc))); buffer.resize(7); using fmt::detail::to_unsigned; for (int i = 0; i < 7; ++i) buffer[to_unsigned(i)] = i * i; @@ -306,7 +302,7 @@ TEST(MemoryBufferTest, Grow) { int mem[20]; mem[7] = 0xdead; EXPECT_CALL(alloc, allocate(20)).WillOnce(Return(mem)); - buffer.grow(20); + buffer.try_reserve(20); EXPECT_EQ(20u, buffer.capacity()); // Check if size elements have been copied for (int i = 0; i < 7; ++i) EXPECT_EQ(i * i, buffer[to_unsigned(i)]); diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 407b05a109ec..ebf14210ad42 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -150,7 +150,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) { std::streamsize max_streamsize = fmt::detail::max_value(); if (max_size <= fmt::detail::to_unsigned(max_streamsize)) return; - struct test_buffer : fmt::detail::buffer { + struct test_buffer final : fmt::detail::buffer { explicit test_buffer(size_t size) : fmt::detail::buffer(nullptr, size, size) {} void grow(size_t) {}