Fixes #71226
Change-Id: I91c46a4310a9c7a9fcd1e3a131ca16e46949edb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/642235
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
+extern size_t _GoStringLen(_GoString_ s);
+extern const char *_GoStringPtr(_GoString_ s);
#endif
#endif
--- /dev/null
+// 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 -Wimplicit-function-declaration
+
+#include <stdio.h>
+
+static void CFn(_GoString_ gostr) {
+ printf("%.*s\n", _GoStringLen(gostr), _GoStringPtr(gostr));
+}
+*/
+import "C"
+
+func main() {
+ C.CFn("hello, world")
+}
+
+// The bug only occurs if there is an exported function.
+//export Fn
+func Fn() {
+}