From 84eb48794cd23249c6aee93da67f1023d97850fa Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 5 Mar 2002 13:09:45 +0100 Subject: [PATCH] 2002-03-05 Paolo Carlini 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. From-SVN: r50317 --- libstdc++-v3/ChangeLog | 11 ++++++++ libstdc++-v3/include/bits/locale_facets.tcc | 6 ++++- .../22_locale/num_get_members_char.cc | 25 ++++++++++++++++++- .../22_locale/num_get_members_wchar_t.cc | 23 +++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index aff975de1fc..fe2cca8526c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2002-03-05 Paolo Carlini + + 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. + 2002-03-04 Craig Rodrigues * docs/html/17_intro/porting-howto.xml: Refer to diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 4f31bd6e0c9..edee81472e3 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -174,7 +174,11 @@ namespace std } else if (__c == __dec && !__found_dec) { - __found_grouping += static_cast(__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(__sep_pos); ++__pos; __xtrc += '.'; __c = *(++__beg); diff --git a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc index e8f2219543c..5630351e2d5 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc @@ -343,7 +343,7 @@ void test04() 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 @@ void test04() 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& ng = use_facet >(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 --git a/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc index 807fb5b1474..c4927e18fb7 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc @@ -391,6 +391,28 @@ void test04() 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& ng = use_facet >(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 @@ int main() test02(); test03(); test04(); + test05(); #endif return 0; } -- 2.30.2