@@ -1094,6 +1094,26 @@ bool CompilerInvocation::shouldImportSwiftBacktracing() const {
1094
1094
FrontendOptions::ParseInputMode::SwiftModuleInterface;
1095
1095
}
1096
1096
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
+
1097
1117
// / Implicitly import the SwiftOnoneSupport module in non-optimized
1098
1118
// / builds. This allows for use of popular specialized functions
1099
1119
// / from the standard library, which makes the non-optimized builds
@@ -1286,9 +1306,7 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
1286
1306
}
1287
1307
1288
1308
if (Invocation.getLangOptions ().EnableCXXInterop ) {
1289
- if (imports.StdlibKind != ImplicitStdlibKind::Builtin &&
1290
- Invocation.getFrontendOptions ().ModuleName != CXX_MODULE_NAME &&
1291
- canImportCxx ())
1309
+ if (Invocation.shouldImportCxx () && canImportCxx ())
1292
1310
pushImport (CXX_MODULE_NAME);
1293
1311
if (canImportCxxShim ())
1294
1312
pushImport (CXX_SHIM_NAME, {ImportFlags::ImplementationOnly});
0 commit comments