[clang] [Index] Skip adding call relations to deduction guides (PR #126151)

Ben Barham via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 6 15:29:26 PST 2025


https://github.com/bnbarham updated https://github.com/llvm/llvm-project/pull/126151

>From 322959db3c22fd4053c31f4f4c2008bd726f89ce Mon Sep 17 00:00:00 2001
From: Ben Barham <ben_barham at apple.com>
Date: Thu, 6 Feb 2025 15:17:56 -0800
Subject: [PATCH] [Index] Skip adding call relations to deduction guides

Deduction guides have no name and we already skip adding occurrences to
them for that reason. Also skip adding any relations to them.
---
 clang/lib/Index/IndexBody.cpp              |  3 +++
 clang/test/Index/index-deduction-guide.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/Index/index-deduction-guide.cpp

diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index c18daf7faa74979..f1dc4d5831ce746 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -130,6 +130,9 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
 
   void addCallRole(SymbolRoleSet &Roles,
                    SmallVectorImpl<SymbolRelation> &Relations) {
+    if (isa<CXXDeductionGuideDecl>(ParentDC))
+      return;
+
     Roles |= (unsigned)SymbolRole::Call;
     if (auto *FD = dyn_cast<FunctionDecl>(ParentDC))
       Relations.emplace_back((unsigned)SymbolRole::RelationCalledBy, FD);
diff --git a/clang/test/Index/index-deduction-guide.cpp b/clang/test/Index/index-deduction-guide.cpp
new file mode 100644
index 000000000000000..a29162e8588e8a1
--- /dev/null
+++ b/clang/test/Index/index-deduction-guide.cpp
@@ -0,0 +1,10 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=gnu++17 | FileCheck %s
+
+template<typename T>
+typename T::type declval() {}
+template <typename T> struct Test;
+template <typename C, typename T = decltype(declval<C>().d())> Test(C &) -> Test<T>;
+// CHECK: [[@LINE-1]]:45 | function/C | declval
+// CHECK-NOT: RelCall
+// CHECK: [[@LINE-3]]:77 | struct(Gen)/C++ | Test
+// CHECK: [[@LINE-4]]:64 | struct(Gen)/C++ | Test



More information about the cfe-commits mailing list