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

staticcheck: cgo: SA4000 false positive on generated 0 == 0 #430

Closed
sergefdrv opened this issue Mar 27, 2019 · 5 comments
Closed

staticcheck: cgo: SA4000 false positive on generated 0 == 0 #430

sergefdrv opened this issue Mar 27, 2019 · 5 comments

Comments

@sergefdrv
Copy link

This code

package pkg

// void foo(void **p) {}
import "C"
import "unsafe"

func Foo() {
	var p unsafe.Pointer

	C.foo(&p)
}

gives a false positive error identical expressions on the left and right side of the '==' operator (SA4000) pointing beyond the end of the line C.foo(&p).

The reason is that cgo generates the following Go code

// Code generated by cmd/cgo; DO NOT EDIT.

//line test.go:1:1
package pkg

// void foo(void **p) {}
import _ "unsafe"
import "unsafe"

func Foo() {
	var p unsafe.Pointer

	func() { _cgoBase0 := /*line :10:8*/&p; _cgo0 := _cgoBase0; _cgoCheckPointer(_cgoBase0, 0 == 0); _Cfunc_foo(_cgo0); }()
}

So staticcheck actually complains on 0 == 0 expression generated by cgo.

@sergefdrv
Copy link
Author

I was thinking for a moment that this can be a fault of cgo generating the offending code. But it might actually be a bit more complicated.

@ainar-g
Copy link
Contributor

ainar-g commented Mar 27, 2019

When will the evils of shadowing end?

@dominikh
Copy link
Owner

When will the evils of shadowing end?

Part of me wishes for a way to refer to outer scopes, and the universe scope, explicitly. But I worry that would only make things worse :-)

@ainar-g
Copy link
Contributor

ainar-g commented Mar 28, 2019

@dominikh You can kind–of–sort–of do that. See my comment on the Go issue tracker. Stinky, but works.

@sergefdrv
Copy link
Author

@dominikh Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants