summarylogtreecommitdiffstats
path: root/hover-ptrfn-args.patch
blob: 047021342e1403d31e2544015feb40f5f47f5bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 1e4b524f4514fcde8d98dbd6448477b82bd3d780 Mon Sep 17 00:00:00 2001
From: Qwinci <32550582+Qwinci@users.noreply.github.com>
Date: Fri, 13 Oct 2023 19:38:19 +0300
Subject: [PATCH] clangd: Show argument names for function pointer struct
 fields

---
 .../clangd/unittests/CodeCompleteTests.cpp      | 17 +++++++++++++++++
 clang/lib/Sema/SemaCodeComplete.cpp             | 12 +++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 766998eb4f3c719..bd88a0912b537d1 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) {
     typedef void (__stdcall *fn)(int x, int y);
     fn foo;
     int main() { foo(^); }
+  )cpp",
+      // Field of function pointer type
+      R"cpp(
+    struct S {
+      void (*foo)(int x, int y);
+    };
+    S s;
+    int main() { s.foo(^); }
+  )cpp",
+      // Field of function pointer typedef type
+      R"cpp(
+    typedef void (*fn)(int x, int y);
+    struct S {
+      fn foo;
+    };
+    S s;
+    int main() { s.foo(^); }
   )cpp"};
   for (auto Test : Tests)
     EXPECT_THAT(signatures(Test).signatures,
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index adb82d3f6d176ab..5e3aed53fd8e218 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6133,7 +6133,17 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef<ResultCandidate> Candidates,
 // so that we can recover argument names from it.
 static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
   TypeLoc Target;
-  if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
+
+  if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
+    const auto *MD = ME->getMemberDecl();
+    if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
+      if (const auto *T = FD->getType().getTypePtr()->getAs<TypedefType>()) {
+        Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
+      } else {
+        Target = FD->getTypeSourceInfo()->getTypeLoc();
+      }
+    }
+  } else if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
     Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();

   } else if (const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {