From 12250c48395d75451e7fd5da641f29c8951de9e6 Mon Sep 17 00:00:00 2001 From: Kostiantyn Lazukin Date: Wed, 21 Jan 2026 02:25:47 +0000 Subject: [PATCH] Silence -Wc2y-extensions warning around __COUNTER__ clang-23 in pedantic mode now warns that __COUNTER__ macro is c2y extension. This patch silences this warning around uses of this macro. --- AUTHORS | 1 + CONTRIBUTORS | 1 + include/benchmark/benchmark.h | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index ef905531df..11d28f7229 100644 --- a/AUTHORS +++ b/AUTHORS @@ -44,6 +44,7 @@ Jordan Williams Jussi Knuuttila Kaito Udagawa Kishan Kumar +Kostiantyn Lazukin Lei Xu Marcel Jacobse Matt Clarkson diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4b015925aa..52e49cce46 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -67,6 +67,7 @@ Jussi Knuuttila Kaito Udagawa Kai Wolf Kishan Kumar +Kostiantyn Lazukin Lei Xu Marcel Jacobse Matt Clarkson diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index a67a24ef4b..f7d1341c8f 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -1484,14 +1484,29 @@ class Fixture : public Benchmark { // ------------------------------------------------------ // Macro to register benchmarks +// clang-format off +#if defined(__clang__) +#define BENCHMARK_DISABLE_COUNTER_WARNING \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\"") \ + _Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"") +#define BENCHMARK_RESTORE_COUNTER_WARNING _Pragma("GCC diagnostic pop") +#else +#define BENCHMARK_DISABLE_COUNTER_WARNING +#define BENCHMARK_RESTORE_COUNTER_WARNING +#endif +// clang-format on + // Check that __COUNTER__ is defined and that __COUNTER__ increases by 1 // every time it is expanded. X + 1 == X + 0 is used in case X is defined to be // empty. If X is empty the expression becomes (+1 == +0). +BENCHMARK_DISABLE_COUNTER_WARNING #if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0) #define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__ #else #define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__ #endif +BENCHMARK_RESTORE_COUNTER_WARNING // Helpers for generating unique variable names #define BENCHMARK_PRIVATE_NAME(...) \ @@ -1505,9 +1520,10 @@ class Fixture : public Benchmark { BaseClass##_##Method##_Benchmark #define BENCHMARK_PRIVATE_DECLARE(n) \ + BENCHMARK_DISABLE_COUNTER_WARNING \ /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \ static ::benchmark::Benchmark const* const BENCHMARK_PRIVATE_NAME(n) \ - BENCHMARK_UNUSED + BENCHMARK_RESTORE_COUNTER_WARNING BENCHMARK_UNUSED #define BENCHMARK(...) \ BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \ @@ -1695,9 +1711,11 @@ class Fixture : public Benchmark { ::benchmark::internal::make_unique())) #define BENCHMARK_TEMPLATE_INSTANTIATE_F(BaseClass, Method, ...) \ + BENCHMARK_DISABLE_COUNTER_WARNING \ BENCHMARK_TEMPLATE_PRIVATE_INSTANTIATE_F( \ BaseClass, Method, BENCHMARK_PRIVATE_NAME(BaseClass##Method), \ - __VA_ARGS__) + __VA_ARGS__) \ + BENCHMARK_RESTORE_COUNTER_WARNING // This macro will define and register a benchmark within a fixture class. #define BENCHMARK_F(BaseClass, Method) \