summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/Selection.cpp2
-rw-r--r--clang-tools-extra/unittests/clangd/SelectionTests.cpp10
2 files changed, 11 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index 2c2fd476072..d1ea30e7ede 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -51,7 +51,7 @@ public:
// - 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<TranslationUnitDecl>(X))
+ if (X && isa<TranslationUnitDecl>(X))
return Base::TraverseDecl(X); // Already pushed by constructor.
return traverseNode(X, [&] { return Base::TraverseDecl(X); });
}
diff --git a/clang-tools-extra/unittests/clangd/SelectionTests.cpp b/clang-tools-extra/unittests/clangd/SelectionTests.cpp
index 88406b6331e..2322a0e6a54 100644
--- a/clang-tools-extra/unittests/clangd/SelectionTests.cpp
+++ b/clang-tools-extra/unittests/clangd/SelectionTests.cpp
@@ -176,6 +176,16 @@ TEST(SelectionTest, CommonAncestor) {
// Node types that have caused problems in the past.
{"template <typename T> void foo() { [[^T]] t; }", "TypeLoc"},
+
+ // No crash
+ {
+ R"cpp(
+ template <class T> struct Foo {};
+ template <[[template<class> class /*cursor here*/^U]]>
+ struct Foo<U<int>*> {};
+ )cpp",
+ "TemplateTemplateParmDecl"
+ },
};
for (const Case &C : Cases) {
Annotations Test(C.Code);
OpenPOWER on IntegriCloud