Skip to content

Commit 258af5b

Browse files
committed
ensure we have warnings set everywhere and fix some
1 parent 4df610b commit 258af5b

12 files changed

+34
-15
lines changed

BUILD.bazel

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
licenses(["notice"])
22

3+
COPTS = [
4+
"-pedantic",
5+
"-pedantic-errors",
6+
"-std=c++11",
7+
"-Wall",
8+
"-Wconversion",
9+
"-Wextra",
10+
"-Wshadow",
11+
# "-Wshorten-64-to-32",
12+
"-Wfloat-equal",
13+
"-fstrict-aliasing",
14+
## assert() are used a lot in tests upstream, which may be optimised out leading to
15+
## unused-variable warning.
16+
"-Wno-unused-variable",
17+
"-Werror=old-style-cast",
18+
]
19+
320
config_setting(
421
name = "qnx",
522
constraint_values = ["@platforms//os:qnx"],
@@ -47,7 +64,7 @@ cc_library(
4764
],
4865
copts = select({
4966
":windows": [],
50-
"//conditions:default": ["-Werror=old-style-cast"],
67+
"//conditions:default": COPTS,
5168
}),
5269
defines = [
5370
"BENCHMARK_STATIC_DEFINE",

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ else()
190190
add_cxx_compiler_flag(-Wshadow)
191191
add_cxx_compiler_flag(-Wfloat-equal)
192192
add_cxx_compiler_flag(-Wold-style-cast)
193+
add_cxx_compiler_flag(-Wconversion)
193194
if(BENCHMARK_ENABLE_WERROR)
194195
add_cxx_compiler_flag(-Werror)
195196
endif()

include/benchmark/benchmark.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ class BENCHMARK_EXPORT Benchmark {
13041304
public:
13051305
const char* GetName() const;
13061306
int ArgsCnt() const;
1307-
const char* GetArgName(int arg) const;
1307+
const char* GetArgName(size_t arg) const;
13081308

13091309
private:
13101310
friend class BenchmarkFamilies;

src/benchmark.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
407407
benchmarks_with_threads += (benchmark.threads() > 1);
408408
runners.emplace_back(benchmark, &perfcounters, reports_for_family);
409409
int num_repeats_of_this_instance = runners.back().GetNumRepeats();
410-
num_repetitions_total += num_repeats_of_this_instance;
410+
num_repetitions_total +=
411+
static_cast<size_t>(num_repeats_of_this_instance);
411412
if (reports_for_family)
412413
reports_for_family->num_runs_total += num_repeats_of_this_instance;
413414
}

src/benchmark_register.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,8 @@ int Benchmark::ArgsCnt() const {
480480
return static_cast<int>(args_.front().size());
481481
}
482482

483-
const char* Benchmark::GetArgName(int arg) const {
484-
BM_CHECK_GE(arg, 0);
485-
BM_CHECK_LT(arg, static_cast<int>(arg_names_.size()));
483+
const char* Benchmark::GetArgName(size_t arg) const {
484+
BM_CHECK_LT(arg, arg_names_.size());
486485
return arg_names_[arg].c_str();
487486
}
488487

src/benchmark_runner.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ BenchmarkRunner::BenchmarkRunner(
235235
has_explicit_iteration_count(b.iterations() != 0 ||
236236
parsed_benchtime_flag.tag ==
237237
BenchTimeType::ITERS),
238-
pool(b.threads() - 1),
238+
pool(static_cast<size_t>(b.threads() - 1)),
239239
iters(has_explicit_iteration_count
240240
? ComputeIters(b_, parsed_benchtime_flag)
241241
: 1),

src/cycleclock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
8282
#elif defined(__x86_64__) || defined(__amd64__)
8383
uint64_t low, high;
8484
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
85-
return (high << 32) | low;
85+
return static_cast<int64_t>((high << 32) | low);
8686
#elif defined(__powerpc__) || defined(__ppc__)
8787
// This returns a time-base, which is not always precisely a cycle-count.
8888
#if defined(__powerpc64__) || defined(__ppc64__)

src/statistics.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
9797
auto error_count = std::count_if(reports.begin(), reports.end(),
9898
[](Run const& run) { return run.skipped; });
9999

100-
if (reports.size() - error_count < 2) {
100+
if (reports.size() - static_cast<size_t>(error_count) < 2) {
101101
// We don't report aggregated data if there was a single run.
102102
return results;
103103
}
@@ -179,7 +179,7 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
179179
// Similarly, if there are N repetitions with 1 iterations each,
180180
// an aggregate will be computed over N measurements, not 1.
181181
// Thus it is best to simply use the count of separate reports.
182-
data.iterations = reports.size();
182+
data.iterations = static_cast<IterationCount>(reports.size());
183183

184184
data.real_accumulated_time = Stat.compute_(real_accumulated_time_stat);
185185
data.cpu_accumulated_time = Stat.compute_(cpu_accumulated_time_stat);

src/string_util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void ToExponentAndMantissa(double val, int precision, double one_k,
5656
scaled /= one_k;
5757
if (scaled <= big_threshold) {
5858
mantissa_stream << scaled;
59-
*exponent = i + 1;
59+
*exponent = static_cast<int64_t>(i + 1);
6060
*mantissa = mantissa_stream.str();
6161
return;
6262
}

src/sysinfo.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ValueUnion {
120120

121121
explicit ValueUnion(std::size_t buff_size)
122122
: size(sizeof(DataT) + buff_size),
123-
buff(::new (std::malloc(size)) DataT(), &std::free) {}
123+
buff(::new(std::malloc(size)) DataT(), &std::free) {}
124124

125125
ValueUnion(ValueUnion&& other) = default;
126126

@@ -837,7 +837,7 @@ std::vector<double> GetLoadAvg() {
837837
!(defined(__ANDROID__) && __ANDROID_API__ < 29)
838838
static constexpr int kMaxSamples = 3;
839839
std::vector<double> res(kMaxSamples, 0.0);
840-
const int nelem = getloadavg(res.data(), kMaxSamples);
840+
const size_t nelem = static_cast<size_t>(getloadavg(res.data(), kMaxSamples));
841841
if (nelem < 1) {
842842
res.clear();
843843
} else {

src/timers.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ std::string LocalDateTimeString() {
245245
tz_offset_sign = '-';
246246
}
247247

248-
tz_len =
248+
tz_len = static_cast<size_t>(
249249
::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
250-
tz_offset_sign, offset_minutes / 100, offset_minutes % 100);
250+
tz_offset_sign, offset_minutes / 100, offset_minutes % 100));
251251
BM_CHECK(tz_len == kTzOffsetLen);
252252
((void)tz_len); // Prevent unused variable warning in optimized build.
253253
} else {

test/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ TEST_COPTS = [
2121
## assert() are used a lot in tests upstream, which may be optimised out leading to
2222
## unused-variable warning.
2323
"-Wno-unused-variable",
24+
"-Werror=old-style-cast",
2425
]
2526

2627
# Some of the issues with DoNotOptimize only occur when optimization is enabled

0 commit comments

Comments
 (0)