https://gcc.gnu.org/g:878bb62cfc158b5324cc2b2476f92fb4237fd82a

commit r15-3067-g878bb62cfc158b5324cc2b2476f92fb4237fd82a
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed May 8 10:03:20 2024 +0100

    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.

Diff:
---
 libstdc++-v3/src/c++98/locale_facets.cc            | 13 +++---
 .../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 fa469b1b8727..02f53fd5ec1c 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 000000000000..b7c7da11f863
--- /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();
+}

Reply via email to