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 @@ -210,8 +210,10 @@ return false; if (auto *D = Node->ASTNode.get()) { - QualifierToRemove = D->getQualifierLoc(); - Name = D->getDecl()->getName(); + if (auto *II = D->getDecl()->getIdentifier()) { + QualifierToRemove = D->getQualifierLoc(); + Name = II->getName(); + } } else if (auto *T = Node->ASTNode.get()) { if (auto E = T->getAs()) { if (auto *BaseTypeIdentifier = 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 @@ -2444,6 +2444,7 @@ public: struct st {}; static void mm() {} + cc operator|(const cc& x) const { return x; } }; } })cpp"; @@ -2463,6 +2464,9 @@ // test that we don't crash. EXPECT_UNAVAILABLE(Header + "template using foo = one::tt;"); + // Test that we don't crash or misbehave on unnamed DeclRefExpr. + EXPECT_UNAVAILABLE(Header + + "void fun() { one::two::cc() ^| one::two::cc(); }"); // Check that we do not trigger in header files. FileName = "test.h";