diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-05-08 10:03:20 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-08-21 10:16:59 +0100 |
commit | 878bb62cfc158b5324cc2b2476f92fb4237fd82a (patch) | |
tree | 16ca59ef81dbf1c77364e8c94a6145221e8c7f23 | |
parent | 723b30bee4e4fa3feba9ef03ce7dca95501e1555 (diff) | |
download | gcc-878bb62cfc158b5324cc2b2476f92fb4237fd82a.zip gcc-878bb62cfc158b5324cc2b2476f92fb4237fd82a.tar.gz gcc-878bb62cfc158b5324cc2b2476f92fb4237fd82a.tar.bz2 |
libstdc++: Check ios::uppercase for ios::fixed floating-point output [PR114862]
This is LWG 4084 which I filed recently. LWG seems to support making the
change, so that std::num_put can use the %F format for floating-point
numbers.
libstdc++-v3/ChangeLog:
PR libstdc++/114862
* src/c++98/locale_facets.cc (__num_base::_S_format_float):
Check uppercase flag for fixed format.
* testsuite/22_locale/num_put/put/char/lwg4084.cc: New test.
-rw-r--r-- | libstdc++-v3/src/c++98/locale_facets.cc | 13 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc | 46 |
2 files changed, 54 insertions, 5 deletions
diff --git a/libstdc++-v3/src/c++98/locale_facets.cc b/libstdc++-v3/src/c++98/locale_facets.cc index fa469b1..02f53fd 100644 --- a/libstdc++-v3/src/c++98/locale_facets.cc +++ b/libstdc++-v3/src/c++98/locale_facets.cc @@ -84,17 +84,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__mod) *__fptr++ = __mod; - // [22.2.2.2.2] Table 58 + // C++11 [facet.num.put.virtuals] Table 88 + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4084. std::fixed ignores std::uppercase + bool __upper = __flags & ios_base::uppercase; if (__fltfield == ios_base::fixed) - *__fptr++ = 'f'; + *__fptr++ = __upper ? 'F' : 'f'; else if (__fltfield == ios_base::scientific) - *__fptr++ = (__flags & ios_base::uppercase) ? 'E' : 'e'; + *__fptr++ = __upper ? 'E' : 'e'; #if _GLIBCXX_USE_C99_STDIO else if (__fltfield == (ios_base::fixed | ios_base::scientific)) - *__fptr++ = (__flags & ios_base::uppercase) ? 'A' : 'a'; + *__fptr++ = __upper ? 'A' : 'a'; #endif else - *__fptr++ = (__flags & ios_base::uppercase) ? 'G' : 'g'; + *__fptr++ = __upper ? 'G' : 'g'; *__fptr = '\0'; } diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc new file mode 100644 index 0000000..b7c7da1 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc @@ -0,0 +1,46 @@ +// { dg-do run } +// LWG 4084. std::fixed ignores std::uppercase +// PR libstdc++/114862 std::uppercase not applying to nan's and inf's + +#include <sstream> +#include <limits> +#include <iomanip> +#include <testsuite_hooks.h> + +void +test_nan() +{ + std::ostringstream out; + double nan = std::numeric_limits<double>::quiet_NaN(); + out << std::fixed; + out << ' ' << nan << ' ' << -nan; + out << std::uppercase; + out << ' ' << nan << ' ' << -nan; + out << std::showpoint; + out << ' ' << nan << ' ' << -nan; + out << std::showpos; + out << ' ' << nan << ' ' << -nan; + VERIFY( out.str() == " nan -nan NAN -NAN NAN -NAN +NAN -NAN" ); +} + +void +test_inf() +{ + std::ostringstream out; + double inf = std::numeric_limits<double>::infinity(); + out << std::fixed; + out << ' ' << inf << ' ' << -inf; + out << std::uppercase; + out << ' ' << inf << ' ' << -inf; + out << std::showpoint; + out << ' ' << inf << ' ' << -inf; + out << std::showpos; + out << ' ' << inf << ' ' << -inf; + VERIFY( out.str() == " inf -inf INF -INF INF -INF +INF -INF" ); +} + +int main() +{ + test_nan(); + test_inf(); +} |