* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
@ 2023-07-13 9:43 ` redi at gcc dot gnu.org
2023-07-13 13:46 ` redi at gcc dot gnu.org
` (21 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-13 9:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2023-07-13
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
std::stoi, std::stol and stoul only depend on strtol and strtoul which are in
C89, so don't need to be guarded by _GLIBCXX_USE_C99_STDLIB
std::stoll and std::stoull can be implemented without C99 strtoll and strtoull
if sizeof(long) == sizeof(long long).
std::stod only depends on strtod which is in C89.
std::stold can be implemented without C99 strtold if DBL_MANT_DIG ==
LDBL_MANT_DIG.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
2023-07-13 9:43 ` [Bug libstdc++/110653] " redi at gcc dot gnu.org
@ 2023-07-13 13:46 ` redi at gcc dot gnu.org
2023-07-13 15:14 ` dave.anglin at bell dot net
` (20 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-13 13:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 55534
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55534&action=edit
libstdc++: std::stoi etc. do not need C99 <stdlib.h> support
Dave, does this patch work for hppa64-hp-hpux11.11 ?
It should allow you to compile + run the code below:
#include <string>
int main()
{
std::string z = "0";
return std::stoi(z) + std::stol(z) + std::stoul(z) + std::stoll(z)
+ std::stoull(z) + std::stod(z);
}
I'm not sure if double and long double are the same representation on this
target, but if they are then std::stold("0.0") should work too.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
2023-07-13 9:43 ` [Bug libstdc++/110653] " redi at gcc dot gnu.org
2023-07-13 13:46 ` redi at gcc dot gnu.org
@ 2023-07-13 15:14 ` dave.anglin at bell dot net
2023-07-13 16:59 ` cvs-commit at gcc dot gnu.org
` (19 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-13 15:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #3 from dave.anglin at bell dot net ---
On 2023-07-13 9:46 a.m., redi at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
>
> --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> Created attachment 55534
> --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55534&action=edit
> libstdc++: std::stoi etc. do not need C99 <stdlib.h> support
>
> Dave, does this patch work for hppa64-hp-hpux11.11 ?
Yes.
>
> It should allow you to compile + run the code below:
>
> #include <string>
> int main()
> {
> std::string z = "0";
> return std::stoi(z) + std::stol(z) + std::stoul(z) + std::stoll(z)
> + std::stoull(z) + std::stod(z);
> }
The above code compiles and runs successfully on hppa64-hp-hpux11.11 with the
patch.
>
> I'm not sure if double and long double are the same representation on this
> target, but if they are then std::stold("0.0") should work too.
Adding std::stold("0.0") to test, we get:
bash-5.1$ gcc/xg++ -Bgcc/ -o xxx xxx.cc
-I./hppa64-hp-hpux11.11/libstdc++-v3/include
-I./hppa64-hp-hpux11.11/libstdc++-v3/include/hppa64-hp-hpux11.11
-I/home/dave/gnu/gcc/gcc/libstdc++-v3/libsupc++
-Lhppa64-hp-hpux11.11/libstdc++-v3/src/.libs -O2
xxx.cc: In function 'int main()':
xxx.cc:6:48: error: 'stold' is not a member of 'std'
6 | + std::stoull(z) + std::stod(z) + std::stold("0.0");
| ^~~~~
xxx.cc:2:1: note: 'std::stold' is defined in header '<string>'; this is
probably fixable by adding '#include <string>'
1 | #include <string>
+++ |+#include <string>
2 | int main()
On hpux, double and long double have different representations (they are same
on linux). hpux11.11 has both
strtod and strtold. strtold is checked for:
/* Define to 1 if you have the `strtof' function. */
/* #undef HAVE_STRTOF */
/* Define to 1 if you have the `strtold' function. */
#define HAVE_STRTOLD 1
There doesn't seem to be a configure check for strtod.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (2 preceding siblings ...)
2023-07-13 15:14 ` dave.anglin at bell dot net
@ 2023-07-13 16:59 ` cvs-commit at gcc dot gnu.org
2023-07-13 17:09 ` redi at gcc dot gnu.org
` (18 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-13 16:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
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.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (3 preceding siblings ...)
2023-07-13 16:59 ` cvs-commit at gcc dot gnu.org
@ 2023-07-13 17:09 ` redi at gcc dot gnu.org
2023-07-13 17:57 ` dave.anglin at bell dot net
` (17 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-13 17:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to dave.anglin from comment #3)
> On 2023-07-13 9:46 a.m., redi at gcc dot gnu.org wrote:
> > Dave, does this patch work for hppa64-hp-hpux11.11 ?
> Yes.
Great - pushed to trunk.
> On hpux, double and long double have different representations (they are
> same on linux). hpux11.11 has both
> strtod and strtold. strtold is checked for:
>
> /* Define to 1 if you have the `strtof' function. */
> /* #undef HAVE_STRTOF */
>
> /* Define to 1 if you have the `strtold' function. */
> #define HAVE_STRTOLD 1
Ah yes. That comes from libstdc++-v3/linkage.m4 which I think I've never even
looked at before!
> There doesn't seem to be a configure check for strtod.
That's from C89 and we already assume that's available unconditionally e.g. for
this code in <cstdlib>:
using ::strtod;
using ::strtol;
using ::strtoul;
I'm testing this, which should define std::stof and std::stold for hpux11.11:
--- 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
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (4 preceding siblings ...)
2023-07-13 17:09 ` redi at gcc dot gnu.org
@ 2023-07-13 17:57 ` dave.anglin at bell dot net
2023-07-13 18:16 ` dave.anglin at bell dot net
` (16 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-13 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #6 from dave.anglin at bell dot net ---
On 2023-07-13 1:09 p.m., redi at gcc dot gnu.org wrote:
> I'm testing this, which should define std::stof and std::stold for hpux11.11:
>
> --- 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
We get this error with the above:
bash-5.1$ gcc/xg++ -Bgcc/ -o xxx xxx.cc
-I./hppa64-hp-hpux11.11/libstdc++-v3/include
-I./hppa64-hp-hpux11.11/libstdc++-v3/include/hppa64-hp-hpux11.11
-I/home/dave/gnu/gcc/gcc/libstdc++-v3/libsupc++
-Lhppa64-hp-hpux11.11/libstdc++-v3/src/.libs -O2
In file included from ./hppa64-hp-hpux11.11/libstdc++-v3/include/string:54,
from xxx.cc:1:
./hppa64-hp-hpux11.11/libstdc++-v3/include/bits/basic_string.h: In function
'long double std::__cxx11::stold(const std::string&, std::size_t*)':
./hppa64-hp-hpux11.11/libstdc++-v3/include/bits/basic_string.h:4161:36: error:
'strtold' is not a member of 'std'; did you mean 'strtoll'?
4161 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(),
__idx); }
| ^~~~~~~
| strtoll
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (5 preceding siblings ...)
2023-07-13 17:57 ` dave.anglin at bell dot net
@ 2023-07-13 18:16 ` dave.anglin at bell dot net
2023-07-14 1:20 ` dave.anglin at bell dot net
` (15 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-13 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #7 from dave.anglin at bell dot net ---
On 2023-07-13 1:57 p.m., dave.anglin at bell dot net wrote:
> ./hppa64-hp-hpux11.11/libstdc++-v3/include/bits/basic_string.h:4161:36: error:
> 'strtold' is not a member of 'std'; did you mean 'strtoll'?
That's a problem with stdlib.h header.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (6 preceding siblings ...)
2023-07-13 18:16 ` dave.anglin at bell dot net
@ 2023-07-14 1:20 ` dave.anglin at bell dot net
2023-07-14 7:39 ` redi at gcc dot gnu.org
` (14 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-14 1:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #8 from dave.anglin at bell dot net ---
On 2023-07-13 2:16 p.m., dave.anglin at bell dot net wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
>
> --- Comment #7 from dave.anglin at bell dot net ---
> On 2023-07-13 1:57 p.m., dave.anglin at bell dot net wrote:
>> ./hppa64-hp-hpux11.11/libstdc++-v3/include/bits/basic_string.h:4161:36: error:
>> 'strtold' is not a member of 'std'; did you mean 'strtoll'?
> That's a problem with stdlib.h header.
I thought this was because we lack _NAMESPACE_STD_START and _NAMESPACE_STD_END
statements
around the strtold declaration in stdlib.h, but this didn't help. Maybe we lack
a define for _NAMESPACE_STD
/* ANSI C++ namespace std support */
#ifdef _NAMESPACE_STD
#define _NAMESPACE_STD_START namespace std {
#define _NAMESPACE_STD_END }
or maybe "using::strtold" additions are needed to various cstdlib files in gcc.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (7 preceding siblings ...)
2023-07-14 1:20 ` dave.anglin at bell dot net
@ 2023-07-14 7:39 ` redi at gcc dot gnu.org
2023-07-14 9:58 ` redi at gcc dot gnu.org
` (13 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-14 7:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to dave.anglin from comment #8)
> or maybe "using::strtold" additions are needed to various cstdlib files in
> gcc.
Yes, that's the problem.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (8 preceding siblings ...)
2023-07-14 7:39 ` redi at gcc dot gnu.org
@ 2023-07-14 9:58 ` redi at gcc dot gnu.org
2023-07-15 14:52 ` dave.anglin at bell dot net
` (12 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-14 9:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And this should fix it:
--- 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++"
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (9 preceding siblings ...)
2023-07-14 9:58 ` redi at gcc dot gnu.org
@ 2023-07-15 14:52 ` dave.anglin at bell dot net
2023-07-15 19:39 ` redi at gcc dot gnu.org
` (11 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-15 14:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #11 from dave.anglin at bell dot net ---
On 2023-07-14 5:58 a.m., redi at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
>
> --- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> And this should fix it:
>
> --- 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++"
Yes, this works.
hppa64-hpux does not have have strtof. Could std::stof be implemented using
strtod in this case?
I'm thinking a test to check the presence and maybe compliance of these
routines might be good.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (10 preceding siblings ...)
2023-07-15 14:52 ` dave.anglin at bell dot net
@ 2023-07-15 19:39 ` redi at gcc dot gnu.org
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
` (10 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-15 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to dave.anglin from comment #11)
> Yes, this works.
Great, thanks.
> hppa64-hpux does not have have strtof. Could std::stof be implemented using
> strtod in this case?
Maybe something like this:
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -4153,6 +4153,25 @@ _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__)
+ errno = ERANGE;
+ else if (__abs_d > __FLT_MAX__)
+ {
+ errno = ERANGE;
+ float __f = __builtin_huge_valf();
+ return __d > 0.0 ? __f : -__f;
+ }
+ }
+ return __d;
+ }
#endif
#if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOLD
> I'm thinking a test to check the presence and maybe compliance of these
> routines might be good.
We have some:
testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc
But they depend on { dg-require-string-conversions "" } which is only true if
we have the full set of them:
return [check_v3_target_prop_cached et_string_conversions {
set cond "_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB"
set cond "$cond && _GLIBCXX_USE_C99_WCHAR"
set cond "$cond && !defined _GLIBCXX_HAVE_BROKEN_VSWPRINTF"
return [v3_check_preprocessor_condition string_conversions $cond]
}]
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (11 preceding siblings ...)
2023-07-15 19:39 ` redi at gcc dot gnu.org
@ 2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
` (9 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-19 10:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:58303d42809f0e01f23262f592d37943f7703f71
commit r14-2635-g58303d42809f0e01f23262f592d37943f7703f71
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jul 13 10:44:57 2023 +0100
libstdc++: Check autoconf macros for strtof and strtold [PR110653]
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.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (12 preceding siblings ...)
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
@ 2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
` (8 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-19 10:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:f0b0c21152b337bc9a8ef3a72a15c8dcdff1d847
commit r14-2636-gf0b0c21152b337bc9a8ef3a72a15c8dcdff1d847
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Jul 15 20:41:28 2023 +0100
libstdc++: Define std::stof fallback in terms of std::stod [PR110653]
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.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (13 preceding siblings ...)
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
@ 2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
2023-07-19 10:10 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-19 10:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #15 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:f07136af570b145fe0df6b142defc9558998bf53
commit r14-2637-gf07136af570b145fe0df6b142defc9558998bf53
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Jul 15 20:58:22 2023 +0100
libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653]
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.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (14 preceding siblings ...)
2023-07-19 10:04 ` cvs-commit at gcc dot gnu.org
@ 2023-07-19 10:10 ` redi at gcc dot gnu.org
2023-07-19 10:10 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 10:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #16 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This should be fixed now, and you should see these in libstdc++.sum
PASS: 21_strings/basic_string/numeric_conversions/char/stod.cc (test for excess
errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stod.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stof.cc (test for excess
errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stoi.cc (test for excess
errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stoi.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stol.cc (test for excess
errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stol.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stold.cc (test for
excess errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stold.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc (test for
excess errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc execution test
PASS: 21_strings/basic_string/numeric_conversions/char/stoul.cc (test for
excess errors)
PASS: 21_strings/basic_string/numeric_conversions/char/stoul.cc execution test
The char/stoll.cc and char/stoull.cc tests would actually pass for hpux11.11 as
well, but they have the { dg-require-string-conversions "" } check which fails.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (15 preceding siblings ...)
2023-07-19 10:10 ` redi at gcc dot gnu.org
@ 2023-07-19 10:10 ` redi at gcc dot gnu.org
2023-07-19 13:48 ` dave.anglin at bell dot net
` (5 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 10:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #16)
> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc (test for
> excess errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc execution
> test
Oops, sorry, not that one! As mentioned, that will be UNSUPPORTED for hpux11.11
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (16 preceding siblings ...)
2023-07-19 10:10 ` redi at gcc dot gnu.org
@ 2023-07-19 13:48 ` dave.anglin at bell dot net
2023-07-19 13:51 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-19 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #18 from dave.anglin at bell dot net ---
On 2023-07-19 6:10 a.m., redi at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
>
> --- Comment #16 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> This should be fixed now, and you should see these in libstdc++.sum
>
> PASS: 21_strings/basic_string/numeric_conversions/char/stod.cc (test for excess
> errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stod.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stof.cc (test for excess
> errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stoi.cc (test for excess
> errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stoi.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stol.cc (test for excess
> errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stol.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stold.cc (test for
> excess errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stold.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc (test for
> excess errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc execution test
> PASS: 21_strings/basic_string/numeric_conversions/char/stoul.cc (test for
> excess errors)
> PASS: 21_strings/basic_string/numeric_conversions/char/stoul.cc execution test
>
> The char/stoll.cc and char/stoull.cc tests would actually pass for hpux11.11 as
> well, but they have the { dg-require-string-conversions "" } check which fails.
Had the following fails with attached patch:
Running target unix
FAIL: 20_util/from_chars/4.cc execution test
FAIL: 20_util/from_chars/8.cc execution test
FAIL: 20_util/to_chars/float128_c++23.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/char/stold.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc (test for
excess errors)
UNRESOLVED: 21_strings/basic_string/numeric_conversions/wchar_t/dr1261.cc
compilation failed to produce executable
FAIL: 26_numerics/headers/cmath/constexpr_std_c++23.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/functions_std_c++23.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/nextafter_c++23.cc (test for excess errors)
UNRESOLVED: 26_numerics/headers/cmath/nextafter_c++23.cc compilation failed to
produce executable
FAIL: 27_io/basic_ofstream/open/char/noreplace.cc execution test
FAIL: 27_io/basic_ofstream/open/wchar_t/noreplace.cc execution test
FAIL: 27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc execution test
FAIL: 29_atomics/atomic/compare_exchange_padding.cc execution test
FAIL: 29_atomics/atomic/lock_free_aliases.cc (test for excess errors)
FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc execution test
=== libstdc++ Summary ===
# of expected passes 14134
# of unexpected failures 15
# of expected failures 106
# of unresolved testcases 2
# of unsupported tests 1014
The stof.cc and stold.cc tests fail in try-catch.
/home/dave/gnu/gcc/gcc/libstdc++-v3/testsuite/21_strings/basic_string/numeric_co
nversions/char/stof.cc:128: void test01(): Assertion 'test' failed.
FAIL: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test
/home/dave/gnu/gcc/gcc/libstdc++-v3/testsuite/21_strings/basic_string/numeric_co
nversions/char/stold.cc:95: void test01(): Assertion 'test' failed.
FAIL: 21_strings/basic_string/numeric_conversions/char/stold.cc execution test
Will retest with your commit.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (17 preceding siblings ...)
2023-07-19 13:48 ` dave.anglin at bell dot net
@ 2023-07-19 13:51 ` redi at gcc dot gnu.org
2023-07-21 18:25 ` dave.anglin at bell dot net
` (3 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 13:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #19 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to dave.anglin from comment #18)
> The stof.cc and stold.cc tests fail in try-catch.
Yes, my suggested patch in comment 12 was wrong, because it only set errno on
error and didn't throw an exception.
What I committed should be OK.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (18 preceding siblings ...)
2023-07-19 13:51 ` redi at gcc dot gnu.org
@ 2023-07-21 18:25 ` dave.anglin at bell dot net
2023-07-21 18:27 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: dave.anglin at bell dot net @ 2023-07-21 18:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #20 from dave.anglin at bell dot net ---
On 2023-07-19 6:10 a.m., redi at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
>
> --- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> (In reply to Jonathan Wakely from comment #16)
>> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc (test for
>> excess errors)
>> PASS: 21_strings/basic_string/numeric_conversions/char/stoll.cc execution
>> test
> Oops, sorry, not that one! As mentioned, that will be UNSUPPORTED for hpux11.11
Yes, stoll and stoull tests are UNSUPPORTED.
We also have:
UNSUPPORTED: 21_strings/basic_string/numeric_conversions/char/stold.cc
The rest of the non wide character conversion tests pass.
The stoll and stoull tests pass when dg-require-string-conversions is 1. The
stold test
fails, I think because it returns LDBL_MAX instead of HUGE_VALL (inf). See
_GLIBCXX_HAVE_BROKEN_STRTOLD comment in /config/os/hpux/os_defines.h.
There is a problem with std::stof. It throws an out of range exception for 0.
It needs to
check for 0 value.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (19 preceding siblings ...)
2023-07-21 18:25 ` dave.anglin at bell dot net
@ 2023-07-21 18:27 ` redi at gcc dot gnu.org
2023-07-24 20:04 ` cvs-commit at gcc dot gnu.org
2023-08-10 19:25 ` danglin at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-21 18:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #21 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to dave.anglin from comment #20)
> The stoll and stoull tests pass when dg-require-string-conversions is 1.
> The stold test
> fails, I think because it returns LDBL_MAX instead of HUGE_VALL (inf). See
> _GLIBCXX_HAVE_BROKEN_STRTOLD comment in /config/os/hpux/os_defines.h.
Aha.
> There is a problem with std::stof. It throws an out of range exception for
> 0. It needs to
> check for 0 value.
Oops :-)
I'll fix both of these on Monday - thanks for the testing and analysis.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (20 preceding siblings ...)
2023-07-21 18:27 ` redi at gcc dot gnu.org
@ 2023-07-24 20:04 ` cvs-commit at gcc dot gnu.org
2023-08-10 19:25 ` danglin at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-24 20:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #22 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:31c3b67dfc6e67773d13260bc38b833663698b74
commit r14-2753-g31c3b67dfc6e67773d13260bc38b833663698b74
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jul 24 11:45:43 2023 +0100
libstdc++; Do not use strtold for hppa-hpux [PR110653]
When I switched std::stold to depend on HAVE_STRTOLD that enabled it for
hppa-hpux which defines HAVE_BROKEN_STRTOLD. Add a check for that macro
so that we don't use strtold, and fall through to the check for double
and long double having the same representation. That should mean we
define a conforming std::stold in terms of std::stod, instead of trying
to use the broken strtold.
Also fix a logic error in the fallback definition of std::stod, which
should not treat zero as a subnormal number.
libstdc++-v3/ChangeLog:
PR libstdc++/110653
* include/bits/basic_string.h [!HAVE_STOF] (stof): Do not
throw an exception for zero result.
[HAVE_BROKEN_STRTOLD] (stold): Do not use strtold.
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Bug libstdc++/110653] Support std::stoi etc. without C99 APIs
2023-07-13 9:40 [Bug libstdc++/110653] New: Support std::stoi etc. without C99 APIs redi at gcc dot gnu.org
` (21 preceding siblings ...)
2023-07-24 20:04 ` cvs-commit at gcc dot gnu.org
@ 2023-08-10 19:25 ` danglin at gcc dot gnu.org
22 siblings, 0 replies; 24+ messages in thread
From: danglin at gcc dot gnu.org @ 2023-08-10 19:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
John David Anglin <danglin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #23 from John David Anglin <danglin at gcc dot gnu.org> ---
Fixed by last commit.
^ permalink raw reply [flat|nested] 24+ messages in thread