diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 839cf6332fe8b..3d73e77b16aff 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -443,9 +443,16 @@ struct TargetFinder { Outer.add(TST->getAliasedType(), Flags | Rel::Underlying); // Don't *traverse* the alias, which would result in traversing the // template of the underlying type. - Outer.report( - TST->getTemplateName().getAsTemplateDecl()->getTemplatedDecl(), - Flags | Rel::Alias | Rel::TemplatePattern); + + TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl(); + // Builtin templates e.g. __make_integer_seq, __type_pack_element + // are such that they don't have alias *decls*. Even then, we still + // traverse their desugared *types* so that instantiated decls are + // collected. + if (llvm::isa(TD)) + return; + Outer.report(TD->getTemplatedDecl(), + Flags | Rel::Alias | Rel::TemplatePattern); } // specializations of template template parameters aren't instantiated // into decls, so they must refer to the parameter itself. diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index fbd10c4a47a79..29cff68cf03b2 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -709,6 +709,33 @@ TEST_F(TargetDeclTest, TypeAliasTemplate) { Rel::Alias | Rel::TemplatePattern}); } +TEST_F(TargetDeclTest, BuiltinTemplates) { + Code = R"cpp( + template struct integer_sequence {}; + [[__make_integer_seq]] X; + )cpp"; + EXPECT_DECLS( + "TemplateSpecializationTypeLoc", + {"struct integer_sequence", Rel::TemplatePattern | Rel::Underlying}, + {"template<> struct integer_sequence>", + Rel::TemplateInstantiation | Rel::Underlying}); + + // Dependent context. + Code = R"cpp( + template struct integer_sequence; + + template + using make_integer_sequence = [[__make_integer_seq]]; + )cpp"; + EXPECT_DECLS("TemplateSpecializationTypeLoc"); + + Code = R"cpp( + template + using type_pack_element = [[__type_pack_element]]; + )cpp"; + EXPECT_DECLS("TemplateSpecializationTypeLoc"); +} + TEST_F(TargetDeclTest, MemberOfTemplate) { Code = R"cpp( template struct Foo {