diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1140,11 +1140,22 @@ } 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 Decls = + getDeclAtPosition(AST, *CurLoc, Relations); + std::vector AdditionalDecls; + // 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(D) || llvm::isa(D)) { + for (const NamedDecl *AD : + getDeclAtPosition(AST, *CurLoc, DeclRelation::Underlying)) + AdditionalDecls.push_back(AD); + break; + } + } + llvm::copy(AdditionalDecls, 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 --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1582,6 +1582,13 @@ f.[[^~]]Foo(); } )cpp", + R"cpp(// Renaming alias + template class Vector {}; + using [[^X]] = Vector; + [[X]] x1; + Vector x2; + Vector y; + )cpp", }; for (const char *Test : Tests) { Annotations T(Test);