[PATCH] D21747: [clang-tidy] Warning enum unused using declarations.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 27 04:25:51 PDT 2016


hokein created this revision.
hokein added a reviewer: alexfh.
hokein added a subscriber: cfe-commits.

http://reviews.llvm.org/D21747

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
@@ -43,7 +43,14 @@
 };
 extern ostream cout;
 ostream &endl(ostream &os);
-}
+
+enum Color {
+  Green,
+  Red,
+  Yellow
+};
+
+}  // namespace n
 
 // ----- Using declarations -----
 // eol-comments aren't removed (yet)
@@ -119,6 +126,12 @@
 using n::H;
 }
 
+using n::Color;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color' is unused
+using n::Green;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Green' is unused
+using n::Red;
+
 // ----- Usages -----
 void f(B b);
 void g() {
@@ -131,4 +144,5 @@
   UsedFunc();
   UsedTemplateFunc<int>();
   cout << endl;
+  int t = Red;
 }
Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -19,12 +19,13 @@
 namespace misc {
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
-// checked. Only variable, function, function template, class template and class
-// are considered.
+// checked. Only variable, function, function template, class template, class,
+// enum declaration and enum constant declaration are considered.
 static bool ShouldCheckDecl(const Decl *TargetDecl) {
   return isa<RecordDecl>(TargetDecl) || isa<ClassTemplateDecl>(TargetDecl) ||
          isa<FunctionDecl>(TargetDecl) || isa<VarDecl>(TargetDecl) ||
-         isa<FunctionTemplateDecl>(TargetDecl);
+         isa<FunctionTemplateDecl>(TargetDecl) || isa<EnumDecl>(TargetDecl) ||
+         isa<EnumConstantDecl>(TargetDecl);
 }
 
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
@@ -91,6 +92,8 @@
         removeFromFoundDecls(FD);
     } else if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
       removeFromFoundDecls(VD);
+    } else if (const auto *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
+      removeFromFoundDecls(ECD);
     }
   }
   // Check the uninstantiated template function usage.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21747.61955.patch
Type: text/x-patch
Size: 2191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160627/377c1781/attachment.bin>


More information about the cfe-commits mailing list