[clang-tools-extra] 0e54581 - [include-cleaner] Handle dependent type members in AST.

Viktoriia Bakalova via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 19 04:46:43 PST 2022


Author: Viktoriia Bakalova
Date: 2022-12-19T12:45:41Z
New Revision: 0e545816a9e582af29ea4b9441fea8ed376cf52a

URL: https://github.com/llvm/llvm-project/commit/0e545816a9e582af29ea4b9441fea8ed376cf52a
DIFF: https://github.com/llvm/llvm-project/commit/0e545816a9e582af29ea4b9441fea8ed376cf52a.diff

LOG: [include-cleaner] Handle dependent type members in AST.

Handles dependent type members in AST.

Fix: https://github.com/llvm/llvm-project/issues/59354
Differential Revision: https://reviews.llvm.org/D139409

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index 639add8f5c4be..cf2373d43389d 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -84,6 +84,10 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
     report(E->getMemberLoc(), getMemberProvider(Type));
     return true;
   }
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+    report(E->getMemberLoc(), getMemberProvider(E->getBaseType()));
+    return true;
+  }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
     report(E->getLocation(), E->getConstructor(),

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index cb41ebb35cd58..2a2fbc438ab9b 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -229,6 +229,13 @@ TEST(WalkAST, MemberExprs) {
       namespace ns { template<typename> struct Foo { int a; }; }
       using ns::$explicit^Foo;)cpp",
            "void k(Foo<int> b) { b.^a; }");
+  // Test the dependent-type case (CXXDependentScopeMemberExpr)
+  testWalk("template<typename T> struct $explicit^Base { void method(); };",
+           "template<typename T> void k(Base<T> t) { t.^method(); }");
+  testWalk("template<typename T> struct $explicit^Base { void method(); };",
+           "template<typename T> void k(Base<T>& t) { t.^method(); }");
+  testWalk("template<typename T> struct $explicit^Base { void method(); };",
+           "template<typename T> void k(Base<T>* t) { t->^method(); }");
 }
 
 TEST(WalkAST, ConstructExprs) {


        


More information about the cfe-commits mailing list