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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
BENCHMARK_UNUSED

Expand Down