Skip to content

[cxx-interop] Add conversion to Bool for types that define operator bool() #68578

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
Oct 5, 2023

Conversation

egorzhdan
Copy link
Contributor

C++ operator bool() is currently imported into Swift as __convertToBool(), which shouldn't be used by clients directly.

This adds a new protocol into the C++ stdlib overlay: CxxConvertibleToBool, along with an intitializer for Swift.Bool taking an instance of CxxConvertibleToBool.

rdar://115074954

…bool()`

C++ `operator bool()` is currently imported into Swift as `__convertToBool()`, which shouldn't be used by clients directly.

This adds a new protocol into the C++ stdlib overlay: `CxxConvertibleToBool`, along with an intitializer for `Swift.Bool` taking an instance of `CxxConvertibleToBool`.

rdar://115074954
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Sep 18, 2023
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@hyp
Copy link
Contributor

hyp commented Sep 25, 2023

can this be done without the fromCxx label?

@egorzhdan
Copy link
Contributor Author

I think it's safer to keep the fromCxx label for now, to prevent accidental source breakages if an Obj-C type defines operator bool() under #ifdef __cplusplus. I chose fromCxx as a label to keep it consistent with Optional.init(fromCxx:). We can always add an initializer without a label later and deprecate the one with the label.

@egorzhdan
Copy link
Contributor Author

Briefly discussed this offline with Karoy.

@egorzhdan egorzhdan merged commit 0b2048d into main Oct 5, 2023
@egorzhdan egorzhdan deleted the egorzhdan/cxx-convertible-to-bool branch October 5, 2023 14:52
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