Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2023

Conversation

egorzhdan
Copy link
Contributor

Explanation: 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.
Scope: Only takes effect when C++ interop is enabled via a compiler flag.
Risk: Low, this only changes the code path that is specific to C++ interop.

rdar://109727620
(cherry picked from commit fec48f9)

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
(cherry picked from commit fec48f9)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 1, 2023
@egorzhdan egorzhdan requested a review from a team as a code owner June 1, 2023 10:53
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit d62f9cd into release/5.9 Jun 2, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.9-c-default-init branch June 2, 2023 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants