[PATCH] D21833: [clang-tidy] Fix more enum declaration cases in misc-unused-using-decls check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 02:41:03 PDT 2016


hokein created this revision.
hokein added a reviewer: alexfh.
hokein added subscribers: cfe-commits, Eugene.Zelenko.

Fix PR28350.

http://reviews.llvm.org/D21833

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
@@ -44,11 +44,13 @@
 extern ostream cout;
 ostream &endl(ostream &os);
 
-enum Color {
-  Green,
-  Red,
-  Yellow
-};
+enum Color1 { Green };
+
+enum Color2 { Red };
+
+enum Color3 { Yellow };
+
+enum Color4 { Blue };
 
 }  // namespace n
 
@@ -126,11 +128,11 @@
 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;
+using n::Color1;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color1' is unused
+using n::Color2;
+using n::Color3;
+using n::Blue;
 
 // ----- Usages -----
 void f(B b);
@@ -144,5 +146,7 @@
   UsedFunc();
   UsedTemplateFunc<int>();
   cout << endl;
-  int t = Red;
+  Color2 color2;
+  int t1 = Color3::Yellow;
+  int t2 = Blue;
 }
Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -18,6 +18,11 @@
 namespace tidy {
 namespace misc {
 
+namespace {
+// FIXME: Move this node matcher to ASTMatcher.
+const internal::VariadicDynCastAllOfMatcher<Type, EnumType> enumType;
+} // namespace
+
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
 // checked. Only variable, function, function template, class template, class,
 // enum declaration and enum constant declaration are considered.
@@ -31,6 +36,7 @@
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
   auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
+  Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
@@ -94,6 +100,8 @@
       removeFromFoundDecls(VD);
     } else if (const auto *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
       removeFromFoundDecls(ECD);
+      if (const auto *ET = ECD->getType()->getAs<EnumType>())
+        removeFromFoundDecls(ET->getDecl());
     }
   }
   // Check the uninstantiated template function usage.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21833.62190.patch
Type: text/x-patch
Size: 2507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160629/6e543610/attachment-0001.bin>


More information about the cfe-commits mailing list