diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -206,9 +206,11 @@ Name = D->getDecl()->getName(); } else if (auto *T = Node->ASTNode.get()) { if (auto E = T->getAs()) { - QualifierToRemove = E.getQualifierLoc(); - Name = - E.getType().getUnqualifiedType().getBaseTypeIdentifier()->getName(); + if (auto *BaseTypeIdentifier = + E.getType().getUnqualifiedType().getBaseTypeIdentifier()) { + Name = BaseTypeIdentifier->getName(); + QualifierToRemove = E.getQualifierLoc(); + } } } diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp --- a/clang-tools-extra/clangd/unittests/TweakTests.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -2436,6 +2436,7 @@ #define NS(name) one::two::name namespace one { void oo() {} +template class tt {}; namespace two { enum ee {}; void ff() {} @@ -2458,6 +2459,10 @@ EXPECT_UNAVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }"); EXPECT_UNAVAILABLE(Header + "void fun() { N^S(c^c) inst; }"); + // This used to crash. Ideally we would support this case, but for now we just + // test that we don't crash. + EXPECT_UNAVAILABLE(Header + + "template using foo = one::tt;"); } TEST_F(AddUsingTest, Apply) {