summaryrefslogtreecommitdiff
path: root/misc/cgo
diff options
context:
space:
mode:
authorsnyh <snyh@snyh.org>2014-07-18 02:47:21 -0400
committersnyh <snyh@snyh.org>2014-07-18 02:47:21 -0400
commit1e08d624017fafdff66db1db283bb510a4f69db7 (patch)
tree2ed14c35fed781d04265da471ee2bb4504257e0e /misc/cgo
parentca66322e6f510d19ff89f39a7e538fd9b80c0e62 (diff)
downloadgo-1e08d624017fafdff66db1db283bb510a4f69db7.tar.gz
cmd/cgo: disable inappropriate warnings when the gcc struct is empty
package main //#cgo CFLAGS: -Wall //void test() {} import "C" func main() { C.test() } This code will cause gcc issuing warnings about unused variable. This commit use offset of the second return value of Packages.structType to detect whether the gcc struct is empty, and if it's directly invoke the C function instead of writing an unused code. LGTM=dave, minux R=golang-codereviews, iant, minux, dave CC=golang-codereviews https://codereview.appspot.com/109640045 Committer: Shenghou Ma <minux@golang.org>
Diffstat (limited to 'misc/cgo')
-rw-r--r--misc/cgo/test/empty.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/misc/cgo/test/empty.go b/misc/cgo/test/empty.go
new file mode 100644
index 000000000..daa748549
--- /dev/null
+++ b/misc/cgo/test/empty.go
@@ -0,0 +1,18 @@
+// Copyright 2014 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 cgotest
+
+/*
+#cgo CFLAGS: -Werror=unused-variable
+void funcWithoutAnyParams() {}
+*/
+import "C"
+
+// Only test whether this can be compiled, unused
+// variable (e.g. empty gcc strut) could cause
+// warning/error under stricter CFLAGS.
+func testEmptyGccStruct() {
+ C.funcWithoutAnyParams()
+}