Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -18,20 +18,9 @@ namespace tidy { namespace misc { -// A function that helps to tell whether a TargetDecl will be checked. -// We only check a TargetDecl if : -// * The corresponding UsingDecl is not defined in macros or in class -// definitions. -// * Only variable, function and class types are considered. +// A function that helps to tell whether a TargetDecl of a UsingDecl will be +// checked. We only check variable, function and class types. static bool ShouldCheckDecl(const Decl *TargetDecl) { - // Ignores using-declarations defined in macros. - if (TargetDecl->getLocation().isMacroID()) - return false; - - // Ignores using-declarations defined in class definition. - if (isa(TargetDecl->getDeclContext())) - return false; - return isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl) || isa(TargetDecl); @@ -49,6 +38,17 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Using = Result.Nodes.getNodeAs("using")) { + // Ignores using-declarations defined in macros. + if (Using->getLocation().isMacroID()) + return; + // Ignores using-declarations defined in class definitions. + if (isa(Using->getDeclContext())) + return; + // Ignores using-declarations defined in function definitions to avoid + // arguement-dependent lookup. + if (isa(Using->getDeclContext())) + return; + UsingDeclContext Context(Using); Context.UsingDeclRange = CharSourceRange::getCharRange( Using->getLocStart(), 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 @@ -93,6 +93,14 @@ DEFINE_INT(test); #undef DEFIND_INT +namespace N1 { + struct S {}; + template void f(S); +} +namespace N2 { + template void f(T t); +} + // ----- Usages ----- void f(B b); void g() { @@ -107,3 +115,7 @@ cout << endl; } +void ADL(N1::S s) { + using N2::f; + f<3>(s); +}