hokein created this revision. hokein added a reviewer: alexfh. hokein added a subscriber: cfe-commits.
http://reviews.llvm.org/D20519 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 @@ -93,6 +93,14 @@ DEFINE_INT(test); #undef DEFIND_INT +namespace N1 { + struct S {}; + template<int X> void f(S); +} +namespace N2 { + template<class T> 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); +} 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<CXXRecordDecl>(TargetDecl->getDeclContext())) - return false; - return isa<RecordDecl>(TargetDecl) || isa<ClassTemplateDecl>(TargetDecl) || isa<FunctionDecl>(TargetDecl) || isa<VarDecl>(TargetDecl) || isa<FunctionTemplateDecl>(TargetDecl); @@ -49,6 +38,17 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Using = Result.Nodes.getNodeAs<UsingDecl>("using")) { + // Ignores using-declarations defined in macros. + if (Using->getLocation().isMacroID()) + return; + // Ignores using-declarations defined in class definitions. + if (isa<CXXRecordDecl>(Using->getDeclContext())) + return; + // Ignores using-declarations defined in function definitions to avoid + // arguement-dependent lookup. + if (isa<FunctionDecl>(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<int X> void f(S); +} +namespace N2 { + template<class T> 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); +} 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<CXXRecordDecl>(TargetDecl->getDeclContext())) - return false; - return isa<RecordDecl>(TargetDecl) || isa<ClassTemplateDecl>(TargetDecl) || isa<FunctionDecl>(TargetDecl) || isa<VarDecl>(TargetDecl) || isa<FunctionTemplateDecl>(TargetDecl); @@ -49,6 +38,17 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Using = Result.Nodes.getNodeAs<UsingDecl>("using")) { + // Ignores using-declarations defined in macros. + if (Using->getLocation().isMacroID()) + return; + // Ignores using-declarations defined in class definitions. + if (isa<CXXRecordDecl>(Using->getDeclContext())) + return; + // Ignores using-declarations defined in function definitions to avoid + // arguement-dependent lookup. + if (isa<FunctionDecl>(Using->getDeclContext())) + return; + UsingDeclContext Context(Using); Context.UsingDeclRange = CharSourceRange::getCharRange( Using->getLocStart(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits