Skip to content
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: allow P(x) with type P unsafe.Pointer #4679

Closed
griesemer opened this issue Jan 18, 2013 · 4 comments
Closed

spec: allow P(x) with type P unsafe.Pointer #4679

griesemer opened this issue Jan 18, 2013 · 4 comments
Milestone

Comments

@griesemer
Copy link
Contributor

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)
}
@rsc
Copy link
Contributor

rsc commented Jan 22, 2013

Comment 1:

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.

@rsc
Copy link
Contributor

rsc commented Jan 30, 2013

Comment 2:

Labels changed: added priority-later, removed priority-triage, compilerbug, gccgo.

Status changed to Thinking.

@rsc
Copy link
Contributor

rsc commented Feb 9, 2013

Comment 3:

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Feb 9, 2013

Comment 4:

This issue was closed by revision 81eb930.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants