hokein updated this revision to Diff 242065. hokein marked an inline comment as done. hokein added a comment.
address comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D73876/new/ https://reviews.llvm.org/D73876 Files: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp @@ -0,0 +1,30 @@ +// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/ + +namespace ns { + +template <typename T> class Foo { +public: + Foo(T); +}; +// Deduction guide (CTAD) +template <typename T> Foo(T t) -> Foo<T>; + +template <typename T> class Bar { +public: + Bar(T); +}; + +template <typename T> class Unused {}; + +} // namespace ns + +using ns::Bar; +using ns::Foo; +using ns::Unused; // Unused +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused +// CHECK-FIXES: {{^}}// Unused + +void f() { + Foo(123); + Bar(1); +} Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -38,6 +38,13 @@ *Builder = std::move(Result); return Matched; } + +AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl, + clang::ast_matchers::internal::Matcher<NamedDecl>, DeclMatcher) { + if (const auto *TD = Node.getTemplateName().getAsTemplateDecl()) + return DeclMatcher.matches(*TD, Finder, Builder); + return false; +} } // namespace // A function that helps to tell whether a TargetDecl in a UsingDecl will be @@ -56,6 +63,9 @@ Finder->addMatcher(loc(enumType(DeclMatcher)), this); Finder->addMatcher(loc(recordType(DeclMatcher)), this); Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this); + Finder->addMatcher(loc(deducedTemplateSpecializationType( + refsToTemplatedDecl(namedDecl().bind("used")))), + this); Finder->addMatcher(declRefExpr().bind("used"), this); Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))), this);
Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp @@ -0,0 +1,30 @@ +// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/ + +namespace ns { + +template <typename T> class Foo { +public: + Foo(T); +}; +// Deduction guide (CTAD) +template <typename T> Foo(T t) -> Foo<T>; + +template <typename T> class Bar { +public: + Bar(T); +}; + +template <typename T> class Unused {}; + +} // namespace ns + +using ns::Bar; +using ns::Foo; +using ns::Unused; // Unused +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused +// CHECK-FIXES: {{^}}// Unused + +void f() { + Foo(123); + Bar(1); +} Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -38,6 +38,13 @@ *Builder = std::move(Result); return Matched; } + +AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl, + clang::ast_matchers::internal::Matcher<NamedDecl>, DeclMatcher) { + if (const auto *TD = Node.getTemplateName().getAsTemplateDecl()) + return DeclMatcher.matches(*TD, Finder, Builder); + return false; +} } // namespace // A function that helps to tell whether a TargetDecl in a UsingDecl will be @@ -56,6 +63,9 @@ Finder->addMatcher(loc(enumType(DeclMatcher)), this); Finder->addMatcher(loc(recordType(DeclMatcher)), this); Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this); + Finder->addMatcher(loc(deducedTemplateSpecializationType( + refsToTemplatedDecl(namedDecl().bind("used")))), + this); Finder->addMatcher(declRefExpr().bind("used"), this); Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))), this);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits