Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Cleanup some stuff found by MSVC's /analyze

* Added some missing `noexcept`s on custom destructors.
* Fixed `std::move` being called on a const-reference.
* Initialized `ScopedMessage::m_moved` in class definition, instead
of doing so in constructors explicitly.
* Turned some `enum`s into `enum class`es.
* Initialized `StreamingReporterBase::currentTestCaseInfo` in class
definition.
* Some cleanups in SelfTest code.
Commit
1a97af45f168b24769301906cad9dcfe235d78e5
Author
Martin Hořeňovský ·
Parents
2e480b6e560a

Files · Download .tar.gz

Changes

 .../benchmark/detail/catch_benchmark_function.hpp   |  9 +++++----
 src/catch2/catch_message.cpp                        | 10 ++++------
 src/catch2/catch_message.hpp                        |  4 ++--
 src/catch2/internal/catch_list.cpp                  |  2 +-
 src/catch2/reporters/catch_reporter_bases.hpp       |  2 +-
 src/catch2/reporters/catch_reporter_console.cpp     | 21 +++++++++++----------
 .../SelfTest/IntrospectiveTests/UniquePtr.tests.cpp |  4 ++--
 tests/SelfTest/UsageTests/Tricky.tests.cpp          |  2 +-
 8 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/src/catch2/benchmark/detail/catch_benchmark_function.hpp
