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 @@ -82,10 +82,6 @@ for (const auto *Shadow : UD->shadows()) { auto *TD = Shadow->getTargetDecl(); auto IsUsed = TD->isUsed() || TD->isReferenced(); - // We ignore unused overloads inside implementation files, as the ones in - // headers might still be used by the dependents of the header. - if (!IsUsed && !IsHeader) - continue; report(UD->getLocation(), TD, IsUsed ? RefType::Explicit : RefType::Ambiguous); } 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 @@ -88,12 +88,10 @@ auto RTStr = llvm::to_string(RT); for (auto Expected : Target.points(RTStr)) if (!llvm::is_contained(ReferencedOffsets[RT], Expected)) - DiagnosePoint("location not marked used with type " + RTStr, - Expected); + DiagnosePoint("location not marked used with type " + RTStr, Expected); for (auto Actual : ReferencedOffsets[RT]) if (!llvm::is_contained(Target.points(RTStr), Actual)) - DiagnosePoint("location unexpectedly used with type " + RTStr, - Actual); + DiagnosePoint("location unexpectedly used with type " + RTStr, Actual); } // If there were any differences, we print the entire referencing code once. @@ -132,7 +130,7 @@ // Make sure we ignore unused overloads. testWalk(R"cpp( namespace ns { - void $explicit^x(); void x(int); void x(char); + void $explicit^x(); void $ambiguous^x(int); void $ambiguous^x(char); })cpp", "using ns::^x; void foo() { x(); }"); // We should report unused overloads if main file is a header. @@ -142,6 +140,15 @@ })cpp", "// c++-header\n using ns::^x;"); testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;"); + // We should report templates with at least one instantiation + testWalk(R"cpp( + namespace ns { + template + class Y {}; + } + using ns::$explicit^Y; + )cpp", + "^Y x;"); } TEST(WalkAST, Namespaces) {