Title
std::format: missing rules for arg-id in width and precision
Status
new
Section
[format.string]
Submitter
Richard Smith

Created on 2019-07-31.00:00:00, last changed 2019-08-02.18:34:47.

Messages

Date: 2019-08-03.17:54:00

Proposed resolution:

This wording is relative to the Post Cologne working draft.

  1. Modify the width and precision grammar in the syntax of format specifications of [format.string] as indicated:

    width      ::= nonzero-digit [integer] | '{' [arg-id] '}'
    precision  ::= integer | '{' [arg-id] '}'
    
Date: 2019-07-31.00:00:00

According to [format.string] we have:

If the numeric arg-ids in a format string are 0, 1, 2, ... in sequence, they can all be omitted (not just some) and the numbers 0, 1, 2, ... will be automatically used in that order. A format string does not contain a mixture of automatic and manual indexing.

… but what does that mean in the presence of arg-id in width and precision? Can one replace

"{0:{1}} {2}"

with

"{:{}} {}"

? The grammar says the answer is no, because the arg-id in width is not optional, but the normative wording says the answer is yes.

Victor Zverovich:

That's a bug in the grammar. The arg-id should be optional in width and precision:

width     ::= nonzero-digit [integer] | '{' [arg-id] '}'
precision ::= integer | '{' [arg-id] '}'
History
Date User Action Args
2019-08-02 18:34:47adminsetmessages: + msg10530
2019-07-31 00:00:00admincreate