Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: run
shell: bash
working-directory: ${{ runner.workspace }}/_build
run: run-clang-tidy -checks=*,-clang-analyzer-deadcode*,-clang-analyzer-optin*
run: run-clang-tidy -checks=*,-clang-analyzer-deadcode*,-clang-analyzer-optin*,-fuchsia-*,-llvmlibc-*,-modernize-use-trailing-return-type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to place this in a .clang-tidy file in the root source directory

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i'm also going to reduce the number of checks we're running.

65 changes: 38 additions & 27 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ class MemoryManager {
int64_t net_heap_growth;
};

virtual ~MemoryManager() {}
MemoryManager() {}
virtual ~MemoryManager() = default;
MemoryManager(MemoryManager const&) = delete;

// Implement this to start recording allocation information.
virtual void Start() = 0;
Expand All @@ -425,7 +427,9 @@ void RegisterMemoryManager(MemoryManager* memory_manager);
// report profile metrics for the run of the benchmark.
class ProfilerManager {
public:
virtual ~ProfilerManager() {}
ProfilerManager() {}
virtual ~ProfilerManager() = default;
ProfilerManager(ProfilerManager const&) = delete;

// This is called after `Setup()` code and right before the benchmark is run.
virtual void AfterSetupStart() = 0;
Expand Down Expand Up @@ -460,7 +464,7 @@ BENCHMARK_EXPORT Benchmark* RegisterBenchmarkInternal(Benchmark*);

// Ensure that the standard streams are properly initialized in every TU.
BENCHMARK_EXPORT int InitializeStreams();
[[maybe_unused]] static int stream_init_anchor = InitializeStreams();
[[maybe_unused]] static const int stream_init_anchor = InitializeStreams();

} // namespace internal

Expand Down Expand Up @@ -626,11 +630,14 @@ class Counter {
OneK oneK;

BENCHMARK_ALWAYS_INLINE
Counter(double v = 0., Flags f = kDefaults, OneK k = kIs1000)
: value(v), flags(f), oneK(k) {}
Counter(double val = 0., Flags flg = kDefaults,
OneK onek = kIs1000) // NOLINT
: value(val), flags(flg), oneK(onek) {}

BENCHMARK_ALWAYS_INLINE operator double const &() const { return value; }
BENCHMARK_ALWAYS_INLINE operator double&() { return value; }
BENCHMARK_ALWAYS_INLINE operator double const&() const { // NOLINT
return value;
}
BENCHMARK_ALWAYS_INLINE operator double&() { return value; } // NOLINT
};

// A helper for user code to create unforeseen combinations of Flags, without
Expand All @@ -642,17 +649,17 @@ Counter::Flags inline operator|(const Counter::Flags& LHS,
}

// This is the container for the user-defined counters.
typedef std::map<std::string, Counter> UserCounters;
using UserCounters = std::map<std::string, Counter>;

// BigO is passed to a benchmark in order to specify the asymptotic
// computational
// complexity for the benchmark. In case oAuto is selected, complexity will be
// calculated automatically to the best fit.
enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };

typedef int64_t ComplexityN;
using ComplexityN = int64_t;

typedef int64_t IterationCount;
using IterationCount = int64_t;

enum StatisticUnit { kTime, kPercentage };

Expand All @@ -670,9 +677,9 @@ struct Statistics {
StatisticsFunc* compute_;
StatisticUnit unit_;

Statistics(const std::string& name, StatisticsFunc* compute,
Statistics(std::string name, StatisticsFunc* compute,
StatisticUnit unit = kTime)
: name_(name), compute_(compute), unit_(unit) {}
: name_(std::move(name)), compute_(compute), unit_(unit) {}
};

class BenchmarkInstance;
Expand Down Expand Up @@ -840,9 +847,9 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {

BENCHMARK_ALWAYS_INLINE
int64_t bytes_processed() const {
if (counters.find("bytes_per_second") != counters.end())
return static_cast<int64_t>(counters.at("bytes_per_second"));
return 0;
return (counters.find("bytes_per_second") != counters.end())
? static_cast<int64_t>(counters.at("bytes_per_second"))
: 0;
}

// If this routine is called with complexity_n > 0 and complexity report is
Expand Down Expand Up @@ -872,9 +879,9 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {

BENCHMARK_ALWAYS_INLINE
int64_t items_processed() const {
if (counters.find("items_per_second") != counters.end())
return static_cast<int64_t>(counters.at("items_per_second"));
return 0;
return (counters.find("items_per_second") != counters.end())
? static_cast<int64_t>(counters.at("items_per_second"))
: 0;
}

// If this routine is called, the specified label is printed at the
Expand Down Expand Up @@ -1017,11 +1024,11 @@ inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(IterationCount n,

struct State::StateIterator {
struct [[maybe_unused]] Value {};
typedef std::forward_iterator_tag iterator_category;
typedef Value value_type;
typedef Value reference;
typedef Value pointer;
typedef std::ptrdiff_t difference_type;
using iterator_category = std::forward_iterator_tag;
using value_type = Value;
using reference = Value;
using pointer = Value;
using difference_type = std::ptrdiff_t;

private:
friend class State;
Expand All @@ -1034,7 +1041,7 @@ struct State::StateIterator {

public:
BENCHMARK_ALWAYS_INLINE
Value operator*() const { return Value(); }
Value operator*() const { return {}; }

BENCHMARK_ALWAYS_INLINE
StateIterator& operator++() {
Expand All @@ -1045,7 +1052,9 @@ struct State::StateIterator {

BENCHMARK_ALWAYS_INLINE
bool operator!=(StateIterator const&) const {
if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) return true;
if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) {
return true;
}
parent_->FinishKeepRunning();
return false;
}
Expand All @@ -1060,7 +1069,7 @@ inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() {
}
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {
StartKeepRunning();
return StateIterator();
return {};
}

namespace internal {
Expand Down Expand Up @@ -1354,6 +1363,7 @@ class LambdaBenchmark : public Benchmark {
LambdaBenchmark(const std::string& name, OLambda&& lam)
: Benchmark(name), lambda_(std::forward<OLambda>(lam)) {}

virtual ~LambdaBenchmark() = default;
LambdaBenchmark(LambdaBenchmark const&) = delete;

template <class Lam> // NOLINTNEXTLINE(readability-redundant-declaration)
Expand Down Expand Up @@ -1721,7 +1731,7 @@ class BENCHMARK_EXPORT BenchmarkReporter {
complexity_n(0),
report_big_o(false),
report_rms(false),
memory_result(NULL),
memory_result(nullptr),
allocs_per_iter(0.0) {}

std::string benchmark_name() const;
Expand Down Expand Up @@ -1844,6 +1854,7 @@ class BENCHMARK_EXPORT BenchmarkReporter {
std::ostream& GetErrorStream() const { return *error_stream_; }

virtual ~BenchmarkReporter();
BenchmarkReporter(const BenchmarkReporter&) = delete;

// Write a human readable string to 'out' representing the specified
// 'context'.
Expand Down
10 changes: 5 additions & 5 deletions src/check.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "check.h"

namespace benchmark {
namespace internal {
namespace benchmark::internal {

static AbortHandlerT* handler = &std::abort;
namespace {
AbortHandlerT* handler = &std::abort;
} // namespace

BENCHMARK_EXPORT AbortHandlerT*& GetAbortHandler() { return handler; }

} // namespace internal
} // namespace benchmark
} // namespace benchmark::internal
6 changes: 2 additions & 4 deletions src/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#define BENCHMARK_NOEXCEPT_OP(x)
#endif

namespace benchmark {
namespace internal {
namespace benchmark::internal {

typedef void(AbortHandlerT)();

Expand Down Expand Up @@ -74,8 +73,7 @@ class CheckHandler {
LogType& log_;
};

} // end namespace internal
} // end namespace benchmark
} // namespace benchmark::internal

// The BM_CHECK macro returns a std::ostream object that can have extra
// information written to it.
Expand Down
8 changes: 3 additions & 5 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ class LogType {
friend LogType& operator<<(LogType&, Tp const&);
friend LogType& operator<<(LogType&, EndLType*);

LogType(const LogType&) = delete;
LogType& operator=(const LogType&) = delete;

private:
LogType(std::ostream* out) : out_(out) {}
std::ostream* out_;

// NOTE: we could use BENCHMARK_DISALLOW_COPY_AND_ASSIGN but we shouldn't have
// a dependency on benchmark.h from here.
LogType(const LogType&) = delete;
LogType& operator=(const LogType&) = delete;
};

template <class Tp>
Expand Down
Loading