fmt: is %% a literal percent, or a degenerate conversion? #71384
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
During the review of the printf format-string parser used by gopls (extracted from the one in vet's printf checker), the question arose as to whether %% is nothing more than a literal percent sign, dealt with by the printf scanner, or a degenerate conversion supporting width, flags, precision, and so on.
Empirically, the surprising answer is that it is very much a conversion. Observe that it accepts a width, even indirectly, and updates the argument index accordingly (though it doesn't actually left-pad the output):
https://go.dev/play/p/Z4s7oV2HIM7
(Either way this seems wrong: the argument at index 4 should either be rejected or consumed by the %%; instead it becomes the operand of %v.)
Aside: I checked C for precedent, and found that it too empirically treats %% as a conversion:
Notice the left-padding to ten spaces. However, this program has undefined behavior according to POSIX.1:
What is the intended behavior for Go?
The text was updated successfully, but these errors were encountered: