]> Cypherpunks.ru repositories - gostls13.git/commitdiff
doc: update unsafe.Pointer rule in spec
authorRobert Griesemer <gri@golang.org>
Tue, 19 Dec 2023 21:32:07 +0000 (13:32 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 20 Dec 2023 02:18:50 +0000 (02:18 +0000)
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 #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>

doc/go_spec.html

index f68441e664b4caeb62b0f08e9f1c7921ae12104e..89ab2d35d1e432d2bc1b7b908443ac71197aa751 100644 (file)
@@ -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"
 }-->
 
@@ -8232,8 +8232,8 @@ of if the general conversion rules take care of this.
 <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>
 
@@ -8244,6 +8244,10 @@ bits = *(*uint64)(unsafe.Pointer(&amp;f))
 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>