diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1686,8 +1686,8 @@ Module *DeclModule = SemaRef.getOwningModule(D); assert(DeclModule && "hidden decl has no owning module"); - // If the owning module is visible, the decl is visible. if (SemaRef.isModuleVisible(DeclModule, D->isModulePrivate())) + // If the owning module is visible, the decl is visible. return true; // Determine whether a decl context is a file context for the purpose of @@ -1761,6 +1761,21 @@ if (ModulePrivate) { if (isInCurrentModule(M, getLangOpts())) return true; + else if (M->Kind == Module::ModuleKind::ModulePartitionImplementation && + isModuleDirectlyImported(M)) + // Unless a partition implementation is directly imported it is not + // counted as visible for lookup, although the contained decls might + // still be reachable. It's a partition, so it must be part of the + // current module to be a valid import. + return true; + else if (getLangOpts().CPlusPlusModules && !ModuleScopes.empty() && + ModuleScopes[0].Module->Kind == + Module::ModuleKind::ModulePartitionImplementation && + ModuleScopes[0].Module->getPrimaryModuleInterfaceName() == + M->Name && isModuleDirectlyImported(M)) + // We are building a module implementation partition and the TU imports + // the primary module interface unit. + return true; } else { if (VisibleModules.isVisible(M)) return true;