From a5245ac76b18beae4a5b6ed62bbf4ae0194b457c Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 28 Dec 2023 16:39:19 -0600 Subject: [PATCH] Remove redundant destructors Classes will automatically inherit the virtual-ness of their base class destructors. If the base class already has a virtual destructor and the derived class needs default destructor semantics then the derived class can omit defining the destructor in favor of the compiler automatically defining it. This has an additional benefit of reenabling move semantics. The presence of a user-specified destructor automatically disables move operations. --- extras/catch_amalgamated.hpp | 13 ------------- src/catch2/generators/catch_generators.hpp | 6 ------ src/catch2/internal/catch_istream.cpp | 5 ----- src/catch2/internal/catch_run_context.cpp | 1 - .../internal/catch_test_case_registry_impl.hpp | 2 -- src/catch2/reporters/catch_reporter_junit.hpp | 2 -- src/catch2/reporters/catch_reporter_sonarqube.hpp | 2 -- src/catch2/reporters/catch_reporter_tap.hpp | 1 - 8 files changed, 32 deletions(-) diff --git a/extras/catch_amalgamated.hpp b/extras/catch_amalgamated.hpp index bec588d4fe..7a6953ca2d 100644 --- a/extras/catch_amalgamated.hpp +++ b/extras/catch_amalgamated.hpp @@ -7391,12 +7391,6 @@ namespace Detail { } public: - ~IGenerator() override = default; - IGenerator() = default; - IGenerator(IGenerator const&) = default; - IGenerator& operator=(IGenerator const&) = default; - - // Returns the current element of the generator // // \Precondition The generator is either freshly constructed, @@ -10662,8 +10656,6 @@ namespace Catch { class TestRegistry : public ITestCaseRegistry { public: - ~TestRegistry() override = default; - void registerTest( Detail::unique_ptr testInfo, Detail::unique_ptr testInvoker ); std::vector const& getAllInfos() const override; @@ -13312,8 +13304,6 @@ namespace Catch { public: JunitReporter(ReporterConfig&& _config); - ~JunitReporter() override = default; - static std::string getDescription(); void testRunStarting(TestRunInfo const& runInfo) override; @@ -13554,8 +13544,6 @@ namespace Catch { m_shouldStoreSuccesfulAssertions = false; } - ~SonarQubeReporter() override = default; - static std::string getDescription() { using namespace std::string_literals; return "Reports test results in the Generic Test Data SonarQube XML format"s; @@ -13602,7 +13590,6 @@ namespace Catch { StreamingReporterBase( CATCH_MOVE(config) ) { m_preferences.shouldReportAllAssertions = true; } - ~TAPReporter() override = default; static std::string getDescription() { using namespace std::string_literals; diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index 117f190193..0f35a9968a 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -37,12 +37,6 @@ namespace Detail { } public: - ~IGenerator() override = default; - IGenerator() = default; - IGenerator(IGenerator const&) = default; - IGenerator& operator=(IGenerator const&) = default; - - // Returns the current element of the generator // // \Precondition The generator is either freshly constructed, diff --git a/src/catch2/internal/catch_istream.cpp b/src/catch2/internal/catch_istream.cpp index bf0f66e423..2867ce747c 100644 --- a/src/catch2/internal/catch_istream.cpp +++ b/src/catch2/internal/catch_istream.cpp @@ -80,7 +80,6 @@ namespace Detail { CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << '\'' ); m_ofs << std::unitbuf; } - ~FileStream() override = default; public: // IStream std::ostream& stream() override { return m_ofs; @@ -95,7 +94,6 @@ namespace Detail { // Store the streambuf from cout up-front because // cout may get redirected when running tests CoutStream() : m_os( Catch::cout().rdbuf() ) {} - ~CoutStream() override = default; public: // IStream std::ostream& stream() override { return m_os; } @@ -109,7 +107,6 @@ namespace Detail { // Store the streambuf from cerr up-front because // cout may get redirected when running tests CerrStream(): m_os( Catch::cerr().rdbuf() ) {} - ~CerrStream() override = default; public: // IStream std::ostream& stream() override { return m_os; } @@ -127,8 +124,6 @@ namespace Detail { m_os( m_streamBuf.get() ) {} - ~DebugOutStream() override = default; - public: // IStream std::ostream& stream() override { return m_os; } }; diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index e568100d60..77b476d82a 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -38,7 +38,6 @@ namespace Catch { TrackerContext& ctx, ITracker* parent ): TrackerBase( CATCH_MOVE( nameAndLocation ), ctx, parent ) {} - ~GeneratorTracker() override = default; static GeneratorTracker* acquire( TrackerContext& ctx, diff --git a/src/catch2/internal/catch_test_case_registry_impl.hpp b/src/catch2/internal/catch_test_case_registry_impl.hpp index a4a27ed122..99a38498f8 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.hpp +++ b/src/catch2/internal/catch_test_case_registry_impl.hpp @@ -30,8 +30,6 @@ namespace Catch { class TestRegistry : public ITestCaseRegistry { public: - ~TestRegistry() override = default; - void registerTest( Detail::unique_ptr testInfo, Detail::unique_ptr testInvoker ); std::vector const& getAllInfos() const override; diff --git a/src/catch2/reporters/catch_reporter_junit.hpp b/src/catch2/reporters/catch_reporter_junit.hpp index 87c7c5679e..7cb53c25b5 100644 --- a/src/catch2/reporters/catch_reporter_junit.hpp +++ b/src/catch2/reporters/catch_reporter_junit.hpp @@ -19,8 +19,6 @@ namespace Catch { public: JunitReporter(ReporterConfig&& _config); - ~JunitReporter() override = default; - static std::string getDescription(); void testRunStarting(TestRunInfo const& runInfo) override; diff --git a/src/catch2/reporters/catch_reporter_sonarqube.hpp b/src/catch2/reporters/catch_reporter_sonarqube.hpp index cad6deec8c..d26af62e89 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.hpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.hpp @@ -25,8 +25,6 @@ namespace Catch { m_shouldStoreSuccesfulAssertions = false; } - ~SonarQubeReporter() override = default; - static std::string getDescription() { using namespace std::string_literals; return "Reports test results in the Generic Test Data SonarQube XML format"s; diff --git a/src/catch2/reporters/catch_reporter_tap.hpp b/src/catch2/reporters/catch_reporter_tap.hpp index fe45df63e8..e6889bb110 100644 --- a/src/catch2/reporters/catch_reporter_tap.hpp +++ b/src/catch2/reporters/catch_reporter_tap.hpp @@ -19,7 +19,6 @@ namespace Catch { StreamingReporterBase( CATCH_MOVE(config) ) { m_preferences.shouldReportAllAssertions = true; } - ~TAPReporter() override = default; static std::string getDescription() { using namespace std::string_literals;