VitaNuo created this revision. Herald added a subscriber: kadircet. Herald added a project: All. VitaNuo requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Removes filtering from the VisitUsingDecl method for implementation files. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138821 Files: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ 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 T> + class Y {}; + } + using ns::$explicit^Y; + )cpp", + "^Y<int> x;"); } TEST(WalkAST, Namespaces) { Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ 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); }
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ 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 T> + class Y {}; + } + using ns::$explicit^Y; + )cpp", + "^Y<int> x;"); } TEST(WalkAST, Namespaces) { Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ 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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits