Skip to content

runtime/cgo: does not build with -Wdeclaration-after-statement #71961

Closed
@ianlancetaylor

Description

@ianlancetaylor

Go version

HEAD

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/iant/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/iant/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build182329227=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/iant/go/src/go.mod'
GOMODCACHE='/home/iant/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/iant/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org'
GOROOT='/home/iant/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/iant/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/iant/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.25-778a558d08 Tue Feb 25 09:37:58 2025 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

CGO_CFLAGS=-Wdeclaration-after-statement go build runtime/cgo

What did you see happen?

# runtime/cgo
gcc_libinit.c: In function ‘x_cgo_sys_thread_create’:
gcc_libinit.c:45:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
   45 |         int err = _cgo_try_pthread_create(&p, &attr, func, arg);
      |         ^~~
gcc_libinit.c: In function ‘_cgo_wait_runtime_init_done’:
gcc_libinit.c:57:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
   57 |         int done = 2;
      |         ^~~
cc1: all warnings being treated as errors

What did you expect to see?

I did not expect to see any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions