[clang-tools-extra] r273882 - [clang-tidy] Warning enum unused using declarations.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 27 07:47:39 PDT 2016


Author: hokein
Date: Mon Jun 27 09:47:39 2016
New Revision: 273882

URL: http://llvm.org/viewvc/llvm-project?rev=273882&view=rev
Log:
[clang-tidy] Warning enum unused using declarations.

Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D21747

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
    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=273882&r1=273881&r2=273882&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Mon Jun 27 09:47:39 2016
@@ -19,12 +19,13 @@ namespace tidy {
 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 @@ void UnusedUsingDeclsCheck::check(const
         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.

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=273882&r1=273881&r2=273882&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 Mon Jun 27 09:47:39 2016
@@ -43,7 +43,14 @@ public:
 };
 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 @@ void IgnoreFunctionScope() {
 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 @@ void g() {
   UsedFunc();
   UsedTemplateFunc<int>();
   cout << endl;
+  int t = Red;
 }




More information about the cfe-commits mailing list