Skip to content

Silence -Wc2y-extensions warning around __COUNTER__#2108

Merged
dmah42 merged 2 commits intogoogle:mainfrom
Sunday111:silence_counter_warning
Jan 21, 2026
Merged

Silence -Wc2y-extensions warning around __COUNTER__#2108
dmah42 merged 2 commits intogoogle:mainfrom
Sunday111:silence_counter_warning

Conversation

@Sunday111
Copy link
Contributor

@Sunday111 Sunday111 commented Jan 21, 2026

clang-23 in pedantic mode now warns that __COUNTER__ macro is c2y extension. This patch silences this warning around uses of this macro.

Fixes #2057

Note: I had to fix this with ifdefs in a few places because __COUNTER__ is used for token generation. Also tried to do this with __extension__ but it simply becomes a part of generated name.

@Sunday111
Copy link
Contributor Author

Tested this locally with
clang version 23.0.0git (https://github.com/llvm/llvm-project ec080ab8bdc66808b0b7bba605b49103f1c82d0a)

cmake -S . -B ./build -G Ninja -DCMAKE_TOOLCHAIN_FILE=~/llvm/generated/llvm-toolchain-static-libcxx.cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON -DBENCHMARK_ENABLE_TESTING=ON -DCMAKE_BUILD_TYPE=Release
(cmake --build ./build && cd build && ctest)

one test failed, but fails on main as well

99% tests passed, 1 tests failed out of 84

Total Test time (real) =  11.02 sec

The following tests FAILED:
         72 - locale_impermeability_test (Subprocess aborted)
Errors while running CTest

// Macro to register benchmarks

#if defined(__clang__)
#define BENCHMARK_SILENCE_COUNTER_WARNING_PUSH \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's follow the existing naming scheme for these,
BENCHMARK_DISABLE_COUNTER_WARNING an BENCHMARK_RESTORE_COUNTER_WARNING

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

#if defined(__clang__)
#define BENCHMARK_SILENCE_COUNTER_WARNING_PUSH \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing there is no more fine-grained flag for this specific warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not find one

@LebedevRI
Copy link
Collaborator

And of course earlier clang's barf at that diag group,
you'll need to also silence -Wunknown-warning-option or also check clang version...

@Sunday111 Sunday111 force-pushed the silence_counter_warning branch from 8a65006 to fb33aa9 Compare January 21, 2026 11:19
@Sunday111 Sunday111 requested a review from LebedevRI January 21, 2026 11:21
clang-23 in pedantic mode now warns that __COUNTER__ macro is c2y
extension. This patch silences this warning around uses of this
macro.
@Sunday111 Sunday111 force-pushed the silence_counter_warning branch from fb33aa9 to 12250c4 Compare January 21, 2026 11:48
@dmah42
Copy link
Member

dmah42 commented Jan 21, 2026

bazel issues are not related. i'll take a look at that.

@dmah42
Copy link
Member

dmah42 commented Jan 21, 2026

bazel issues are not related. i'll take a look at that.

this is due to bazel silently bumping to 9.0.0 which changes how googletest needs to load library rules. i've pinned us to 8.2.1 until googletest upgrades.

@dmah42 dmah42 merged commit d8db2f9 into google:main Jan 21, 2026
84 checks passed
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
static ::benchmark::Benchmark const* const BENCHMARK_PRIVATE_NAME(n) \
BENCHMARK_UNUSED
BENCHMARK_RESTORE_COUNTER_WARNING BENCHMARK_UNUSED
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no semantical difference, but these should have been on different lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LebedevRI, yes, sorry I was in a rush to get it done. Would you like another pr to fix that or thats fine?

@Sunday111 Sunday111 deleted the silence_counter_warning branch January 21, 2026 14:54
krzysz00 added a commit to krzysz00/iree that referenced this pull request Feb 20, 2026
This pulls in google/benchmark#2108 , which
fixes a build error when using extremely new Clangs, which can occur
during gfx1250 testing.

Note that this does bump us past
google/benchmark#1836, which gets rid of a
division by number of threads on certain reported time values. I don't
know if this impacts us, but I'm going to flag it anyway.
krzysz00 added a commit to iree-org/iree that referenced this pull request Feb 21, 2026
This pulls in google/benchmark#2108 , which
fixes a build error when using extremely new Clangs, which can occur
during gfx1250 testing.

Note that this does bump us past
google/benchmark#1836, which gets rid of a
division by number of threads on certain reported time values. I don't
know if this impacts us, but I'm going to flag it anyway.
AaronStGeorge added a commit to AaronStGeorge/fusilli that referenced this pull request Feb 25, 2026
__COUNTER__ is supported by all major compilers but newer Clangs
flag it as use of upcoming C2y standard. Add diagnostic push/pop
macros around call sites that expand __COUNTER__ for unique names.

Follows the same pattern as google/benchmark#2108.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AaronStGeorge added a commit to AaronStGeorge/fusilli that referenced this pull request Feb 25, 2026
__COUNTER__ is supported by all major compilers but newer Clangs
flag it as use of upcoming C2y standard. Add diagnostic push/pop
macros around call sites that expand __COUNTER__ for unique names.

Follows the same pattern as google/benchmark#2108.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AaronStGeorge added a commit to AaronStGeorge/fusilli that referenced this pull request Feb 25, 2026
__COUNTER__ is supported by all major compilers but newer Clangs
flag it as use of upcoming C2y standard. Add diagnostic push/pop
macros around call sites that expand __COUNTER__ for unique names.

Follows the same pattern as google/benchmark#2108.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AaronStGeorge added a commit to AaronStGeorge/fusilli that referenced this pull request Feb 25, 2026
__COUNTER__ is supported by all major compilers but newer Clangs
flag it as use of upcoming C2y standard. Add diagnostic push/pop
macros around call sites that expand __COUNTER__ for unique names.

Follows the same pattern as google/benchmark#2108.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sjain-stanford pushed a commit to iree-org/fusilli that referenced this pull request Feb 25, 2026
…COUNTER__` usage (#190)

Fusilli builds using a very new Clang and `-Werror` (for example in
[`TheRock`](https://github.com/ROCm/TheRock/tree/main/iree-libs)) will
fail with `-Wc2y-extensions`. The error is warning about uses of
`__COUNTER__`, which is supported by all major compilers, though
technically unstandardized and part of the upcoming C2y standard. The
`__COUNTER__` use isn't a practical problem, so we can add diagnostic
push/pop macros around call sites that expand `__COUNTER__` to silence
the error.

The other options are for every consumer of fusilli to add
`-Wno-c2y-extensions` to their builds, or to just use `__LINE__`. The
former is pretty annoying, the latter option would probably be fine
though could cause an issue if anyone used multiple
`FUSILLI_ASSIGN_OR_RETURN`s on one line (unlikely).

This PR follows the same pattern as
google/benchmark#2108.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Passing -pedantic -Werror but relying on extensions

3 participants