[PATCH] D74900: [clangd] Fix the incomplete template specialization in findTarget.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 00:50:27 PST 2020
hokein updated this revision to Diff 245800.
hokein added a comment.
Fxi the tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74900/new/
https://reviews.llvm.org/D74900
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -954,6 +954,12 @@
class [[Fo^o]] {};
void func([[Foo]]<int>);
)cpp",
+
+ R"cpp(
+ template <typename T>
+ class [[Foo]] {};
+ void func([[Fo^o]]<int>);
+ )cpp",
};
for (const char *Test : Tests) {
Annotations T(Test);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -309,6 +309,16 @@
{"template<> class Foo<42>", Rel::TemplateInstantiation},
{"class Foo", Rel::TemplatePattern});
+ Code = R"cpp(
+ template<typename T> class Foo {};
+ // The "Foo<int>" SpecializationDecl is incomplete, there is no
+ // instantiation happening.
+ void func([[Foo<int>]] *);
+ )cpp";
+ EXPECT_DECLS("TemplateSpecializationTypeLoc",
+ {"class Foo", Rel::TemplatePattern},
+ {"template<> class Foo<int>", Rel::TemplateInstantiation});
+
Code = R"cpp(
// Explicit specialization.
template<int x> class Foo{};
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -31,6 +31,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
@@ -139,7 +140,14 @@
const NamedDecl *getTemplatePattern(const NamedDecl *D) {
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
- return CRD->getTemplateInstantiationPattern();
+ if (const auto *Result = CRD->getTemplateInstantiationPattern())
+ return Result;
+ // getTemplateInstantiationPattern returns null if the Specialization is
+ // incomplete (e.g. the type didn't need to be complete), fall back to the
+ // primary template.
+ if (CRD->getTemplateSpecializationKind() == TSK_Undeclared)
+ if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(CRD))
+ return Spec->getSpecializedTemplate()->getTemplatedDecl();
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
return FD->getTemplateInstantiationPattern();
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74900.245800.patch
Type: text/x-patch
Size: 2713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200221/3e0cb75e/attachment-0001.bin>
More information about the cfe-commits
mailing list