This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix libstdc++/5816


Hi,

with Nathan's help for the correct interpretation of the standard, I have easily
fixed the problem. Now in locales expecting grouping (e.g., de_DE) doubles
behave as integers do when no grouping chars are seen.

Many thanks to Peter Schmid for continuos testing!!

Tested i686-pc-linux-gnu.

Ciao, Paolo.

/////////////

2002-03-04  Paolo Carlini  <pcarlini@unitus.it>

        libstdc++/5816
        * include/bits/locale_facets.tcc
        (num_get::_M_extract_float): Fix the parsing of __dec, since
        the standard prescribes that if no grouping characters are
        seen, no grouping check is applied.
        * testsuite/22_locale/num_get_members_char.cc: Add test05
        distilled from the PR.
        * testsuite/22_locale/num_get_members_wchar_t.cc: Ditto.

diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc
libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc Sun Mar  3 19:18:41 2002
+++ libstdc++-v3/include/bits/locale_facets.tcc Mon Mar  4 00:12:23 2002
@@ -174,7 +174,11 @@
             }
    else if (__c == __dec && !__found_dec)
      {
-       __found_grouping += static_cast<char>(__sep_pos);
+       // According to the standard, if no grouping chars are seen,
+       // no grouping check is applied. Therefore __found_grouping
+       // must be adjusted only if __dec comes after some __sep.
+       if (__found_grouping.size())
+  __found_grouping += static_cast<char>(__sep_pos);
        ++__pos;
        __xtrc += '.';
        __c = *(++__beg);
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get_members_char.cc
libstdc++-v3/testsuite/22_locale/num_get_members_char.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get_members_char.cc Sat Mar  2
12:04:47 2002
+++ libstdc++-v3/testsuite/22_locale/num_get_members_char.cc Mon Mar  4 00:46:20
2002
@@ -343,7 +343,7 @@

   istringstream iss;

-  // A locale that expects grouping
+  // A locale that expects grouping
   locale loc_de("de_DE");
   iss.imbue(loc_de);

@@ -390,12 +390,35 @@
   VERIFY( ul == 0776 );
 }

+// libstdc++/5816
+void test05()
+{
+  using namespace std;
+
+  double d = 0.0;
+
+  istringstream iss;
+  locale loc_de("de_DE");
+  iss.imbue(loc_de);
+
+  const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
+  const ios_base::iostate goodbit = ios_base::goodbit;
+  ios_base::iostate err = ios_base::goodbit;
+
+  iss.str("1234,5 ");
+  err = goodbit;
+  ng.get(iss.rdbuf(), 0, iss, err, d);
+  VERIFY( err == goodbit );
+  VERIFY( d == 1234.5 );
+}
+
 int main()
 {
   test01();
   test02();
   test03();
   test04();
+  test05();
   return 0;
 }

diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get_members_wchar_t.cc
libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get_members_wchar_t.cc Sat Mar  2
12:06:22 2002
+++ libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc Mon Mar  4
00:43:35 2002
@@ -391,6 +391,28 @@
   VERIFY( err == goodbit );
   VERIFY( ul == 0776 );
 }
+
+// libstdc++/5816
+void test05()
+{
+  using namespace std;
+
+  double d = 0.0;
+
+  wistringstream iss;
+  locale loc_de("de_DE");
+  iss.imbue(loc_de);
+
+  const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc());
+  const ios_base::iostate goodbit = ios_base::goodbit;
+  ios_base::iostate err = ios_base::goodbit;
+
+  iss.str(L"1234,5 ");
+  err = goodbit;
+  ng.get(iss.rdbuf(), 0, iss, err, d);
+  VERIFY( err == goodbit );
+  VERIFY( d == 1234.5 );
+}
 #endif

 int main()
@@ -400,6 +422,7 @@
   test02();
   test03();
   test04();
+  test05();
 #endif
   return 0;
 }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]