From: Paolo Carlini Date: Sat, 1 Nov 2008 22:09:43 +0000 (+0000) Subject: PR libstdc++/37958 (cont again) X-Git-Tag: releases/gcc-4.4.0~1856 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ea6fdf55ed1bb2986e26f6a627d1d04b36491d7;p=thirdparty%2Fgcc.git PR libstdc++/37958 (cont again) 2008-11-01 Paolo Carlini PR libstdc++/37958 (cont again) * include/bits/locale_facets.tcc (num_get<>::do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&): Fix again. * testsuite/22_locale/num_get/get/char/37958.cc: Extend. * testsuite/22_locale/num_get/get/wchar_t/37958.cc: Likewise. From-SVN: r141523 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e3388df23b78..18fd23283d3e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2008-11-01 Paolo Carlini + + PR libstdc++/37958 (cont again) + * include/bits/locale_facets.tcc (num_get<>::do_get(iter_type, + iter_type, ios_base&, ios_base::iostate&, bool&): Fix again. + * testsuite/22_locale/num_get/get/char/37958.cc: Extend. + * testsuite/22_locale/num_get/get/wchar_t/37958.cc: Likewise. + 2008-11-01 Paolo Carlini * include/bits/locale_facets.tcc (num_get<>::do_get(, long&), diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index bee770bd03f9..36a2d9b80c4a 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -606,11 +606,11 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE bool __testf = true; bool __testt = true; + bool __donef = __lc->_M_falsename_size == 0; + bool __donet = __lc->_M_truename_size == 0; bool __testeof = false; - size_t __n; - const size_t __lim = std::max(__lc->_M_falsename_size, - __lc->_M_truename_size); - for (__n = 0; __n < __lim; ++__n, ++__beg) + size_t __n = 0; + while (!__donef || !__donet) { if (__beg == __end) { @@ -620,10 +620,10 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE const char_type __c = *__beg; - if (__testf && __n < __lc->_M_falsename_size) + if (!__donef) __testf = __c == __lc->_M_falsename[__n]; - if (__testt && __n < __lc->_M_truename_size) + if (!__donet) __testt = __c == __lc->_M_truename[__n]; if (!__testt && !__testf) @@ -632,6 +632,12 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE if ((!__testt && __n >= __lc->_M_falsename_size) || (!__testf && __n >= __lc->_M_truename_size)) break; + + ++__n; + ++__beg; + + __donef = !__testf || __n >= __lc->_M_falsename_size; + __donet = !__testt || __n >= __lc->_M_truename_size; } if (__testf && __n == __lc->_M_falsename_size && __n) { diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc index 6e931705da61..9f7a43c4c1e9 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc @@ -50,20 +50,36 @@ void test01() bool test __attribute__((unused)) = true; - istringstream iss1, iss2, iss3; + istringstream iss0, iss1, iss2, iss3; iss1.imbue(locale(iss1.getloc(), new Punct1)); iss2.imbue(locale(iss2.getloc(), new Punct2)); iss3.imbue(locale(iss3.getloc(), new Punct3)); + const num_get& ng0 = use_facet >(iss0.getloc()); const num_get& ng1 = use_facet >(iss1.getloc()); const num_get& ng2 = use_facet >(iss2.getloc()); const num_get& ng3 = use_facet >(iss3.getloc()); ios_base::iostate err = ios_base::goodbit; iterator_type end; + bool b0 = false; bool b1 = false; bool b2 = false; bool b3 = true; + iss0.str("true"); + iss0.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == true ); + + iss0.str("false"); + iss0.clear(); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == false ); + iss1.str("a"); iss1.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -93,6 +109,13 @@ void test01() VERIFY( err == ios_base::goodbit ); VERIFY( b2 == true ); + iss2.str("0"); + iss2.clear(); + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::goodbit ); + VERIFY( b2 == false ); + iss3.str("blah"); iss3.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -100,6 +123,14 @@ void test01() VERIFY( err == ios_base::failbit ); VERIFY( b3 == false ); VERIFY( *end == 'b' ); + + iss3.str(""); + iss3.clear(); + b3 = true; + err = ios_base::goodbit; + end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); + VERIFY( err == ios_base::failbit ); + VERIFY( b3 == false ); } int main() diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/37958.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/37958.cc index a9ce6df01277..b36573697a40 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/37958.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/37958.cc @@ -50,20 +50,36 @@ void test01() bool test __attribute__((unused)) = true; - wistringstream iss1, iss2, iss3; + wistringstream iss0, iss1, iss2, iss3; iss1.imbue(locale(iss1.getloc(), new Punct1)); iss2.imbue(locale(iss2.getloc(), new Punct2)); iss3.imbue(locale(iss3.getloc(), new Punct3)); + const num_get& ng0 = use_facet >(iss0.getloc()); const num_get& ng1 = use_facet >(iss1.getloc()); const num_get& ng2 = use_facet >(iss2.getloc()); const num_get& ng3 = use_facet >(iss3.getloc()); ios_base::iostate err = ios_base::goodbit; iterator_type end; + bool b0 = false; bool b1 = false; bool b2 = false; bool b3 = true; + iss0.str(L"true"); + iss0.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == true ); + + iss0.str(L"false"); + iss0.clear(); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == false ); + iss1.str(L"a"); iss1.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -93,6 +109,13 @@ void test01() VERIFY( err == ios_base::goodbit ); VERIFY( b2 == true ); + iss2.str(L"0"); + iss2.clear(); + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::goodbit ); + VERIFY( b2 == false ); + iss3.str(L"blah"); iss3.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -100,6 +123,14 @@ void test01() VERIFY( err == ios_base::failbit ); VERIFY( b3 == false ); VERIFY( *end == L'b' ); + + iss3.str(L""); + iss3.clear(); + b3 = true; + err = ios_base::goodbit; + end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); + VERIFY( err == ios_base::failbit ); + VERIFY( b3 == false ); } int main()