public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-110149-4-Sqw0IAtnIx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110149-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110149

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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=c++20 and
-std=c++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 = __spec._M_parse_zero_fill(__first, __last);
        if (__finished())
          return __first;
+#endif

        __first = __spec._M_parse_width(__first, __last, __pc);

-       if (__first != __last && (*__first == 'p' || *__first == 'P'))
+       if (__first != __last)
          {
-           if (*__first == 'P')
+           if (*__first == 'p')
+             ++__first;
+#if __cplusplus > 202302L || ! defined __STRICT_ANSI__
+           else if (*__first == 'P'))
+           {
+             // _GLIBCXX_RESOLVE_LIB_DEFECTS
+             // P2519R3 Formatting pointers
              __spec._M_type = __format::_Pres_P;
-           ++__first;
+             ++__first;
+           }
+#endif
          }

        if (__finished())
@@ -2113,6 +2123,18 @@ namespace __format
          const int __n = __ptr - __buf;
          __buf[0] = '0';
          __buf[1] = 'x';
+#if __cplusplus > 202302L || ! defined __STRICT_ANSI__
+         if (_M_spec._M_type == _Pres_)
+           {
+             __buf[1] = 'X';
+             for (auto __p = __buf + 2; __p != __res.ptr; ++__p)
+#if __has_builtin(__builtin_toupper)
+               *__p = __builtin_toupper(*__p);
+#else
+               *__p = std::toupper(*__p);
+#endif
+           }
+#endif

          basic_string_view<_CharT> __str;
          if constexpr (is_same_v<_CharT, char>)

  parent reply	other threads:[~2023-06-06 22:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 21:05 [Bug libstdc++/110149] New: " bruno at clisp dot org
2023-06-06 22:20 ` [Bug libstdc++/110149] " redi at gcc dot gnu.org
2023-06-06 22:46 ` redi at gcc dot gnu.org
2023-06-06 22:57 ` redi at gcc dot gnu.org [this message]
2023-06-08 12:59 ` redi at gcc dot gnu.org
2023-06-09 12:09 ` cvs-commit at gcc dot gnu.org
2023-06-09 12:21 ` redi at gcc dot gnu.org
2023-06-29 23:01 ` cvs-commit at gcc dot gnu.org
2023-06-29 23:02 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110149-4-Sqw0IAtnIx@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).