Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: go build failed on _cgo_main.c if there's '#cgo CFLAGS: -W -Werror' in cgo preamble #43639

Closed
hzzb opened this issue Jan 12, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hzzb
Copy link
Contributor

hzzb commented Jan 12, 2021

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

$ go version
go version go1.12.8 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hans/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hans/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hans/github.com/hzzb/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/42/38j1_hsd0ql20_c0g6hcgxww0000gn/T/go-build122131844=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

demo code: https://play.golang.org/p/JybuNyX-bqf

cd to the package directory containing above two files and run go build

What did you expect to see?

go build ran successfully and nothing outputted

What did you see instead?

_cgo_main.c:2:23: error: unused parameter 'fn' [-Werror,-Wunused-parameter]
_cgo_main.c:2:61: error: unused parameter 'a' [-Werror,-Wunused-parameter]
_cgo_main.c:2:68: error: unused parameter 'c' [-Werror,-Wunused-parameter]
_cgo_main.c:2:85: error: unused parameter 'ctxt' [-Werror,-Wunused-parameter]
_cgo_main.c:4:41: error: unused parameter 'ctxt' [-Werror,-Wunused-parameter]
_cgo_main.c:6:26: error: unused parameter 'a' [-Werror,-Wunused-parameter]
_cgo_main.c:6:33: error: unused parameter 'c' [-Werror,-Wunused-parameter]
_cgo_main.c:7:23: error: unused parameter 'a' [-Werror,-Wunused-parameter]
_cgo_main.c:7:30: error: unused parameter 'c' [-Werror,-Wunused-parameter]

hzzb added a commit to hzzb/go that referenced this issue Jan 12, 2021
Applying -Werror compiler option to request warnings is an usual
way to discover potential errors. Go user may put a cgo directive
in preamble: `// #cgo CFLAGS: -Werror=unused-parameter`.

However, the directive also takes effect on the cgo generated files.
I cleaned _cgo_main.c to help Go user only concentrate on warnings
of their own file.

Fixes golang#43639
@gopherbot
Copy link

Change https://golang.org/cl/283232 mentions this issue: cmd/cgo: fix unused parameter warnings in generated _cgo_main.c

hzzb added a commit to hzzb/go that referenced this issue Jan 12, 2021
Applying -Werror compiler option to request warnings is an usual
way to discover potential errors. Go user may put a cgo directive
in preamble: `// #cgo CFLAGS: -Werror=unused-parameter`.

However, the directive also takes effect on the cgo generated files.
I cleaned _cgo_main.c to help Go user only concentrate on warnings
of their own file.

Fixes golang#43639
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 12, 2021
@bcmills bcmills added this to the Backlog milestone Jan 12, 2021
@gopherbot
Copy link

Change https://golang.org/cl/322232 mentions this issue: Cmd/cgo/fix unused parameter warning

@golang golang locked and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
3 participants