[clang-tools-extra] 22db1fb - [include-cleaner] Treat a constructor call as a use of the class type.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 12 04:17:01 PST 2023


Author: Haojian Wu
Date: 2023-01-12T13:12:14+01:00
New Revision: 22db1fb10b8384907b43408f5d2703f96f806bc2

URL: https://github.com/llvm/llvm-project/commit/22db1fb10b8384907b43408f5d2703f96f806bc2
DIFF: https://github.com/llvm/llvm-project/commit/22db1fb10b8384907b43408f5d2703f96f806bc2.diff

LOG: [include-cleaner] Treat a constructor call as a use of the class type.

Per the discussion in https://github.com/llvm/llvm-project/issues/59916.

Differential Revision: https://reviews.llvm.org/D141592

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 18e6d5e21df07..6a5594e3d6d35 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -104,7 +104,7 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
-    report(E->getLocation(), E->getConstructor(),
+    report(E->getLocation(), getMemberProvider(E->getType()),
            E->getParenOrBraceRange().isValid() ? RefType::Explicit
                                                : RefType::Implicit);
     return true;

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index c8959e7eb6735..af7e155b58fb3 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -240,9 +240,10 @@ TEST(WalkAST, MemberExprs) {
 
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
-  testWalk("struct S { $implicit^S(); };", "S ^t;");
-  testWalk("struct S { $explicit^S(int); };", "S ^t(42);");
-  testWalk("struct S { $implicit^S(int); };", "S t = ^42;");
+  testWalk("struct $implicit^S { S(); };", "S ^t;");
+  testWalk("struct $explicit^S { S(int); };", "S ^t(42);");
+  testWalk("struct $implicit^S { S(int); };", "S t = ^42;");
+  testWalk("namespace ns { struct S{}; } using ns::$implicit^S;", "S ^t;");
 }
 
 TEST(WalkAST, Operator) {


        


More information about the cfe-commits mailing list