-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Warn on implicit raw pointer conversion to non-bitwise-copyable values #63825
Conversation
@swift-ci test |
@swift-ci toolchain |
@swift-ci test source compatibility |
@swift-ci Please Build Toolchain macOS Platform |
d65a6a4
to
6cf0e2e
Compare
@swift-ci test |
@swift-ci Please Build Toolchain macOS Platform |
@swift-ci test source compatibility |
6cf0e2e
to
54f7aad
Compare
@swift-ci test |
54f7aad
to
9b30bff
Compare
@swift-ci smoke test |
9b30bff
to
1ecc3f8
Compare
@swift-ci smoke test |
@swift-ci smoke test macOS platform |
@swift-ci build toolchain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sema related changes look good to me!
1ecc3f8
to
2c60527
Compare
@swift-ci test |
This is also needed in SIL diagnostics, not just Sema diagnostics, because implicit Array conversion generates special SIL patterns.
Fixes a usability problem with implicit inout conversion to raw pointers. For example, supporting this conversion turns out to be bad: void read_void(const void *input); func foo(data: inout Data) { read_void(&data) } People understandably expect Foundation.Data to have the same sort of implicit conversion as Array. But it does something very wrong instead. We could have added an an attribute to Data and other copy-on-write containers to selectively suppress implicit conversion. But there is no good reason to allow implicit conversion from any non-trivial type. It is extremely dangerous, and almost always accidental. Note that this problem becomes worse now that the compiler views imported `char *` arguments as raw pointers. For example: void read_char(const char *input); var object: AnyObject = ... read_void(&object1) This seems like a good time to correct this old Swift 3 behavior. Plan: Add a warning now. Convert it to an error in Swift 6 language mode based on feedback. Fixes rdar://97963116 (It's really easy to accidentally corrupt a Data object with the & operator)
2c60527
to
a354f26
Compare
@swift-ci test |
@swift-ci toolchain |
@swift-ci test source compatibility |
@swift-ci smoke test |
Fixes a usability problem with implicit inout conversion to raw pointers.