summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 5fbc041c32a..1e23f198d13 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/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/ASTMatchersInternal.h"
#include "clang/Lex/Lexer.h"
using namespace clang::ast_matchers;
@@ -18,12 +19,20 @@ namespace clang {
namespace tidy {
namespace misc {
+namespace {
+// FIXME: Move this node matcher to ASTMatcher.
+const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
+ unresolvedLookupExpr;
+}
+
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(callee(unresolvedLookupExpr().bind("used"))),
+ this);
}
void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
@@ -81,6 +90,13 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
removeFromFoundDecls(VD);
}
}
+ // Check the uninstantiated template function usage.
+ if (const auto *ULE = Result.Nodes.getNodeAs<UnresolvedLookupExpr>("used")) {
+ for (const NamedDecl* ND : ULE->decls()) {
+ if (const auto *USD = dyn_cast<UsingShadowDecl>(ND))
+ removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
+ }
+ }
}
void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
OpenPOWER on IntegriCloud