Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp @@ -680,7 +680,8 @@ T = Property->getType(); else if (const auto *Value = dyn_cast(ND)) T = Value->getType(); - else + + if (T.isNull()) return QualType(); // Dig through references, function pointers, and block pointers to Index: cfe/trunk/test/CodeCompletion/crash-null-type.cpp =================================================================== --- cfe/trunk/test/CodeCompletion/crash-null-type.cpp +++ cfe/trunk/test/CodeCompletion/crash-null-type.cpp @@ -0,0 +1,8 @@ +void test() { + for (auto [loopVar] : y) { // y has to be unresolved + loopVa + } +} +// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:3:11 %s -o - \ +// RUN: | FileCheck %s +// CHECK: COMPLETION: loopVar Index: clang-tools-extra/trunk/clangd/ExpectedTypes.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ExpectedTypes.cpp +++ clang-tools-extra/trunk/clangd/ExpectedTypes.cpp @@ -35,8 +35,10 @@ typeOfCompletion(const CodeCompletionResult &R) { auto *VD = dyn_cast_or_null(R.Declaration); if (!VD) - return None; // We handle only variables and functions below. + return llvm::None; // We handle only variables and functions below. auto T = VD->getType(); + if (T.isNull()) + return llvm::None; if (auto FuncT = T->getAs()) { // Functions are a special case. They are completed as 'foo()' and we want // to match their return type rather than the function type itself. Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp @@ -2319,6 +2319,17 @@ EXPECT_THAT(C, ElementsAre(SnippetSuffix("${1:(unsigned int)}"))); } +TEST(CompletionTest, WorksWithNullType) { + auto R = completions(R"cpp( + int main() { + for (auto [loopVar] : y ) { // y has to be unresolved. + int z = loopV^; + } + } + )cpp"); + EXPECT_THAT(R.Completions, ElementsAre(Named("loopVar"))); +} + } // namespace } // namespace clangd } // namespace clang