You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program compiles and runs (both gc and gccgo):
package main
import "unsafe"
type P unsafe.Pointer
func main() {
var x uintptr
_ = P(x)
}
The conversion P(x) should not be legal. According to the spec (
http://tip.golang.org/ref/spec#Package_unsafe ):
"Any pointer or value of underlying type uintptr can be converted into a Pointer
and vice versa."
It does not say "into a (unsafe.)Pointer type" - only _the_ (unsafe.)Pointer
type.
It also opens the door for unsafe-ness to escape. With:
package safe
import "unsafe"
type Pointer unsafe.Pointer
One can now write:
package main
import "safe"
func main() {
var x uintptr
_ = safe.Pointer(x)
}
The text was updated successfully, but these errors were encountered:
For what it's worth, Ian and I discussed this at some point in the past and
interpreted the spec as meaning the current behavior. (I think one can read
"a Pointer" as "a value of an unsafe.Pointer type".) Gccgo originally
behaved as requested in this bug, but Ian changed it to match 6g. The
reflect package uses this functionality. It would not be hard to remove but
I also wonder if others are using it. To avoid breaking things, I am
inclined to reword the spec to match what the two compilers do.
The text was updated successfully, but these errors were encountered: