File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,12 @@ using namespace clang::ast_matchers;
15
15
16
16
namespace clang ::tidy::readability {
17
17
18
+ namespace {
19
+ AST_MATCHER (CXXMethodDecl, isStatic) { return Node.isStatic (); }
20
+ } // namespace
21
+
18
22
static unsigned getNameSpecifierNestingLevel (const QualType &QType) {
19
- if (const ElaboratedType *ElType = QType->getAs <ElaboratedType>()) {
23
+ if (const auto *ElType = QType->getAs <ElaboratedType>()) {
20
24
if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier ()) {
21
25
unsigned NameSpecifierNestingLevel = 1 ;
22
26
do {
@@ -38,7 +42,7 @@ void StaticAccessedThroughInstanceCheck::storeOptions(
38
42
39
43
void StaticAccessedThroughInstanceCheck::registerMatchers (MatchFinder *Finder) {
40
44
Finder->addMatcher (
41
- memberExpr (hasDeclaration (anyOf (cxxMethodDecl (isStaticStorageClass ()),
45
+ memberExpr (hasDeclaration (anyOf (cxxMethodDecl (isStatic ()),
42
46
varDecl (hasStaticStorageDuration ()),
43
47
enumConstantDecl ())))
44
48
.bind (" memberExpression" ),
Original file line number Diff line number Diff line change @@ -219,6 +219,10 @@ Changes in existing checks
219
219
do-while loops into account for the `AllowIntegerConditions ` and
220
220
`AllowPointerConditions ` options.
221
221
222
+ - Improved :doc: `readability-static-accessed-through-instance
223
+ <clang-tidy/checks/readability/static-accessed-through-instance>` check to
224
+ identify calls to static member functions with out-of-class inline definitions.
225
+
222
226
Removed checks
223
227
^^^^^^^^^^^^^^
224
228
Original file line number Diff line number Diff line change @@ -363,3 +363,20 @@ void testEmbeddedAnonymousStructAndClass() {
363
363
}
364
364
365
365
} // namespace llvm_issue_61736
366
+
367
+ namespace PR51861 {
368
+ class Foo {
369
+ public:
370
+ static Foo& getInstance ();
371
+ static int getBar ();
372
+ };
373
+
374
+ inline int Foo::getBar () { return 42 ; }
375
+
376
+ void test () {
377
+ auto & params = Foo::getInstance ();
378
+ params.getBar ();
379
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through instance [readability-static-accessed-through-instance]
380
+ // CHECK-FIXES: {{^}} PR51861::Foo::getBar();{{$}}
381
+ }
382
+ }
You can’t perform that action at this time.
0 commit comments