[PATCH] D72085: [clangd] Fix hover for functions inside templated classes

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 2 07:16:45 PST 2020


kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Fixes https://github.com/clangd/clangd/issues/235


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72085

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1531,7 +1531,11 @@
 TEST(Hover, DocsFromAST) {
   Annotations T(R"cpp(
   // doc
-  template <typename T> class X {};
+  template <typename T> class X {
+   public:
+    // doc
+    void foo();
+  };
   // doc
   template <typename T> void bar() {}
   // doc
@@ -1542,6 +1546,7 @@
     b^ar<int>();
     au^to T = ba^z<X<int>>;
     ba^z<int> = 0;
+    X<int>().f^oo();
   })cpp");
 
   TestTU TU = TestTU::withCode(T.code());
@@ -1560,15 +1565,28 @@
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1
-  template <typename T> class $doc1^X {};
+  template <typename T> struct $doc1^X {
+    // doc1
+    void foo();
+  };
   // doc2
-  template <> class $doc2^X<int> {};
+  template <> struct $doc2^X<int> {
+    // doc2
+    void foo();
+  };
   // doc3
-  template <typename T> class $doc3^X<T*> {};
+  template <typename T> struct $doc3^X<T*> {
+    // doc3
+    void foo();
+  };
   void foo() {
     X$doc1^<char>();
     X$doc2^<int>();
     X$doc3^<int*>();
+
+    X<char>().fo$doc1^o();
+    X<int>().fo$doc2^o();
+    X<int*>().fo$doc3^o();
   })cpp");
 
   TestTU TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -195,7 +195,7 @@
       return VTSD->getTemplateInstantiationPattern();
   if (auto *FD = D->getAsFunction())
     if (FD->isTemplateInstantiation())
-      return FD->getTemplateSpecializationInfo()->getTemplate();
+      return FD->getTemplateInstantiationPattern();
   return D;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72085.235871.patch
Type: text/x-patch
Size: 1843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200102/babf9bc5/attachment.bin>


More information about the cfe-commits mailing list