From f3ed75cfbeb028969cd685d048b8653e964a653f Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Wed, 8 Jan 2025 10:51:45 +0000 Subject: [PATCH 1/4] changes to support newer clang-tidy errors --- include/benchmark/benchmark.h | 76 +++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 86f9dbbabb..c680b2c5bf 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -403,7 +403,16 @@ RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter, // TimeUnit is passed to a benchmark in order to specify the order of magnitude // for the measured time. -enum TimeUnit { kNanosecond, kMicrosecond, kMillisecond, kSecond }; +enum TimeUnit +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif +{ + kNanosecond, + kMicrosecond, + kMillisecond, + kSecond +}; BENCHMARK_EXPORT TimeUnit GetDefaultTimeUnit(); @@ -698,7 +707,11 @@ class Counter { kInvert = 1 << 31 }; - enum OneK { + enum OneK +#if defined(BENCHMARK_HAS_CXX11) + : uint16_t +#endif + { // 1'000 items per 1k kIs1000 = 1000, // 1'024 items per 1k @@ -713,7 +726,7 @@ class Counter { Counter(double v = 0., Flags f = kDefaults, OneK k = kIs1000) : value(v), flags(f), oneK(k) {} - BENCHMARK_ALWAYS_INLINE operator double const &() const { return value; } + BENCHMARK_ALWAYS_INLINE operator double const&() const { return value; } BENCHMARK_ALWAYS_INLINE operator double&() { return value; } }; @@ -732,13 +745,34 @@ typedef std::map UserCounters; // 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 }; +enum BigO +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif +{ + oNone, + o1, + oN, + oNSquared, + oNCubed, + oLogN, + oNLogN, + oAuto, + oLambda +}; typedef int64_t ComplexityN; typedef int64_t IterationCount; -enum StatisticUnit { kTime, kPercentage }; +enum StatisticUnit +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif +{ + kTime, + kPercentage +}; // BigOFunc is passed to a benchmark in order to specify the asymptotic // computational complexity for the benchmark. @@ -766,8 +800,7 @@ class PerfCountersMeasurement; enum AggregationReportMode #if defined(BENCHMARK_HAS_CXX11) - : unsigned -#else + : uint8_t #endif { // The mode has not been manually specified @@ -786,7 +819,7 @@ enum AggregationReportMode enum Skipped #if defined(BENCHMARK_HAS_CXX11) - : unsigned + : uint8_t #endif { NotSkipped = 0, @@ -1109,7 +1142,7 @@ inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(IterationCount n, } struct State::StateIterator { - struct BENCHMARK_UNUSED Value {}; + struct BENCHMARK_UNUSED Value{}; typedef std::forward_iterator_tag iterator_category; typedef Value value_type; typedef Value reference; @@ -1789,7 +1822,15 @@ struct BENCHMARK_EXPORT CPUInfo { int num_sharing; }; - enum Scaling { UNKNOWN, ENABLED, DISABLED }; + enum Scaling +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif + { + UNKNOWN, + ENABLED, + DISABLED + }; int num_cpus; Scaling scaling; @@ -1850,7 +1891,14 @@ class BENCHMARK_EXPORT BenchmarkReporter { struct BENCHMARK_EXPORT Run { static const int64_t no_repetition_index = -1; - enum RunType { RT_Iteration, RT_Aggregate }; + enum RunType +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif + { + RT_Iteration, + RT_Aggregate + }; Run() : run_type(RT_Iteration), @@ -2006,7 +2054,11 @@ class BENCHMARK_EXPORT BenchmarkReporter { // default reporter used by RunSpecifiedBenchmarks(). class BENCHMARK_EXPORT ConsoleReporter : public BenchmarkReporter { public: - enum OutputOptions { + enum OutputOptions +#if defined(BENCHMARK_HAS_CXX11) + : uint8_t +#endif + { OO_None = 0, OO_Color = 1, OO_Tabular = 2, From 2b5602e1f60c3917d1e9fc1047f60bc20df63ab3 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Wed, 8 Jan 2025 11:23:02 +0000 Subject: [PATCH 2/4] make sure we're using the cxx17 check correctly --- include/benchmark/benchmark.h | 2 ++ src/log.h | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index c680b2c5bf..61b99fe4c4 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -171,6 +171,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); // This _MSC_VER check should detect VS 2017 v15.3 and newer. #if __cplusplus >= 201703L || \ (defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L) +// CXX17 implies CXX11 +#define BENCHMARK_HAS_CXX11 #define BENCHMARK_HAS_CXX17 #endif diff --git a/src/log.h b/src/log.h index 9a21400b09..54e22a6361 100644 --- a/src/log.h +++ b/src/log.h @@ -11,6 +11,14 @@ #define BENCHMARK_HAS_CXX11 #endif +// This _MSC_VER check should detect VS 2017 v15.3 and newer. +#if __cplusplus >= 201703L || \ + (defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L) +// CXX17 implies CXX11 +#define BENCHMARK_HAS_CXX11 +#define BENCHMARK_HAS_CXX17 +#endif + namespace benchmark { namespace internal { From ec0508d7e1107cbf90237a9c29ecdc7239d0af7f Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Wed, 8 Jan 2025 12:35:42 +0000 Subject: [PATCH 3/4] fix package changes for msys2 --- .github/workflows/build-and-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d05300db06..ae92cca886 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -141,8 +141,9 @@ jobs: git base-devel pacboy: >- - cc:p cmake:p + gcc:p + llvm:p ninja:p - name: configure cmake From ed47c863f43eb6e002b214a7514735c720814a8c Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Wed, 8 Jan 2025 12:44:06 +0000 Subject: [PATCH 4/4] clang-format --- include/benchmark/benchmark.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 61b99fe4c4..f4c062f45e 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -728,7 +728,7 @@ class Counter { Counter(double v = 0., Flags f = kDefaults, OneK k = kIs1000) : value(v), flags(f), oneK(k) {} - BENCHMARK_ALWAYS_INLINE operator double const&() const { return value; } + BENCHMARK_ALWAYS_INLINE operator double const &() const { return value; } BENCHMARK_ALWAYS_INLINE operator double&() { return value; } }; @@ -1144,7 +1144,7 @@ inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(IterationCount n, } struct State::StateIterator { - struct BENCHMARK_UNUSED Value{}; + struct BENCHMARK_UNUSED Value {}; typedef std::forward_iterator_tag iterator_category; typedef Value value_type; typedef Value reference;