Author: Nathan Ridge Date: 2023-06-20T03:22:52-04:00 New Revision: c3075023850bbb7276085198d42b69938d48380d
URL: https://github.com/llvm/llvm-project/commit/c3075023850bbb7276085198d42b69938d48380d DIFF: https://github.com/llvm/llvm-project/commit/c3075023850bbb7276085198d42b69938d48380d.diff LOG: [clangd] Index the type of a non-type template parameter Fixes https://github.com/clangd/clangd/issues/1666 Differential Revision: https://reviews.llvm.org/D153251 Added: Modified: clang/lib/Index/IndexDecl.cpp clang/unittests/Index/IndexTests.cpp Removed: ################################################################################ diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index 882e02836d4fb..1c04aa17d53fb 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -705,6 +705,7 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> { IndexCtx.handleReference(C->getNamedConcept(), C->getConceptNameLoc(), Parent, TTP->getLexicalDeclContext()); } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) { + IndexCtx.indexTypeSourceInfo(NTTP->getTypeSourceInfo(), Parent); if (NTTP->hasDefaultArgument()) IndexCtx.indexBody(NTTP->getDefaultArgument(), Parent); } else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) { diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp index 88ad63b97b92a..690673a1072b0 100644 --- a/clang/unittests/Index/IndexTests.cpp +++ b/clang/unittests/Index/IndexTests.cpp @@ -392,6 +392,20 @@ TEST(IndexTest, EnumBase) { Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference), WrittenAt(Position(4, 16)))))); } + +TEST(IndexTest, NonTypeTemplateParameter) { + std::string Code = R"cpp( + enum class Foobar { foo }; + template <Foobar f> + constexpr void func() {} + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("Foobar"), HasRole(SymbolRole::Reference), + WrittenAt(Position(3, 15))))); +} + } // namespace } // namespace index } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits