Author: Kadir Cetinkaya Date: 2020-01-22T11:43:53+01:00 New Revision: 9570f1e5a612348e92c2f149f5073ef06f9e5da5
URL: https://github.com/llvm/llvm-project/commit/9570f1e5a612348e92c2f149f5073ef06f9e5da5 DIFF: https://github.com/llvm/llvm-project/commit/9570f1e5a612348e92c2f149f5073ef06f9e5da5.diff LOG: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73101 Added: Modified: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/FindTargetTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index bed32c394089..31cdcee0cfe7 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -586,6 +586,13 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) { } void VisitNamedDecl(const NamedDecl *ND) { + // We choose to ignore {Class, Function, Var, TypeAlias}TemplateDecls. As + // as their underlying decls, covering the same range, will be visited. + if (llvm::isa<ClassTemplateDecl>(ND) || + llvm::isa<FunctionTemplateDecl>(ND) || + llvm::isa<VarTemplateDecl>(ND) || + llvm::isa<TypeAliasTemplateDecl>(ND)) + return; // FIXME: decide on how to surface destructors when we need them. if (llvm::isa<CXXDestructorDecl>(ND)) return; diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index c6ad75144f96..ed3da28aa0d1 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -741,21 +741,17 @@ TEST_F(FindExplicitReferencesTest, All) { {R"cpp( namespace foo { template <typename $0^T> - class $1^$2^Bar { - ~$3^Bar(); - void $4^f($5^Bar); + class $1^Bar { + ~$2^Bar(); + void $3^f($4^Bar); }; } )cpp", "0: targets = {foo::Bar::T}, decl\n" - // FIXME: avoid the 2 duplicated foo::Bar references below, the first - // one comes from ClassTemplateDecl; the second comes from the - // underlying CXXRecordDecl. "1: targets = {foo::Bar}, decl\n" - "2: targets = {foo::Bar}, decl\n" - "3: targets = {foo::Bar}\n" - "4: targets = {foo::Bar::f}, decl\n" - "5: targets = {foo::Bar}\n"}, + "2: targets = {foo::Bar}\n" + "3: targets = {foo::Bar::f}, decl\n" + "4: targets = {foo::Bar}\n"}, // MemberExpr should know their using declaration. {R"cpp( struct X { void func(int); }; @@ -1055,7 +1051,47 @@ TEST_F(FindExplicitReferencesTest, All) { } )cpp", "0: targets = {Test}\n" - "1: targets = {a}, decl\n"}}; + "1: targets = {a}, decl\n"}, + // Templates + {R"cpp( + namespace foo { + template <typename $0^T> + class $1^Bar {}; + } + )cpp", + "0: targets = {foo::Bar::T}, decl\n" + "1: targets = {foo::Bar}, decl\n"}, + // Templates + {R"cpp( + namespace foo { + template <typename $0^T> + void $1^func(); + } + )cpp", + "0: targets = {T}, decl\n" + "1: targets = {foo::func}, decl\n"}, + // Templates + {R"cpp( + namespace foo { + template <typename $0^T> + $1^T $2^x; + } + )cpp", + "0: targets = {foo::T}, decl\n" + "1: targets = {foo::T}\n" + "2: targets = {foo::x}, decl\n"}, + // Templates + {R"cpp( + template<typename T> class vector {}; + namespace foo { + template <typename $0^T> + using $1^V = $2^vector<$3^T>; + } + )cpp", + "0: targets = {foo::T}, decl\n" + "1: targets = {foo::V}, decl\n" + "2: targets = {vector}\n" + "3: targets = {foo::T}\n"}}; for (const auto &C : Cases) { llvm::StringRef ExpectedCode = C.first; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits