From patchwork Tue Nov 22 17:55:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 60987 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 842DD3860744 for ; Tue, 22 Nov 2022 17:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 842DD3860744 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669139788; bh=+ct6Ac5/noG9ayqAswjMiBGIZHNLXlCW2L8kRWJFKsQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=u3WprV30KbdtIG0hn34bdQeKtuPN5cfVoqaWXTTuad6YuA6/ZM+/zHg7oi9FklKK6 n/3Xz4XbvAIUHAe0yu5LWvo+nDynvsONcPIbOTKL5D9zpKdGZQhGTt4WZBTzR3qVBP oykM2zM5GKuC6NNOgkjMlWpKSv8OpgGlh0rTvPYA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 0E6293853D73 for ; Tue, 22 Nov 2022 17:55:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E6293853D73 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) 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 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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);