@@ -2598,34 +2598,30 @@ namespace {
25982598 result->addMember (ctor);
25992599 }
26002600 } else {
2601- if (!Impl.SwiftContext .LangOpts .hasFeature (
2602- Feature::SuppressCXXForeignReferenceTypeInitializers)) {
2603- assert (
2604- isa<ClassDecl>(result) &&
2605- " Expected result to be a ClassDecl as it cannot be a StructDecl" );
2606- // When we add full support for C foreign reference types then we
2607- // should synthesize static factories for them as well
2608- if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
2609- bool hasUserProvidedStaticFactory = llvm::any_of (
2610- cxxRecordDecl->methods (),
2611- [](const clang::CXXMethodDecl *method) {
2612- return method->isStatic () &&
2613- llvm::any_of (
2614- method->specific_attrs <clang::SwiftNameAttr>(),
2615- [](const auto *attr) {
2616- return attr->getName ().starts_with (" init(" );
2617- });
2618- });
2619- if (!hasUserProvidedStaticFactory) {
2620- auto generatedCxxMethodDecls =
2621- synthesizer.synthesizeStaticFactoryForCXXForeignRef (
2622- cxxRecordDecl);
2623- for (auto *methodDecl : generatedCxxMethodDecls) {
2624- if (Decl *importedInitDecl =
2625- Impl.SwiftContext .getClangModuleLoader ()
2626- ->importDeclDirectly (methodDecl))
2627- result->addMember (importedInitDecl);
2628- }
2601+ assert (
2602+ isa<ClassDecl>(result) &&
2603+ " Expected result to be a ClassDecl as it cannot be a StructDecl" );
2604+ // When we add full support for C foreign reference types then we
2605+ // should synthesize static factories for them as well
2606+ if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
2607+ bool hasUserProvidedStaticFactory = llvm::any_of (
2608+ cxxRecordDecl->methods (), [](const clang::CXXMethodDecl *method) {
2609+ return method->isStatic () &&
2610+ llvm::any_of (
2611+ method->specific_attrs <clang::SwiftNameAttr>(),
2612+ [](const auto *attr) {
2613+ return attr->getName ().starts_with (" init(" );
2614+ });
2615+ });
2616+ if (!hasUserProvidedStaticFactory) {
2617+ auto generatedCxxMethodDecls =
2618+ synthesizer.synthesizeStaticFactoryForCXXForeignRef (
2619+ cxxRecordDecl);
2620+ for (auto *methodDecl : generatedCxxMethodDecls) {
2621+ if (Decl *importedInitDecl =
2622+ Impl.SwiftContext .getClangModuleLoader ()
2623+ ->importDeclDirectly (methodDecl))
2624+ result->addMember (importedInitDecl);
26292625 }
26302626 }
26312627 }
0 commit comments