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,14 +119,15 @@ (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; + } else { + continue; } // Stop if this namespace is already visible at DestContext. if (IsVisible(NNS))