From 22db1fb10b8384907b43408f5d2703f96f806bc2 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 12 Jan 2023 12:40:12 +0100 Subject: [PATCH] [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 --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp | 2 +- .../include-cleaner/unittests/WalkASTTest.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index 18e6d5e21df0..6a5594e3d6d3 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -104,7 +104,7 @@ public: } 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 c8959e7eb673..af7e155b58fb 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) { -- 2.34.1