From 2d832318e8d60572cf9fbabdc72eabeb76c00825 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sat, 5 Aug 2023 19:06:24 -0700 Subject: [PATCH 1/2] Test style: Drop `virtual` when we `override`. This follows the product code convention, and is an extremely safe change that can't disturb test coverage. --- .../tests/Dev11_0496153_locale_ctor/test.cpp | 2 +- .../test.cpp | 2 +- .../test.cpp | 2 +- .../test.cpp | 25 +++++++++---------- tests/std/tests/P0476R2_bit_cast/test.cpp | 2 +- tests/tr1/tests/future1/test.cpp | 12 ++++----- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tests/std/tests/Dev11_0496153_locale_ctor/test.cpp b/tests/std/tests/Dev11_0496153_locale_ctor/test.cpp index 73659075e5..83cf98a779 100644 --- a/tests/std/tests/Dev11_0496153_locale_ctor/test.cpp +++ b/tests/std/tests/Dev11_0496153_locale_ctor/test.cpp @@ -34,7 +34,7 @@ void test_Dev11_496153_locale_ctor_should_not_throw() noexcept { } struct comma_separator : numpunct { - virtual char do_decimal_point() const override { + char do_decimal_point() const override { return ','; } }; diff --git a/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp b/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp index 51151f4a36..c81667641e 100644 --- a/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp +++ b/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp @@ -741,7 +741,7 @@ struct BaseMeow { }; struct DerivedMeow : BaseMeow { - virtual int operator()(int x, int y) override { + int operator()(int x, int y) override { return x * x * x + y * y * y; } }; diff --git a/tests/std/tests/Dev11_1066589_shared_ptr_atomic_deadlock/test.cpp b/tests/std/tests/Dev11_1066589_shared_ptr_atomic_deadlock/test.cpp index 097f9dd14c..9e40990af0 100644 --- a/tests/std/tests/Dev11_1066589_shared_ptr_atomic_deadlock/test.cpp +++ b/tests/std/tests/Dev11_1066589_shared_ptr_atomic_deadlock/test.cpp @@ -129,7 +129,7 @@ int main() { }; struct Derived final : Base { - virtual void test() override {} + void test() override {} }; shared_ptr object; diff --git a/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp b/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp index d981d14803..5be276e1ac 100644 --- a/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp +++ b/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp @@ -158,7 +158,7 @@ namespace { struct malloc_resource final : std::pmr::memory_resource { private: - virtual void* do_allocate(std::size_t bytes, std::size_t align) override { + void* do_allocate(std::size_t bytes, std::size_t align) override { if (!bytes) { return nullptr; } @@ -175,7 +175,7 @@ namespace { throw std::bad_alloc{}; } - virtual void do_deallocate(void* ptr, std::size_t, std::size_t align) noexcept override { + void do_deallocate(void* ptr, std::size_t, std::size_t align) noexcept override { if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { _aligned_free(ptr); } else { @@ -183,7 +183,7 @@ namespace { } } - virtual bool do_is_equal(const memory_resource& that) const noexcept override { + bool do_is_equal(const memory_resource& that) const noexcept override { return typeid(malloc_resource) == typeid(that); } }; @@ -194,7 +194,7 @@ namespace { void* ptr_{}; private: - virtual void* do_allocate(std::size_t bytes, std::size_t align) override { + void* do_allocate(std::size_t bytes, std::size_t align) override { if (bytes_ != 0) { CHECK(bytes == bytes_); } else { @@ -214,7 +214,7 @@ namespace { } } - virtual void do_deallocate(void* ptr, std::size_t bytes, std::size_t align) noexcept override { + void do_deallocate(void* ptr, std::size_t bytes, std::size_t align) noexcept override { if (ptr_) { CHECK(ptr == ptr_); if (bytes_ != 0) { @@ -245,7 +245,7 @@ namespace { } } - virtual bool do_is_equal(const memory_resource& that) const noexcept override { + bool do_is_equal(const memory_resource& that) const noexcept override { CHECK(ptr_ == &that); return typeid(checked_resource) == typeid(that); } @@ -273,14 +273,13 @@ namespace { } } - virtual void* do_allocate(std::size_t const bytes, std::size_t const align) override { + void* do_allocate(std::size_t const bytes, std::size_t const align) override { void* const result = upstream_->allocate(bytes, align); allocations_.push_back({result, bytes, align}); return result; } - virtual void do_deallocate( - void* const ptr, std::size_t const bytes, std::size_t const align) noexcept override { + void do_deallocate(void* const ptr, std::size_t const bytes, std::size_t const align) noexcept override { allocation const alloc{ptr, bytes, align}; auto const end = allocations_.end(); auto pos = std::find(allocations_.begin(), end, alloc); @@ -289,7 +288,7 @@ namespace { upstream_->deallocate(ptr, bytes, align); } - virtual bool do_is_equal(const memory_resource& that) const noexcept override { + bool do_is_equal(const memory_resource& that) const noexcept override { return this == &that; } }; @@ -496,15 +495,15 @@ namespace { struct max_align_checker final : std::pmr::memory_resource { private: - virtual void* do_allocate(std::size_t bytes, std::size_t align) override { + void* do_allocate(std::size_t bytes, std::size_t align) override { CHECK(align == alignof(std::max_align_t)); return std::malloc(bytes); } - virtual void do_deallocate(void* ptr, std::size_t, std::size_t align) override { + void do_deallocate(void* ptr, std::size_t, std::size_t align) override { CHECK(align == alignof(std::max_align_t)); std::free(ptr); } - virtual bool do_is_equal(const memory_resource& that) const noexcept override { + bool do_is_equal(const memory_resource& that) const noexcept override { return typeid(max_align_checker) == typeid(that); } }; diff --git a/tests/std/tests/P0476R2_bit_cast/test.cpp b/tests/std/tests/P0476R2_bit_cast/test.cpp index 288f960b42..1abee26ce0 100644 --- a/tests/std/tests/P0476R2_bit_cast/test.cpp +++ b/tests/std/tests/P0476R2_bit_cast/test.cpp @@ -32,7 +32,7 @@ struct middle_class_2 { }; struct derived_class : middle_class_1, middle_class_2 { - virtual void a_member_function_2() override {} + void a_member_function_2() override {} }; struct test_struct_1 { diff --git a/tests/tr1/tests/future1/test.cpp b/tests/tr1/tests/future1/test.cpp index 205deb4f11..a19f5aa7ef 100644 --- a/tests/tr1/tests/future1/test.cpp +++ b/tests/tr1/tests/future1/test.cpp @@ -105,10 +105,10 @@ class future_tester_base { // base class for testing future types with set and g template