diff options
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 9 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp | 16 |
2 files changed, 21 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 7499190d5c3..30ff7b80a6c 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -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 MatchFinder::MatchResult &Result) { 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. 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 4d6b33252f1..a5399fa5545 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 @@ -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; } |