Misc cleanups from exploring Clang warnings

This commit is contained in:
Martin Hořeňovský 2022-05-02 12:52:55 +02:00
parent 198713e5dc
commit 198808a24e
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
6 changed files with 10 additions and 10 deletions

View File

@ -51,10 +51,10 @@ namespace Catch {
private: private:
// If this is a constructor benchmark, destruct the underlying object // If this is a constructor benchmark, destruct the underlying object
template <typename U> template <typename U>
void destruct_on_exit(std::enable_if_t<Destruct, U>* = 0) { destruct<true>(); } void destruct_on_exit(std::enable_if_t<Destruct, U>* = nullptr) { destruct<true>(); }
// Otherwise, don't // Otherwise, don't
template <typename U> template <typename U>
void destruct_on_exit(std::enable_if_t<!Destruct, U>* = 0) { } void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { }
T& stored_object() { T& stored_object() {
return *static_cast<T*>(static_cast<void*>(&data)); return *static_cast<T*>(static_cast<void*>(&data));

View File

@ -54,7 +54,7 @@ namespace Catch {
double mean(Iterator first, Iterator last) { double mean(Iterator first, Iterator last) {
auto count = last - first; auto count = last - first;
double sum = std::accumulate(first, last, 0.); double sum = std::accumulate(first, last, 0.);
return sum / count; return sum / static_cast<double>(count);
} }
template <typename Estimator, typename Iterator> template <typename Estimator, typename Iterator>
@ -100,7 +100,7 @@ namespace Catch {
}); });
double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5)); double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
int n = static_cast<int>(resample.size()); long n = static_cast<long>(resample.size());
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n); double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
// degenerate case with uniform samples // degenerate case with uniform samples
if (prob_n == 0) return { point, point, point, confidence_level }; if (prob_n == 0) return { point, point, point, confidence_level };
@ -108,7 +108,7 @@ namespace Catch {
double bias = normal_quantile(prob_n); double bias = normal_quantile(prob_n);
double z1 = normal_quantile((1. - confidence_level) / 2.); double z1 = normal_quantile((1. - confidence_level) / 2.);
auto cumn = [n]( double x ) -> int { auto cumn = [n]( double x ) -> long {
return std::lround( normal_cdf( x ) * n ); return std::lround( normal_cdf( x ) * n );
}; };
auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); }; auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); };
@ -116,7 +116,7 @@ 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 = static_cast<size_t>((std::max)(cumn(a1), 0)); auto lo = static_cast<size_t>((std::max)(cumn(a1), 0l));
auto hi = static_cast<size_t>((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 };

View File

@ -81,4 +81,4 @@ namespace Catch {
#endif #endif
#endif // CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED #endif // CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED

View File

@ -27,4 +27,4 @@ namespace Catch {
} // namespace Detail } // namespace Detail
} // namespace Catch } // namespace Catch
#endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED #endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED

View File

@ -12,4 +12,4 @@
#define CATCH_CONFIG_CONSOLE_WIDTH 80 #define CATCH_CONFIG_CONSOLE_WIDTH 80
#endif #endif
#endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED #endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED

View File

@ -42,4 +42,4 @@ TEST_CASE("Sharding Function", "[approvals]") {
for(std::size_t i = 0; i < sizes[shardIndex]; i++) { for(std::size_t i = 0; i < sizes[shardIndex]; i++) {
CHECK(result[i] == testContainer[i + startIndex]); CHECK(result[i] == testContainer[i + startIndex]);
} }
} }