@@ -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
}
@@ -7697,12 +7705,7 @@ const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
7697
7705
7698
7706
bool importer::requiresCPlusPlus (const clang::Module *module ) {
7699
7707
// The libc++ modulemap doesn't currently declare the requirement.
7700
- if (module ->getTopLevelModuleName () == " std" )
7701
- return true ;
7702
- // In recent libc++ versions the module is split into multiple top-level
7703
- // modules (std_vector, std_utility, etc).
7704
- if (module ->getTopLevelModule ()->IsSystem &&
7705
- module ->getTopLevelModuleName ().starts_with (" std_" ))
7708
+ if (isCxxStdModule (module ))
7706
7709
return true ;
7707
7710
7708
7711
// Modulemaps often declare the requirement for the top-level module only.
@@ -7716,6 +7719,18 @@ bool importer::requiresCPlusPlus(const clang::Module *module) {
7716
7719
});
7717
7720
}
7718
7721
7722
+ bool importer::isCxxStdModule (const clang::Module *module ) {
7723
+ if (module ->getTopLevelModuleName () == " std" )
7724
+ return true ;
7725
+ // In recent libc++ versions the module is split into multiple top-level
7726
+ // modules (std_vector, std_utility, etc).
7727
+ if (module ->getTopLevelModule ()->IsSystem &&
7728
+ module ->getTopLevelModuleName ().starts_with (" std_" ))
7729
+ return true ;
7730
+
7731
+ return false ;
7732
+ }
7733
+
7719
7734
llvm::Optional<clang::QualType>
7720
7735
importer::getCxxReferencePointeeTypeOrNone (const clang::Type *type) {
7721
7736
if (type->isReferenceType ())
0 commit comments