[cxx-interop] Synthesize a deprecated zero initializer for C++ structs

When importing a C header in the C++ language mode, Clang/Swift treat C structs as C++ structs.

Currently Swift synthesizes a default initializer that zero-initializes the backing memory of the struct for C structs, but not for C++ structs.

This is causing issues in existing projects that use C libraries and rely on having the default initializer available in Swift. This change enables the synthesis of a default initializer for C++ structs. Since many C++ structs are not designed to be initialized this way, the initializer is marked as deprecated in Swift.

rdar://109727620
This commit is contained in:
Egor Zhdan
2023-05-30 19:47:36 +01:00
parent 4920e4af84
commit fec48f9e63
6 changed files with 36 additions and 9 deletions

View File

@@ -438,10 +438,6 @@ synthesizeStructDefaultConstructorBody(AbstractFunctionDecl *afd,
ASTContext &ctx = constructor->getASTContext();
auto structDecl = static_cast<StructDecl *>(context);
// We should call into C++ constructors directly.
assert(!isa<clang::CXXRecordDecl>(structDecl->getClangDecl()) &&
"Should not synthesize a C++ object constructor.");
// Use a builtin to produce a zero initializer, and assign it to self.
// Construct the left-hand reference to self.