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,17 @@ (void)ReachedNS; NNS = NestedNameSpecifier::Create(Context, nullptr, false, TD->getTypeForDecl()); - } else { - 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. - if (NSD->isAnonymousNamespace() || NSD->isInlineNamespace()) - continue; - } + } else + (auto *NSD = llvm::dyn_cast(CurContext)) { + ReachedNS = true; + NNS = NestedNameSpecifier::Create(Context, nullptr, NSD); + // 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);