https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110149
Bug ID: 110149 Summary: std::format for pointer arguments allows a '0' option Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: bruno at clisp dot org Target Milestone: --- Created attachment 55275 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55275&action=edit test case bug.cc In C++ 20, a sign, a '#' option, and a '0' option are disallowed for std::format strings with a pointer argument. The text has the same language for all three: In https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf ยง 22.14.2.2 Standard format specifiers [format.string.std] Paragraph 5: "The sign option is only valid for arithmetic types other than charT and bool or when an integer presentation type is specified." Paragraph 7: "The # option .... This option is valid for arithmetic types other than charT and bool or when an integer presentation type is specified, and not otherwise." Paragraph 8: "The 0 option is valid for arithmetic types other than charT and bool or when an integer presentation type is specified." Paragraph 21 specifies the available integer presentation types; 'p' is not one of them, it is listed in paragraph 25 instead. Therefore in the attached program bug.cc, an error should be signalled in line 28 and in line 29. How to reproduce: 1) $ g++ -Wall -std=gnu++20 bug.cc <no error> 2) Enable line 18 or line 19 or line 23 or line 24. $ g++ -Wall -std=gnu++20 bug.cc <compilation error> Note also that the '0' option cannot be part of a width specification, because the width cannot start with '0'.