[PATCH] D148552: [include-cleaner] Unify behaviour for static & instance members

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 11:28:22 PDT 2023


kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/62185


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148552

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,7 +114,7 @@
   testWalk("int $explicit^x;", "int y = ^x;");
   testWalk("int $explicit^foo();", "int y = ^foo();");
   testWalk("namespace ns { int $explicit^x; }", "int y = ns::^x;");
-  testWalk("struct S { static int $explicit^x; };", "int y = S::^x;");
+  testWalk("struct $implicit^S { static int x; };", "int y = S::^x;");
   // Canonical declaration only.
   testWalk("extern int $explicit^x; int x;", "int y = ^x;");
   // Return type of `foo` isn't used.
@@ -342,6 +342,9 @@
 }
 
 TEST(WalkAST, MemberExprs) {
+  testWalk("struct $implicit^S { static int f; };", "void foo() { S::^f; }");
+  testWalk("struct B { static int f; }; struct $implicit^S : B {};",
+           "void foo() { S::^f; }");
   testWalk("struct $implicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
       "struct S { void foo(); }; struct $implicit^X : S { using S::foo; };",
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -125,7 +125,12 @@
   }
 
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
-    report(DRE->getLocation(), DRE->getFoundDecl());
+    if (DRE->getFoundDecl()->isCXXClassMember()) {
+      report(DRE->getLocation(), DRE->getQualifier()->getAsRecordDecl(),
+             RefType::Implicit);
+    } else {
+      report(DRE->getLocation(), DRE->getFoundDecl());
+    }
     return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148552.514334.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230417/512bffc0/attachment-0001.bin>


More information about the cfe-commits mailing list