-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: empty struct addresses are not equal #23370
Comments
You are comparing addresses of empty structs. If you compare values, then it returns true. |
@mvdan the OPs example prints true in previous versions of Go. They want to know if this change was intentional, or a bug. |
I did not get that impression from reading the post, my apologies. |
The title is misleading. You're not comparing empty structs, you are comparing the addresses of two Also your expectations are incorrect. The two addresses does not need to be equal. The spec says:
So both |
I'd argue that it doesn't really matter whether the change (which btw was introduced in go1.6, the first version that prints |
Two distinct zero-size variables may have the same address in memory. |
Yes, this is working as intended per the spec, as others have pointed out. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN="/vagrant/gopath/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/vagrant/gopath"
GORACE=""
GOROOT="/vagrant/go"
GOTOOLDIR="/vagrant/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build779422972=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
code link: https://play.golang.org/p/zUnW3LHCCbi.
What did you expect to see?
Print
true
.What did you see instead?
Print
false
. Go with version 1.3.3 printstrue
but 1.9 printfalse
. Is this reasonable or a bug?The text was updated successfully, but these errors were encountered: