This revision was automatically updated to reflect the committed changes. Closed by commit rL273882: [clang-tidy] Warning enum unused using declarations. (authored by hokein).
Changed prior to commit: http://reviews.llvm.org/D21747?vs=61955&id=61966#toc Repository: rL LLVM http://reviews.llvm.org/D21747 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 @@ -19,12 +19,13 @@ 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 @@ 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. 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 @@ -43,7 +43,14 @@ }; 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 @@ 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 @@ UsedFunc(); UsedTemplateFunc<int>(); cout << endl; + int t = Red; }
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 @@ -19,12 +19,13 @@ 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 @@ 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. 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 @@ -43,7 +43,14 @@ }; 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 @@ 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 @@ UsedFunc(); UsedTemplateFunc<int>(); cout << endl; + int t = Red; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits