Skip to content

[stdlib] Clean up some more unsafeBitCast warnings #7329

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

Closed

Conversation

natecook1000
Copy link
Member

This cleans up (I think) the remainder of the warnings that fell out of the improved unsafeBitcast. 🤞

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test Linux platform

@natecook1000
Copy link
Member Author

Ah, beaten to the punch by #7314

@natecook1000 natecook1000 deleted the nc-bitcast-warnings branch February 8, 2017 20:16
return withUnsafePointer(to: &bytes) {
return NSUUID(uuidBytes: unsafeBitCast($0, to: UnsafePointer<UInt8>.self))
return withUnsafeMutablePointer(to: &bytes, as: UInt8.self, capacity: MemoryLayout.size(ofValue: bytes)) {
return NSUUID(uuidBytes: $0)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know about that form of withUnsafePointer. That might be a better recommendation for the compiler to emit a warning for when bitcasting from a homogeneous tuple to its element type. Mind filing a bug for that diagnostic improvement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was one I'd written just for UUID.swift since it has so many of the two operations together (convert to pointer and then cast). It's here—could be a nice addition, but I don't know that it's necessary: https://github.com/apple/swift/pull/7329/files/cf260a26173985f867fb33cf52c808ec481aad44#diff-9e8b701cacc2a5ba71da8979a386a127R16

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that. It does seem like a generally useful variant.

@moiseev
Copy link
Contributor

moiseev commented Feb 9, 2017

Oops. Sorry =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants