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

gccgo: does not error on unused var #12317

Closed
dvyukov opened this issue Aug 25, 2015 · 4 comments
Closed

gccgo: does not error on unused var #12317

dvyukov opened this issue Aug 25, 2015 · 4 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Aug 25, 2015

gccgo successfully compiles the following incorrect program:

package a
func g() {
    var f = func() {}
}

Both gc and gotype say:

test.go:3:6: f declared but not used

gofrontend is on commit 81810917af7ba19e1f9f8efc8b1989f7d6419d30

@dvyukov
Copy link
Member Author

dvyukov commented Aug 25, 2015

@ianlancetaylor

@cespare
Copy link
Contributor

cespare commented Aug 25, 2015

That program is not incorrect. From the spec:

Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used.

So gccgo is free to allow the unused var.

I'm not sure whether gccgo disallows other unused vars, though (don't have a gccgo installation available right now).

@paranoiacblack paranoiacblack added this to the Gccgo milestone Aug 25, 2015
@paranoiacblack
Copy link
Contributor

This is a gccgo bug; it doesn't check if variables initialized by a function literal are ever used. I don't think this is on purpose, despite the disclaimer in the specification.

@gopherbot
Copy link

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

pbeeler pushed a commit to SaberMod/GCC_SaberMod that referenced this issue Aug 28, 2015
    
    Fixes golang/go#12317.
    
    Reviewed-on: https://go-review.googlesource.com/13908


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227285 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Sep 4, 2016
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

4 participants