index ebeb7fa0..29c435bc 100644
--- a/src/catch2/benchmark/detail/catch_benchmark_function.hpp
+++ b/src/catch2/benchmark/detail/catch_benchmark_function.hpp
@@ -81,14 +81,15 @@ namespace Catch {
                     BenchmarkFunction(Fun&& fun)
                     : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
 
-                BenchmarkFunction(BenchmarkFunction&& that)
-                    : f(std::move(that.f)) {}
+                BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
+                    f( std::move( that.f ) ) {}
 
                 BenchmarkFunction(BenchmarkFunction const& that)
                     : f(that.f->clone()) {}
 
-                BenchmarkFunction& operator=(BenchmarkFunction&& that) {
-                    f = std::move(that.f);
+                BenchmarkFunction&
+                operator=( BenchmarkFunction&& that ) noexcept {
+                    f = std::move( that.f );
                     return *this;
                 }
 
diff --git a/src/catch2/catch_message.cpp b/src/catch2/catch_message.cpp
index 6c4a0989..2689592c 100644
--- a/src/catch2/catch_message.cpp
+++ b/src/catch2/catch_message.cpp
@@ -26,16 +26,14 @@ namespace Catch {
     ////////////////////////////////////////////////////////////////////////////
 
 
-    ScopedMessage::ScopedMessage( MessageBuilder const& builder )
-    : m_info( builder.m_info ), m_moved()
-    {
+    ScopedMessage::ScopedMessage( MessageBuilder const& builder ):
+        m_info( builder.m_info ) {
         m_info.message = builder.m_stream.str();
         getResultCapture().pushScopedMessage( m_info );
     }
 
-    ScopedMessage::ScopedMessage( ScopedMessage&& old )
-    : m_info( old.m_info ), m_moved()
-    {
+    ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
+        m_info( std::move( old.m_info ) ) {
         old.m_moved = true;
     }
 
diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp
index b302ee39..7f484d11 100644
--- a/src/catch2/catch_message.hpp
+++ b/src/catch2/catch_message.hpp
@@ -49,11 +49,11 @@ namespace Catch {
     public:
         explicit ScopedMessage( MessageBuilder const& builder );
         ScopedMessage( ScopedMessage& duplicate ) = delete;
-        ScopedMessage( ScopedMessage&& old );
+        ScopedMessage( ScopedMessage&& old ) noexcept;
         ~ScopedMessage();
 
         MessageInfo m_info;
-        bool m_moved;
+        bool m_moved = false;
     };
 
     class Capturer {
diff --git a/src/catch2/internal/catch_list.cpp b/src/catch2/internal/catch_list.cpp
index 378a30e0..478ace0c 100644
--- a/src/catch2/internal/catch_list.cpp
+++ b/src/catch2/internal/catch_list.cpp
@@ -41,7 +41,7 @@ namespace Catch {
             }
 
             std::vector<TagInfo> infos; infos.reserve(tagCounts.size());
-            for (auto const& tagc : tagCounts) {
+            for (auto& tagc : tagCounts) {
                 infos.push_back(std::move(tagc.second));
             }
 
diff --git a/src/catch2/reporters/catch_reporter_bases.hpp b/src/catch2/reporters/catch_reporter_bases.hpp
index cdf2b227..282394eb 100644
--- a/src/catch2/reporters/catch_reporter_bases.hpp
+++ b/src/catch2/reporters/catch_reporter_bases.hpp
@@ -71,7 +71,7 @@ namespace Catch {
 
         LazyStat<TestRunInfo> currentTestRunInfo;
         LazyStat<GroupInfo> currentGroupInfo;
-        TestCaseInfo const* currentTestCaseInfo;
+        TestCaseInfo const* currentTestCaseInfo = nullptr;
 
         std::vector<SectionInfo> m_sectionStack;
     };
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index 5e64e75d..8bf57fef 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -192,8 +192,9 @@ std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) {
         return k;
 }
 
+enum class Justification { Left, Right };
+
 struct ColumnInfo {
-    enum Justification { Left, Right };
     std::string name;
     int width;
     Justification justification;
@@ -335,7 +336,7 @@ public:
         auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
             ? std::string(colInfo.width - (strSize + 1), ' ')
             : std::string();
-        if (colInfo.justification == ColumnInfo::Left)
+        if (colInfo.justification == Justification::Left)
             tp.m_os << colStr << padding << ' ';
         else
             tp.m_os << padding << colStr << ' ';
@@ -358,19 +359,19 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
         if (config.fullConfig()->benchmarkNoAnalysis())
         {
             return{
-                { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
-                { "     samples", 14, ColumnInfo::Right },
-                { "  iterations", 14, ColumnInfo::Right },
-                { "        mean", 14, ColumnInfo::Right }
+                { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
+                { "     samples", 14, Justification::Right },
+                { "  iterations", 14, Justification::Right },
+                { "        mean", 14, Justification::Right }
             };
         }
         else
         {
             return{
-                { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
-                { "samples      mean       std dev", 14, ColumnInfo::Right },
-                { "iterations   low mean   low std dev", 14, ColumnInfo::Right },
-                { "estimated    high mean  high std dev", 14, ColumnInfo::Right }
+                { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, Justification::Left },
+                { "samples      mean       std dev", 14, Justification::Right },
+                { "iterations   low mean   low std dev", 14, Justification::Right },
+                { "estimated    high mean  high std dev", 14, Justification::Right }
             };
         }
     }())) {}
diff --git a/tests/SelfTest/IntrospectiveTests/UniquePtr.tests.cpp b/tests/SelfTest/IntrospectiveTests/UniquePtr.tests.cpp
index bc7fe228..fcdb8a32 100644
--- a/tests/SelfTest/IntrospectiveTests/UniquePtr.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/UniquePtr.tests.cpp
@@ -104,10 +104,10 @@ namespace {
         move_detector(move_detector const& rhs) = default;
         move_detector& operator=(move_detector const& rhs) = default;
 
-        move_detector(move_detector&& rhs) {
+        move_detector(move_detector&& rhs) noexcept {
             rhs.has_moved = true;
         }
-        move_detector& operator=(move_detector&& rhs) {
+        move_detector& operator=(move_detector&& rhs) noexcept {
             rhs.has_moved = true;
             return *this;
         }
diff --git a/tests/SelfTest/UsageTests/Tricky.tests.cpp b/tests/SelfTest/UsageTests/Tricky.tests.cpp
index 9fe4779d..7627f0a0 100644
--- a/tests/SelfTest/UsageTests/Tricky.tests.cpp
+++ b/tests/SelfTest/UsageTests/Tricky.tests.cpp
@@ -185,7 +185,7 @@ struct Obj
 {
     Obj():prop(&p){}
 
-    int p;
+    int p = 0;
     int* prop;
 };