Otherwise, vet might have false positives when "C" is a variable and
we're just using a method on it. Or when an import was renamed to "C".
Add test files for both of these cases.
Fixes #20655.
Change-Id: I55fb93119444a67fcf7891ad92653678cbd4670e
Reviewed-on: https://go-review.googlesource.com/45551
Run-TryBot: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
return
}
id, ok := sel.X.(*ast.Ident)
- if !ok || id.Name != "C" {
+ if !ok {
+ return
+ }
+
+ pkgname, ok := f.pkg.uses[id].(*types.PkgName)
+ if !ok || pkgname.Imported().Path() != "C" {
return
}
package testdata
var _ = C.f(*p(**p))
+
+// Passing a pointer (via the slice), but C isn't cgo.
+var _ = C.f([]int{3})
--- /dev/null
+// Copyright 2017 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.
+
+// Test the cgo checker on a file that doesn't use cgo, but has an
+// import named "C".
+
+package testdata
+
+import C "fmt"
+
+var _ = C.Println(*p(**p))
+
+// Passing a pointer (via a slice), but C is fmt, not cgo.
+var _ = C.Println([]int{3})