[PATCH] D139197: Do not warn about redundant static in misc-use-anonymous-namespace

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 06:58:21 PST 2022


lebedev.ri added a comment.

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?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139197/new/

https://reviews.llvm.org/D139197



More information about the cfe-commits mailing list