compiler: alignof(func) is 1 pointer, not 2

This ensures that an embedded [0]func() never ends up being larger
than 1 pointer, which is requried by protobuf processing code.
This commit is contained in:
Steven Kabbes
2022-05-21 04:19:39 -07:00
committed by Ron Evans
parent f308d7d28c
commit 52c61de19f
3 changed files with 14 additions and 6 deletions
+7
View File
@@ -347,6 +347,13 @@ func main() {
println("errorValue.Implements(errorType) was true, expected false")
}
println("\nalignment / offset:")
v2 := struct {
noCompare [0]func()
data byte
}{}
println("struct{[0]func(); byte}:", unsafe.Offsetof(v2.data) == uintptr(unsafe.Pointer(&v2.data))-uintptr(unsafe.Pointer(&v2)))
println("\nstruct tags")
TestStructTag()
+3
View File
@@ -405,6 +405,9 @@ offset for int64 matches: true
offset for complex128 matches: true
type assertion succeeded for unreferenced type
alignment / offset:
struct{[0]func(); byte}: true
struct tags
blue gopher