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

x/tools/cmd/stringer: "declared but not used" even though variable is used #20358

Closed
distributed opened this issue May 13, 2017 · 4 comments
Closed

Comments

@distributed
Copy link

What did you do?

Run go generate on the following program:

package main

/*
struct A {
	int flag;
};
*/
import "C"

//go:generate stringer -type Flag
type Flag int

const (
	FlagSet Flag = 1
)

func main() {
	var flag = FlagSet
	A := C.struct_A{
		flag: C.int(flag),
	}
	_ = A
}

What did you expect to see?

I expect go generate to run without error.

What did you see instead?

stringer: checking package: stringercgo.go:18:6: flag declared but not used
stringercgo.go:10: running "stringer": exit status 1

System details

go version go1.8.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/joe/gop"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build547335153=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version go1.8.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.8.1 X:framepointer
uname -sr: Linux 4.8.0-49-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.23-0ubuntu7) stable release version 2.23, by Roland McGrath et al.
gdb --version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
@bradfitz bradfitz changed the title cmd/go/stringer: "declared but not used" even though variable is used x/tools/cmd/stringer: "declared but not used" even though variable is used May 13, 2017
@gopherbot gopherbot added this to the Unreleased milestone May 13, 2017
@bradfitz
Copy link
Contributor

@alandonovan, @griesemer, @mdempsky, is this because go/types doesn't understand cgo?

@griesemer
Copy link
Contributor

@bradfitz Yes, that's the cause. gotype reports the same error. That said, go/types could probably do better here.

Temp. work-around: _ = flag .

@griesemer griesemer assigned griesemer and unassigned alandonovan May 14, 2017
@griesemer griesemer modified the milestones: Go1.9Maybe, Unreleased May 14, 2017
@distributed
Copy link
Author

Thanks for the confirmation.

I'm doing exactly that workaround :)

@gopherbot
Copy link

CL https://golang.org/cl/43500 mentions this issue.

@golang golang locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants