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. @@ -129,19 +127,39 @@ } TEST(WalkAST, Using) { - // Make sure we ignore unused overloads. + // We should report unused overloads as ambiguous. 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. testWalk(R"cpp( namespace ns { void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char); })cpp", "// c++-header\n using ns::^x;"); + testWalk(R"cpp( + namespace ns { + void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char); + })cpp", + "using ns::^x;"); testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;"); + + // We should report references to templates as ambiguous. + testWalk(R"cpp( + namespace ns { + template + class $ambiguous^Y {}; + } + )cpp", + "using ns::^Y; Y x;"); + testWalk(R"cpp( + namespace ns { + template + class $ambiguous^Y {}; + } + )cpp", + "using ns::^Y;"); } TEST(WalkAST, Namespaces) {