From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Replace std::isdigit and std::isxdigit in <format> [PR107817]
Date: Tue, 22 Nov 2022 17:55:02 +0000 [thread overview]
Message-ID: <20221122175502.2141235-1-jwakely@redhat.com> (raw)
Tested x86_64-linux. Pushed to trunk.
-- >8 --
These functions aren't usable in constant expressions. Provide our own
implementations, based on __from_chars_alnum_to_val from <charconv>.
libstdc++-v3/ChangeLog:
PR libstdc++/107817
* include/std/charconv (__from_chars_alnum_to_val): Add
constexpr for C++20.
* include/std/format (__is_digit, __is_xdigit): New functions.
(_Spec::_S_parse_width_or_precision): Use __is_digit.
(__formatter_fp::parse): Use __is_xdigit.
---
libstdc++-v3/include/std/charconv | 2 +-
libstdc++-v3/include/std/format | 12 +++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
index 8f02395172f..8b2acc5bf8d 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -454,7 +454,7 @@ namespace __detail
// If _DecOnly is false: if the character is an alphanumeric digit, then
// return its corresponding base-36 value, otherwise return a value >= 127.
template<bool _DecOnly = false>
- _GLIBCXX23_CONSTEXPR unsigned char
+ _GLIBCXX20_CONSTEXPR unsigned char
__from_chars_alnum_to_val(unsigned char __c)
{
if _GLIBCXX17_CONSTEXPR (_DecOnly)
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 7ae58eb2416..23ffbdabed8 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -358,6 +358,12 @@ namespace __format
size_t
__int_from_arg(const basic_format_arg<_Context>& __arg);
+ constexpr bool __is_digit(char __c)
+ { return std::__detail::__from_chars_alnum_to_val(__c) < 10; }
+
+ constexpr bool __is_xdigit(char __c)
+ { return std::__detail::__from_chars_alnum_to_val(__c) < 16; }
+
template<typename _CharT>
struct _Spec
{
@@ -469,7 +475,7 @@ namespace __format
unsigned short& __val, bool& __arg_id,
basic_format_parse_context<_CharT>& __pc)
{
- if (std::isdigit(*__first))
+ if (__format::__is_digit(*__first))
{
auto [__v, __ptr] = __format::__parse_integer(__first, __last);
if (!__ptr)
@@ -1537,7 +1543,7 @@ namespace __format
if (__trailing_zeros)
{
- if (!std::isxdigit(__s[0]))
+ if (!__format::__is_xdigit(__s[0]))
--__sigfigs;
__z = __prec - __sigfigs;
}
@@ -1627,7 +1633,7 @@ namespace __format
{
__fill_char = _CharT('0');
// Write sign before zero filling.
- if (!std::isxdigit(__narrow_str[0]))
+ if (!__format::__is_xdigit(__narrow_str[0]))
{
*__out++ = __str[0];
__str.remove_prefix(1);
--
2.38.1
reply other threads:[~2022-11-22 17:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221122175502.2141235-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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).