This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.
std::format
Section: 28.5.2.2 [format.string.std] Status: C++23 Submitter: Victor Zverovich Opened: 2021-10-02 Last modified: 2023-11-22
Priority: Not Prioritized
View other active issues in [format.string.std].
View all other issues in [format.string.std].
View all issues with C++23 status.
Discussion:
According to [tab:format.type.ptr] pointers are formatted as hexadecimal integers (at least in the
common case when uintptr_t
is available). However, it appears that they have left alignment
by default according to [tab:format.align]:
Forces the field to be aligned to the start of the available space. This is the default for non-arithmetic types,
charT
, andbool
, unless an integer presentation type is specified.
because pointers are not arithmetic types.
For example:void* p = … std::format("{:#16x}", std::bit_cast<uintptr_t>(p)); std::format("{:16}", p);
may produce " 0x7fff88716c84"
and "0x7fff88716c84 "
(the actual output depends
on the value of p
).
[2021-10-14; Reflector poll]
Set status to Tentatively Ready after seven votes in favour during reflector poll.
[2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP.]
Proposed resolution:
This wording is relative to N4892.
Modify 28.5.2.2 [format.string.std], Table [tab:format.align], as indicated:
Table 59 — Meaning of align options [tab:format.align] Option Meaning <
Forces the field to be aligned to the start of the available space. This is the default for non-arithmetic non-pointer types, charT
, andbool
, unless an integer presentation type is specified.>
Forces the field to be aligned to the end of the available space. This is the default for arithmetic types other than charT
andbool
, pointer types or when an integer presentation type is specified.[…]
[Drafting note: The wording above touches a similar area as LWG 3586(i). To help solving the merge conflict the following shows the delta of this proposed wording on top of the LWG 3586(i) merge result]
Table 59 — Meaning of align options [tab:format.align] Option Meaning <
Forces the field to be aligned to the start of the available space. This is the default when the presentation type is a non-arithmetic non-pointer type. >
Forces the field to be aligned to the end of the available space. This is the default when the presentation type is an arithmetic or pointer type. […]