Author: Adam Czachorowski Date: 2020-12-03T20:25:38+01:00 New Revision: c282b7de5a5de8151a19228702867e2299f1d3fe
URL: https://github.com/llvm/llvm-project/commit/c282b7de5a5de8151a19228702867e2299f1d3fe DIFF: https://github.com/llvm/llvm-project/commit/c282b7de5a5de8151a19228702867e2299f1d3fe.diff LOG: [clangd] AddUsing: Fix a crash on ElaboratedTypes without NestedNameSpecfiiers. Differential Revision: https://reviews.llvm.org/D92579 Added: Modified: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp clang-tools-extra/clangd/unittests/TweakTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp index b00c2716005c7..d6a57efeeef13 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -274,6 +274,8 @@ bool AddUsing::prepare(const Selection &Inputs) { } else if (auto *T = Node->ASTNode.get<TypeLoc>()) { if (auto E = T->getAs<ElaboratedTypeLoc>()) { 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 index eefc50d754e2a..07f061b3f2e39 100644 --- a/clang-tools-extra/clangd/unittests/TweakTests.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -2523,6 +2523,9 @@ class cc { // 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits