Skip to content

🍒[cxx-interop] Tweak C++ type semantics detection #67127

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
Jul 6, 2023

Conversation

egorzhdan
Copy link
Contributor

Explanation: This fixes the handling of types that are move-only and store a pointer at the same time. Swift allowed the usage of these types (under the rules for UnsafePointerMember types) when move-only types are disabled, and did not apply the move-only attribute on such types when move-only types are enabled.
Scope: This changes the way ClangImporter detects the semantics of C++ types.
Risk: Low, this only has an effect when C++ interop is enabled.

Original PR: #67115

rdar://110644300
(cherry picked from commit 6e7fb32)

`CxxRecordSemanticsKind::ExplicitlyUnsafe` and `CxxRecordSemanticsKind::UnsafePointerMember` were never directly used, and those do not indicate semantics: they indicate safety of the type when used from Swift, which should be handled by another request `IsSafeUseOfCxxDecl` instead of `CxxRecordSemantics`.

Having `ExplicitlyUnsafe` and `UnsafePointerMember` as semantics indicators was problematic, for instance, for types that are move-only and store a pointer at the same time. Swift allowed the usage of these types (under the rules for `UnsafePointerMember` types) when move-only types are disabled, and did not apply the move-only attribute on such types when move-only types are enabled.

rdar://110644300
(cherry picked from commit 6e7fb32)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jul 5, 2023
@egorzhdan egorzhdan requested a review from a team as a code owner July 5, 2023 18:55
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit 4b521e3 into release/5.9 Jul 6, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.9-cxx-semantics-kind branch July 6, 2023 11:03
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