@@ -1094,6 +1094,26 @@ bool CompilerInvocation::shouldImportSwiftBacktracing() const {
10941094 FrontendOptions::ParseInputMode::SwiftModuleInterface;
10951095}
10961096
1097+ bool CompilerInvocation::shouldImportCxx () const {
1098+ // C++ Interop is disabled
1099+ if (!getLangOptions ().EnableCXXInterop )
1100+ return false ;
1101+ // Avoid C++ stdlib when building Swift stdlib
1102+ if (getImplicitStdlibKind () == ImplicitStdlibKind::Builtin)
1103+ return false ;
1104+ // Avoid importing Cxx when building Cxx itself
1105+ if (getFrontendOptions ().ModuleName == CXX_MODULE_NAME)
1106+ return false ;
1107+ // Cxx cannot be imported when Library evolution is enabled
1108+ if (getFrontendOptions ().EnableLibraryEvolution )
1109+ return false ;
1110+ // Implicit import of Cxx is disabled
1111+ if (getLangOptions ().DisableImplicitCxxModuleImport )
1112+ return false ;
1113+
1114+ return true ;
1115+ }
1116+
10971117// / Implicitly import the SwiftOnoneSupport module in non-optimized
10981118// / builds. This allows for use of popular specialized functions
10991119// / from the standard library, which makes the non-optimized builds
@@ -1286,9 +1306,7 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
12861306 }
12871307
12881308 if (Invocation.getLangOptions ().EnableCXXInterop ) {
1289- if (imports.StdlibKind != ImplicitStdlibKind::Builtin &&
1290- Invocation.getFrontendOptions ().ModuleName != CXX_MODULE_NAME &&
1291- canImportCxx ())
1309+ if (Invocation.shouldImportCxx () && canImportCxx ())
12921310 pushImport (CXX_MODULE_NAME);
12931311 if (canImportCxxShim ())
12941312 pushImport (CXX_SHIM_NAME, {ImportFlags::ImplementationOnly});
0 commit comments