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

Sweep out some Wsign-conversion warnings

Commit
8cb8f0b08b0ec35edd346df999f3b854ad05aa41
Author
Martin Hořeňovský ·
Parents
9952f29f01ae

Files · Download .tar.gz

Changes

 src/catch2/benchmark/detail/catch_analyse.hpp      |  4 ++--
 .../benchmark/detail/catch_estimate_clock.hpp      |  6 +++---
 src/catch2/benchmark/detail/catch_stats.cpp        |  8 ++++----
 src/catch2/benchmark/detail/catch_stats.hpp        |  8 ++++----
 src/catch2/catch_config.cpp                        |  2 +-
 src/catch2/catch_config.hpp                        |  2 +-
 src/catch2/interfaces/catch_interfaces_config.hpp  |  2 +-
 .../interfaces/catch_interfaces_reporter.hpp       |  2 +-
 src/catch2/internal/catch_sharding.hpp             |  4 ++--
 .../internal/catch_template_test_registry.hpp      | 24 +++++++++++-----------
 src/catch2/internal/catch_test_registry.cpp        |  4 +++-
 src/catch2/internal/catch_xmlwriter.cpp            |  4 ++--
 src/catch2/matchers/catch_matchers_templated.cpp   |  2 +-
 src/catch2/reporters/catch_reporter_console.cpp    | 10 ++++-----
 tests/SelfTest/TestRegistrations.cpp               |  2 +-
 15 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/src/catch2/benchmark/detail/catch_analyse.hpp b/src/catch2/benchmark/detail/catch_analyse.hpp
index cf96a3d2..6652f5f4 100644
--- a/src/catch2/benchmark/detail/catch_analyse.hpp
+++ b/src/catch2/benchmark/detail/catch_analyse.hpp
@@ -28,7 +28,7 @@ namespace Catch {
             SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
                 if (!cfg.benchmarkNoAnalysis()) {
                     std::vector<double> samples;
-                    samples.reserve(last - first);
+                    samples.reserve(static_cast<size_t>(last - first));
                     std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); });
 
                     auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
@@ -54,7 +54,7 @@ namespace Catch {
                     };
                 } else {
                     std::vector<Duration> samples;
-                    samples.reserve(last - first);
+                    samples.reserve(static_cast<size_t>(last - first));
 
                     Duration mean = Duration(0);
                     int i = 0;
diff --git a/src/catch2/benchmark/detail/catch_estimate_clock.hpp b/src/catch2/benchmark/detail/catch_estimate_clock.hpp
index 3bba791e..c392ca4f 100644
--- a/src/catch2/benchmark/detail/catch_estimate_clock.hpp
+++ b/src/catch2/benchmark/detail/catch_estimate_clock.hpp
@@ -29,11 +29,11 @@ namespace Catch {
             template <typename Clock>
             std::vector<double> resolution(int k) {
                 std::vector<TimePoint<Clock>> times;
-                times.reserve(k + 1);
+                times.reserve(static_cast<size_t>(k + 1));
                 std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
 
                 std::vector<double> deltas;
-                deltas.reserve(k);
+                deltas.reserve(static_cast<size_t>(k));
                 std::transform(std::next(times.begin()), times.end(), times.begin(),
                     std::back_inserter(deltas),
                     [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
@@ -83,7 +83,7 @@ namespace Catch {
                 auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
                 std::vector<double> times;
                 int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
-                times.reserve(nsamples);
+                times.reserve(static_cast<size_t>(nsamples));
                 std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
                     return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
                 });
diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp
index 45190da8..b7f69f89 100644
--- a/src/catch2/benchmark/detail/catch_stats.cpp
+++ b/src/catch2/benchmark/detail/catch_stats.cpp
@@ -25,8 +25,8 @@ namespace {
 using Catch::Benchmark::Detail::sample;
 
      template <typename URng, typename Estimator>
-     sample resample(URng& rng, int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
-         auto n = last - first;
+     sample resample(URng& rng, unsigned int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
+         auto n = static_cast<size_t>(last - first);
          std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
 
          sample out;
@@ -34,7 +34,7 @@ using Catch::Benchmark::Detail::sample;
          std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
              std::vector<double> resampled;
              resampled.reserve(n);
-             std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
+             std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[static_cast<std::ptrdiff_t>(dist(rng))]; });
              return estimator(resampled.begin(), resampled.end());
          });
          std::sort(out.begin(), out.end());
@@ -194,7 +194,7 @@ namespace Catch {
             }
 
 
-            bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
+            bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
                 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
                 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
                 static std::random_device entropy;
diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp
index 8985670f..dc2ad4ab 100644
--- a/src/catch2/benchmark/detail/catch_stats.hpp
+++ b/src/catch2/benchmark/detail/catch_stats.hpp
@@ -59,7 +59,7 @@ namespace Catch {
 
             template <typename Estimator, typename Iterator>
             sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
-                auto n = last - first;
+                auto n = static_cast<size_t>(last - first);
                 auto second = first;
                 ++second;
                 sample results;
@@ -115,8 +115,8 @@ namespace Catch {
                 double b2 = bias - z1;
                 double a1 = a(b1);
                 double a2 = a(b2);
-                auto lo = (std::max)(cumn(a1), 0);
-                auto hi = (std::min)(cumn(a2), n - 1);
+                auto lo = static_cast<size_t>((std::max)(cumn(a1), 0));
+                auto hi = static_cast<size_t>((std::min)(cumn(a2), n - 1));
 
                 return { point, resample[lo], resample[hi], confidence_level };
             }
@@ -129,7 +129,7 @@ namespace Catch {
                 double outlier_variance;
             };
 
-            bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
+            bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
         } // namespace Detail
     } // namespace Benchmark
 } // namespace Catch
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index c9fc8eef..e2569de9 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -82,7 +82,7 @@ namespace Catch {
     Verbosity Config::verbosity() const                { return m_data.verbosity; }
 
     bool Config::benchmarkNoAnalysis() const                      { return m_data.benchmarkNoAnalysis; }
-    int Config::benchmarkSamples() const                          { return m_data.benchmarkSamples; }
+    unsigned int Config::benchmarkSamples() const                 { return m_data.benchmarkSamples; }
     double Config::benchmarkConfidenceInterval() const            { return m_data.benchmarkConfidenceInterval; }
     unsigned int Config::benchmarkResamples() const               { return m_data.benchmarkResamples; }
     std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index 6aa6c4d6..dbb9bf0e 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -110,7 +110,7 @@ namespace Catch {
         bool showInvisibles() const override;
         Verbosity verbosity() const override;
         bool benchmarkNoAnalysis() const override;
-        int benchmarkSamples() const override;
+        unsigned int benchmarkSamples() const override;
         double benchmarkConfidenceInterval() const override;
         unsigned int benchmarkResamples() const override;
         std::chrono::milliseconds benchmarkWarmupTime() const override;
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index bd0c8a40..4f466b22 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -81,7 +81,7 @@ namespace Catch {
         virtual Verbosity verbosity() const = 0;
 
         virtual bool benchmarkNoAnalysis() const = 0;
-        virtual int benchmarkSamples() const = 0;
+        virtual unsigned int benchmarkSamples() const = 0;
         virtual double benchmarkConfidenceInterval() const = 0;
         virtual unsigned int benchmarkResamples() const = 0;
         virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0;
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp
index 3a7cd32c..d6197902 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp
@@ -105,7 +105,7 @@ namespace Catch {
         std::string name;
         double estimatedDuration;
         int iterations;
-        int samples;
+        unsigned int samples;
         unsigned int resamples;
         double clockResolution;
         double clockCost;
diff --git a/src/catch2/internal/catch_sharding.hpp b/src/catch2/internal/catch_sharding.hpp
index 0e8822ee..17a206f8 100644
--- a/src/catch2/internal/catch_sharding.hpp
+++ b/src/catch2/internal/catch_sharding.hpp
@@ -30,8 +30,8 @@ namespace Catch {
         const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests);
         const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests);
 
-        auto startIterator = std::next(container.begin(), startIndex);
-        auto endIterator = std::next(container.begin(), endIndex);
+        auto startIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(startIndex));
+        auto endIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(endIndex));
 
         return Container(startIterator, endIterator);
     }
diff --git a/src/catch2/internal/catch_template_test_registry.hpp b/src/catch2/internal/catch_template_test_registry.hpp
index 235ee3e4..bfac3bc8 100644
--- a/src/catch2/internal/catch_template_test_registry.hpp
+++ b/src/catch2/internal/catch_template_test_registry.hpp
@@ -83,9 +83,9 @@
             template<typename...Types> \
             struct TestName{\
                 TestName(){\
-                    int index = 0;                                    \
+                    size_t index = 0;                                    \
                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
-                    using expander = int[];\
+                    using expander = size_t[];\
                     (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
                 }\
             };\
@@ -128,8 +128,8 @@
             template<typename... Types>                               \
             struct TestName {                                         \
                 void reg_tests() {                                          \
-                    int index = 0;                                    \
-                    using expander = int[];                           \
+                    size_t index = 0;                                    \
+                    using expander = size_t[];                           \
                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
                     constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
                     constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
@@ -176,8 +176,8 @@
         template<typename... Types>                               \
         struct TestName {                                         \
             void reg_tests() {                                          \
-                int index = 0;                                    \
-                using expander = int[];                           \
+                size_t index = 0;                                    \
+                using expander = size_t[];                           \
                 (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
             }                                                     \
         };\
@@ -211,9 +211,9 @@
             template<typename...Types> \
             struct TestNameClass{\
                 TestNameClass(){\
-                    int index = 0;                                    \
+                    size_t index = 0;                                    \
                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
-                    using expander = int[];\
+                    using expander = size_t[];\
                     (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
                 }\
             };\
@@ -259,8 +259,8 @@
             template<typename...Types>\
             struct TestNameClass{\
                 void reg_tests(){\
-                    int index = 0;\
-                    using expander = int[];\
+                    std::size_t index = 0;\
+                    using expander = std::size_t[];\
                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
                     constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
                     constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
@@ -310,8 +310,8 @@
             template<typename...Types>\
             struct TestNameClass{\
                 void reg_tests(){\
-                    int index = 0;\
-                    using expander = int[];\
+                    size_t index = 0;\
+                    using expander = size_t[];\
                     (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
                 }\
             };\
diff --git a/src/catch2/internal/catch_test_registry.cpp b/src/catch2/internal/catch_test_registry.cpp
index c9e9fe4f..faadb101 100644
--- a/src/catch2/internal/catch_test_registry.cpp
+++ b/src/catch2/internal/catch_test_registry.cpp
@@ -42,7 +42,9 @@ namespace Catch {
             auto const startIdx = reverseEnd - secondLastColons;
             auto const classNameSize = secondLastColons - lastColons - 1;
 
-            return methodName.substr( startIdx, classNameSize );
+            return methodName.substr(
+                static_cast<std::size_t>( startIdx ),
+                static_cast<std::size_t>( classNameSize ) );
         }
     } // namespace
 
diff --git a/src/catch2/internal/catch_xmlwriter.cpp b/src/catch2/internal/catch_xmlwriter.cpp
index 24af491a..93758cba 100644
--- a/src/catch2/internal/catch_xmlwriter.cpp
+++ b/src/catch2/internal/catch_xmlwriter.cpp
@@ -87,7 +87,7 @@ namespace {
         // (see: http://www.w3.org/TR/xml/#syntax)
 
         for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
-            unsigned char c = m_str[idx];
+            unsigned char c = static_cast<unsigned char>(m_str[idx]);
             switch (c) {
             case '<':   os << "&lt;"; break;
             case '&':   os << "&amp;"; break;
@@ -147,7 +147,7 @@ namespace {
                 bool valid = true;
                 uint32_t value = headerValue(c);
                 for (std::size_t n = 1; n < encBytes; ++n) {
-                    unsigned char nc = m_str[idx + n];
+                    unsigned char nc = static_cast<unsigned char>(m_str[idx + n]);
                     valid &= ((nc & 0xC0) == 0x80);
                     value = (value << 6) | (nc & 0x3F);
                 }
diff --git a/src/catch2/matchers/catch_matchers_templated.cpp b/src/catch2/matchers/catch_matchers_templated.cpp
index 3431bde0..a336d898 100644
--- a/src/catch2/matchers/catch_matchers_templated.cpp
+++ b/src/catch2/matchers/catch_matchers_templated.cpp
@@ -19,7 +19,7 @@ namespace Matchers {
             for ( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) {
                 combined_size += desc->size();
             }
-            combined_size += (descriptions_end - descriptions_begin - 1) * combine.size();
+            combined_size += static_cast<size_t>(descriptions_end - descriptions_begin - 1) * combine.size();
 
             description.reserve(combined_size);
 
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index f260da52..6e9ea34b 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -196,7 +196,7 @@ enum class Justification { Left, Right };
 
 struct ColumnInfo {
     std::string name;
-    int width;
+    std::size_t width;
     Justification justification;
 };
 struct ColumnBreak {};
@@ -299,7 +299,8 @@ public:
 			TextFlow::Columns headerCols;
 			auto spacer = TextFlow::Spacer(2);
 			for (auto const& info : m_columnInfos) {
-				headerCols += TextFlow::Column(info.name).width(static_cast<std::size_t>(info.width - 2));
+                assert(info.width > 2);
+				headerCols += TextFlow::Column(info.name).width(info.width - 2);
 				headerCols += spacer;
 			}
 			m_os << headerCols << '\n';
@@ -333,7 +334,7 @@ public:
         tp.m_currentColumn++;
 
         auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
-        auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
+        auto padding = (strSize + 1 < colInfo.width)
             ? std::string(colInfo.width - (strSize + 1), ' ')
             : std::string();
         if (colInfo.justification == Justification::Left)
@@ -437,8 +438,7 @@ void ConsoleReporter::benchmarkPreparing( StringRef name ) {
 	lazyPrintWithoutClosingBenchmarkTable();
 
 	auto nameCol = TextFlow::Column( static_cast<std::string>( name ) )
-                       .width( static_cast<std::size_t>(
-                           m_tablePrinter->columnInfos()[0].width - 2 ) );
+                       .width( m_tablePrinter->columnInfos()[0].width - 2 );
 
 	bool firstLine = true;
 	for (auto line : nameCol) {
diff --git a/tests/SelfTest/TestRegistrations.cpp b/tests/SelfTest/TestRegistrations.cpp
index 160266fd..2b28c379 100644
--- a/tests/SelfTest/TestRegistrations.cpp
+++ b/tests/SelfTest/TestRegistrations.cpp
@@ -67,7 +67,7 @@ public:
         ++m_testCaseCounter.starting;
 
         // Reset the part tracking for partial test case events
-        m_lastSeenPartNumber = -1;
+        m_lastSeenPartNumber = uint64_t(-1);
     }
 
     void testCasePartialStarting(Catch::TestCaseInfo const&,