[clang-tools-extra] r266864 - clang-tidy: [misc-unused-using-decls] Always use the canonical decl to

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 20 01:58:28 PDT 2016


Author: djasper
Date: Wed Apr 20 03:58:27 2016
New Revision: 266864

URL: http://llvm.org/viewvc/llvm-project?rev=266864&view=rev
Log:
clang-tidy: [misc-unused-using-decls] Always use the canonical decl to
identify things.

This fixes llvm.org/PR27430.

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
    clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h
    clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp?rev=266864&r1=266863&r2=266864&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Wed Apr 20 03:58:27 2016
@@ -30,7 +30,8 @@ void UnusedUsingDeclsCheck::check(const
     // than one shadow.
     if (Using->shadow_size() != 1)
       return;
-    const auto* TargetDecl = Using->shadow_begin()->getTargetDecl();
+    const auto *TargetDecl =
+        Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
     // FIXME: Handle other target types.
     if (!isa<RecordDecl>(TargetDecl))
@@ -52,8 +53,9 @@ void UnusedUsingDeclsCheck::check(const
   // 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<NamedDecl>("used")) {
-    if (FoundDecls.find(Used) != FoundDecls.end())
-      FoundDecls[Used] = nullptr;
+    auto I = FoundDecls.find(Used->getCanonicalDecl());
+    if (I != FoundDecls.end())
+      I->second = nullptr;
   }
 }
 

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h?rev=266864&r1=266863&r2=266864&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h Wed Apr 20 03:58:27 2016
@@ -30,8 +30,8 @@ public:
   void onEndOfTranslationUnit() override;
 
 private:
-  llvm::DenseMap<const NamedDecl*, const UsingDecl*> FoundDecls;
-  llvm::DenseMap<const NamedDecl*, CharSourceRange> FoundRanges;
+  llvm::DenseMap<const Decl*, const UsingDecl*> FoundDecls;
+  llvm::DenseMap<const Decl*, CharSourceRange> FoundRanges;
 };
 
 } // namespace misc

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp?rev=266864&r1=266863&r2=266864&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp Wed Apr 20 03:58:27 2016
@@ -6,6 +6,7 @@ namespace n {
 class A;
 class B;
 class C;
+class D;
 class D { public: static int i; };
 }
 




More information about the cfe-commits mailing list