From patchwork Wed Jul 19 10:05:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 122505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2327780vqt; Wed, 19 Jul 2023 03:08:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFHiboat02NFhT7ArkRofVSaQo9NoRnwaEAszBiTRgLoWZKTCzk1zAAHPIY0D6oYfc/2gY X-Received: by 2002:ac2:58d1:0:b0:4fb:81f2:4228 with SMTP id u17-20020ac258d1000000b004fb81f24228mr11044616lfo.31.1689761314027; Wed, 19 Jul 2023 03:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689761313; cv=none; d=google.com; s=arc-20160816; b=oQ/qlJtPa7Gaws6VBduRZCwUl2Pib7XRHu3aJeY+mKmYi7tbA0qPoMIijr4LEViLxr Tostkmnm0EdE51UOuPVCBmDAMp+OUXvZQNARhb/lzsY67dXALPJsReUz9SfZYoqCa84J +I3DuzJrzMvfmR58InNu4aeza7x41RQ5iWDV2XWDl7GL3jpKEBK4bYLeIiidEZIoGfL7 M78OeXthzT3pb4DomUFh87Dh+W5z9IHfu87dlv2Gk1QNpr9lsmosb1zfKAy6eA/+9N9j 6QrqLeIzjK0pwAj47nPZbYf0Ay7IZ9r8/MnpE1KI8XOvz6pMHJYYqiOTvDg7SuX26g9M YX/w== 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=g1esaaytBLIeWhcO4pNoGldZ2VNn53gwnVyBwCZDhJE=; fh=sC8lnOfyH6gL5FYlMbZ1VDz6qVPMj/3ViLJWKNUCUgQ=; b=bMi3lYbxRQxz3a8xXDxnoguvhlXo42wv9dhoYRJBSQEuxx7DEFM6vxuI2oUVVFTcCL c1GgtWJw9w8YlWsU1+7EcTLJugHkUi+Z0IpzPCZXv1iXFApSzUADTPBybHPhjZt3kxx8 a44aelCjtW7bYtFdIApb2ugxM7yVdufhTQktT2d9xS/ZDFRNGcmA1hVNzYY2Miaww6vf XGqKKF1Om/b5+tvB5BKZ0ufeR95zkco+/usPii8Rg4griLrobzIy7fbaitWliWpnOeVi z/+9R1ut4aQkeryWkwfQAYPQL6EwWnryIykUzrgVrO/gr6RddvS+RafE/EJpo/4+o/um ax+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GxN4C7bP; 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 h9-20020a50ed89000000b0051dd3cccddasi2628406edr.348.2023.07.19.03.08.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 03:08:33 -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=GxN4C7bP; 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 A836E3865C23 for ; Wed, 19 Jul 2023 10:07:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A836E3865C23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689761232; bh=g1esaaytBLIeWhcO4pNoGldZ2VNn53gwnVyBwCZDhJE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GxN4C7bP+HiWVUDgHfmGvq3pz4PVEUKD9kDPPkdELxezNXHSSwnUZuL/k08wfuhwj UOZesvZz9QhD5ThVYz8SJR67+ziyGvTzk48s5b6GUCAaGeJheStjGr11l3okVR8MVn Z07IALIuKzkmGuUDT8NgyNk55r7KES+9H+VB4r9k= 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 5D2203858C33 for ; Wed, 19 Jul 2023 10:06:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D2203858C33 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-302-vvXZkYzyMFKMZr53xUKgBw-1; Wed, 19 Jul 2023 06:06:26 -0400 X-MC-Unique: vvXZkYzyMFKMZr53xUKgBw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58487101156F; Wed, 19 Jul 2023 10:06:26 +0000 (UTC) Received: from localhost (unknown [10.42.28.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 082B31121315; Wed, 19 Jul 2023 10:06:25 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 1/3] libstdc++: Check autoconf macros for strtof and strtold [PR110653] Date: Wed, 19 Jul 2023 11:05:10 +0100 Message-ID: <20230719100625.2494437-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: 1771843159687126606 X-GMAIL-MSGID: 1771843159687126606 Tested x86_64-linux. Pushed to trunk. -- >8 -- As well as the _GLIBCXX_USE_C99_STDLIB check, we also have a separate check in linkage.m4 for just strtof and strtold. We can use that to declare std::strtof and std::strtold in for additional targets. That allows us to enable std::stold on hpux11.11 which is missing strtoll, strtoull and strtof, so doesn't define _GLIBCXX_USE_C99_STDLIB. Although it doesn't help hpux11.11, we can define std::stof for more targets this way too. As with the previous commit for PR110653, this only affects the narrow character overloads. std::stof and std::stold for wstring still requires C99 support. libstdc++-v3/ChangeLog: PR libstdc++/110653 * include/bits/basic_string.h [_GLIBCXX_HAVE_STRTOF] (stof): Define. [_GLIBCXX_HAVE_STRTOLD] (stold): Define. * include/c_global/cstdlib [_GLIBCXX_HAVE_STRTOF] (strtof): Declare in namespace std. [_GLIBCXX_HAVE_STRTOLD] (strtold): Likewise. --- libstdc++-v3/include/bits/basic_string.h | 6 ++++-- libstdc++-v3/include/c_global/cstdlib | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 01e25dad20e..32f5d4421f7 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -4148,12 +4148,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 stod(const string& __str, size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } -#if _GLIBCXX_USE_C99_STDLIB +#if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOF // 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); } +#endif +#if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOLD inline long double stold(const string& __str, size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } @@ -4161,7 +4163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 inline long double stold(const string& __str, size_t* __idx = 0) { return std::stod(__str, __idx); } -#endif // _GLIBCXX_USE_C99_STDLIB +#endif // DR 1261. Insufficent overloads for to_string / to_wstring diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib index aeb961ad69d..60317aa9a4a 100644 --- a/libstdc++-v3/include/c_global/cstdlib +++ b/libstdc++-v3/include/c_global/cstdlib @@ -256,6 +256,20 @@ namespace std using ::__gnu_cxx::strtold; } // namespace std +#else // ! _GLIBCXX_USE_C99_STDLIB + +// We also check for strtof and strtold separately from _GLIBCXX_USE_C99_STDLIB + +#if _GLIBCXX_HAVE_STRTOF +#undef strtof +namespace std { using ::strtof; } +#endif + +#if _GLIBCXX_HAVE_STRTOLD +#undef strtold +namespace std { using ::strtold; } +#endif + #endif // _GLIBCXX_USE_C99_STDLIB } // extern "C++"