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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits