Skip to content

cmd/compile: failure to reject embedding of unsafe.Pointer in struct #14729

@mdempsky

Description

@mdempsky

cmd/compile accepts this invalid Go source file:

package p
import "unsafe"
type s struct { unsafe.Pointer }

gotype and gccgo correctly reject it:

$ gotype p.go
p.go:3:17: anonymous field type cannot be unsafe.Pointer
$ gccgo-4.8 -c p.go
p.go:3:17: error: embedded type may not be a pointer
 type s struct { unsafe.Pointer }
                 ^

The Go spec says:

A field declared with a type but no explicit field name is an anonymous field, also called an embedded field or an embedding of the type in the struct. 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.

And later describing package unsafe:

A Pointer is a pointer type but a Pointer value may not be dereferenced.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions