The same functionality is already implemented in the
readability-static-definition-in-anonymous-namespace
check, including automatic fixes.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
My plan was to apply this removal in the same patch where I add the new check, but I know I'd get comments like "please do the removal in a separate patch". So that's what I'm doing :)
I was commenting because we already have a similar diagnostic in clang-tidy 15:
namespace { static void foo(); static void bar(){} void foo() {} static int x; }
$ clang-tidy-15 -checks=\*,-llvmlibc-* /tmp/test.cpp Error while trying to load a compilation database: Could not auto-detect compilation database for file "/tmp/test.cpp" No compilation database found in /tmp or any parent directory fixed-compilation-database: Error while opening fixed database: No such file or directory json-compilation-database: Error while opening JSON database: No such file or directory Running without flags. 5 warnings generated. /tmp/test.cpp:3:17: warning: 'bar' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace] static void bar(){} ~~~~~~~ ^ /tmp/test.cpp:5:16: warning: variable 'x' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] static int x; ^ /tmp/test.cpp:5:16: warning: variable name 'x' is too short, expected at least 3 characters [readability-identifier-length] /tmp/test.cpp:5:16: warning: 'x' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace] static int x; ~~~~~~~ ^ /tmp/test.cpp:6:3: warning: anonymous namespace not terminated with a closing comment [llvm-namespace-comment] } ^ // namespace /tmp/test.cpp:1:13: note: anonymous namespace starts here namespace { ^
that for some reason only fires on definitions, not declarations.
I thought this was changing that old check.
I think it may be good to not have duplicate coverage,
but do we need a new check given that there is one already?
Ah, then it has the exact same functionality! My idea for readability-redundant-static was to warn about:
- static in anonymous namespace
- static const/constexpr at global scope (since const gives implicit internal linkage in C++).
I will see what I can do about that.
This shouldn't be a blocker for this patch though, it's just removing functionality that belongs in another check. As said, the check is 1 day old so it's unlikely anyone is relying on it yet :)
This shouldn't be a blocker for this patch though, it's just removing functionality that belongs in another check. As said, the check is 1 day old so it's unlikely anyone is relying on it yet :)
SGTM in general.
@lebedev.ri If you are happy with the patch, would you mind approving it? Or do you have additional comments that should be addressed? The patch does not need to be approved by the Code Owner.
@njames93 @JonasToth @LegalizeAdulthood Do you have any comments that I should address? If not, could you approve the patch?
To recap: this check is a few days old (I added it myself). I realized there's functionality that shouldn't be here so I'm just removing it. Should be a fairly safe change.
The original check is just a few days old. It didn't exist in the previous release. Should I still add a comment about this change?
Oh, I hadn't realized the original check was part of this release. No need for a release note in this case.
Happy to help where I can!