//go:build go1.22 //golangcitest:args -Ecopyloopvar package testdata /* #include #include void myprint(char* s) { printf("%d\n", s); } */ import "C" import ( "fmt" "unsafe" ) func _() { cs := C.CString("Hello from stdio\n") C.myprint(cs) C.free(unsafe.Pointer(cs)) } func copyloopvarCase2() { loopCount := 3 fns := make([]func(), 0, loopCount) for i := 1; i <= loopCount; i++ { i := i // want `The copy of the 'for' variable "i" can be deleted \(Go 1\.22\+\)` fns = append(fns, func() { fmt.Println(i) }) } for _, fn := range fns { fn() } }