This revision was automatically updated to reflect the committed changes. Closed by commit rL274496: [clang-tidy] Fix more enum declaration cases in misc-unused-using-decls check. (authored by hokein).
Changed prior to commit: http://reviews.llvm.org/D21833?vs=62354&id=62668#toc Repository: rL LLVM http://reviews.llvm.org/D21833 Files: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -31,6 +31,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 +95,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. Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp +++ clang-tools-extra/trunk/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,13 @@ using n::H; } -using n::Color; -// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color' is unused +using n::Color1; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color1' is unused using n::Green; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Green' is unused -using n::Red; +using n::Color2; +using n::Color3; +using n::Blue; // ----- Usages ----- void f(B b); @@ -144,5 +148,7 @@ UsedFunc(); UsedTemplateFunc<int>(); cout << endl; - int t = Red; + Color2 color2; + int t1 = Color3::Yellow; + int t2 = Blue; }
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -31,6 +31,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 +95,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. Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp +++ clang-tools-extra/trunk/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,13 @@ using n::H; } -using n::Color; -// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color' is unused +using n::Color1; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Color1' is unused using n::Green; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Green' is unused -using n::Red; +using n::Color2; +using n::Color3; +using n::Blue; // ----- Usages ----- void f(B b); @@ -144,5 +148,7 @@ UsedFunc(); UsedTemplateFunc<int>(); cout << endl; - int t = Red; + Color2 color2; + int t1 = Color3::Yellow; + int t2 = Blue; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits