Go version

go version go1.24.1 linux/amd64

Output of go env in your module/workspace:

See below for go env run on go1.23.5 and go.24.1.

What did you do?

Go 1.24.1 breaks alot of Go test code that I have had for ages.

I don't know if this is officially covered under the Go 1 compatibility promise, but I feels like it certainly should be. I mean, I have tons of Go test code, written over years and years, from packages that are solid, and now with 1.24.1 those tests won't even compile because of this recent change.

Simple reproducer:

jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go version
go version go1.24.1 linux/amd64
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ cat fmt_test.go
package main

import (
    "fmt"
    "testing"
)

func getString() string {
    return fmt.Sprintf("hello")
}

func TestFmt(t *testing.T) {
    r := getString()
    fmt.Printf(r)
}
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go version
go version go1.24.1 linux/amd64
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go test -v
# github.com/glycerine/fmt_break
# [github.com/glycerine/fmt_break]
./fmt_test.go:14:13: non-constant format string in call to fmt.Printf
FAIL    github.com/glycerine/fmt_break [build failed]
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ ls -al /usr/local/go
lrwxrwxrwx 1 jaten jaten 8 Mar 24 04:32 /usr/local/go -> go1.24.1
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ rm /usr/local/go
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ ln -s /usr/local/go1.23.5 /usr/local/go
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go version
go version go1.23.5 linux/amd64
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go test -v
=== RUN   TestFmt
hello--- PASS: TestFmt (0.00s)
PASS
ok      github.com/glycerine/fmt_break  0.002s
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go env
GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jaten/.cache/go-build'
GOENV='/home/jaten/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jaten/go/pkg/mod'
GONOPROXY='github.com/glycerine/*'
GONOSUMDB='github.com/glycerine/*'
GOOS='linux'
GOPATH='/home/jaten/go'
GOPRIVATE='github.com/glycerine/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.23.5'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.23.5/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.5'
GODEBUG=''
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/jaten/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2606543426=/tmp/go-build -gno-record-gcc-switches'
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ rm /usr/local/go
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ ln -s /usr/local/go1.24.1 /usr/local/go
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go version
go version go1.24.1 linux/amd64
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='auto'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/jaten/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/jaten/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2193786646=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD=''
GOMODCACHE='/home/jaten/go/pkg/mod'
GONOPROXY='github.com/glycerine/*'
GONOSUMDB='github.com/glycerine/*'
GOOS='linux'
GOPATH='/home/jaten/go'
GOPRIVATE='github.com/glycerine/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.24.1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/jaten/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.24.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'
jaten@rog ~/go/src/github.com/glycerine/fmt_break $ 

What did you see happen?

See above.

What did you expect to see?

I expected test code that has worked for years to continue to work.

Please revert this new test build behavior to go1.23.5 behavior.

Comment From: seankhliao

We've determined this vet check to be accurate enough to enable by default. Closing as working as intended.

Comment From: gabyhelp

Related Issues

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: thepudds

Hi @glycerine, FYI, my understanding is that this is gated by the go version declared in your go.mod file.

As @findleyr wrote in #71485:

The new check added to the printf analyzer in https://github.com/golang/go/issues/60529 reports errors for non-constant format strings. In almost all cases we've investigated, these turn out to be bugs. However, they are mild bugs, and the analyzer can produce quite a large number of findings.

[...]

To reduce the friction caused by this change, we should gate the new check on a 1.24 language version, so as to not break the tests of existing codebases. Users can address the new vet errors incrementally as they update the language versions of their modules.

See the discussion in #71485 and #57063 if interested.