@@ -533,6 +533,40 @@ static void diagnoseCxxInteropCompatMode(Arg *verArg, ArgList &Args,
533533 diags.diagnose (SourceLoc (), diag::valid_cxx_interop_modes, versStr);
534534}
535535
536+ void LangOptions::setCxxInteropFromArgs (ArgList &Args,
537+ swift::DiagnosticEngine &Diags) {
538+ if (Arg *A = Args.getLastArg (options::OPT_cxx_interoperability_mode)) {
539+ if (Args.hasArg (options::OPT_enable_experimental_cxx_interop)) {
540+ Diags.diagnose (SourceLoc (), diag::dont_enable_interop_and_compat);
541+ }
542+
543+ auto interopCompatMode = validateCxxInteropCompatibilityMode (A->getValue ());
544+ EnableCXXInterop |=
545+ (interopCompatMode.first == CxxCompatMode::enabled);
546+ if (EnableCXXInterop) {
547+ cxxInteropCompatVersion = interopCompatMode.second ;
548+ // The default is tied to the current language version.
549+ if (cxxInteropCompatVersion.empty ())
550+ cxxInteropCompatVersion =
551+ EffectiveLanguageVersion.asMajorVersion ();
552+ }
553+
554+ if (interopCompatMode.first == CxxCompatMode::invalid)
555+ diagnoseCxxInteropCompatMode (A, Args, Diags);
556+ }
557+
558+ if (Args.hasArg (options::OPT_enable_experimental_cxx_interop)) {
559+ Diags.diagnose (SourceLoc (), diag::enable_interop_flag_deprecated);
560+ Diags.diagnose (SourceLoc (), diag::swift_will_maintain_compat);
561+ EnableCXXInterop |= true ;
562+ // Using the deprecated option only forces the 'swift-5.9' compat
563+ // mode.
564+ if (cxxInteropCompatVersion.empty ())
565+ cxxInteropCompatVersion =
566+ validateCxxInteropCompatibilityMode (" swift-5.9" ).second ;
567+ }
568+ }
569+
536570static std::optional<swift::StrictConcurrency>
537571parseStrictConcurrency (StringRef value) {
538572 return llvm::StringSwitch<std::optional<swift::StrictConcurrency>>(value)
@@ -1263,37 +1297,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
12631297 if (const Arg *A = Args.getLastArg (OPT_clang_target)) {
12641298 Opts.ClangTarget = llvm::Triple (A->getValue ());
12651299 }
1266-
1267- if (Arg *A = Args.getLastArg (OPT_cxx_interoperability_mode)) {
1268- if (Args.hasArg (OPT_enable_experimental_cxx_interop)) {
1269- Diags.diagnose (SourceLoc (), diag::dont_enable_interop_and_compat);
1270- }
1271-
1272- auto interopCompatMode = validateCxxInteropCompatibilityMode (A->getValue ());
1273- Opts.EnableCXXInterop |=
1274- (interopCompatMode.first == CxxCompatMode::enabled);
1275- if (Opts.EnableCXXInterop ) {
1276- Opts.cxxInteropCompatVersion = interopCompatMode.second ;
1277- // The default is tied to the current language version.
1278- if (Opts.cxxInteropCompatVersion .empty ())
1279- Opts.cxxInteropCompatVersion =
1280- Opts.EffectiveLanguageVersion .asMajorVersion ();
1281- }
1282-
1283- if (interopCompatMode.first == CxxCompatMode::invalid)
1284- diagnoseCxxInteropCompatMode (A, Args, Diags);
1285- }
1286-
1287- if (Args.hasArg (OPT_enable_experimental_cxx_interop)) {
1288- Diags.diagnose (SourceLoc (), diag::enable_interop_flag_deprecated);
1289- Diags.diagnose (SourceLoc (), diag::swift_will_maintain_compat);
1290- Opts.EnableCXXInterop |= true ;
1291- // Using the deprecated option only forces the 'swift-5.9' compat
1292- // mode.
1293- if (Opts.cxxInteropCompatVersion .empty ())
1294- Opts.cxxInteropCompatVersion =
1295- validateCxxInteropCompatibilityMode (" swift-5.9" ).second ;
1296- }
1300+
1301+ Opts.setCxxInteropFromArgs (Args, Diags);
12971302
12981303 Opts.EnableObjCInterop =
12991304 Args.hasFlag (OPT_enable_objc_interop, OPT_disable_objc_interop,
0 commit comments