From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 976DD3857715; Tue, 6 Jun 2023 22:57:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 976DD3857715 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686092227; bh=u7kygP6Jm4c3gJ/0nLtLs8yJ0RfWefOqILC+Fdk0yz0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RhUqm2JhhAkcQ4km6zqYqkorcMNgP5/KfSkvzJ8EVqsBFDe0HwZe2+ro8cVn5msl8 2c09fn57076fxgNZy6/wI/wbTB+COFf48q025uibm6VmUME7OhUtxPXJeN5dX1LzAm C+RKu9e+4PdUEPFb7Xl/xQbOk8EOKxulF4gH0e3o= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110149] std::format for pointer arguments allows a '0' option Date: Tue, 06 Jun 2023 22:57:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110149 --- Comment #3 from Jonathan Wakely --- It looks like I forgot to actually format using 'P' though, I only parsed it from the format string. This would fix that, and disable the P2519 changes for -std=3Dc++20 and -std=3Dc++23: --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -2081,19 +2081,29 @@ namespace __format if (__finished()) return __first; +#if __cplusplus > 202302L || ! defined __STRICT_ANSI__ // _GLIBCXX_RESOLVE_LIB_DEFECTS // P2519R3 Formatting pointers __first =3D __spec._M_parse_zero_fill(__first, __last); if (__finished()) return __first; +#endif __first =3D __spec._M_parse_width(__first, __last, __pc); - if (__first !=3D __last && (*__first =3D=3D 'p' || *__first =3D=3D = 'P')) + if (__first !=3D __last) { - if (*__first =3D=3D 'P') + if (*__first =3D=3D 'p') + ++__first; +#if __cplusplus > 202302L || ! defined __STRICT_ANSI__ + else if (*__first =3D=3D 'P')) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // P2519R3 Formatting pointers __spec._M_type =3D __format::_Pres_P; - ++__first; + ++__first; + } +#endif } if (__finished()) @@ -2113,6 +2123,18 @@ namespace __format const int __n =3D __ptr - __buf; __buf[0] =3D '0'; __buf[1] =3D 'x'; +#if __cplusplus > 202302L || ! defined __STRICT_ANSI__ + if (_M_spec._M_type =3D=3D _Pres_) + { + __buf[1] =3D 'X'; + for (auto __p =3D __buf + 2; __p !=3D __res.ptr; ++__p) +#if __has_builtin(__builtin_toupper) + *__p =3D __builtin_toupper(*__p); +#else + *__p =3D std::toupper(*__p); +#endif + } +#endif basic_string_view<_CharT> __str; if constexpr (is_same_v<_CharT, char>)=