diff --git a/toolchain/check/cpp/generate_ast.cpp b/toolchain/check/cpp/generate_ast.cpp index dfb4c87cfe59..38040fb53ea9 100644 --- a/toolchain/check/cpp/generate_ast.cpp +++ b/toolchain/check/cpp/generate_ast.cpp @@ -383,8 +383,8 @@ auto CarbonExternalASTSource::MapInstIdToClangDecl( auto* namespace_decl = clang::NamespaceDecl::Create( *ast_context_, &decl_context, false, clang::SourceLocation(), clang::SourceLocation(), identifier_info, nullptr, false); - auto result = scope_mapping.Insert( - static_cast(namespace_decl), target_inst_id); + auto result = scope_mapping.Insert(namespace_decl->getPrimaryContext(), + target_inst_id); CARBON_CHECK(result.is_inserted(), "Inserting over an existing entry."); namespace_decl->setHasExternalVisibleStorage(); return namespace_decl; @@ -395,7 +395,8 @@ auto CarbonExternalASTSource::MapInstIdToClangDecl( auto CarbonExternalASTSource::FindExternalVisibleDeclsByName( const clang::DeclContext* decl_context, clang::DeclarationName decl_name, const clang::DeclContext* /*OriginalDC*/) -> bool { - auto decl_context_inst_id = scope_mapping.Lookup(decl_context); + auto decl_context_inst_id = + scope_mapping.Lookup(decl_context->getPrimaryContext()); if (!decl_context_inst_id) { // If the context doesn't already have a mapping between C++ and Carbon, @@ -420,9 +421,9 @@ auto CarbonExternalASTSource::FindExternalVisibleDeclsByName( clang::SourceLocation(), &ast_context.Idents.get(carbon_namespace_name), nullptr, false); carbon_cpp_namespace->setHasExternalVisibleStorage(); - auto result = scope_mapping.Insert( - static_cast(carbon_cpp_namespace), - SemIR::Namespace::PackageInstId); + auto result = + scope_mapping.Insert(carbon_cpp_namespace->getPrimaryContext(), + SemIR::Namespace::PackageInstId); CARBON_CHECK(result.is_inserted(), "Inserting over an existing entry."); SetExternalVisibleDeclsForName(decl_context, decl_name, {carbon_cpp_namespace});