Title
Are std::format alignment specifiers applied to string arguments?
Status
new
Section
[format.string]
Submitter
Richard Smith

Created on 2019-08-02.00:00:00, last changed 2019-08-21.19:16:09.

Messages

Date: 2019-08-21.19:16:09

Proposed resolution:

This wording is relative to N4830.

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

    -3- The align specifier applies to all argument types. The meaning of the various alignment options is as specified in Table [tab:format.align]. [Example: […

Date: 2019-08-15.00:00:00

[ 2019-08-21; Victor Zverovich suggests wording ]

Date: 2019-08-21.00:00:00

[ 2019-08-21 Priority set to 2 based on reflector discussion ]

Date: 2019-08-02.00:00:00

We are told:

Formatting of objects of arithmetic types and const void* is done as if by calling to_chars (unless otherwise specified) and copying the output through the output iterator of the format context with additional padding and adjustments as specified by the format specifiers.

… but there is no corresponding rule for strings. Is an alignment specifier intended to be applied to strings or not? The wording as-is is ambiguous.

(The above also doesn't cover formatting void* or std::nullptr_t. Presumably at least those two should have the relevant adjustments applied to them!)

The wording never actually anywhere says that the basic_format_args are in any way involved in the formatting process, or how formatting actually happens. (The wording doesn't say that basic_format_arg::handle::format is ever called, for example.)

Victor Zverovich:

An alignment specifier is intended to be applied to strings as well, void* and std::nullptr_t are converted into const void* when constructing basic_format_arg.

The wording for vformat and similar functions says that basic_format_args is involved:

Returns: A string object holding the character representation of formatting arguments provided by args formatted according to specifications given in fmt.

but I admit that it is hand-wavy. Perhaps we could add something along the lines of

For each replacement field referring to the argument with index (arg-id) i, the basic_format_arg object referring to the argument is obtained via args.get(i) and the parse and format functions of the formatter specialization for the underlying argument type are called to parse the format specification and format the value.

to clarify how we format args (basic_format_args).

History
Date User Action Args
2019-08-21 19:16:09adminsetmessages: + msg10576
2019-08-21 19:16:09adminsetmessages: + msg10575
2019-08-21 19:09:21adminsetmessages: + msg10574
2019-08-02 00:00:00admincreate