[PATCH] D87225: [clangd] When finding refs for a template specialization, do not return refs to other specializations
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 6 23:29:41 PDT 2020
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Fixes https://github.com/clangd/clangd/issues/515
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87225
Files:
clang-tools-extra/clangd/XRefs.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
@@ -1570,7 +1570,7 @@
R"cpp(
template <typename T>
- class [[Foo]] {};
+ class Foo {};
void func([[Fo^o]]<int>);
)cpp",
R"cpp(// Not touching any identifiers.
@@ -1582,6 +1582,13 @@
f.[[^~]]Foo();
}
)cpp",
+ R"cpp(// Temlate specialization
+ template <typename> class Vector {};
+ using [[^X]] = [[Vector]]<int>;
+ [[X]] x1;
+ [[Vector]]<int> x2;
+ Vector<double> y;
+ )cpp",
};
for (const char *Test : Tests) {
Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -767,7 +767,12 @@
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
const SourceManager &SM = AST.getSourceManager();
- if (!CanonicalTargets.count(D) || !isInsideMainFile(Loc, SM))
+ // For references to template specializations, `D` will contain the
+ // template and `ASTNode.OrigD` the specialization. We want to find
+ // references to specializations, to check `ASTNode.OrigD` as well.
+ bool ReferencesCanonicalTarget =
+ CanonicalTargets.count(D) || CanonicalTargets.count(ASTNode.OrigD);
+ if (!ReferencesCanonicalTarget || !isInsideMainFile(Loc, SM))
return true;
const auto &TB = AST.getTokens();
Loc = SM.getFileLoc(Loc);
@@ -1142,7 +1147,7 @@
// We also show references to the targets of using-decls, so we include
// DeclRelation::Underlying.
- DeclRelationSet Relations = DeclRelation::TemplatePattern |
+ DeclRelationSet Relations = DeclRelation::TemplateInstantiation |
DeclRelation::Alias | DeclRelation::Underlying;
auto Decls = getDeclAtPosition(AST, *CurLoc, Relations);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87225.290185.patch
Type: text/x-patch
Size: 2199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200907/a93ed91b/attachment.bin>
More information about the cfe-commits
mailing list