public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed 1/3] libstdc++: Check autoconf macros for strtof and strtold [PR110653]
@ 2023-07-19 10:05 Jonathan Wakely
  2023-07-19 10:05 ` [committed 2/3] libstdc++: Define std::stof fallback in terms of std::stod [PR110653] Jonathan Wakely
  2023-07-19 10:05 ` [committed 3/3] libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653] Jonathan Wakely
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-07-19 10:05 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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 <cstdlib> 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 <wchar.h> 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++"
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed 2/3] libstdc++: Define std::stof fallback in terms of std::stod [PR110653]
  2023-07-19 10:05 [committed 1/3] libstdc++: Check autoconf macros for strtof and strtold [PR110653] Jonathan Wakely
@ 2023-07-19 10:05 ` Jonathan Wakely
  2023-07-19 10:05 ` [committed 3/3] libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653] Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-07-19 10:05 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8 --

For targets without std::strtof we can define std::stof by calling
std::stod and then checking if the result is out of range of float.

libstdc++-v3/ChangeLog:

	PR libstdc++/110653
	* include/bits/basic_string.h [!_GLIBCXX_HAVE_STRTOF] (stof):
	Define in terms of std::stod.
---
 libstdc++-v3/include/bits/basic_string.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 32f5d4421f7..e4cb9846025 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -4153,6 +4153,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   inline float
   stof(const string& __str, size_t* __idx = 0)
   { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
+#else
+  inline float
+  stof(const string& __str, size_t* __idx = 0)
+  {
+    double __d = std::stod(__str, __idx);
+    if (__builtin_isfinite(__d))
+      {
+	double __abs_d = __builtin_fabs(__d);
+	if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
+	  {
+	    errno = ERANGE;
+	    std::__throw_out_of_range("stof");
+	  }
+      }
+    return __d;
+  }
 #endif
 
 #if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOLD
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed 3/3] libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653]
  2023-07-19 10:05 [committed 1/3] libstdc++: Check autoconf macros for strtof and strtold [PR110653] Jonathan Wakely
  2023-07-19 10:05 ` [committed 2/3] libstdc++: Define std::stof fallback in terms of std::stod [PR110653] Jonathan Wakely
@ 2023-07-19 10:05 ` Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-07-19 10:05 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8 --

Since the narrow string versions of std::stoi, std::stol, std::stoul,
std::stof and std::stod are now always defined, we don't need to check
dg-require-string-conversions in the relevant tests.

libstdc++-v3/ChangeLog:

	PR libstdc++/110653
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Remove dg-require-string-conversions.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
---
 .../21_strings/basic_string/numeric_conversions/char/stod.cc     | 1 -
 .../21_strings/basic_string/numeric_conversions/char/stof.cc     | 1 -
 .../21_strings/basic_string/numeric_conversions/char/stoi.cc     | 1 -
 .../21_strings/basic_string/numeric_conversions/char/stol.cc     | 1 -
 .../21_strings/basic_string/numeric_conversions/char/stoul.cc    | 1 -
 5 files changed, 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc
index 062a0203c7c..c899a69ec17 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc
@@ -1,5 +1,4 @@
 // { dg-do run { target c++11 } }
-// { dg-require-string-conversions "" }
 // { dg-xfail-run-if "broken long double IO" { newlib_broken_long_double_io  } }
 
 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
index 584af6d072e..a06cd7e48c7 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
@@ -1,5 +1,4 @@
 // { dg-do run { target c++11 } }
-// { dg-require-string-conversions "" }
 
 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc
index 1ef89728caf..f7d88065d94 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc
@@ -1,5 +1,4 @@
 // { dg-do run { target c++11 } }
-// { dg-require-string-conversions "" }
 
 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc
index 4617e38c2a9..a3e4e9cdd76 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc
@@ -1,5 +1,4 @@
 // { dg-do run { target c++11 } }
-// { dg-require-string-conversions "" }
 
 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc
index 1562d5d9fbe..705feaa5e84 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc
@@ -1,5 +1,4 @@
 // { dg-do run { target c++11 } }
-// { dg-require-string-conversions "" }
 
 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-19 10:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 10:05 [committed 1/3] libstdc++: Check autoconf macros for strtof and strtold [PR110653] Jonathan Wakely
2023-07-19 10:05 ` [committed 2/3] libstdc++: Define std::stof fallback in terms of std::stod [PR110653] Jonathan Wakely
2023-07-19 10:05 ` [committed 3/3] libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653] Jonathan Wakely

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).