[clang-tools-extra] [clang-tidy] Skip overloaded functions in modernize-use-string-view (PR #183921)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 21 00:06:45 PDT 2026


================
@@ -21,6 +21,40 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::modernize {
 
+namespace {
+AST_MATCHER(FunctionDecl, isOverloaded) {
+  const DeclarationName Name = Node.getDeclName();
+  // Sanity check
+  if (Name.isEmpty())
+    return false;
+  const DeclContext *DC = Node.getDeclContext();
+  auto LookupResult = DC->lookup(Name);
+  size_t UniqueSignatures = 0;
+  llvm::SmallPtrSet<const FunctionDecl *, 2> SeenFunctions;
+  for (NamedDecl *ND : LookupResult) {
+    const FunctionDecl *FD = nullptr;
+    if (const auto *Func = dyn_cast<FunctionDecl>(ND)) {
+      // Regular functions
+      FD = Func;
+    } else if (const auto *USD = dyn_cast<UsingShadowDecl>(ND)) {
+      // Overloads via "using ns::func_name"
+      FD = dyn_cast<FunctionDecl>(USD->getTargetDecl());
+    } else if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND)) {
+      // Templated functions
+      FD = FTD->getTemplatedDecl();
+    }
+    if (FD) {
+      if (SeenFunctions.insert(FD->getCanonicalDecl()).second) {
----------------
zwuis wrote:

```cpp
if (FD && SeenFunctions.insert(FD->getCanonicalDecl()).second) {
```


https://github.com/llvm/llvm-project/pull/183921


More information about the cfe-commits mailing list