hokein created this revision. hokein added a subscriber: cfe-commits. - Fix a false postive when an using class is used in an explicit template instantiation. - Fix a false postive when an using template class is used as template argument.
https://reviews.llvm.org/D25437 Files: clang-tidy/misc/UnusedUsingDeclsCheck.cpp test/clang-tidy/misc-unused-using-decls.cpp Index: test/clang-tidy/misc-unused-using-decls.cpp =================================================================== --- test/clang-tidy/misc-unused-using-decls.cpp +++ test/clang-tidy/misc-unused-using-decls.cpp @@ -21,6 +21,13 @@ class G; class H; +template <typename T> class K {}; +template <template <typename> class S> +class L {}; + +template <typename T> class M {}; +class N {}; + class Base { public: void f(); @@ -150,6 +157,10 @@ using ns::AA; using ns::ff; +using n::K; + +using n::N; + // ----- Usages ----- void f(B b); void g() { @@ -170,4 +181,11 @@ int t3 = 0; a.func1<AA>(&t3); a.func2<int, ff>(t3); + + n::L<K> l; } + +template<class T> +void h(n::M<T>* t) {} +// n::N is using in the explicit template instantiations. +template void h(n::M<N>* t); Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -42,6 +42,8 @@ anyOf(refersToTemplate(templateName().bind("used")), refersToDeclaration(functionDecl().bind("used"))))))), this); + Finder->addMatcher(loc(templateSpecializationType( + hasAnyTemplateArgument(templateArgument().bind("used")))), this); } void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { @@ -91,6 +93,17 @@ return; } + if (const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>("used")) { + if (Used->getKind() == TemplateArgument::Template) { + if (const auto *TD = Used->getAsTemplate().getAsTemplateDecl()) + removeFromFoundDecls(TD); + } else if (Used->getKind() == TemplateArgument::Type) { + if (auto *RD = Used->getAsType()->getAsCXXRecordDecl()) + removeFromFoundDecls(RD); + } + return; + } + if (const auto *Used = Result.Nodes.getNodeAs<TemplateName>("used")) { removeFromFoundDecls(Used->getAsTemplateDecl()); return;
Index: test/clang-tidy/misc-unused-using-decls.cpp =================================================================== --- test/clang-tidy/misc-unused-using-decls.cpp +++ test/clang-tidy/misc-unused-using-decls.cpp @@ -21,6 +21,13 @@ class G; class H; +template <typename T> class K {}; +template <template <typename> class S> +class L {}; + +template <typename T> class M {}; +class N {}; + class Base { public: void f(); @@ -150,6 +157,10 @@ using ns::AA; using ns::ff; +using n::K; + +using n::N; + // ----- Usages ----- void f(B b); void g() { @@ -170,4 +181,11 @@ int t3 = 0; a.func1<AA>(&t3); a.func2<int, ff>(t3); + + n::L<K> l; } + +template<class T> +void h(n::M<T>* t) {} +// n::N is using in the explicit template instantiations. +template void h(n::M<N>* t); Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -42,6 +42,8 @@ anyOf(refersToTemplate(templateName().bind("used")), refersToDeclaration(functionDecl().bind("used"))))))), this); + Finder->addMatcher(loc(templateSpecializationType( + hasAnyTemplateArgument(templateArgument().bind("used")))), this); } void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { @@ -91,6 +93,17 @@ return; } + if (const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>("used")) { + if (Used->getKind() == TemplateArgument::Template) { + if (const auto *TD = Used->getAsTemplate().getAsTemplateDecl()) + removeFromFoundDecls(TD); + } else if (Used->getKind() == TemplateArgument::Type) { + if (auto *RD = Used->getAsType()->getAsCXXRecordDecl()) + removeFromFoundDecls(RD); + } + return; + } + if (const auto *Used = Result.Nodes.getNodeAs<TemplateName>("used")) { removeFromFoundDecls(Used->getAsTemplateDecl()); return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits