Skip to content

Commit

Permalink
doc: update unsafe.Pointer rule in spec
Browse files Browse the repository at this point in the history
The valid conversions consider the core types of operands, not just
their underlying type.

This also explains the valid arguments for unsafe.Slice which are
explained in terms of unsafe.Pointer conversions.

unsafe.SliceData simply refers to "slice argument" and we use
similar terminology elsewhere in the spec to denote values that
have a core type of slice (or any other type for that matter).
Leaving alone for now.

Fixes golang#64452.

Change-Id: I0eed3abbc0606f22358835e5d434f026fe0909c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/551379
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
  • Loading branch information
griesemer authored and ezz-no committed Feb 17, 2024
1 parent 65753ec commit 0011591
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of Nov 1, 2023",
"Subtitle": "Version of Dec 19, 2023",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -8232,8 +8232,8 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
<p>
A <code>Pointer</code> is a <a href="#Pointer_types">pointer type</a> but a <code>Pointer</code>
value may not be <a href="#Address_operators">dereferenced</a>.
Any pointer or value of <a href="#Underlying_types">underlying type</a> <code>uintptr</code> can be
<a href="#Conversions">converted</a> to a type of underlying type <code>Pointer</code> and vice versa.
Any pointer or value of <a href="#Core_types">core type</a> <code>uintptr</code> can be
<a href="#Conversions">converted</a> to a type of core type <code>Pointer</code> and vice versa.
The effect of converting between <code>Pointer</code> and <code>uintptr</code> is implementation-defined.
</p>

Expand All @@ -8244,6 +8244,10 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
type ptr unsafe.Pointer
bits = *(*uint64)(ptr(&amp;f))

func f[P ~*B, B any](p P) uintptr {
return uintptr(unsafe.Pointer(p))
}

var p ptr = nil
</pre>

Expand Down

0 comments on commit 0011591

Please sign in to comment.