From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.CeBiTec.Uni-Bielefeld.DE (smtp.CeBiTec.Uni-Bielefeld.DE [129.70.160.84]) by sourceware.org (Postfix) with ESMTPS id 033ED3858D35; Mon, 27 Jul 2020 09:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 033ED3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=CeBiTec.Uni-Bielefeld.DE Authentication-Results: sourceware.org; spf=none smtp.mailfrom=ro@cebitec.uni-bielefeld.de Received: from localhost (localhost [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 887EBAEE9E; Mon, 27 Jul 2020 11:41:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (smtp.cebitec.uni-bielefeld.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kZDOpJ-WC84F; Mon, 27 Jul 2020 11:41:31 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (p4fddbb33.dip0.t-ipconnect.de [79.221.187.51]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPSA id A33C4AEDA9; Mon, 27 Jul 2020 11:41:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=CeBiTec.Uni-Bielefeld.DE; s=20200306; t=1595842891; bh=t3q6NZ0Z9VE7f68KoCSbHmBv8P3sg7uOI56FWltGfwo=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=FSoh31XdGO9jNyWKB7E0zTu+9YjaBE/p2nzupkGqPXRBsEuQf18LStCM/DDvjo5+h bY3smHS7TxAz3iUGnIMXeeDbKM+Y4aJ+1pS6ExFLJt1kRBeQ0yXa7EpJiOnX/XJ8PP hxYNdObde9sc2ZPWFFWDwNBMNuJD1ytPlisVPQenjucsssXsgybmOchyhyL6JX3z0W usUFRs6aWvRgbjxX5H/aUVKyn9KuPTwpXr4QV/ny1T4NZS2BrtV3MmIvy5M2atvgtt I/b56yQDqTyU8tXEy1vMB6lRb5LUdir3KNPoYoSjTTsnJEuEoQGQ5mC4JayP2udDkI XdQP2B+DMdjxA== From: Rainer Orth To: Jonathan Wakely via Gcc-patches Cc: libstdc++@gcc.gnu.org, Jonathan Wakely Subject: Re: [committed] libstdc++: Add std::from_chars for floating-point types References: <20200720225233.GA174400@redhat.com> Date: Mon, 27 Jul 2020 11:41:30 +0200 In-Reply-To: <20200720225233.GA174400@redhat.com> (Jonathan Wakely via Gcc-patches's message of "Mon, 20 Jul 2020 23:52:33 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3790.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2020 09:41:36 -0000 Hi Jonathan, > This adds the missing std::from_chars overloads for floating-point > types, as required for C++17 conformance. > > The implementation is a hack and not intended to be used in the long > term. Rather than parsing the string directly, this determines the > initial portion of the string that matches the pattern determined by the > chars_format parameter, then creates a NTBS to be parsed by strtod (or > strtold or strtof). > > Because creating a NTBS requires allocating memory, but std::from_chars > is noexcept, we need to be careful to minimise allocation. Even after > being careful, allocation failure is still possible, and so a > non-conforming std::no_more_memory error code might be returned. > > Because strtod et al depend on the current locale, but std::from_chars > does not, we change the current thread's locale to "C" using newlocale > and uselocale before calling strtod, and restore it afterwards. > > Because strtod doesn't have the equivalent of a std::chars_format > parameter, it has to examine the input to determine the format in use, > even though the std::from_chars code has already parsed it once (or > twice for large input strings!) > > By replacing the use of strtod we could avoid allocation, avoid changing > locale, and use optimised code paths specific to each std::chars_format > case. We would also get more portable behaviour, rather than depending > on the presence of uselocale, and on any bugs or quirks of the target > libc's strtod. Replacing strtod is a project for a later date. two of the new tests FAIL on Solaris 11.3 only: +FAIL: 20_util/from_chars/4.cc (test for excess errors) +UNRESOLVED: 20_util/from_chars/4.cc compilation failed to produce executable +FAIL: 20_util/from_chars/5.cc (test for excess errors) +UNRESOLVED: 20_util/from_chars/5.cc compilation failed to produce executable Excess errors: /vol/gcc/src/hg/master/local/libstdc++-v3/testsuite/20_util/from_chars/4.cc:41: error: no matching function for call to 'from_chars(char*, char*, double&, std::chars_format&)' [...] AFAICT that's due to the fact that Solaris 11.3 (unlike 11.4) lacks uselocale. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University