-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
spec: no rules for converting between unsafe.Pointer and *T #68086
Comments
You shouldn't use this API if you want to be safe, because that's how it's used and it doesn't report errors. That's the very practical value of it. You might consider using it this way or staying away from it, but what's wrong with it?
|
@Merovius We probably were (implicitly) assuming that since an |
Change https://go.dev/cl/593755 mentions this issue: |
Based on a golang-nuts thread.
Consider this program:
The spec says about
unsafe.Pointer
:Notably, while this does specify that conversion between
unsafe.Pointer
anduintptr
is implementation-defined, it doesn't contain the same caveat for conversion betweenunsafe.Pointer
and other pointers (like*int
in the example above). So the spec does not give any way to reason about the behavior of the above program - not even that it is implementation defined.The
unsafe.Pointer
rules do of course rule that program out, so the implementation-defined rules do allow us to reason about the program. But, technically speaking, we are not giving it purview to do that.I would propose to change "The effect of converting between Pointer and uintptr is implementation-defined" to "The effect of such conversions is implementation-defined".
The text was updated successfully, but these errors were encountered: