Skip to content

Commit 8003c1d

Browse files
v1nh1shungryymand
authored andcommitted
[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
1 parent fc91c70 commit 8003c1d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
5454
Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument(
5555
templateArgument().bind("used")))),
5656
this);
57+
Finder->addMatcher(userDefinedLiteral().bind("used"), this);
5758
// Cases where we can identify the UsingShadowDecl directly, rather than
5859
// just its target.
5960
// FIXME: cover more cases in this way, as the AST supports it.
@@ -150,7 +151,11 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
150151
if (const auto *USD = dyn_cast<UsingShadowDecl>(ND))
151152
removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
152153
}
154+
return;
153155
}
156+
// Check user-defined literals
157+
if (const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>("used"))
158+
removeFromFoundDecls(UDL->getCalleeDecl());
154159
}
155160

156161
void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {

clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ template <typename T> int UsedInTemplateFunc() { return 1; }
4848
void OverloadFunc(int);
4949
void OverloadFunc(double);
5050
int FuncUsedByUsingDeclInMacro() { return 1; }
51+
long double operator""_w(long double);
5152

5253
class ostream {
5354
public:
@@ -106,6 +107,7 @@ using n::UnusedInstance; // UnusedInstance
106107
using n::UnusedFunc; // UnusedFunc
107108
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'UnusedFunc' is unused
108109
// CHECK-FIXES: {{^}}// UnusedFunc
110+
using n::operator""_w;
109111
using n::cout;
110112
using n::endl;
111113

@@ -183,6 +185,7 @@ void g() {
183185
UsedInstance.i;
184186
UsedFunc();
185187
UsedTemplateFunc<int>();
188+
1.5_w;
186189
cout << endl;
187190
Color2 color2;
188191
int t1 = Color3::Yellow;

0 commit comments

Comments
 (0)