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) {
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;

View File

@ -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());
});

View File

@ -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;

View File

@ -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

View File

@ -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); }

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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 */ \
}\
};\

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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&,