@@ -2163,7 +2163,8 @@ ModuleDecl *ClangImporter::Implementation::loadModule(
2163
2163
ASTContext &ctx = getNameImporter ().getContext ();
2164
2164
2165
2165
// `CxxStdlib` is the only accepted spelling of the C++ stdlib module name.
2166
- if (path.front ().Item .is (" std" ))
2166
+ if (path.front ().Item .is (" std" ) ||
2167
+ path.front ().Item .str ().starts_with (" std_" ))
2167
2168
return nullptr ;
2168
2169
if (path.front ().Item == ctx.Id_CxxStdlib ) {
2169
2170
ImportPath::Builder adjustedPath (ctx.getIdentifier (" std" ), importLoc);
@@ -3985,6 +3986,13 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
3985
3986
ImportPath::Module::Builder builder (M->getName ());
3986
3987
(void ) owner.loadModule (SourceLoc (), std::move (builder).get ());
3987
3988
}
3989
+ // If this Clang module is a part of the C++ stdlib, and we haven't loaded
3990
+ // the overlay for it so far, it is a split libc++ module (e.g. std_vector).
3991
+ // Load the CxxStdlib overlay explicitly.
3992
+ if (!overlay && importer::isCxxStdModule (clangModule)) {
3993
+ ImportPath::Module::Builder builder (Ctx.Id_CxxStdlib );
3994
+ overlay = owner.loadModule (SourceLoc (), std::move (builder).get ());
3995
+ }
3988
3996
auto mutableThis = const_cast <ClangModuleUnit *>(this );
3989
3997
mutableThis->overlayModule .setPointerAndInt (overlay, true );
3990
3998
}
@@ -7624,12 +7632,7 @@ const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
7624
7632
7625
7633
bool importer::requiresCPlusPlus (const clang::Module *module ) {
7626
7634
// The libc++ modulemap doesn't currently declare the requirement.
7627
- if (module ->getTopLevelModuleName () == " std" )
7628
- return true ;
7629
- // In recent libc++ versions the module is split into multiple top-level
7630
- // modules (std_vector, std_utility, etc).
7631
- if (module ->getTopLevelModule ()->IsSystem &&
7632
- module ->getTopLevelModuleName ().starts_with (" std_" ))
7635
+ if (isCxxStdModule (module ))
7633
7636
return true ;
7634
7637
7635
7638
// Modulemaps often declare the requirement for the top-level module only.
@@ -7643,6 +7646,18 @@ bool importer::requiresCPlusPlus(const clang::Module *module) {
7643
7646
});
7644
7647
}
7645
7648
7649
+ bool importer::isCxxStdModule (const clang::Module *module ) {
7650
+ if (module ->getTopLevelModuleName () == " std" )
7651
+ return true ;
7652
+ // In recent libc++ versions the module is split into multiple top-level
7653
+ // modules (std_vector, std_utility, etc).
7654
+ if (module ->getTopLevelModule ()->IsSystem &&
7655
+ module ->getTopLevelModuleName ().starts_with (" std_" ))
7656
+ return true ;
7657
+
7658
+ return false ;
7659
+ }
7660
+
7646
7661
llvm::Optional<clang::QualType>
7647
7662
importer::getCxxReferencePointeeTypeOrNone (const clang::Type *type) {
7648
7663
if (type->isReferenceType ())
0 commit comments