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

unsafe: Alignof, Offsetof, Sizeof documentation does not account for variable-size types #53921

Closed
zephyrtronium opened this issue Jul 16, 2022 · 1 comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zephyrtronium
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

yes (master)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zephyr/.cache/go-build"
GOENV="/home/zephyr/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zephyr/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zephyr/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1655306045=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go doc unsafe.Sizeof

What did you expect to see?

A statement that variables whose types are or contain type parameters have variable size, and so Alignof, Offsetof, and Sizeof are not constant expressions in those cases.

What did you see instead?

The return value of Sizeof is a Go constant.

This implies that https://go.dev/play/p/ZcHTDWGcQgG should compile, but it does not.

Partially related: #40322

@gopherbot please add label Documentation

@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jul 16, 2022
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 16, 2022
@gopherbot
Copy link

Change https://go.dev/cl/417917 mentions this issue: unsafe: document when Sizeof/Offsetof/Alignof are not constant

jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
They are not constant if their arguments have types that are variable size.

Fixes golang#53921

Change-Id: I2d46754c27f55a281331c099a11ea3cd85ec4e89
Reviewed-on: https://go-review.googlesource.com/c/go/+/417917
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants