Updates #14839
Fixes #14994
Change-Id: I9bb51bad19105a17c80d690c5486e5dd007ac84a
Reviewed-on: https://go-review.googlesource.com/21222
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
}
}
-// checkCopyLocksCallExpr detects lock copy in function call
+// checkCopyLocksCallExpr detects lock copy in the arguments to a function call
func checkCopyLocksCallExpr(f *File, ce *ast.CallExpr) {
+ if id, ok := ce.Fun.(*ast.Ident); ok && id.Name == "new" && f.pkg.types[id].IsBuiltin() {
+ // Skip 'new(Type)' for built-in 'new'
+ return
+ }
for _, x := range ce.Args {
if path := lockPathRhs(f, x); path != nil {
f.Badf(x.Pos(), "function call copies lock value: %v", path)
}
yy := []Tlock{
- sync.Tlock{},
- sync.Tlock{
+ Tlock{},
+ Tlock{
once: sync.Once{},
},
}
+
+ nl := new(sync.Mutex)
+ mx := make([]sync.Mutex, 10)
+ xx := struct{ L *sync.Mutex }{
+ L: new(sync.Mutex),
+ }
}
type Tlock struct {
t, // ERROR "literal copies lock value from t: testdata.Tlock contains sync.Once contains sync.Mutex"
*tp, // ERROR "literal copies lock value from \*tp: testdata.Tlock contains sync.Once contains sync.Mutex"
}
+
+ // override 'new' keyword
+ new := func(interface{}) {}
+ new(t) // ERROR "function call copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
}