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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 3 10:47:19 PST 2022


sammccall added a comment.

Yeah, this is a thorny question. The language hasn't chosen clear names and neither has the AST in many cases.
(Just yesterday I lost a lot of time to CXXRecordDecl->getBodyRBrace()...)

I think `anyRedeclaration(functionDecl(isStaticStorageClass))`is too difficult to get right and too easy to get wrong for such a common/simple concept.
I know what a static method is, but I would have made the same mistake here. In general asking people to describe syntax to answer a semantic question invites this.

Here's a hack: CXXMethodDecl has both `isStatic()` and `isInstance()`. I agree that `isStatic` is a risky name, but I don't think `isInstance` is. Can we just spell the matcher you want `not(isInstance())`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115106



More information about the cfe-commits mailing list