From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F02C43852C52 for ; Tue, 22 Nov 2022 17:55:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F02C43852C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669139708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+ct6Ac5/noG9ayqAswjMiBGIZHNLXlCW2L8kRWJFKsQ=; b=HsQWZbMDPpO1RPZ2BRG6RtKEPO/Rj5rO0P/RsgCIrtSJWZYDOQfHXIFk8GGgZ9Rj5gAm63 MogjD/AzCI86cjh0hbtlipjprgUPkruy3LT8OpJIS0ImepUdLbVuB2QLRQ0StOylYs69s4 bzLz/c+e8PtSSZr7dUaq59++aKiWwg0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-60-NRsQGH-xM26ON43pstuouA-1; Tue, 22 Nov 2022 12:55:05 -0500 X-MC-Unique: NRsQGH-xM26ON43pstuouA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44FDC833AEF; Tue, 22 Nov 2022 17:55:05 +0000 (UTC) Received: from localhost (unknown [10.33.36.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CFFC492B17; Tue, 22 Nov 2022 17:55:04 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Replace std::isdigit and std::isxdigit in [PR107817] Date: Tue, 22 Nov 2022 17:55:02 +0000 Message-Id: <20221122175502.2141235-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 . 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 - _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 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