From: Daniel Jasper Date: Wed, 20 Apr 2016 09:48:56 +0000 (+0000) Subject: clang-tidy: [misc-unused-using-decls] Support template types. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25e17df6638123d13232535f461c52cc7bd74c2a;p=platform%2Fupstream%2Fllvm.git clang-tidy: [misc-unused-using-decls] Support template types. This fixes llvm.org/PR27429. llvm-svn: 266866 --- diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index b2aff4d..219cc1f 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -20,8 +20,9 @@ namespace misc { void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this); - Finder->addMatcher(recordType(hasDeclaration(namedDecl().bind("used"))), - this); + auto DeclMatcher = hasDeclaration(namedDecl().bind("used")); + Finder->addMatcher(loc(recordType(DeclMatcher)), this); + Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this); } void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { @@ -34,7 +35,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { Using->shadow_begin()->getTargetDecl()->getCanonicalDecl(); // FIXME: Handle other target types. - if (!isa(TargetDecl)) + if (!isa(TargetDecl) && !isa(TargetDecl)) return; FoundDecls[TargetDecl] = Using; @@ -53,6 +54,9 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { // FIXME: This currently doesn't look at whether the type reference is // actually found with the help of the using declaration. if (const auto *Used = Result.Nodes.getNodeAs("used")) { + if (const auto *Specialization = + dyn_cast(Used)) + Used = Specialization->getSpecializedTemplate(); auto I = FoundDecls.find(Used->getCanonicalDecl()); if (I != FoundDecls.end()) I->second = nullptr; diff --git a/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp b/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp index 053e65d..d9f6b21 100644 --- a/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp @@ -8,6 +8,8 @@ class B; class C; class D; class D { public: static int i; }; +template class E {}; +template class F {}; } // ----- Using declarations ----- @@ -18,11 +20,16 @@ using n::A; // A using n::B; using n::C; using n::D; +using n::E; // E +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'E' is unused +// CHECK-FIXES: {{^}}// E +using n::F; // ----- Usages ----- void f(B b); void g() { vector data; D::i = 1; + F f; }