Title
Allow an arg-id with a value of zero for width in std-format-spec
Status
c++23
Section
[format.string.std]
Submitter
Mark de Wever

Created on 2022-06-19.00:00:00 last changed 12 months ago

Messages

Date: 2022-07-25.20:32:58

Proposed resolution:

This wording is relative to N4910.

  1. Modify [format.string.std] as indicated:

    -7- 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.

Date: 2022-07-25.00:00:00

[ 2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP. ]

Date: 2022-07-15.00:00:00

[ 2022-07-15; LWG telecon: move to Ready ]

Date: 2022-07-15.00:00:00

[ 2022-07-11; Reflector poll ]

Set status to Tentatively Ready after seven votes in favour during reflector poll.

Date: 2022-07-15.00:00:00

[ 2022-07-08; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2022-06-19.00:00:00

Per [format.string.std]/7

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.

During a libc++ code review Victor mentioned it would be nice to allow zero as a valid value for the arg-id when used for the width. This would simplify the code by having the same requirements for the arg-id for the width and precision fields. A width of zero has no effect on the output.

In the std-format-spec the width is restricted to a positive-integer to avoid parsing ambiguity with the zero-padding option. This ambiguity doesn't happen using an arg-id with the value zero. Therefore I only propose to change the arg-id's requirement.

Note the Standard doesn't specify the width field's effect on the output. Specifically [tab:format.align] doesn't refer to the width field. This is one of the items addressed by P2572. The proposed resolution works in combination with the wording of that paper.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-07-25 20:32:58adminsetmessages: + msg12657
2022-07-25 20:32:58adminsetstatus: ready -> wp
2022-07-25 20:28:19adminsetmessages: + msg12631
2022-07-11 10:09:12adminsetmessages: + msg12578
2022-07-11 10:09:12adminsetstatus: new -> ready
2022-07-08 20:04:38adminsetmessages: + msg12561
2022-06-25 18:43:19adminsetmessages: + msg12531
2022-06-19 00:00:00admincreate