[PATCH] D157326: [clang-tidy] Fix handling of out-of-line functions in readability-static-accessed-through-instance
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 23:06:32 PDT 2023
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 @@
<clang-tidy/checks/readability/identifier-naming>` check to emit proper
warnings when a type forward declaration precedes its definition.
+- Improved :doc:`readability-static-accessed-through-instance
+ <clang-tidy/checks/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 &QType) {
- if (const ElaboratedType *ElType = QType->getAs<ElaboratedType>()) {
+ if (const auto *ElType = QType->getAs<ElaboratedType>()) {
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"),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157326.548066.patch
Type: text/x-patch
Size: 2766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230808/0ee69082/attachment.bin>
More information about the cfe-commits
mailing list