Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] Warning 'misc-use-anonymous-namespace' should be disabled within BENCHMARK macro #1860

Closed
codeinred opened this issue Oct 10, 2024 · 1 comment · Fixed by #1861
Closed

Comments

@codeinred
Copy link
Contributor

Describe the bug

Use of the BENCHMARK macro results in a clang-tidy warning, because the macro expands to a global variable declared with static.

bench.cpp:88:1: warning: variable 'benchmark_uniq_5_benchmark_' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
   88 | BENCHMARK( myFunc );

To reproduce
Run clang-tidy on any file containing BENCHMARK macro, with the misc-use-anonymous-namespace check enabled

Expected behavior
No warning is emitted (warning should be suppressed)

Screenshots
Image

Additional context:

This can be fixed by adding NOLINTNEXTLINE(misc-use-anonymous-namespace) within the macro declaration. Adding this silences the warning, only for BENCHMARK statement itself.

#define BENCHMARK_PRIVATE_DECLARE(n)                                 \
  /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */                 \
  static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
      BENCHMARK_UNUSED
codeinred added a commit to codeinred/benchmark that referenced this issue Oct 10, 2024
Disables 'misc-use-anonymous-namespace' for usage of the BENCHMARK
macro. This warning is spurious, and the variable declared by the
BENCHMARK macro can't be moved into an annonymous namespace.

We don't want to disable it globally, but it can be disabled locally,
for the `BENCHMARK` statement, as this warning appears downstream for
users.

See:
https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics
LebedevRI pushed a commit that referenced this issue Oct 10, 2024
Disables 'misc-use-anonymous-namespace' for usage of the BENCHMARK
macro. This warning is spurious, and the variable declared by the
BENCHMARK macro can't be moved into an annonymous namespace.

We don't want to disable it globally, but it can be disabled locally,
for the `BENCHMARK` statement, as this warning appears downstream for
users.

See:
https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics
@LebedevRI
Copy link
Collaborator

This was fixed by #1861 but that PR/commit lacked "Fixes:".

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants