[PATCH] D72119: [clangd] Handle DeducedTemplateSpecializationType in TargetFinder
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 11:51:35 PST 2020
nridge updated this revision to Diff 236652.
nridge marked an inline comment as done.
nridge added a comment.
Address review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72119/new/
https://reviews.llvm.org/D72119
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
@@ -513,6 +513,7 @@
// FIXME: Auto-completion in a template requires disabling delayed template
// parsing.
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+ TU.ExtraArgs.push_back("-std=c++17");
auto AST = TU.build();
for (auto &D : AST.getDiagnostics())
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -315,6 +315,20 @@
EXPECT_DECLS("TemplateSpecializationTypeLoc",
{"template<> class Foo<int *>", Rel::TemplateInstantiation},
{"template <typename T> class Foo<T *>", Rel::TemplatePattern});
+
+ Code = R"cpp(
+ // Class template argument deduction
+ template <typename T>
+ struct Test {
+ Test(T);
+ };
+ void foo() {
+ [[Test]] a(5);
+ }
+ )cpp";
+ Flags.push_back("-std=c++17");
+ EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+ {"struct Test", Rel::TemplatePattern});
}
TEST_F(TargetDeclTest, FunctionTemplate) {
@@ -549,6 +563,7 @@
// FIXME: Auto-completion in a template requires disabling delayed template
// parsing.
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+ TU.ExtraArgs.push_back("-std=c++17");
auto AST = TU.build();
@@ -937,7 +952,20 @@
};
)cpp",
"0: targets = {size}, decl\n"
- "1: targets = {E}\n"}};
+ "1: targets = {E}\n"},
+ // Class template argument deduction
+ {
+ R"cpp(
+ template <typename T>
+ struct Test {
+ Test(T);
+ };
+ void foo() {
+ $0^Test $1^a(5);
+ }
+ )cpp",
+ "0: targets = {Test}\n"
+ "1: targets = {a}, decl\n"}};
for (const auto &C : Cases) {
llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -358,6 +358,18 @@
// TypeLoc never has a deduced type. https://llvm.org/PR42914
Outer.add(DT->getDeducedType(), Flags | Rel::Underlying);
}
+ void VisitDeducedTemplateSpecializationType(
+ const DeducedTemplateSpecializationType *DTST) {
+ // FIXME: This is a workaround for https://llvm.org/PR42914,
+ // which is causing DTST->getDeducedType() to be empty. We
+ // fall back to the template pattern and miss the instantiation
+ // even when it's known in principle. Once that bug is fixed,
+ // this method can be removed (the existing handling in
+ // VisitDeducedType() is sufficient).
+ if (auto *TD = DTST->getTemplateName().getAsTemplateDecl()) {
+ Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
+ }
+ }
void VisitTypedefType(const TypedefType *TT) {
Outer.add(TT->getDecl(), Flags);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72119.236652.patch
Type: text/x-patch
Size: 3410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200107/689afe1c/attachment.bin>
More information about the cfe-commits
mailing list