blob: 34d944ce970dc873cd9e53e898b3f656df6081a7 [file] [log] [blame] [edit]
This test checks for the correct suppression (or activation) of the
non-constant format string check (golang/go#60529), in a go1.24 module.
See golang/go#71485 for details.
-- go.mod --
module example.com/nonconst
go 1.24
-- nonconst.go --
package nonconst
import (
"fmt"
"log"
"os"
)
func _(s string) {
fmt.Printf(s) // want `non-constant format string in call to fmt.Printf`
fmt.Printf(s, "arg")
fmt.Fprintf(os.Stderr, s) // want `non-constant format string in call to fmt.Fprintf`
log.Printf(s) // want `non-constant format string in call to log.Printf`
}
-- nonconst.go.golden --
package nonconst
import (
"fmt"
"log"
"os"
)
func _(s string) {
fmt.Printf("%s", s) // want `non-constant format string in call to fmt.Printf`
fmt.Printf(s, "arg")
fmt.Fprintf(os.Stderr, "%s", s) // want `non-constant format string in call to fmt.Fprintf`
log.Printf("%s", s) // want `non-constant format string in call to log.Printf`
}
-- nonconst_go123.go --
//go:build go1.23
package nonconst
import (
"fmt"
"log"
"os"
)
// The analyzer should be silent, as this is a go1.23 file.
func _(s string) {
fmt.Printf(s)
fmt.Printf(s, "arg")
fmt.Fprintf(os.Stderr, s)
log.Printf(s)
}