diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -102,9 +102,12 @@ } bool VisitCXXConstructExpr(CXXConstructExpr *E) { + // Always treat consturctor calls as implicit. We'll have an explicit + // reference for the constructor calls that mention the type-name (through + // TypeLocs). This reference only matters for cases where there's no + // explicit syntax at all or there're only braces. report(E->getLocation(), getMemberProvider(E->getType()), - E->getParenOrBraceRange().isValid() ? RefType::Explicit - : RefType::Implicit); + RefType::Implicit); return true; } diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -111,6 +111,9 @@ testWalk("struct $explicit^S {};", "^S *y;"); testWalk("enum $explicit^E {};", "^E *y;"); testWalk("struct $explicit^S { static int x; };", "int y = ^S::x;"); + // One explicit call from the TypeLoc in constructor spelling, another + // implicit reference through the constructor call. + testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();"); } TEST(WalkAST, Alias) { @@ -241,7 +244,7 @@ TEST(WalkAST, ConstructExprs) { testWalk("struct $implicit^S {};", "S ^t;"); 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("struct $implicit^S { S(int); };", "S t = ^42;"); testWalk("namespace ns { struct S{}; } using ns::$implicit^S;", "S ^t;"); }