[PATCH] D138204: [clang-tidy] Fix misc-unused-using-decls for user-defined literals

v1nh1shungry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 17 05:36:30 PST 2022


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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138204.476100.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221117/966da8b7/attachment.bin>


More information about the cfe-commits mailing list