From patchwork Thu Jul 13 16:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 120031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1959940vqm; Thu, 13 Jul 2023 10:01:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlErPlOAJW4aomS7utd4XmvDtxxmoqRDPMskp5d7g9GRZEpAVeQnBLmf6QTjef6RM9PLOdzV X-Received: by 2002:a05:6512:516:b0:4fb:7665:9b0d with SMTP id o22-20020a056512051600b004fb76659b0dmr1616220lfb.12.1689267703196; Thu, 13 Jul 2023 10:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689267703; cv=none; d=google.com; s=arc-20160816; b=PC627+A+q6LdTNbX+jrXDrUC/HkH8DHe4qlOFdJyw6ez7z8/8InzTTnwGpuhvhfsjR bN2kZLe7ll5OOQpMaTx+ctI1iKTRmBby8pTkZXODw0vTHgF3whPnw1/wUtX3kFKyLpGQ +fLkHDsjK2FsmSNOLrW/L5WqOgHwulY/pIW1N9XCZt7KCis8bo1hTJWsBUfTCFbgQVTR 6y2YIsbmbYHWCYUDX9i4HUGz9Bjhb5dNtu9LtrzlZmEZC+4rcW2N6vggbzu6rP/FkDqm eopHm4qqrsv9Jgh4kMBSpZmx4qYDhjLlQq5XsM6as7BFnNWf3OvPazVTjAHBIKqZOL/T bFbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=EDW5F4RFJTDPu5sXjaSbEl6Kk+Q1lQuNxwTowv4NJzU=; fh=sC8lnOfyH6gL5FYlMbZ1VDz6qVPMj/3ViLJWKNUCUgQ=; b=B60x+JYqCfi98Q8rE2dXpsdcPAUg3FoWWtoTK7MVBrXYt1ZMuHQepTEzzJ0HVW+TIx 4jDjH6QPYV5YRPEn6+L14SICr55gSspY4JNn2nC23zlT2TNOoSb28CJlsGg6dMjsqDJp 0z6ww/u8XsiXVi7/7ql7ruQZitq3tsb2UFD9s9+immfTs22vYcb9fLKUN6CPyqZJq1t3 WE1h4G6nNMMuXIZ4DWan1KHRjz/AP3s2d/PCeqOSqvMLSVaGYAHunpAA3mfRwb5KeUx+ wEnO5WZCHAGsXuxoZOWpdbGjF7cfNXcodoa4yZi6SaaACiGyyLeL0xlIkS3dgBInaYRf cWug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tGWPkC8E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w21-20020aa7d295000000b0051e2784b154si7238957edq.446.2023.07.13.10.01.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 10:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tGWPkC8E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E4863858C33 for ; Thu, 13 Jul 2023 17:01:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E4863858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689267672; bh=EDW5F4RFJTDPu5sXjaSbEl6Kk+Q1lQuNxwTowv4NJzU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tGWPkC8EZaNoAzD+VaoHqk1lyVGR/7D52AoiXv8Tt1vNPXkypd3uJEWDtM7JvlUq2 a1pPEwWcF6gYzNXS7rMjPkRc4frw4ffEYbDfbvTsiDhIOHKzfAnIidrX+fQpLRwG+6 m5s+Mi9ht/dN3YjxUqJqo3W/Cmekee3KD9wVlhcg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id DA08D385772D for ; Thu, 13 Jul 2023 16:59:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA08D385772D 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-645-bBhuJYU0PuSfJsvoywgWdA-1; Thu, 13 Jul 2023 12:59:49 -0400 X-MC-Unique: bBhuJYU0PuSfJsvoywgWdA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 917EE800193; Thu, 13 Jul 2023 16:59:49 +0000 (UTC) Received: from localhost (unknown [10.42.28.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 567694028AA4; Thu, 13 Jul 2023 16:59:49 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: std::stoi etc. do not need C99 support [PR110653] Date: Thu, 13 Jul 2023 17:59:30 +0100 Message-ID: <20230713165948.1993395-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771325571205680664 X-GMAIL-MSGID: 1771325571205680664 Tested powerpc64le-linux. Pushed to trunk. -- >8 -- std::stoi, std::stol, std::stoul, and std::stod only depend on C89 functions, so don't need to be guarded by _GLIBCXX_USE_C99_STDLIB std::stoll and std::stoull don't need C99 strtoll and strtoull if sizeof(long) == sizeof(long long). std::stold doesn't need C99 strtold if DBL_MANT_DIG == LDBL_MANT_DIG. This only applies to the narrow character overloads, the wchar_t overloads depend on a separate _GLIBCXX_USE_C99_WCHAR macro and none of them can be implemented in C89 easily. libstdc++-v3/ChangeLog: PR libstdc++/110653 * include/bits/basic_string.h (stoi, stol, stoul, stod): Do not depend on _GLIBCXX_USE_C99_STDLIB. [__LONG_WIDTH__ == __LONG_LONG_WIDTH__] (stoll, stoull): Define in terms of stol and stoul respectively. [__DBL_MANT_DIG__ == __LDBL_MANT_DIG__] (stold): Define in terms of stod. --- libstdc++-v3/include/bits/basic_string.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index d15f0f0589f..01e25dad20e 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -4108,7 +4108,6 @@ namespace std _GLIBCXX_VISIBILITY(default) _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_CXX11 -#if _GLIBCXX_USE_C99_STDLIB // 21.4 Numeric Conversions [string.conversions]. inline int stoi(const string& __str, size_t* __idx = 0, int __base = 10) @@ -4125,6 +4124,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), __idx, __base); } +#if _GLIBCXX_USE_C99_STDLIB inline long long stoll(const string& __str, size_t* __idx = 0, int __base = 10) { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), @@ -4134,19 +4134,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 stoull(const string& __str, size_t* __idx = 0, int __base = 10) { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), __idx, __base); } +#elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__ + inline long long + stoll(const string& __str, size_t* __idx = 0, int __base = 10) + { return std::stol(__str, __idx, __base); } - // NB: strtof vs strtod. - inline float - stof(const string& __str, size_t* __idx = 0) - { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } + inline unsigned long long + stoull(const string& __str, size_t* __idx = 0, int __base = 10) + { return std::stoul(__str, __idx, __base); } +#endif inline double stod(const string& __str, size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } +#if _GLIBCXX_USE_C99_STDLIB + // NB: strtof vs strtod. + inline float + stof(const string& __str, size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } + inline long double stold(const string& __str, size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } +#elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__ + inline long double + stold(const string& __str, size_t* __idx = 0) + { return std::stod(__str, __idx); } #endif // _GLIBCXX_USE_C99_STDLIB // DR 1261. Insufficent overloads for to_string / to_wstring