Skip to content

Commit

Permalink
Sweep out some Wsign-conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Nov 23, 2021
1 parent 9952f29 commit 8cb8f0b
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/catch2/benchmark/detail/catch_analyse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/catch2/benchmark/detail/catch_estimate_clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()); });
Expand Down Expand Up @@ -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());
});
Expand Down
8 changes: 4 additions & 4 deletions src/catch2/benchmark/detail/catch_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ 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;
out.reserve(resamples);
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());
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/catch2/benchmark/detail/catch_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/catch_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/catch_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/interfaces/catch_interfaces_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/interfaces/catch_interfaces_reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_sharding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 12 additions & 12 deletions src/catch2/internal/catch_template_test_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ \
}\
};\
Expand Down Expand Up @@ -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]);\
Expand Down Expand Up @@ -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 */\
} \
};\
Expand Down Expand Up @@ -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 */ \
}\
};\
Expand Down Expand Up @@ -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]);\
Expand Down Expand Up @@ -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 */ \
}\
};\
Expand Down
4 changes: 3 additions & 1 deletion src/catch2/internal/catch_test_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_xmlwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/matchers/catch_matchers_templated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/catch2/reporters/catch_reporter_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ enum class Justification { Left, Right };

struct ColumnInfo {
std::string name;
int width;
std::size_t width;
Justification justification;
};
struct ColumnBreak {};
Expand Down Expand Up @@ -299,7 +299,8 @@ class TablePrinter {
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';
Expand Down Expand Up @@ -333,7 +334,7 @@ class TablePrinter {
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)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/SelfTest/TestRegistrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ValidatingTestListener : public Catch::EventListenerBase {
++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&,
Expand Down

0 comments on commit 8cb8f0b

Please sign in to comment.