Skip to content

cmd/gc: failure to detect set but not used variable captured by anon func #10286

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

Closed
davecheney opened this issue Mar 30, 2015 · 3 comments
Closed

Comments

@davecheney
Copy link
Contributor

For this function

package main

func f(fn func() error) error {
        return fn()
}

func main() {
        called := false
        f(func() error {
                called = true
                return nil
        })

}

gc considers called to be both set and used although nowhere in the scope is the value of called ever consulted.

gccgo-5.0 on the other hand considers this code to be faulty

% env LD_LIBRARY_PATH=/opt/gccgo/lib64 PATH=$PATH:/opt/gccgo/bin go build -compiler=gccgo /tmp/x.go
# command-line-arguments
/tmp/x.go:8:2: error: ‘called’ declared and not used
  called := false
  ^

gccgo version

% env LD_LIBRARY_PATH=/opt/gccgo/lib64 PATH=$PATH:/opt/gccgo/bin gccgo -v
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/opt/gccgo/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/trunk/configure --prefix=/opt/gccgo --enable-languages=c,c++,go --disable-bootstrap
Thread model: posix
gcc version 5.0.0 20150324 (experimental) (GCC) 
@minux
Copy link
Member

minux commented Mar 30, 2015 via email

@davecheney
Copy link
Contributor Author

Yup, its a duplicate.

@minux
Copy link
Member

minux commented Mar 30, 2015

(I assume you reopened this issue accidentally.)

@minux minux closed this as completed Mar 30, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 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

3 participants