From 64ba272911c2413cee516af849c4c80d7ae993b9 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 12 Mar 2015 19:16:06 -0400 Subject: [PATCH] Enable zero as NULL warnings and fix all occurences --- CMakeLists.txt | 3 +-- include/benchmark/benchmark.h | 18 ++++++++++++++++-- src/benchmark.cc | 3 +++ src/sysinfo.cc | 2 +- src/walltime.cc | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4296b235..4255dc73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,7 @@ add_cxx_compiler_flag(-Wextra) add_cxx_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Werror) add_cxx_compiler_flag(-pedantic-errors) -# TODO(ericwf): enable this for g++ -#add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) +add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) # Release flags add_cxx_compiler_flag(-fno-strict-aliasing RELEASE) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index aa80bbc8..f796dc31 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -152,7 +152,8 @@ void Initialize(int* argc, const char** argv); // Otherwise, run all benchmarks specified by the --benchmark_filter flag, // and exit after running the benchmarks. -void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = NULL); +void RunSpecifiedBenchmarks(); +void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter); // If this routine is called, peak memory allocation past this point in the // benchmark is reported at the end of the benchmark report line. (It is @@ -164,6 +165,19 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = NULL); namespace internal { class Benchmark; class BenchmarkFamilies; + +template struct Voider { + typedef void type; +}; + +template +struct EnableIfString {}; + +template +struct EnableIfString::type> { + typedef int type; +}; + } // State is passed to a running Benchmark and contains state for the @@ -279,7 +293,7 @@ public: // as an injected class name in the case of std::string. template void SetLabel(StringType const & str, - typename StringType::basic_string* = 0) { + typename internal::EnableIfString::type = 1) { this->SetLabel(str.c_str()); } diff --git a/src/benchmark.cc b/src/benchmark.cc index 8b0682e6..82f5f5f0 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -898,6 +898,9 @@ void RunMatchingBenchmarks(const std::string& spec, } // end namespace internal +void RunSpecifiedBenchmarks() { + RunSpecifiedBenchmarks(nullptr); +} void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter) { std::string spec = FLAGS_benchmark_filter; diff --git a/src/sysinfo.cc b/src/sysinfo.cc index ace7caa4..b275360f 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -303,7 +303,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) { cputime_fd = -1; return false; } - unsigned long long result = strtoull(buff, NULL, 0); + unsigned long long result = strtoull(buff, nullptr, 0); if (result == (std::numeric_limits::max)()) { close(cputime_fd); cputime_fd = -1; diff --git a/src/walltime.cc b/src/walltime.cc index 39c04975..fa1b61f4 100644 --- a/src/walltime.cc +++ b/src/walltime.cc @@ -89,7 +89,7 @@ private: WallTime Slow() const { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); return tv.tv_sec + tv.tv_usec * 1e-6; }