From a2a2c5b947263ee9328674d229892841197a0a94 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 19 Dec 2023 13:32:07 -0800 Subject: [PATCH] doc: update unsafe.Pointer rule in spec 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 Reviewed-by: Robert Griesemer Reviewed-by: Matthew Dempsky TryBot-Bypass: Robert Griesemer --- doc/go_spec.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index f68441e664b..89ab2d35d1e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -8232,8 +8232,8 @@ of if the general conversion rules take care of this.

A Pointer is a pointer type but a Pointer value may not be dereferenced. -Any pointer or value of underlying type uintptr can be -converted to a type of underlying type Pointer and vice versa. +Any pointer or value of core type uintptr can be +converted to a type of core type Pointer and vice versa. The effect of converting between Pointer and uintptr is implementation-defined.

@@ -8244,6 +8244,10 @@ bits = *(*uint64)(unsafe.Pointer(&f)) type ptr unsafe.Pointer bits = *(*uint64)(ptr(&f)) +func f[P ~*B, B any](p P) uintptr { + return uintptr(unsafe.Pointer(p)) +} + var p ptr = nil