Unverified Commit 7d0d9061 by Guillaume Chatelet Committed by GitHub

Support -Wsuggest-override (#1059)

* Support -Wsuggest-override google/benchmark is C++11 compatible but doesn't use the `override` keyword. Projects using google/benchmark with enabled `-Wsuggest-override` and `-Werror` will fail to compile. * Add -Wsuggest-override cxx flag * Revert unrelated formatting * Revert unrelated formatting, take 2 * Revert unrelated formatting, take 3 * Disable -Wsuggest-override when compiling tests, gtest does not handle it yet Co-authored-by: 's avatarDominic Hamon <dominichamon@users.noreply.github.com>
parent 3b508fad
...@@ -157,6 +157,10 @@ else() ...@@ -157,6 +157,10 @@ else()
add_cxx_compiler_flag(-Werror RELEASE) add_cxx_compiler_flag(-Werror RELEASE)
add_cxx_compiler_flag(-Werror RELWITHDEBINFO) add_cxx_compiler_flag(-Werror RELWITHDEBINFO)
add_cxx_compiler_flag(-Werror MINSIZEREL) add_cxx_compiler_flag(-Werror MINSIZEREL)
if (NOT BENCHMARK_ENABLE_TESTING)
# Disable warning when compiling tests as gtest does not use 'override'.
add_cxx_compiler_flag(-Wsuggest-override)
endif()
# Disabled until googletest (gmock) stops emitting variadic macro warnings # Disabled until googletest (gmock) stops emitting variadic macro warnings
#add_cxx_compiler_flag(-pedantic) #add_cxx_compiler_flag(-pedantic)
#add_cxx_compiler_flag(-pedantic-errors) #add_cxx_compiler_flag(-pedantic-errors)
...@@ -284,7 +288,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) ...@@ -284,7 +288,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
if (BENCHMARK_ENABLE_LIBPFM) if (BENCHMARK_ENABLE_LIBPFM)
find_package(PFM) find_package(PFM)
endif() endif()
# Set up directories # Set up directories
......
...@@ -263,6 +263,12 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); ...@@ -263,6 +263,12 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#define BENCHMARK_UNREACHABLE() ((void)0) #define BENCHMARK_UNREACHABLE() ((void)0)
#endif #endif
#ifdef BENCHMARK_HAS_CXX11
#define BENCHMARK_OVERRIDE override
#else
#define BENCHMARK_OVERRIDE
#endif
namespace benchmark { namespace benchmark {
class BenchmarkReporter; class BenchmarkReporter;
class MemoryManager; class MemoryManager;
...@@ -1029,7 +1035,7 @@ class FunctionBenchmark : public Benchmark { ...@@ -1029,7 +1035,7 @@ class FunctionBenchmark : public Benchmark {
FunctionBenchmark(const char* name, Function* func) FunctionBenchmark(const char* name, Function* func)
: Benchmark(name), func_(func) {} : Benchmark(name), func_(func) {}
virtual void Run(State& st); virtual void Run(State& st) BENCHMARK_OVERRIDE;
private: private:
Function* func_; Function* func_;
...@@ -1039,7 +1045,7 @@ class FunctionBenchmark : public Benchmark { ...@@ -1039,7 +1045,7 @@ class FunctionBenchmark : public Benchmark {
template <class Lambda> template <class Lambda>
class LambdaBenchmark : public Benchmark { class LambdaBenchmark : public Benchmark {
public: public:
virtual void Run(State& st) { lambda_(st); } virtual void Run(State& st) BENCHMARK_OVERRIDE { lambda_(st); }
private: private:
template <class OLambda> template <class OLambda>
...@@ -1091,7 +1097,7 @@ class Fixture : public internal::Benchmark { ...@@ -1091,7 +1097,7 @@ class Fixture : public internal::Benchmark {
public: public:
Fixture() : internal::Benchmark("") {} Fixture() : internal::Benchmark("") {}
virtual void Run(State& st) { virtual void Run(State& st) BENCHMARK_OVERRIDE {
this->SetUp(st); this->SetUp(st);
this->BenchmarkCase(st); this->BenchmarkCase(st);
this->TearDown(st); this->TearDown(st);
...@@ -1199,37 +1205,37 @@ class Fixture : public internal::Benchmark { ...@@ -1199,37 +1205,37 @@ class Fixture : public internal::Benchmark {
#define BENCHMARK_TEMPLATE(n, a) BENCHMARK_TEMPLATE1(n, a) #define BENCHMARK_TEMPLATE(n, a) BENCHMARK_TEMPLATE1(n, a)
#endif #endif
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \ #define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
class BaseClass##_##Method##_Benchmark : public BaseClass { \ class BaseClass##_##Method##_Benchmark : public BaseClass { \
public: \ public: \
BaseClass##_##Method##_Benchmark() : BaseClass() { \ BaseClass##_##Method##_Benchmark() : BaseClass() { \
this->SetName(#BaseClass "/" #Method); \ this->SetName(#BaseClass "/" #Method); \
} \ } \
\ \
protected: \ protected: \
virtual void BenchmarkCase(::benchmark::State&); \ virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
}; };
#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \ #define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \ class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
public: \ public: \
BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \ BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
this->SetName(#BaseClass "<" #a ">/" #Method); \ this->SetName(#BaseClass "<" #a ">/" #Method); \
} \ } \
\ \
protected: \ protected: \
virtual void BenchmarkCase(::benchmark::State&); \ virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
}; };
#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \ #define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \ class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
public: \ public: \
BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \ BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \ this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \
} \ } \
\ \
protected: \ protected: \
virtual void BenchmarkCase(::benchmark::State&); \ virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
}; };
#ifdef BENCHMARK_HAS_CXX11 #ifdef BENCHMARK_HAS_CXX11
...@@ -1241,7 +1247,7 @@ class Fixture : public internal::Benchmark { ...@@ -1241,7 +1247,7 @@ class Fixture : public internal::Benchmark {
} \ } \
\ \
protected: \ protected: \
virtual void BenchmarkCase(::benchmark::State&); \ virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
}; };
#else #else
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) \ #define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) \
...@@ -1533,8 +1539,8 @@ class ConsoleReporter : public BenchmarkReporter { ...@@ -1533,8 +1539,8 @@ class ConsoleReporter : public BenchmarkReporter {
prev_counters_(), prev_counters_(),
printed_header_(false) {} printed_header_(false) {}
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
protected: protected:
virtual void PrintRunData(const Run& report); virtual void PrintRunData(const Run& report);
...@@ -1549,9 +1555,9 @@ class ConsoleReporter : public BenchmarkReporter { ...@@ -1549,9 +1555,9 @@ class ConsoleReporter : public BenchmarkReporter {
class JSONReporter : public BenchmarkReporter { class JSONReporter : public BenchmarkReporter {
public: public:
JSONReporter() : first_report_(true) {} JSONReporter() : first_report_(true) {}
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
virtual void Finalize(); virtual void Finalize() BENCHMARK_OVERRIDE;
private: private:
void PrintRunData(const Run& report); void PrintRunData(const Run& report);
...@@ -1564,8 +1570,8 @@ class BENCHMARK_DEPRECATED_MSG( ...@@ -1564,8 +1570,8 @@ class BENCHMARK_DEPRECATED_MSG(
: public BenchmarkReporter { : public BenchmarkReporter {
public: public:
CSVReporter() : printed_header_(false) {} CSVReporter() : printed_header_(false) {}
virtual bool ReportContext(const Context& context); virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
virtual void ReportRuns(const std::vector<Run>& reports); virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
private: private:
void PrintRunData(const Run& report); void PrintRunData(const Run& report);
......
...@@ -23,7 +23,7 @@ class ArgsProductFixture : public ::benchmark::Fixture { ...@@ -23,7 +23,7 @@ class ArgsProductFixture : public ::benchmark::Fixture {
{2, 15, 10, 9}, {2, 15, 10, 9},
{4, 5, 6, 11}}) {} {4, 5, 6, 11}}) {}
void SetUp(const ::benchmark::State& state) { void SetUp(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
std::vector<int64_t> ranges = {state.range(0), state.range(1), std::vector<int64_t> ranges = {state.range(0), state.range(1),
state.range(2), state.range(3)}; state.range(2), state.range(3)};
......
...@@ -14,11 +14,11 @@ namespace { ...@@ -14,11 +14,11 @@ namespace {
class TestReporter : public benchmark::ConsoleReporter { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual bool ReportContext(const Context& context) { virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
return ConsoleReporter::ReportContext(context); return ConsoleReporter::ReportContext(context);
}; };
virtual void ReportRuns(const std::vector<Run>& report) { virtual void ReportRuns(const std::vector<Run>& report) BENCHMARK_OVERRIDE {
++count_; ++count_;
ConsoleReporter::ReportRuns(report); ConsoleReporter::ReportRuns(report);
}; };
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
class FIXTURE_BECHMARK_NAME : public ::benchmark::Fixture { class FIXTURE_BECHMARK_NAME : public ::benchmark::Fixture {
public: public:
void SetUp(const ::benchmark::State& state) { void SetUp(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
if (state.thread_index == 0) { if (state.thread_index == 0) {
assert(data.get() == nullptr); assert(data.get() == nullptr);
data.reset(new int(42)); data.reset(new int(42));
} }
} }
void TearDown(const ::benchmark::State& state) { void TearDown(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
if (state.thread_index == 0) { if (state.thread_index == 0) {
assert(data.get() != nullptr); assert(data.get() != nullptr);
data.reset(); data.reset();
......
...@@ -34,11 +34,11 @@ BENCHMARK(BM_MapLookup)->Range(1 << 3, 1 << 12); ...@@ -34,11 +34,11 @@ BENCHMARK(BM_MapLookup)->Range(1 << 3, 1 << 12);
// Using fixtures. // Using fixtures.
class MapFixture : public ::benchmark::Fixture { class MapFixture : public ::benchmark::Fixture {
public: public:
void SetUp(const ::benchmark::State& st) { void SetUp(const ::benchmark::State& st) BENCHMARK_OVERRIDE {
m = ConstructRandomMap(static_cast<int>(st.range(0))); m = ConstructRandomMap(static_cast<int>(st.range(0)));
} }
void TearDown(const ::benchmark::State&) { m.clear(); } void TearDown(const ::benchmark::State&) BENCHMARK_OVERRIDE { m.clear(); }
std::map<int, int> m; std::map<int, int> m;
}; };
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "output_test.h" #include "output_test.h"
class TestMemoryManager : public benchmark::MemoryManager { class TestMemoryManager : public benchmark::MemoryManager {
void Start() {} void Start() BENCHMARK_OVERRIDE {}
void Stop(Result* result) { void Stop(Result* result) BENCHMARK_OVERRIDE {
result->num_allocs = 42; result->num_allocs = 42;
result->max_bytes_used = 42000; result->max_bytes_used = 42000;
} }
......
...@@ -28,7 +28,7 @@ class MultipleRangesFixture : public ::benchmark::Fixture { ...@@ -28,7 +28,7 @@ class MultipleRangesFixture : public ::benchmark::Fixture {
{2, 7, 15}, {2, 7, 15},
{7, 6, 3}}) {} {7, 6, 3}}) {}
void SetUp(const ::benchmark::State& state) { void SetUp(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
std::vector<int64_t> ranges = {state.range(0), state.range(1), std::vector<int64_t> ranges = {state.range(0), state.range(1),
state.range(2)}; state.range(2)};
......
...@@ -139,7 +139,7 @@ class TestReporter : public benchmark::BenchmarkReporter { ...@@ -139,7 +139,7 @@ class TestReporter : public benchmark::BenchmarkReporter {
TestReporter(std::vector<benchmark::BenchmarkReporter*> reps) TestReporter(std::vector<benchmark::BenchmarkReporter*> reps)
: reporters_(reps) {} : reporters_(reps) {}
virtual bool ReportContext(const Context& context) { virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
bool last_ret = false; bool last_ret = false;
bool first = true; bool first = true;
for (auto rep : reporters_) { for (auto rep : reporters_) {
...@@ -153,10 +153,10 @@ class TestReporter : public benchmark::BenchmarkReporter { ...@@ -153,10 +153,10 @@ class TestReporter : public benchmark::BenchmarkReporter {
return last_ret; return last_ret;
} }
void ReportRuns(const std::vector<Run>& report) { void ReportRuns(const std::vector<Run>& report) BENCHMARK_OVERRIDE {
for (auto rep : reporters_) rep->ReportRuns(report); for (auto rep : reporters_) rep->ReportRuns(report);
} }
void Finalize() { void Finalize() BENCHMARK_OVERRIDE {
for (auto rep : reporters_) rep->Finalize(); for (auto rep : reporters_) rep->Finalize();
} }
......
...@@ -10,7 +10,7 @@ namespace { ...@@ -10,7 +10,7 @@ namespace {
class TestReporter : public benchmark::ConsoleReporter { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual void ReportRuns(const std::vector<Run>& report) { virtual void ReportRuns(const std::vector<Run>& report) BENCHMARK_OVERRIDE {
all_runs_.insert(all_runs_.end(), begin(report), end(report)); all_runs_.insert(all_runs_.end(), begin(report), end(report));
ConsoleReporter::ReportRuns(report); ConsoleReporter::ReportRuns(report);
} }
......
...@@ -10,11 +10,11 @@ namespace { ...@@ -10,11 +10,11 @@ namespace {
class TestReporter : public benchmark::ConsoleReporter { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual bool ReportContext(const Context& context) { virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
return ConsoleReporter::ReportContext(context); return ConsoleReporter::ReportContext(context);
}; };
virtual void ReportRuns(const std::vector<Run>& report) { virtual void ReportRuns(const std::vector<Run>& report) BENCHMARK_OVERRIDE {
all_runs_.insert(all_runs_.end(), begin(report), end(report)); all_runs_.insert(all_runs_.end(), begin(report), end(report));
ConsoleReporter::ReportRuns(report); ConsoleReporter::ReportRuns(report);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment