1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:04:46 -07:00

go/analysis/passes/printf: allow # for b flag

Adding the `#` to a `b` flag is allowed and adds a leading `0b` to the output.

Change-Id: I421891f9478d1aaff2585455f38b3aa50e8277ab
GitHub-Last-Rev: 016896ad081bfc23f0c0a481042c90f028509831
GitHub-Pull-Request: golang/tools#182
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203798
Reviewed-by: Erik Dubbelboer <erik@dubbelboer.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This commit is contained in:
Erik Dubbelboer 2019-10-28 08:46:22 +00:00 committed by Rebecca Stambler
parent 9cc4af7d6b
commit 288d118ee9
2 changed files with 2 additions and 1 deletions

View File

@ -791,7 +791,7 @@ var printVerbs = []printVerb{
// '#' is alternate format for several verbs.
// ' ' is spacer for numbers
{'%', noFlag, 0},
{'b', numFlag, argInt | argFloat | argComplex | argPointer},
{'b', sharpNumFlag, argInt | argFloat | argComplex | argPointer},
{'c', "-", argRune | argInt},
{'d', numFlag, argInt | argPointer},
{'e', sharpNumFlag, argFloat | argComplex},

View File

@ -160,6 +160,7 @@ func PrintfTests() {
fmt.Printf("%*% x", 0.22) // want `Printf format %\*% uses non-int 0.22 as argument of \*`
fmt.Printf("%q %q", multi()...) // ok
fmt.Printf("%#q", `blah`) // ok
fmt.Printf("%#b", 3) // ok
// printf("now is the time", "buddy") // no error "printf call has arguments but no formatting directives"
Printf("now is the time", "buddy") // want "Printf call has arguments but no formatting directives"
Printf("hi") // ok