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

cmd/compile: unsafe.Pointer not treated as a pointer for embedding #6357

Open
griesemer opened this issue Sep 10, 2013 · 4 comments

Comments

@griesemer
Copy link
Contributor

commented Sep 10, 2013

http://play.golang.org/p/YhdG1ZoVzp

Per the spec: "An embedded type must be specified as a type name T or as a pointer
to a non-interface type name *T, and T itself may not be a pointer type."  (
http://tip.golang.org/ref/spec#Struct_types )

gc issues an error for line 9 (as expected), but not for line 10. Arguably, an
unsafe.Pointer is a pointer and thus line 10 should not be legal.

The spec is not very clear about whether an unsafe.Pointer should act like a pointer in
these situations, but:

1. The documentation (by pseudo code) defines unsafe.Pointer as *ArbitraryType (
http://tip.golang.org/ref/spec#Package_unsafe )

2. For the purposes of method receivers, they are treated as pointers (see issue #6116)

3. It's ok to assign nil to it (see line 15 of the above code).

4. It's called a "Pointer".
@griesemer

This comment has been minimized.

Copy link
Contributor Author

commented Sep 10, 2013

Comment 1:

PS: gccgo reports an error for line 9 and 10:
x.go:9:6: error: embedded type may not be a pointer
      P1
      ^
x.go:10:6: error: embedded type may not be a pointer
      P2
      ^
@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@rsc rsc removed the compiler-bug label Apr 10, 2015

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

@rsc rsc changed the title cmd/gc: unsafe.Pointer not treated as a pointer for embedding cmd/compile: unsafe.Pointer not treated as a pointer for embedding Jun 8, 2015

tycho added a commit to tycho/go-sdl2 that referenced this issue Dec 26, 2015
sdl_mixer: fix compile error with gccgo
With gccgo I was getting this:

    $ go build
    # github.com/veandco/go-sdl2/sdl_mixer
    ./sdl_mixer.go:83:2: error: embedded type may not be a pointer
      unsafe.Pointer
      ^

Apparently upstream Go hasn't yet added the above error[1].

Fixes veandco#167.

[1] golang/go#6357

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.