Skip to content

cmd/compile: zero-sized type increases size of struct when it's used as a field #58483

Closed
@badisch87

Description

@badisch87

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

$ go version
go version go1.20 windows/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
...
set GOARCH=amd64
...
set GOHOSTARCH=amd64
set GOHOSTOS=windows
...
set GOOS=windows
...

What did you do?

package main

import (
	"fmt"
	"unsafe"
)

type s1 struct {
	a uint16
}

type s2 struct {
	a uint16
	_ [0]int16
}

func main() {
	fmt.Println(unsafe.Sizeof(s1{}))
	fmt.Println(unsafe.Sizeof(s2{}))
}

What did you expect to see?

2
2

What did you see instead?

2
4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions