[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance

2023-08-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG766dd7b80b57: [clang-tidy] Fix handling of out-of-line 
functions in readability-static… (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D157326?vs=548066=550200#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157326

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through 
instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -219,6 +219,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline 
definitions.
+
 Removed checks
 ^^
 
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -15,8 +15,12 @@
 
 namespace clang::tidy::readability {
 
+namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+} // namespace
+
 static unsigned getNameSpecifierNestingLevel(const QualType ) {
-  if (const ElaboratedType *ElType = QType->getAs()) {
+  if (const auto *ElType = QType->getAs()) {
 if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
   unsigned NameSpecifierNestingLevel = 1;
   do {
@@ -38,7 +42,7 @@
 
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) 
{
   Finder->addMatcher(
-  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
+  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStatic()),
   varDecl(hasStaticStorageDuration()),
   enumConstantDecl(
   .bind("memberExpression"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -219,6 +219,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline definitions.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 

[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance

2023-08-14 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157326

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance

2023-08-08 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 548066.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Fix 'auto'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157326

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through 
instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline 
definitions.
+
 Removed checks
 ^^
 
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -15,8 +15,12 @@
 
 namespace clang::tidy::readability {
 
+namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+} // namespace
+
 static unsigned getNameSpecifierNestingLevel(const QualType ) {
-  if (const ElaboratedType *ElType = QType->getAs()) {
+  if (const auto *ElType = QType->getAs()) {
 if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
   unsigned NameSpecifierNestingLevel = 1;
   do {
@@ -38,7 +42,7 @@
 
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) 
{
   Finder->addMatcher(
-  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
+  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStatic()),
   varDecl(hasStaticStorageDuration()),
   enumConstantDecl(
   .bind("memberExpression"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline definitions.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -15,8 +15,12 @@
 
 namespace clang::tidy::readability {
 
+namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+} // namespace
+
 static 

[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance

2023-08-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp:23
 static unsigned getNameSpecifierNestingLevel(const QualType ) {
   if (const ElaboratedType *ElType = QType->getAs()) {
 if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {

Should be `const auto *`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157326

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance

2023-08-07 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Use isStatic instead of isStaticStorageClass to properly
handle a out-of-line definitions.

Fixes: #51861


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157326

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through 
instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline 
definitions.
+
 Removed checks
 ^^
 
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -15,6 +15,10 @@
 
 namespace clang::tidy::readability {
 
+namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+} // namespace
+
 static unsigned getNameSpecifierNestingLevel(const QualType ) {
   if (const ElaboratedType *ElType = QType->getAs()) {
 if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
@@ -38,7 +42,7 @@
 
 void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) 
{
   Finder->addMatcher(
-  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
+  memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStatic()),
   varDecl(hasStaticStorageDuration()),
   enumConstantDecl(
   .bind("memberExpression"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -363,3 +363,20 @@
 }
 
 } // namespace llvm_issue_61736
+
+namespace PR51861 {
+  class Foo {
+public:
+  static Foo& getInstance();
+  static int getBar();
+  };
+
+  inline int Foo::getBar() { return 42; }
+
+  void test() {
+auto& params = Foo::getInstance();
+params.getBar();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through instance [readability-static-accessed-through-instance]
+// CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-static-accessed-through-instance
+  ` check to
+  identify calls to static member functions with out-of-class inline definitions.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -15,6 +15,10 @@
 
 namespace clang::tidy::readability {
 
+namespace {