Closed
Description
🐛 Bug Report
Taking address of any element in this slice produces the same value (because the element is an empty struct):
grpc-gateway/runtime/marshaler_registry_test.go
Lines 30 to 52 in 855204b
So, these test cases almost won't work as expected.
As per the last line of golang spec:
A struct or array type has size zero if it contains no fields (or elements, respectively) that have a size greater than zero.
Two distinct zero-size variables may have the same address in memory.
To Reproduce
See the code at playground:
package main
import (
"fmt"
)
type S struct {
}
type T struct {
b bool
}
func main() {
var s [3]S
var t [3]T
fmt.Printf("%p,%p,%p\n", &s[0], &s[1], &s[2])
fmt.Printf("%p,%p,%p\n", &t[0], &t[1], &t[2])
}
Outputs:
0x58fd18,0x58fd18,0x58fd18
0xc00009400b,0xc00009400c,0xc00009400d
Your Environment
Any.
Metadata
Assignees
Labels
No labels