mirror of
https://github.com/google/benchmark.git
synced 2025-01-13 13:20:13 +08:00
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: Dominic Hamon <dominichamon@users.noreply.github.com>
This commit is contained in:
parent
3b508fad1f
commit
7d0d9061d8
@ -157,6 +157,10 @@ else()
|
||||
add_cxx_compiler_flag(-Werror RELEASE)
|
||||
add_cxx_compiler_flag(-Werror RELWITHDEBINFO)
|
||||
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
|
||||
#add_cxx_compiler_flag(-pedantic)
|
||||
#add_cxx_compiler_flag(-pedantic-errors)
|
||||
@ -284,7 +288,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
if (BENCHMARK_ENABLE_LIBPFM)
|
||||
find_package(PFM)
|
||||
find_package(PFM)
|
||||
endif()
|
||||
|
||||
# Set up directories
|
||||
|
@ -263,6 +263,12 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
|
||||
#define BENCHMARK_UNREACHABLE() ((void)0)
|
||||
#endif
|
||||
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
#define BENCHMARK_OVERRIDE override
|
||||
#else
|
||||
#define BENCHMARK_OVERRIDE
|
||||
#endif
|
||||
|
||||
namespace benchmark {
|
||||
class BenchmarkReporter;
|
||||
class MemoryManager;
|
||||
@ -1029,7 +1035,7 @@ class FunctionBenchmark : public Benchmark {
|
||||
FunctionBenchmark(const char* name, Function* func)
|
||||
: Benchmark(name), func_(func) {}
|
||||
|
||||
virtual void Run(State& st);
|
||||
virtual void Run(State& st) BENCHMARK_OVERRIDE;
|
||||
|
||||
private:
|
||||
Function* func_;
|
||||
@ -1039,7 +1045,7 @@ class FunctionBenchmark : public Benchmark {
|
||||
template <class Lambda>
|
||||
class LambdaBenchmark : public Benchmark {
|
||||
public:
|
||||
virtual void Run(State& st) { lambda_(st); }
|
||||
virtual void Run(State& st) BENCHMARK_OVERRIDE { lambda_(st); }
|
||||
|
||||
private:
|
||||
template <class OLambda>
|
||||
@ -1091,7 +1097,7 @@ class Fixture : public internal::Benchmark {
|
||||
public:
|
||||
Fixture() : internal::Benchmark("") {}
|
||||
|
||||
virtual void Run(State& st) {
|
||||
virtual void Run(State& st) BENCHMARK_OVERRIDE {
|
||||
this->SetUp(st);
|
||||
this->BenchmarkCase(st);
|
||||
this->TearDown(st);
|
||||
@ -1199,37 +1205,37 @@ class Fixture : public internal::Benchmark {
|
||||
#define BENCHMARK_TEMPLATE(n, a) BENCHMARK_TEMPLATE1(n, a)
|
||||
#endif
|
||||
|
||||
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass() { \
|
||||
this->SetName(#BaseClass "/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&); \
|
||||
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass() { \
|
||||
this->SetName(#BaseClass "/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
|
||||
};
|
||||
|
||||
#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
|
||||
this->SetName(#BaseClass "<" #a ">/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&); \
|
||||
#define BENCHMARK_TEMPLATE1_PRIVATE_DECLARE_F(BaseClass, Method, a) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass<a> { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass<a>() { \
|
||||
this->SetName(#BaseClass "<" #a ">/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
|
||||
};
|
||||
|
||||
#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
|
||||
this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&); \
|
||||
#define BENCHMARK_TEMPLATE2_PRIVATE_DECLARE_F(BaseClass, Method, a, b) \
|
||||
class BaseClass##_##Method##_Benchmark : public BaseClass<a, b> { \
|
||||
public: \
|
||||
BaseClass##_##Method##_Benchmark() : BaseClass<a, b>() { \
|
||||
this->SetName(#BaseClass "<" #a "," #b ">/" #Method); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
|
||||
};
|
||||
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
@ -1241,7 +1247,7 @@ class Fixture : public internal::Benchmark {
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void BenchmarkCase(::benchmark::State&); \
|
||||
virtual void BenchmarkCase(::benchmark::State&) BENCHMARK_OVERRIDE; \
|
||||
};
|
||||
#else
|
||||
#define BENCHMARK_TEMPLATE_PRIVATE_DECLARE_F(n, a) \
|
||||
@ -1533,8 +1539,8 @@ class ConsoleReporter : public BenchmarkReporter {
|
||||
prev_counters_(),
|
||||
printed_header_(false) {}
|
||||
|
||||
virtual bool ReportContext(const Context& context);
|
||||
virtual void ReportRuns(const std::vector<Run>& reports);
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
|
||||
virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual void PrintRunData(const Run& report);
|
||||
@ -1549,9 +1555,9 @@ class ConsoleReporter : public BenchmarkReporter {
|
||||
class JSONReporter : public BenchmarkReporter {
|
||||
public:
|
||||
JSONReporter() : first_report_(true) {}
|
||||
virtual bool ReportContext(const Context& context);
|
||||
virtual void ReportRuns(const std::vector<Run>& reports);
|
||||
virtual void Finalize();
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
|
||||
virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
|
||||
virtual void Finalize() BENCHMARK_OVERRIDE;
|
||||
|
||||
private:
|
||||
void PrintRunData(const Run& report);
|
||||
@ -1564,8 +1570,8 @@ class BENCHMARK_DEPRECATED_MSG(
|
||||
: public BenchmarkReporter {
|
||||
public:
|
||||
CSVReporter() : printed_header_(false) {}
|
||||
virtual bool ReportContext(const Context& context);
|
||||
virtual void ReportRuns(const std::vector<Run>& reports);
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE;
|
||||
virtual void ReportRuns(const std::vector<Run>& reports) BENCHMARK_OVERRIDE;
|
||||
|
||||
private:
|
||||
void PrintRunData(const Run& report);
|
||||
|
@ -23,7 +23,7 @@ class ArgsProductFixture : public ::benchmark::Fixture {
|
||||
{2, 15, 10, 9},
|
||||
{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),
|
||||
state.range(2), state.range(3)};
|
||||
|
||||
|
@ -14,11 +14,11 @@ namespace {
|
||||
|
||||
class TestReporter : public benchmark::ConsoleReporter {
|
||||
public:
|
||||
virtual bool ReportContext(const Context& context) {
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
|
||||
return ConsoleReporter::ReportContext(context);
|
||||
};
|
||||
|
||||
virtual void ReportRuns(const std::vector<Run>& report) {
|
||||
virtual void ReportRuns(const std::vector<Run>& report) BENCHMARK_OVERRIDE {
|
||||
++count_;
|
||||
ConsoleReporter::ReportRuns(report);
|
||||
};
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
class FIXTURE_BECHMARK_NAME : public ::benchmark::Fixture {
|
||||
public:
|
||||
void SetUp(const ::benchmark::State& state) {
|
||||
void SetUp(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
|
||||
if (state.thread_index == 0) {
|
||||
assert(data.get() == nullptr);
|
||||
data.reset(new int(42));
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown(const ::benchmark::State& state) {
|
||||
void TearDown(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
|
||||
if (state.thread_index == 0) {
|
||||
assert(data.get() != nullptr);
|
||||
data.reset();
|
||||
|
@ -34,11 +34,11 @@ BENCHMARK(BM_MapLookup)->Range(1 << 3, 1 << 12);
|
||||
// Using fixtures.
|
||||
class MapFixture : public ::benchmark::Fixture {
|
||||
public:
|
||||
void SetUp(const ::benchmark::State& st) {
|
||||
void SetUp(const ::benchmark::State& st) BENCHMARK_OVERRIDE {
|
||||
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;
|
||||
};
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "output_test.h"
|
||||
|
||||
class TestMemoryManager : public benchmark::MemoryManager {
|
||||
void Start() {}
|
||||
void Stop(Result* result) {
|
||||
void Start() BENCHMARK_OVERRIDE {}
|
||||
void Stop(Result* result) BENCHMARK_OVERRIDE {
|
||||
result->num_allocs = 42;
|
||||
result->max_bytes_used = 42000;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class MultipleRangesFixture : public ::benchmark::Fixture {
|
||||
{2, 7, 15},
|
||||
{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),
|
||||
state.range(2)};
|
||||
|
||||
|
@ -139,7 +139,7 @@ class TestReporter : public benchmark::BenchmarkReporter {
|
||||
TestReporter(std::vector<benchmark::BenchmarkReporter*> reps)
|
||||
: reporters_(reps) {}
|
||||
|
||||
virtual bool ReportContext(const Context& context) {
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
|
||||
bool last_ret = false;
|
||||
bool first = true;
|
||||
for (auto rep : reporters_) {
|
||||
@ -153,10 +153,10 @@ class TestReporter : public benchmark::BenchmarkReporter {
|
||||
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);
|
||||
}
|
||||
void Finalize() {
|
||||
void Finalize() BENCHMARK_OVERRIDE {
|
||||
for (auto rep : reporters_) rep->Finalize();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace {
|
||||
|
||||
class TestReporter : public benchmark::ConsoleReporter {
|
||||
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));
|
||||
ConsoleReporter::ReportRuns(report);
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ namespace {
|
||||
|
||||
class TestReporter : public benchmark::ConsoleReporter {
|
||||
public:
|
||||
virtual bool ReportContext(const Context& context) {
|
||||
virtual bool ReportContext(const Context& context) BENCHMARK_OVERRIDE {
|
||||
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));
|
||||
ConsoleReporter::ReportRuns(report);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user