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 analyse(const IConfig &cfg, Environment, Iterator first, Iterator last) { if (!cfg.benchmarkNoAnalysis()) { std::vector samples; - samples.reserve(last - first); + samples.reserve(static_cast(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 samples; - samples.reserve(last - first); + samples.reserve(static_cast(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 std::vector resolution(int k) { std::vector> times; - times.reserve(k + 1); + times.reserve(static_cast(k + 1)); std::generate_n(std::back_inserter(times), k + 1, now{}); std::vector deltas; - deltas.reserve(k); + deltas.reserve(static_cast(k)); std::transform(std::next(times.begin()), times.end(), times.begin(), std::back_inserter(deltas), [](TimePoint a, TimePoint b) { return static_cast((a - b).count()); }); @@ -83,7 +83,7 @@ namespace Catch { auto&& r = run_for_at_least(std::chrono::duration_cast>(clock_cost_estimation_time), iters, time_clock); std::vector times; int nsamples = static_cast(std::ceil(time_limit / r.elapsed)); - times.reserve(nsamples); + times.reserve(static_cast(nsamples)); std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] { return static_cast((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 - sample resample(URng& rng, int resamples, std::vector::iterator first, std::vector::iterator last, Estimator& estimator) { - auto n = last - first; + sample resample(URng& rng, unsigned int resamples, std::vector::iterator first, std::vector::iterator last, Estimator& estimator) { + auto n = static_cast(last - first); std::uniform_int_distribution 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 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(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::iterator first, std::vector::iterator last) { + bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector::iterator first, std::vector::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 sample jackknife(Estimator&& estimator, Iterator first, Iterator last) { - auto n = last - first; + auto n = static_cast(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((std::max)(cumn(a1), 0)); + auto hi = static_cast((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::iterator first, std::vector::iterator last); + bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector::iterator first, std::vector::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(startIndex)); + auto endIterator = std::next(container.begin(), static_cast(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 \ 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 \ 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 \ 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 ), 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 \ 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\ 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\ 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::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( startIdx ), + static_cast( 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(m_str[idx]); switch (c) { case '<': os << "<"; break; case '&': os << "&"; 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(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(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(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(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( name ) ) - .width( static_cast( - 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&,