golang/go

fmt: state that "%q" verb should not be used to print int value

Open

#78486 opened on Apr 1, 2026

View on GitHub
 (6 comments) (3 reactions) (0 assignees)Go (133,883 stars) (19,008 forks)batch import
DocumentationNeedsFixhelp wanted

Description

Go version

go version go1.26.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='…'
GOCACHE='…'
GOCACHEPROG=''
GODEBUG=''
GOENV='…'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/sl/yg232rm16b74lh69dhhscfz40000gn/T/go-build3024692398=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='…'
GOMODCACHE='…'
GONOPROXY='…'
GONOSUMDB='…'
GOOS='darwin'
GOPATH='…'
GOPRIVATE='…'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/nix/store/kh43nhaz1qcpwws2xq805lrmwpmn9i3k-go-1.26.1/share/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='…'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/nix/store/kh43nhaz1qcpwws2xq805lrmwpmn9i3k-go-1.26.1/share/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

import "fmt"

func main() {
	var i int = 42
	fmt.Printf("%q\n", i)
}

https://go.dev/play/p/19ECZqyEHs_A

What did you see happen?

prog.go:7:14: fmt.Printf format %q has arg i of wrong type int

Go vet failed.

'*'

Program exited.

What did you expect to see?

The fmt docs state that the %q verb can be used to print integers:
%q a single-quoted character literal safely escaped with Go syntax.: https://pkg.go.dev/fmt#:~:text=Integer%3A

As of Go 1.26, this however no longer passes go vet:

$ go vet prog.go
prog.go:7:14: fmt.Printf format %q has arg i of wrong type int

The docs on fmt should reflect that.

That vet error was introduced as part of https://github.com/golang/go/issues/72850.

Contributor guide