From 1d25c2e3bea73ea03592abc7e7ef9b6a47c2e90b Mon Sep 17 00:00:00 2001 From: Gary Miguel Date: Wed, 21 Jun 2023 15:35:44 -0700 Subject: [PATCH] remove old-style (C-style) casts (#1614) Remove old-style (C-style) casts This is required by the Google C++ style guide: https://google.github.io/styleguide/cppguide.html#Casting --- BUILD.bazel | 4 ++++ CMakeLists.txt | 1 + src/benchmark.cc | 2 +- src/log.h | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) 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; }