[clang-tools-extra] cc6d1f8 - [clangd] When finding refs for a renaming alias, do not return refs to underlying decls
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 18:18:47 PDT 2020
Author: Nathan Ridge
Date: 2020-09-28T21:18:31-04:00
New Revision: cc6d1f8029b05cd747c46ad3244a1b31ae970c61
URL: https://github.com/llvm/llvm-project/commit/cc6d1f8029b05cd747c46ad3244a1b31ae970c61
DIFF: https://github.com/llvm/llvm-project/commit/cc6d1f8029b05cd747c46ad3244a1b31ae970c61.diff
LOG: [clangd] When finding refs for a renaming alias, do not return refs to underlying decls
Fixes https://github.com/clangd/clangd/issues/515
Differential Revision: https://reviews.llvm.org/D87225
Added:
Modified:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index b4487453847c..9e8791c2a765 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1140,11 +1140,21 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
} else {
// Handle references to Decls.
- // We also show references to the targets of using-decls, so we include
- // DeclRelation::Underlying.
- DeclRelationSet Relations = DeclRelation::TemplatePattern |
- DeclRelation::Alias | DeclRelation::Underlying;
- auto Decls = getDeclAtPosition(AST, *CurLoc, Relations);
+ DeclRelationSet Relations =
+ DeclRelation::TemplatePattern | DeclRelation::Alias;
+ std::vector<const NamedDecl *> Decls =
+ getDeclAtPosition(AST, *CurLoc, Relations);
+ std::vector<const NamedDecl *> NonrenamingAliasUnderlyingDecls;
+ // If the results include a *non-renaming* alias, get its
+ // underlying decls as well. (See similar logic in locateASTReferent()).
+ for (const NamedDecl *D : Decls) {
+ if (llvm::isa<UsingDecl>(D) || llvm::isa<UnresolvedUsingValueDecl>(D)) {
+ for (const NamedDecl *AD :
+ getDeclAtPosition(AST, *CurLoc, DeclRelation::Underlying))
+ NonrenamingAliasUnderlyingDecls.push_back(AD);
+ }
+ }
+ llvm::copy(NonrenamingAliasUnderlyingDecls, std::back_inserter(Decls));
// We traverse the AST to find references in the main file.
auto MainFileRefs = findRefs(Decls, AST);
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 2176b59ab9ed..a48bb9c8c182 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1588,6 +1588,13 @@ TEST(FindReferences, WithinAST) {
auto lambda = [x = [[waldo]]](){};
}
)cpp",
+ R"cpp(// Renaming alias
+ 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);
More information about the cfe-commits
mailing list