diff options
| author | Haojian Wu <hokein@google.com> | 2016-07-04 12:01:56 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2016-07-04 12:01:56 +0000 |
| commit | c1926075c39b350743d58f3b1db4397d0f3fbef3 (patch) | |
| tree | 0bd5078d8a072427a78ae24aa13e2a5f4b1d8a95 | |
| parent | c97b9bda764763ac76813058609cb6dbae859312 (diff) | |
| download | bcm5719-llvm-c1926075c39b350743d58f3b1db4397d0f3fbef3.tar.gz bcm5719-llvm-c1926075c39b350743d58f3b1db4397d0f3fbef3.zip | |
[clang-tidy] Fix more enum declaration cases in misc-unused-using-decls check.
Summary: Fix PR28350.
Reviewers: alexfh
Subscribers: aaron.ballman, Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D21833
llvm-svn: 274496
| -rw-r--r-- | clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 3 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp | 24 |
2 files changed, 18 insertions, 9 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 30ff7b80a6c..8c9859c6792 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -31,6 +31,7 @@ static bool ShouldCheckDecl(const Decl *TargetDecl) { 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 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { 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. diff --git a/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp b/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp index a5399fa5545..618a9f661f9 100644 --- a/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp @@ -44,11 +44,13 @@ public: 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 @@ void IgnoreFunctionScope() { 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 @@ void g() { UsedFunc(); UsedTemplateFunc<int>(); cout << endl; - int t = Red; + Color2 color2; + int t1 = Color3::Yellow; + int t2 = Blue; } |

