diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7c434cf1d8a0..22736cdf2b7f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2009-04-18 Paolo Carlini + + PR libstdc++/39802 + * include/bits/locale_facets.tcc (num_get<>::_M_extract_int + (_InIter, _InIter, ios_base&, ios_base::iostate&, _ValueT&)): + Always accept negative values, for unsigned types too. + * testsuite/22_locale/num_get/get/char/39802.cc: New. + * testsuite/22_locale/num_get/get/wchar_t/39802.cc: Likewise. + 2009-04-18 Jan Hubicka * include/debug/formater.h: Include bits/c++config.h. @@ -5,10 +14,12 @@ * include/bits/c++config (_GLIBCXX_PURE, _GLIBCXX_CONST, _GLIBCXX_NORETURN): New. * include/bits/stl_tree.h (_Rb_tree_increment, _Rb_tree_increment, - _Rb_tree_decrement, _Rb_tree_decrement, _Rb_tree_black_count): Mark pure. - * include/c_compatibility/stdatomic.h (atomic_flag_test_and_set_explicit, - atomic_flag_clear_explicit, __atomic_flag_wait_explicit, - __atomic_flag_for_address): Mark by throw (). + _Rb_tree_decrement, _Rb_tree_decrement, _Rb_tree_black_count): + Mark pure. + * include/c_compatibility/stdatomic.h + (atomic_flag_test_and_set_explicit, atomic_flag_clear_explicit, + __atomic_flag_wait_explicit, __atomic_flag_for_address): + Mark by throw (). * src/atomic.cc (atomic_flag_test_and_set_explicit, atomic_flag_clear_explicit, __atomic_flag_wait_explicit, __atomic_flag_for_address): Mark by throw (). diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 47eac6a44c7c..ba8f3988fd65 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -379,8 +379,7 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE if (!__testeof) { __c = *__beg; - if (__gnu_cxx::__numeric_traits<_ValueT>::__is_signed) - __negative = __c == __lit[__num_base::_S_iminus]; + __negative = __c == __lit[__num_base::_S_iminus]; if ((__negative || __c == __lit[__num_base::_S_iplus]) && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) && !(__c == __lc->_M_decimal_point)) @@ -449,7 +448,8 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE __found_grouping.reserve(32); bool __testfail = false; bool __testoverflow = false; - const __unsigned_type __max = __negative + const __unsigned_type __max = + (__negative && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) ? -__gnu_cxx::__numeric_traits<_ValueT>::__min : __gnu_cxx::__numeric_traits<_ValueT>::__max; const __unsigned_type __smax = __max / __base; @@ -552,7 +552,8 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE } else if (__testoverflow) { - if (__negative) + if (__negative + && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) __v = __gnu_cxx::__numeric_traits<_ValueT>::__min; else __v = __gnu_cxx::__numeric_traits<_ValueT>::__max; diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/char/39802.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/char/39802.cc new file mode 100644 index 000000000000..b31050895a59 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/char/39802.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 22.2.2.1.1 num_get members + +#include +#include +#include +#include + +// libstdc++/39802 +void test01() +{ + using namespace std; + typedef istreambuf_iterator iterator_type; + + bool test __attribute__((unused)) = true; + + stringstream ss; + const num_get& ng = use_facet >(ss.getloc()); + ios_base::iostate err; + iterator_type end; + const string empty; + + unsigned long ul0 = 1; + const unsigned long ul1 = numeric_limits::max(); + + ss << "-0"; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == 0 ); + + ss.clear(); + ss.str(empty); + ss << "-1"; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == ul1 ); + + ss.clear(); + ss.str(empty); + ss << '-' << ul1; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == 1 ); + + ss.clear(); + ss.str(empty); + ss << '-' << ul1 << '0'; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( ul0 == ul1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39802.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39802.cc new file mode 100644 index 000000000000..67138d1dac54 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39802.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 22.2.2.1.1 num_get members + +#include +#include +#include +#include + +// libstdc++/39802 +void test01() +{ + using namespace std; + typedef istreambuf_iterator iterator_type; + + bool test __attribute__((unused)) = true; + + wstringstream ss; + const num_get& ng = use_facet >(ss.getloc()); + ios_base::iostate err; + iterator_type end; + const wstring empty; + + unsigned long ul0 = 1; + const unsigned long ul1 = numeric_limits::max(); + + ss << L"-0"; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == 0 ); + + ss.clear(); + ss.str(empty); + ss << L"-1"; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == ul1 ); + + ss.clear(); + ss.str(empty); + ss << L'-' << ul1; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == ios_base::eofbit ); + VERIFY( ul0 == 1 ); + + ss.clear(); + ss.str(empty); + ss << L'-' << ul1 << L'0'; + err = ios_base::goodbit; + end = ng.get(ss.rdbuf(), 0, ss, err, ul0); + VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( ul0 == ul1 ); +} + +int main() +{ + test01(); + return 0; +}