golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.59k stars 17.48k forks source link

cmd/cgo: generated code uses aliases even in modules using Go older than 1.9 #67738

Open dominikh opened 3 months ago

dominikh commented 3 months ago

Go version

go version devel go1.23-722d59436b Thu May 16 02:00:26 2024 +0000 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/dominikh/.cache/go-build'
GOENV='/home/dominikh/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/dominikh/prj/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/dominikh/prj'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/dominikh/prj/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/dominikh/prj/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.23-722d59436b Thu May 16 02:00:26 2024 +0000'
GODEBUG=''
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/foo/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1611460511=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Try to go build

-- foo.go --
package pkg

// #include <stdlib.h>
import "C"

func foo() {
    C.malloc(0)
}
-- go.mod --
module example.com

go 1.0

What did you see happen?

# example.com
$WORK/b001/_cgo_gotypes.go:23:6: type alias requires go1.9 or later (-lang was set to go1; check go.mod)

What did you expect to see?

No failure.

I'm mostly filing this for the sake of documentation, as it's probably not worth fixing. I don't think it negatively impacts any real projects. Any 1.0 module can upgrade to 1.9 (or 1.21, for that matter) without risking backwards incompatible changes. Additionally, any code base targeting a Go version older than 1.9 is unlikely to be a Go module in the first place.

ianlancetaylor commented 3 months ago

Thanks, I don't think this is worth spending time on. If someone wants to send a fix, we can take a look.