std::format: missing rules for arg-id in width and precision
Richard Smith

Created on 2019-07-31.00:00:00 last changed 4 months ago


Date: 2020-02-13.12:32:11

Proposed resolution:

This wording is relative to N4830.

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

             { arg-idopt }
             . nonnegative-integer  
             . { arg-idopt }   
  2. Modify [format.string.std] as indicated:

    -6- The # option causes […]

    -?- If { arg-idopt } is used in a width or precision, the value of the corresponding formatting argument is used in its place. If the corresponding formatting argument is not of integral type, or its value is negative for precision or non-positive for width, an exception of type format_error is thrown.

    -7- The positive-integer in width is a decimal integer defining the minimum field width. If width is not specified, there is no minimum field width, and the field width is determined based on the content of the field.

Date: 2020-02-13.12:32:11

[ 2020-02 Status to Immediate on Thursday morning in Prague. ]

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}"


"{:{}} {}"

? 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] '}'
Date User Action Args
2020-02-24 16:02:59adminsetstatus: immediate -> wp
2020-02-13 12:32:11adminsetmessages: + msg11056
2020-02-13 12:32:11adminsetstatus: new -> immediate
2019-08-02 18:34:47adminsetmessages: + msg10530
2019-07-31 00:00:00admincreate