From a8940b843be070a16a46bc296785b82fa1430493 Mon Sep 17 00:00:00 2001 From: paolo Date: Mon, 3 Nov 2008 10:23:38 +0000 Subject: 2008-11-03 Paolo Carlini * include/bits/locale_facets.tcc (num_get<>::do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&): Tidy. * testsuite/22_locale/num_get/get/char/37958.cc: Extend. * testsuite/22_locale/num_get/get/wchar_t/37958.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141546 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 7 +++ libstdc++-v3/include/bits/locale_facets.tcc | 8 +-- .../testsuite/22_locale/num_get/get/char/37958.cc | 59 +++++++++++++++++++++- .../22_locale/num_get/get/wchar_t/37958.cc | 59 +++++++++++++++++++++- 4 files changed, 128 insertions(+), 5 deletions(-) (limited to 'libstdc++-v3') diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 18fd23283d3..47ffacc35ce 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2008-11-03 Paolo Carlini + + * include/bits/locale_facets.tcc (num_get<>::do_get(iter_type, + iter_type, ios_base&, ios_base::iostate&, bool&): Tidy. + * 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 PR libstdc++/37958 (cont again) diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 36a2d9b80c4..9a44007e451 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -623,14 +623,16 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE if (!__donef) __testf = __c == __lc->_M_falsename[__n]; + if (!__testf && __donet) + break; + if (!__donet) __testt = __c == __lc->_M_truename[__n]; - if (!__testt && !__testf) + if (!__testt && __donef) break; - if ((!__testt && __n >= __lc->_M_falsename_size) - || (!__testf && __n >= __lc->_M_truename_size)) + if (!__testt && !__testf) break; ++__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 9f7a43c4c1e..fe8161c31d5 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 @@ -42,6 +42,12 @@ struct Punct3: std::numpunct std::string do_falsename() const { return ""; } }; +struct Punct4: std::numpunct +{ + std::string do_truename() const { return "one"; } + std::string do_falsename() const { return "two"; } +}; + // libstdc++/37958 void test01() { @@ -50,14 +56,16 @@ void test01() bool test __attribute__((unused)) = true; - istringstream iss0, iss1, iss2, iss3; + istringstream iss0, iss1, iss2, iss3, iss4; iss1.imbue(locale(iss1.getloc(), new Punct1)); iss2.imbue(locale(iss2.getloc(), new Punct2)); iss3.imbue(locale(iss3.getloc(), new Punct3)); + iss4.imbue(locale(iss4.getloc(), new Punct4)); 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()); + const num_get& ng4 = use_facet >(iss4.getloc()); ios_base::iostate err = ios_base::goodbit; iterator_type end; @@ -65,6 +73,7 @@ void test01() bool b1 = false; bool b2 = false; bool b3 = true; + bool b4 = false; iss0.str("true"); iss0.setf(ios_base::boolalpha); @@ -102,6 +111,14 @@ void test01() VERIFY( b1 == false ); VERIFY( *end == 'c' ); + iss1.str("ab"); + iss1.clear(); + b1 = true; + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b1 == false ); + iss2.str("1"); iss2.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -116,6 +133,15 @@ void test01() VERIFY( err == ios_base::goodbit ); VERIFY( b2 == false ); + iss2.str("2"); + iss2.clear(); + b2 = true; + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::failbit ); + VERIFY( b2 == false ); + VERIFY( *end == '2' ); + iss3.str("blah"); iss3.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -131,6 +157,37 @@ void test01() end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); VERIFY( err == ios_base::failbit ); VERIFY( b3 == false ); + + iss4.str("one"); + iss4.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == true ); + + iss4.str("two"); + iss4.clear(); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == false ); + + iss4.str("three"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::failbit ); + VERIFY( b4 == false ); + VERIFY( *end == 'h' ); + + iss4.str("on"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b4 == 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 b36573697a4..e48024510e0 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 @@ -42,6 +42,12 @@ struct Punct3: std::numpunct std::wstring do_falsename() const { return L""; } }; +struct Punct4: std::numpunct +{ + std::wstring do_truename() const { return L"one"; } + std::wstring do_falsename() const { return L"two"; } +}; + // libstdc++/37958 void test01() { @@ -50,14 +56,16 @@ void test01() bool test __attribute__((unused)) = true; - wistringstream iss0, iss1, iss2, iss3; + wistringstream iss0, iss1, iss2, iss3, iss4; iss1.imbue(locale(iss1.getloc(), new Punct1)); iss2.imbue(locale(iss2.getloc(), new Punct2)); iss3.imbue(locale(iss3.getloc(), new Punct3)); + iss4.imbue(locale(iss4.getloc(), new Punct4)); 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()); + const num_get& ng4 = use_facet >(iss4.getloc()); ios_base::iostate err = ios_base::goodbit; iterator_type end; @@ -65,6 +73,7 @@ void test01() bool b1 = false; bool b2 = false; bool b3 = true; + bool b4 = false; iss0.str(L"true"); iss0.setf(ios_base::boolalpha); @@ -102,6 +111,14 @@ void test01() VERIFY( b1 == false ); VERIFY( *end == L'c' ); + iss1.str(L"ab"); + iss1.clear(); + b1 = true; + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b1 == false ); + iss2.str(L"1"); iss2.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -116,6 +133,15 @@ void test01() VERIFY( err == ios_base::goodbit ); VERIFY( b2 == false ); + iss2.str(L"2"); + iss2.clear(); + b2 = true; + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::failbit ); + VERIFY( b2 == false ); + VERIFY( *end == L'2' ); + iss3.str(L"blah"); iss3.setf(ios_base::boolalpha); err = ios_base::goodbit; @@ -131,6 +157,37 @@ void test01() end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); VERIFY( err == ios_base::failbit ); VERIFY( b3 == false ); + + iss4.str(L"one"); + iss4.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == true ); + + iss4.str(L"two"); + iss4.clear(); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == false ); + + iss4.str(L"three"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::failbit ); + VERIFY( b4 == false ); + VERIFY( *end == L'h' ); + + iss4.str(L"on"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b4 == false ); } int main() -- cgit v1.2.1