Sweep out some Wsign-conversion warnings

This commit is contained in:
Martin Hořeňovský 2021-11-20 23:40:32 +01:00
parent 9952f29f01
commit 8cb8f0b08b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
15 changed files with 43 additions and 41 deletions

View File

@ -28,7 +28,7 @@ namespace Catch {
SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) { SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
if (!cfg.benchmarkNoAnalysis()) { if (!cfg.benchmarkNoAnalysis()) {
std::vector<double> samples; 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(); }); 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()); auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
@ -54,7 +54,7 @@ namespace Catch {
}; };
} else { } else {
std::vector<Duration> samples; std::vector<Duration> samples;
samples.reserve(last - first); samples.reserve(static_cast<size_t>(last - first));
Duration mean = Duration(0); Duration mean = Duration(0);
int i = 0; int i = 0;

View File

@ -29,11 +29,11 @@ namespace Catch {
template <typename Clock> template <typename Clock>
std::vector<double> resolution(int k) { std::vector<double> resolution(int k) {
std::vector<TimePoint<Clock>> times; 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::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
std::vector<double> deltas; 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::transform(std::next(times.begin()), times.end(), times.begin(),
std::back_inserter(deltas), std::back_inserter(deltas),
[](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); }); [](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); auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
std::vector<double> times; std::vector<double> times;
int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed)); 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] { std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
return static_cast<double>((time_clock(r.iterations) / r.iterations).count()); return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
}); });

View File

@ -25,8 +25,8 @@ namespace {
using Catch::Benchmark::Detail::sample; using Catch::Benchmark::Detail::sample;
template <typename URng, typename Estimator> template <typename URng, typename Estimator>
sample resample(URng& rng, int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) { sample resample(URng& rng, unsigned int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
auto n = last - first; auto n = static_cast<size_t>(last - first);
std::uniform_int_distribution<decltype(n)> dist(0, n - 1); std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
sample out; 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::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
std::vector<double> resampled; std::vector<double> resampled;
resampled.reserve(n); 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()); return estimator(resampled.begin(), resampled.end());
}); });
std::sort(out.begin(), out.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_START_WARNINGS_SUPPRESSION
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
static std::random_device entropy; static std::random_device entropy;

View File

@ -59,7 +59,7 @@ namespace Catch {
template <typename Estimator, typename Iterator> template <typename Estimator, typename Iterator>
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) { sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
auto n = last - first; auto n = static_cast<size_t>(last - first);
auto second = first; auto second = first;
++second; ++second;
sample results; sample results;
@ -115,8 +115,8 @@ namespace Catch {
double b2 = bias - z1; double b2 = bias - z1;
double a1 = a(b1); double a1 = a(b1);
double a2 = a(b2); double a2 = a(b2);
auto lo = (std::max)(cumn(a1), 0); auto lo = static_cast<size_t>((std::max)(cumn(a1), 0));
auto hi = (std::min)(cumn(a2), n - 1); auto hi = static_cast<size_t>((std::min)(cumn(a2), n - 1));
return { point, resample[lo], resample[hi], confidence_level }; return { point, resample[lo], resample[hi], confidence_level };
} }
@ -129,7 +129,7 @@ namespace Catch {
double outlier_variance; 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 Detail
} // namespace Benchmark } // namespace Benchmark
} // namespace Catch } // namespace Catch

View File

@ -82,7 +82,7 @@ namespace Catch {
Verbosity Config::verbosity() const { return m_data.verbosity; } Verbosity Config::verbosity() const { return m_data.verbosity; }
bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; } 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; } double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; }
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); } std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }

View File

@ -110,7 +110,7 @@ namespace Catch {
bool showInvisibles() const override; bool showInvisibles() const override;
Verbosity verbosity() const override; Verbosity verbosity() const override;
bool benchmarkNoAnalysis() const override; bool benchmarkNoAnalysis() const override;
int benchmarkSamples() const override; unsigned int benchmarkSamples() const override;
double benchmarkConfidenceInterval() const override; double benchmarkConfidenceInterval() const override;
unsigned int benchmarkResamples() const override; unsigned int benchmarkResamples() const override;
std::chrono::milliseconds benchmarkWarmupTime() const override; std::chrono::milliseconds benchmarkWarmupTime() const override;

View File

@ -81,7 +81,7 @@ namespace Catch {
virtual Verbosity verbosity() const = 0; virtual Verbosity verbosity() const = 0;
virtual bool benchmarkNoAnalysis() const = 0; virtual bool benchmarkNoAnalysis() const = 0;
virtual int benchmarkSamples() const = 0; virtual unsigned int benchmarkSamples() const = 0;
virtual double benchmarkConfidenceInterval() const = 0; virtual double benchmarkConfidenceInterval() const = 0;
virtual unsigned int benchmarkResamples() const = 0; virtual unsigned int benchmarkResamples() const = 0;
virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0; virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0;

View File

@ -105,7 +105,7 @@ namespace Catch {
std::string name; std::string name;
double estimatedDuration; double estimatedDuration;
int iterations; int iterations;
int samples; unsigned int samples;
unsigned int resamples; unsigned int resamples;
double clockResolution; double clockResolution;
double clockCost; double clockCost;

View File

@ -30,8 +30,8 @@ namespace Catch {
const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests); const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests);
const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests); const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests);
auto startIterator = std::next(container.begin(), startIndex); auto startIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(startIndex));
auto endIterator = std::next(container.begin(), endIndex); auto endIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(endIndex));
return Container(startIterator, endIterator); return Container(startIterator, endIterator);
} }

