[PATCH] D115106: [clang-tidy] Fix `readability-static-accessed-through-instance` false negative for static methods

Fabian Wolff via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 4 15:30:27 PST 2021


fwolff created this revision.
fwolff added reviewers: aaron.ballman, simon.giesecke, jcking1034.
fwolff added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
fwolff requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes PR#52519 <https://bugs.llvm.org/show_bug.cgi?id=52519>. The problem actually has nothing to do with the out-of-line definition being `inline`; the problem is that `hasDeclaration()` of the `memberExpr()` will match the out-of-line definition, which obviously isn't marked `static`, so `isStaticStorageClass()` won't match. To find out whether a member function is `static`, one needs to look at the //canonical// declaration, but there doesn't seem to be a matcher for that yet, so I've added an `isStatic()` narrowing matcher for `CXXMethodDecl`s, similar to the `isConst()` matcher that already exists.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115106

Files:
  clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115106.391880.patch
Type: text/x-patch
Size: 4678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211204/5cdb91e7/attachment-0001.bin>


More information about the cfe-commits mailing list