@@ -2381,18 +2381,30 @@ namespace {
2381
2381
hasMemberwiseInitializer = false ;
2382
2382
}
2383
2383
2384
- if (hasZeroInitializableStorage &&
2385
- !(cxxRecordDecl && cxxRecordDecl->hasDefaultConstructor ())) {
2386
- // Add default constructor for the struct if compiling in C mode.
2387
- // If we're compiling for C++:
2388
- // 1. If a default constructor is declared, don't synthesize one.
2389
- // 2. If a default constructor is deleted, don't try to synthesize one.
2390
- // 3. If there is no default constructor, synthesize a C-like default
2391
- // constructor that zero-initializes the backing memory of the
2392
- // struct. This is important to maintain source compatibility when a
2393
- // client enables C++ interop in an existing project that uses C
2394
- // interop and might rely on the fact that C structs have a default
2395
- // constructor available in Swift.
2384
+ // Add default constructor for the struct if compiling in C mode.
2385
+ // If we're compiling for C++:
2386
+ // 1. If a default constructor is declared, don't synthesize one.
2387
+ // 2. If a default constructor is deleted, don't try to synthesize one.
2388
+ // 3. If there is no default constructor, synthesize a C-like default
2389
+ // constructor that zero-initializes the backing memory of the
2390
+ // struct. This is important to maintain source compatibility when a
2391
+ // client enables C++ interop in an existing project that uses C
2392
+ // interop and might rely on the fact that C structs have a default
2393
+ // constructor available in Swift.
2394
+ bool needsEmptyInitializer = true ;
2395
+ if (cxxRecordDecl) {
2396
+ if (auto structResult = dyn_cast<StructDecl>(result)) {
2397
+ for (auto member : structResult->getMembers ()) {
2398
+ if (auto constructorDecl = dyn_cast<ConstructorDecl>(member)) {
2399
+ if (constructorDecl->getParameters ()->size () == 0 ) {
2400
+ needsEmptyInitializer = false ;
2401
+ break ;
2402
+ }
2403
+ }
2404
+ }
2405
+ }
2406
+ }
2407
+ if (hasZeroInitializableStorage && needsEmptyInitializer) {
2396
2408
ConstructorDecl *defaultCtor =
2397
2409
synthesizer.createDefaultConstructor (result);
2398
2410
ctors.push_back (defaultCtor);
0 commit comments