v1nh1shungry created this revision. v1nh1shungry added reviewers: njames93, ymandel. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a project: All. v1nh1shungry requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Current version complains unused using-declaration even if the target user-defined literal is used. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138204 Files: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp Index: clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp @@ -48,6 +48,7 @@ void OverloadFunc(int); void OverloadFunc(double); int FuncUsedByUsingDeclInMacro() { return 1; } +long double operator""_w(long double); class ostream { public: @@ -106,6 +107,7 @@ using n::UnusedFunc; // UnusedFunc // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'UnusedFunc' is unused // CHECK-FIXES: {{^}}// UnusedFunc +using n::operator""_w; using n::cout; using n::endl; @@ -183,6 +185,7 @@ UsedInstance.i; UsedFunc(); UsedTemplateFunc<int>(); + 1.5_w; cout << endl; Color2 color2; int t1 = Color3::Yellow; 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 @@ -54,6 +54,7 @@ Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument( templateArgument().bind("used")))), this); + Finder->addMatcher(userDefinedLiteral().bind("used"), this); // Cases where we can identify the UsingShadowDecl directly, rather than // just its target. // FIXME: cover more cases in this way, as the AST supports it. @@ -150,7 +151,11 @@ if (const auto *USD = dyn_cast<UsingShadowDecl>(ND)) removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl()); } + return; } + // Check user-defined literals + if (const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>("used")) + removeFromFoundDecls(UDL->getCalleeDecl()); } void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
Index: clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp @@ -48,6 +48,7 @@ void OverloadFunc(int); void OverloadFunc(double); int FuncUsedByUsingDeclInMacro() { return 1; } +long double operator""_w(long double); class ostream { public: @@ -106,6 +107,7 @@ using n::UnusedFunc; // UnusedFunc // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'UnusedFunc' is unused // CHECK-FIXES: {{^}}// UnusedFunc +using n::operator""_w; using n::cout; using n::endl; @@ -183,6 +185,7 @@ UsedInstance.i; UsedFunc(); UsedTemplateFunc<int>(); + 1.5_w; cout << endl; Color2 color2; int t1 = Color3::Yellow; 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 @@ -54,6 +54,7 @@ Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument( templateArgument().bind("used")))), this); + Finder->addMatcher(userDefinedLiteral().bind("used"), this); // Cases where we can identify the UsingShadowDecl directly, rather than // just its target. // FIXME: cover more cases in this way, as the AST supports it. @@ -150,7 +151,11 @@ if (const auto *USD = dyn_cast<UsingShadowDecl>(ND)) removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl()); } + return; } + // Check user-defined literals + if (const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>("used")) + removeFromFoundDecls(UDL->getCalleeDecl()); } void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits