[clang-tools-extra] 8003c1d - [clang-tidy] Fix misc-unused-using-decls for user-defined literals
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 17 14:47:23 PST 2022
Author: v1nh1shungry
Date: 2022-11-17T22:47:15Z
New Revision: 8003c1d61e69142cb6e87df719c17f3c4ad86c98
URL: https://github.com/llvm/llvm-project/commit/8003c1d61e69142cb6e87df719c17f3c4ad86c98
DIFF: https://github.com/llvm/llvm-project/commit/8003c1d61e69142cb6e87df719c17f3c4ad86c98.diff
LOG: [clang-tidy] Fix misc-unused-using-decls for user-defined literals
Current version complains unused using-declaration even if the target
user-defined literal is used.
Reviewed By: ymandel
Differential Revision: https://reviews.llvm.org/D138204
Added:
Modified:
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ee757296d93..02aa786aa844 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -54,6 +54,7 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
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 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
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) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 63bf34cfafe9..7d02aa4d2e2b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -48,6 +48,7 @@ template <typename T> int UsedInTemplateFunc() { return 1; }
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::UnusedInstance; // UnusedInstance
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 @@ void g() {
UsedInstance.i;
UsedFunc();
UsedTemplateFunc<int>();
+ 1.5_w;
cout << endl;
Color2 color2;
int t1 = Color3::Yellow;
More information about the cfe-commits
mailing list