diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2025-11-03 07:50:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-03 07:50:25 -0500 |
| commit | df1d786c460e0e47c9074f3533f098190ebfbc1b (patch) | |
| tree | 0154a2150d37f9f81f3194657edd67c644d7a382 /third-party | |
| parent | ef9ff15587cd0aa2676553b64ec3b11e36ebfd02 (diff) | |
[C2y] Support WG14 N3457, the __COUNTER__ macro (#162662)
This implements the parts of
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3457.htm which were
adopted at the recent meeting in Brno.
Clang already implemented `__COUNTER__`, but needed some changes for
conformance. Specifically, we now diagnose when the macro is expanded
more than 2147483647 times. Additionally, we now give the expected
extension and pre-compat warnings for the feature.
To support testing the limits, this also adds a -cc1-only option,
`-finitial-counter-value=`, which lets you specify the initial value the
`__COUNTER__` macro should expand to.
Diffstat (limited to 'third-party')
| -rw-r--r-- | third-party/benchmark/include/benchmark/benchmark.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/third-party/benchmark/include/benchmark/benchmark.h b/third-party/benchmark/include/benchmark/benchmark.h index 08cfe29da344..c2debb216d64 100644 --- a/third-party/benchmark/include/benchmark/benchmark.h +++ b/third-party/benchmark/include/benchmark/benchmark.h @@ -250,6 +250,10 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop") +#define BENCHMARK_DISABLE_PEDANTIC_WARNING \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") +#define BENCHMARK_RESTORE_PEDANTIC_WARNING _Pragma("GCC diagnostic pop") #elif defined(__NVCOMPILER) #define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y) #define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) @@ -257,6 +261,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); _Pragma("diagnostic push") \ _Pragma("diag_suppress deprecated_entity_with_custom_message") #define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("diagnostic pop") +#define BENCHMARK_DISABLE_PEDANTIC_WARNING +#define BENCHMARK_RESTORE_PEDANTIC_WARNING #else #define BENCHMARK_BUILTIN_EXPECT(x, y) x #define BENCHMARK_DEPRECATED_MSG(msg) @@ -265,6 +271,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond); __LINE__) ") : warning note: " msg)) #define BENCHMARK_DISABLE_DEPRECATED_WARNING #define BENCHMARK_RESTORE_DEPRECATED_WARNING +#define BENCHMARK_DISABLE_PEDANTIC_WARNING +#define BENCHMARK_RESTORE_PEDANTIC_WARNING #endif // clang-format on @@ -1462,11 +1470,13 @@ class Fixture : public internal::Benchmark { // 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_PEDANTIC_WARNING #if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0) #define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__ #else #define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__ #endif +BENCHMARK_RESTORE_PEDANTIC_WARNING // Helpers for generating unique variable names #ifdef BENCHMARK_HAS_CXX11 |
