diff --git a/BUILD.bazel b/BUILD.bazel index 99616163..60d31d2f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -49,6 +49,10 @@ cc_library( ":windows": ["-DEFAULTLIB:shlwapi.lib"], "//conditions:default": ["-pthread"], }), + copts = select({ + ":windows": [], + "//conditions:default": ["-Werror=old-style-cast"], + }), strip_include_prefix = "include", visibility = ["//visibility:public"], # Only static linking is allowed; no .so will be produced. diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a74e43..f9d2ad7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,7 @@ else() add_cxx_compiler_flag(-Wextra) add_cxx_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Wfloat-equal) + add_cxx_compiler_flag(-Wold-style-cast) if(BENCHMARK_ENABLE_WERROR) add_cxx_compiler_flag(-Werror) endif() diff --git a/src/benchmark.cc b/src/benchmark.cc index f1633b70..7fb1740a 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -229,7 +229,7 @@ void State::PauseTiming() { for (const auto& name_and_measurement : measurements) { auto name = name_and_measurement.first; auto measurement = name_and_measurement.second; - BM_CHECK_EQ(std::fpclassify((double)counters[name]), FP_ZERO); + BM_CHECK_EQ(std::fpclassify(double{counters[name]}), FP_ZERO); counters[name] = Counter(measurement, Counter::kAvgIterations); } } diff --git a/src/log.h b/src/log.h index 45701667..9a21400b 100644 --- a/src/log.h +++ b/src/log.h @@ -61,7 +61,7 @@ inline int& LogLevel() { } inline LogType& GetNullLogInstance() { - static LogType null_log((std::ostream*)nullptr); + static LogType null_log(static_cast(nullptr)); return null_log; }