Skip to content

Commit d8db2f9

Browse files
Sunday111dmah42
andauthored
Silence -Wc2y-extensions warning around __COUNTER__ (#2108)
clang-23 in pedantic mode now warns that __COUNTER__ macro is c2y extension. This patch silences this warning around uses of this macro. Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
1 parent aa3ed62 commit d8db2f9

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Jordan Williams <jwillikers@protonmail.com>
4444
Jussi Knuuttila <jussi.knuuttila@gmail.com>
4545
Kaito Udagawa <umireon@gmail.com>
4646
Kishan Kumar <kumar.kishan@outlook.com>
47+
Kostiantyn Lazukin <konstantin.lazukin@gmail.com>
4748
Lei Xu <eddyxu@gmail.com>
4849
Marcel Jacobse <mjacobse@uni-bremen.de>
4950
Matt Clarkson <mattyclarkson@gmail.com>

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Jussi Knuuttila <jussi.knuuttila@gmail.com>
6767
Kaito Udagawa <umireon@gmail.com>
6868
Kai Wolf <kai.wolf@gmail.com>
6969
Kishan Kumar <kumar.kishan@outlook.com>
70+
Kostiantyn Lazukin <konstantin.lazukin@gmail.com>
7071
Lei Xu <eddyxu@gmail.com>
7172
Marcel Jacobse <mjacobse@uni-bremen.de>
7273
Matt Clarkson <mattyclarkson@gmail.com>

include/benchmark/benchmark.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,14 +1484,29 @@ class Fixture : public Benchmark {
14841484
// ------------------------------------------------------
14851485
// Macro to register benchmarks
14861486

1487+
// clang-format off
1488+
#if defined(__clang__)
1489+
#define BENCHMARK_DISABLE_COUNTER_WARNING \
1490+
_Pragma("GCC diagnostic push") \
1491+
_Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\"") \
1492+
_Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"")
1493+
#define BENCHMARK_RESTORE_COUNTER_WARNING _Pragma("GCC diagnostic pop")
1494+
#else
1495+
#define BENCHMARK_DISABLE_COUNTER_WARNING
1496+
#define BENCHMARK_RESTORE_COUNTER_WARNING
1497+
#endif
1498+
// clang-format on
1499+
14871500
// Check that __COUNTER__ is defined and that __COUNTER__ increases by 1
14881501
// every time it is expanded. X + 1 == X + 0 is used in case X is defined to be
14891502
// empty. If X is empty the expression becomes (+1 == +0).
1503+
BENCHMARK_DISABLE_COUNTER_WARNING
14901504
#if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
14911505
#define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__
14921506
#else
14931507
#define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
14941508
#endif
1509+
BENCHMARK_RESTORE_COUNTER_WARNING
14951510

14961511
// Helpers for generating unique variable names
14971512
#define BENCHMARK_PRIVATE_NAME(...) \
@@ -1505,9 +1520,10 @@ class Fixture : public Benchmark {
15051520
BaseClass##_##Method##_Benchmark
15061521

15071522
#define BENCHMARK_PRIVATE_DECLARE(n) \
1523+
BENCHMARK_DISABLE_COUNTER_WARNING \
15081524
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
15091525
static ::benchmark::Benchmark const* const BENCHMARK_PRIVATE_NAME(n) \
1510-
BENCHMARK_UNUSED
1526+
BENCHMARK_RESTORE_COUNTER_WARNING BENCHMARK_UNUSED
15111527

15121528
#define BENCHMARK(...) \
15131529
BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \
@@ -1695,9 +1711,11 @@ class Fixture : public Benchmark {
16951711
::benchmark::internal::make_unique<UniqueName>()))
16961712

16971713
#define BENCHMARK_TEMPLATE_INSTANTIATE_F(BaseClass, Method, ...) \
1714+
BENCHMARK_DISABLE_COUNTER_WARNING \
16981715
BENCHMARK_TEMPLATE_PRIVATE_INSTANTIATE_F( \
16991716
BaseClass, Method, BENCHMARK_PRIVATE_NAME(BaseClass##Method), \
1700-
__VA_ARGS__)
1717+
__VA_ARGS__) \
1718+
BENCHMARK_RESTORE_COUNTER_WARNING
17011719

17021720
// This macro will define and register a benchmark within a fixture class.
17031721
#define BENCHMARK_F(BaseClass, Method) \

0 commit comments

Comments
 (0)