Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -10,6 +10,7 @@ #include "UnusedUsingDeclsCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Lex/Lexer.h" using namespace clang::ast_matchers; @@ -18,12 +19,19 @@ namespace tidy { namespace misc { +namespace { +AST_MATCHER(CallExpr, hasUnresolvedLookupExpr) { + return isa(Node.getCallee()); +} +} + void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this); auto DeclMatcher = hasDeclaration(namedDecl().bind("used")); Finder->addMatcher(loc(recordType(DeclMatcher)), this); Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this); Finder->addMatcher(declRefExpr().bind("used"), this); + Finder->addMatcher(callExpr(hasUnresolvedLookupExpr()).bind("used"), this); } void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { @@ -81,6 +89,14 @@ removeFromFoundDecls(VD); } } + // Check the uninstantiated template function usage. + if (auto *CE = Result.Nodes.getNodeAs("used")) { + auto *ULE = dyn_cast(CE->getCallee()); + for (auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I) { + if (auto *USD = dyn_cast(I.getDecl())) + removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl()); + } + } } void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) { 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 @@ -16,6 +16,7 @@ public: static int ii; }; +template class J {}; class Base { public: @@ -29,6 +30,7 @@ int UnusedFunc() { return 1; } template int UsedTemplateFunc() { return 1; } template int UnusedTemplateFunc() { return 1; } +template int UsedInTemplateFunc() { return 1; } class ostream { public: @@ -70,6 +72,13 @@ using n::cout; using n::endl; +using n::UsedInTemplateFunc; +using n::J; +template void Callee() { + J j; + UsedInTemplateFunc(); +} + #define DEFINE_INT(name) \ namespace INT { \ static const int _##name = 1; \