Date
2021-10-03.15:13:06
Message id
12094

Content

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, and bool, 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).

This is inconsistent and clearly a bug in specification that should have included pointers together with arithmetic types in [tab:format.align].