Index: clangd/Selection.cpp =================================================================== --- clangd/Selection.cpp +++ clangd/Selection.cpp @@ -51,7 +51,7 @@ // - those that can't be stored in DynTypedNode. // We're missing some interesting things like Attr due to the latter. bool TraverseDecl(Decl *X) { - if (isa(X)) + if (X && isa(X)) return Base::TraverseDecl(X); // Already pushed by constructor. return traverseNode(X, [&] { return Base::TraverseDecl(X); }); } Index: unittests/clangd/SelectionTests.cpp =================================================================== --- unittests/clangd/SelectionTests.cpp +++ unittests/clangd/SelectionTests.cpp @@ -176,7 +176,18 @@ // Node types that have caused problems in the past. {"template void foo() { [[^T]] t; }", "TypeLoc"}, + + // No crash + { + R"cpp( + template struct Foo {}; + template <[[template class /*cursor here*/^U]]> + struct Foo*> {}; + )cpp", + "TemplateTemplateParmDecl" + }, }; + // template class /*cursor here*/[[^U]]> struct Foo*> for (const Case &C : Cases) { Annotations Test(C.Code); auto AST = TestTU::withCode(Test.code()).build();