diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp --- a/clang-tools-extra/clangd/AST.cpp +++ b/clang-tools-extra/clangd/AST.cpp @@ -119,17 +119,16 @@ (void)ReachedNS; NNS = NestedNameSpecifier::Create(Context, nullptr, false, TD->getTypeForDecl()); - } else { + } else if (auto *NSD = llvm::dyn_cast(CurContext)) { ReachedNS = true; - auto *NSD = llvm::cast(CurContext); NNS = NestedNameSpecifier::Create(Context, nullptr, NSD); - // Anonymous and inline namespace names are not spelled while qualifying a - // name, so skip those. + // Anonymous and inline namespace names are not spelled while qualifying + // a name, so skip those. if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace()) continue; } // Stop if this namespace is already visible at DestContext. - if (IsVisible(NNS)) + if (!NNS || IsVisible(NNS)) break; Parents.push_back(NNS);