From bf351677c4c134f15d28cf5352964838609de129 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 10 Jan 2025 16:22:20 -0800 Subject: [PATCH] cmd/cgo: add C declaration parameter unused attribute Fixes #71225 Change-Id: I3e60fdf632f2aa0e63b24225f13e4ace49906925 Reviewed-on: https://go-review.googlesource.com/c/go/+/642196 Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/out.go | 2 +- test/fixedbugs/issue71225.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue71225.go diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 5e67cc2d33..b3e4c7ccdf 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -1094,7 +1094,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { // This unpacks the argument struct above and calls the Go function. fmt.Fprintf(fgo2, "func _cgoexp%s_%s(a *%s) {\n", cPrefix, exp.ExpName, gotype) - fmt.Fprintf(fm, "void _cgoexp%s_%s(void* p){}\n", cPrefix, exp.ExpName) + fmt.Fprintf(fm, "void _cgoexp%s_%s(void* p __attribute__((unused))){}\n", cPrefix, exp.ExpName) fmt.Fprintf(fgo2, "\t") diff --git a/test/fixedbugs/issue71225.go b/test/fixedbugs/issue71225.go new file mode 100644 index 0000000000..8a6b313eda --- /dev/null +++ b/test/fixedbugs/issue71225.go @@ -0,0 +1,19 @@ +// build + +//go:build cgo + +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// #cgo CFLAGS: -Werror -Wunused-parameter +import "C" + +func main() { +} + +//export Fn +func Fn() { +} -- 2.51.0