Skip to content

Commit 288d118

Browse files
erikdubbelboerstamblerre
authored andcommitted
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: 016896a GitHub-Pull-Request: #182 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203798 Reviewed-by: Erik Dubbelboer <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Michael Matloob <[email protected]>
1 parent 9cc4af7 commit 288d118

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

go/analysis/passes/printf/printf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ var printVerbs = []printVerb{
791791
// '#' is alternate format for several verbs.
792792
// ' ' is spacer for numbers
793793
{'%', noFlag, 0},
794-
{'b', numFlag, argInt | argFloat | argComplex | argPointer},
794+
{'b', sharpNumFlag, argInt | argFloat | argComplex | argPointer},
795795
{'c', "-", argRune | argInt},
796796
{'d', numFlag, argInt | argPointer},
797797
{'e', sharpNumFlag, argFloat | argComplex},

go/analysis/passes/printf/testdata/src/a/a.go

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

0 commit comments

Comments
 (0)