diff --git a/misc/cgo/errors/issue14669.go b/misc/cgo/errors/issue14669.go new file mode 100644 index 00000000000..04d2bcb631d --- /dev/null +++ b/misc/cgo/errors/issue14669.go @@ -0,0 +1,23 @@ +// Copyright 2016 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. + +// Issue 14669: test that fails when build with CGO_CFLAGS selecting +// optimization. + +package p + +/* +const int E = 1; + +typedef struct s { + int c; +} s; +*/ +import "C" + +func F() { + _ = C.s{ + c: C.E, + } +} diff --git a/misc/cgo/errors/test.bash b/misc/cgo/errors/test.bash index cd358a10f81..643d0382050 100755 --- a/misc/cgo/errors/test.bash +++ b/misc/cgo/errors/test.bash @@ -45,6 +45,13 @@ expect issue13129.go C.ushort check issue13423.go expect issue13635.go C.uchar C.schar C.ushort C.uint C.ulong C.longlong C.ulonglong C.complexfloat C.complexdouble +if ! go build issue14669.go; then + exit 1 +fi +if ! CGO_CFLAGS="-O" go build issue14669.go; then + exit 1 +fi + if ! go run ptr.go; then exit 1 fi diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 97ef824c934..451798244f6 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -1243,12 +1243,20 @@ func (p *Package) gccErrors(stdin []byte) string { // TODO(rsc): require failure args := p.gccCmd() + // Optimization options can confuse the error messages; remove them. + nargs := make([]string, 0, len(args)) + for _, arg := range args { + if !strings.HasPrefix(arg, "-O") { + nargs = append(nargs, arg) + } + } + if *debugGcc { - fmt.Fprintf(os.Stderr, "$ %s <