public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: William Schmidt <wschmidt@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/users/wschmidt/heads/builtins3)] libstdc++: Check _GLIBCXX_USE_C99_STDLIB for strtof and strtold
Date: Tue, 18 Aug 2020 18:17:46 +0000 (GMT)	[thread overview]
Message-ID: <20200818181746.3F7B7386F804@sourceware.org> (raw)

https://gcc.gnu.org/g:e513e9aa53121e628e0403438a5bb3861a50c198

commit e513e9aa53121e628e0403438a5bb3861a50c198
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 30 20:55:56 2020 +0100

    libstdc++: Check _GLIBCXX_USE_C99_STDLIB for strtof and strtold
    
    On broken systems we only have strtod, not strtof and strtold. Just use
    strtod for all types, even though that will produce incorrect results in
    some cases.
    
    Similarly, if _GLIBCXX_USE_C99_MATH is not defined then std::isinf won't
    be declared. Just refer to it unqualified, which should find the C
    library's isinf macro if that hasn't been #undef'd by <cmath>.
    
    libstdc++-v3/ChangeLog:
    
            * src/c++17/floating_from_chars.cc (from_chars_impl): Use
            isinf unqualified.
            [!_GLIBCXX_USE_C99_STDLIB]: Use strtod for float and long
            double.

Diff:
---
 libstdc++-v3/src/c++17/floating_from_chars.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
index f1519e5c7b6..26b69a38521 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -300,12 +300,16 @@ namespace
 	errno = 0;
 	char* endptr;
 	T tmpval;
+#if _GLIBCXX_USE_C99_STDLIB
 	if constexpr (is_same_v<T, float>)
 	  tmpval = std::strtof(str, &endptr);
-	if constexpr (is_same_v<T, double>)
+	else if constexpr (is_same_v<T, double>)
 	  tmpval = std::strtod(str, &endptr);
 	else if constexpr (is_same_v<T, long double>)
 	  tmpval = std::strtold(str, &endptr);
+#else
+	tmpval = std::strtod(str, &endptr);
+#endif
 	const int conv_errno = std::__exchange(errno, save_errno);
 
 #if _GLIBCXX_USE_C99_FENV_TR1
@@ -319,7 +323,7 @@ namespace
 	const ptrdiff_t n = endptr - str;
 	if (conv_errno == ERANGE) [[unlikely]]
 	  {
-	    if (std::isinf(tmpval)) // overflow
+	    if (isinf(tmpval)) // overflow
 	      ec = errc::result_out_of_range;
 	    else // underflow (LWG 3081 wants to set value = tmpval here)
 	      ec = errc::result_out_of_range;


                 reply	other threads:[~2020-08-18 18:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200818181746.3F7B7386F804@sourceware.org \
    --to=wschmidt@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).