Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++23 status.

3612. Inconsistent pointer alignment instd::format

Section: 28.5.2.2[format.string.std]Status:C++23Submitter: Victor ZverovichOpened: 2021-10-02Last modified: 2023-11-22

Priority:Not Prioritized

View otheractive issues in [format.string.std].

View all otherissues in [format.string.std].

View all issues withC++23 status.

Discussion:

According to [tab:format.type.ptr] pointers are formatted as hexadecimal integers (at least in the common case whenuintptr_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 ofp).

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

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

  1. Modify 28.5.2.2[format.string.std], Table [tab:format.align], as indicated:

    Table 59 — Meaning ofalign options [tab:format.align]
    OptionMeaning
    <Forces the field to be aligned to the start of the available space. This is the default fornon-arithmeticnon-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 forarithmetic types other thancharT andbool, pointer types or when an integer presentation type is specified.
    […]

    [Drafting note: The wording above touches a similar area as LWG3586(i). To help solving themerge conflict the following shows the delta of this proposed wording on top of the LWG3586(i)merge result]

    Table 59 — Meaning ofalign options [tab:format.align]
    OptionMeaning
    <Forces the field to be aligned to the start of the available space. This is the default when the presentation type is a non-arithmeticnon-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 arithmeticor pointer type.
    […]

[8]ページ先頭

©2009-2025 Movatter.jp