Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix spurious warning 'misc-use-anonymous-namespace' (#1860) #1861

Merged
merged 1 commit into from
Oct 10, 2024

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
@@ -1554,6 +1554,7 @@ class Fixture : public internal::Benchmark {
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