Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@codeinred
Copy link
Contributor

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

Before: (warning shown)

image

After: (no warnings)

image

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
BaseClass##_##Method##_Benchmark

#define BENCHMARK_PRIVATE_DECLARE(n) \
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this use // comment style, like elsewhere in the project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was what I originally tried to use, but the answer is no. The preprocessor interprets the \ at the end of the line as extending the comment to the next line. If you try to compile it, it fails with error: multi-line comment [-Werror,-Wcomment].

The comment has to be scoped by using the /* */ syntax, since the comment is embedded into the macro.

I also tried putting the comment before the macro, but that doesn't work, since the error occurs at the point of expansion.

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me

@LebedevRI LebedevRI merged commit 0c998f7 into google:main Oct 10, 2024
80 checks passed
@LebedevRI
Copy link
Collaborator

@codeinred thank you!

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] Warning 'misc-use-anonymous-namespace' should be disabled within BENCHMARK macro

2 participants