You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"unsafe"
)
varxintconstsz=unsafe.Sizeof(func() int { x++; return0 }())
funcmain() {
println(x)
}
My reading of the spec says this should print 1, but it prints 0.
Relevant bits of the spec:
The functions Alignof and Sizeof take an expression x of any type and return the alignment or size, respectively, of a hypothetical variable v as if v was declared via var v = x.
So we should be evaluating the function expression, as if it were the RHS of an expression, at which point const sz should be evaluated before var x, thus incrementing x.
Seems low priority. If we investigate fixing, we should test handling of iota inside function bodies.
https://play.golang.org/p/5VUF7XrYjp
My reading of the spec says this should print 1, but it prints 0.
Relevant bits of the spec:
So we should be evaluating the function expression, as if it were the RHS of an expression, at which point const sz should be evaluated before var x, thus incrementing x.
Seems low priority. If we investigate fixing, we should test handling of iota inside function bodies.
Related: #20260
The text was updated successfully, but these errors were encountered: