Fix diagnostic for access of protected/private base member. (#5874)

When importing the member, import the access level for the lookup
result, not the declared access of the member declaration.
This commit is contained in:
Richard Smith
2025-07-30 17:17:09 +00:00
committed by GitHub
parent 105618ecb1
commit a6f5143f22
2 changed files with 32 additions and 5 deletions
+5 -3
View File
@@ -1407,14 +1407,15 @@ static auto MapAccess(clang::AccessSpecifier access_specifier)
static auto ImportNameDeclIntoScope(Context& context, SemIR::LocId loc_id,
SemIR::NameScopeId scope_id,
SemIR::NameId name_id,
clang::NamedDecl* clang_decl)
clang::NamedDecl* clang_decl,
clang::AccessSpecifier access)
-> SemIR::ScopeLookupResult {
SemIR::InstId inst_id =
ImportDeclAndDependencies(context, loc_id, clang_decl);
if (!inst_id.has_value()) {
return SemIR::ScopeLookupResult::MakeNotFound();
}
SemIR::AccessKind access_kind = MapAccess(clang_decl->getAccess());
SemIR::AccessKind access_kind = MapAccess(access);
AddNameToScope(context, scope_id, name_id, access_kind, inst_id);
return SemIR::ScopeLookupResult::MakeWrappedLookupResult(inst_id,
access_kind);
@@ -1447,7 +1448,8 @@ auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id,
}
return ImportNameDeclIntoScope(context, loc_id, scope_id, name_id,
lookup->getFoundDecl());
lookup->getFoundDecl(),
lookup->begin().getAccess());
}
} // namespace Carbon::Check