From 3bb156523a9b9b96de408cd72ba277f800f64b5a Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 12 May 2016 10:00:49 +0000 Subject: [PATCH] [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks. Reviewers: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20197 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@269278 91177308-0d34-0410-b5e6-96231b3b80d8 --- clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 4 ++++ test/clang-tidy/misc-unused-using-decls.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 8a70e16..5fbc041 100644 --- a/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -35,6 +35,10 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { const auto *TargetDecl = Using->shadow_begin()->getTargetDecl()->getCanonicalDecl(); + // Ignores using-declarations defined in macros. + if (TargetDecl->getLocation().isMacroID()) + return; + // Ignores using-declarations defined in class definition. if (isa(TargetDecl->getDeclContext())) return; diff --git a/test/clang-tidy/misc-unused-using-decls.cpp b/test/clang-tidy/misc-unused-using-decls.cpp index 47917a8..15538a8 100644 --- a/test/clang-tidy/misc-unused-using-decls.cpp +++ b/test/clang-tidy/misc-unused-using-decls.cpp @@ -70,6 +70,14 @@ using n::UnusedFunc; // UnusedFunc using n::cout; using n::endl; +#define DEFINE_INT(name) \ + namespace INT { \ + static const int _##name = 1; \ + } \ + using INT::_##name +DEFINE_INT(test); +#undef DEFIND_INT + // ----- Usages ----- void f(B b); void g() {