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 @@ -274,6 +274,8 @@ } else if (auto *T = Node->ASTNode.get()) { if (auto E = T->getAs()) { QualifierToRemove = E.getQualifierLoc(); + if (!QualifierToRemove) + return false; auto SpelledTokens = TB.spelledForExpanded(TB.expandedTokens(E.getSourceRange())); 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 @@ -2523,6 +2523,9 @@ // Do not offer code action on typo-corrections. EXPECT_UNAVAILABLE(Header + "/*error-ok*/c^c C;"); + // NestedNameSpecifier, but no namespace. + EXPECT_UNAVAILABLE(Header + "class Foo {}; class F^oo foo;"); + // Check that we do not trigger in header files. FileName = "test.h"; ExtraArgs.push_back("-xc++-header"); // .h file is treated a C by default.