View File

@ -83,9 +83,9 @@
template<typename...Types> \ template<typename...Types> \
struct TestName{\ struct TestName{\
TestName(){\ TestName(){\
int index = 0; \ size_t index = 0; \
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\ 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 */ \ (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
}\ }\
};\ };\
@ -128,8 +128,8 @@
template<typename... Types> \ template<typename... Types> \
struct TestName { \ struct TestName { \
void reg_tests() { \ void reg_tests() { \
int index = 0; \ size_t index = 0; \
using expander = int[]; \ 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* 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 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]);\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
@ -176,8 +176,8 @@
template<typename... Types> \ template<typename... Types> \
struct TestName { \ struct TestName { \
void reg_tests() { \ void reg_tests() { \
int index = 0; \ size_t index = 0; \
using expander = int[]; \ 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 */\ (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> \ template<typename...Types> \
struct TestNameClass{\ struct TestNameClass{\
TestNameClass(){\ TestNameClass(){\
int index = 0; \ size_t index = 0; \
constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\ 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 */ \ (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
}\ }\
};\ };\
@ -259,8 +259,8 @@
template<typename...Types>\ template<typename...Types>\
struct TestNameClass{\ struct TestNameClass{\
void reg_tests(){\ void reg_tests(){\
int index = 0;\ std::size_t index = 0;\
using expander = int[];\ 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* 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 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]);\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
@ -310,8 +310,8 @@
template<typename...Types>\ template<typename...Types>\
struct TestNameClass{\ struct TestNameClass{\
void reg_tests(){\ void reg_tests(){\
int index = 0;\ size_t index = 0;\
using expander = int[];\ 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 */ \ (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 */ \
}\ }\
};\ };\

View File

@ -42,7 +42,9 @@ namespace Catch {
auto const startIdx = reverseEnd - secondLastColons; auto const startIdx = reverseEnd - secondLastColons;
auto const classNameSize = secondLastColons - lastColons - 1; 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 } // namespace

View File

@ -87,7 +87,7 @@ namespace {
// (see: http://www.w3.org/TR/xml/#syntax) // (see: http://www.w3.org/TR/xml/#syntax)
for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { 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) { switch (c) {
case '<': os << "&lt;"; break; case '<': os << "&lt;"; break;
case '&': os << "&amp;"; break; case '&': os << "&amp;"; break;
@ -147,7 +147,7 @@ namespace {
bool valid = true; bool valid = true;
uint32_t value = headerValue(c); uint32_t value = headerValue(c);
for (std::size_t n = 1; n < encBytes; ++n) { 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); valid &= ((nc & 0xC0) == 0x80);
value = (value << 6) | (nc & 0x3F); value = (value << 6) | (nc & 0x3F);
} }

View File

@ -19,7 +19,7 @@ namespace Matchers {
for ( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) { for ( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) {
combined_size += desc->size(); 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); description.reserve(combined_size);

View File

@ -196,7 +196,7 @@ enum class Justification { Left, Right };
struct ColumnInfo { struct ColumnInfo {
std::string name; std::string name;
int width; std::size_t width;
Justification justification; Justification justification;
}; };
struct ColumnBreak {}; struct ColumnBreak {};
@ -299,7 +299,8 @@ public:
TextFlow::Columns headerCols; TextFlow::Columns headerCols;
auto spacer = TextFlow::Spacer(2); auto spacer = TextFlow::Spacer(2);
for (auto const& info : m_columnInfos) { 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; headerCols += spacer;
} }
m_os << headerCols << '\n'; m_os << headerCols << '\n';
@ -333,7 +334,7 @@ public:
tp.m_currentColumn++; tp.m_currentColumn++;
auto colInfo = tp.m_columnInfos[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(colInfo.width - (strSize + 1), ' ')
: std::string(); : std::string();
if (colInfo.justification == Justification::Left) if (colInfo.justification == Justification::Left)
@ -437,8 +438,7 @@ void ConsoleReporter::benchmarkPreparing( StringRef name ) {
lazyPrintWithoutClosingBenchmarkTable(); lazyPrintWithoutClosingBenchmarkTable();
auto nameCol = TextFlow::Column( static_cast<std::string>( name ) ) auto nameCol = TextFlow::Column( static_cast<std::string>( name ) )
.width( static_cast<std::size_t>( .width( m_tablePrinter->columnInfos()[0].width - 2 );
m_tablePrinter->columnInfos()[0].width - 2 ) );
bool firstLine = true; bool firstLine = true;
for (auto line : nameCol) { for (auto line : nameCol) {

View File

@ -67,7 +67,7 @@ public:
++m_testCaseCounter.starting; ++m_testCaseCounter.starting;
// Reset the part tracking for partial test case events // Reset the part tracking for partial test case events
m_lastSeenPartNumber = -1; m_lastSeenPartNumber = uint64_t(-1);
} }
void testCasePartialStarting(Catch::TestCaseInfo const&, void testCasePartialStarting(Catch::TestCaseInfo const&,