public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r14-2504] libstdc++: std::stoi etc. do not need C99 <stdlib.h> support [PR110653]
Date: Thu, 13 Jul 2023 16:59:30 +0000 (GMT)	[thread overview]
Message-ID: <20230713165930.4B75B3858D1E@sourceware.org> (raw)

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

commit r14-2504-ga1d12752f8d45df5d7962cef6e2a87585002e982
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 13 10:44:57 2023 +0100

    libstdc++: std::stoi etc. do not need C99 <stdlib.h> support [PR110653]
    
    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.

Diff:
---
 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

                 reply	other threads:[~2023-07-13 16:59 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=20230713165930.4B75B3858D1E@sourceware.org \
    --to=redi@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).