From 7f1156ed35e4f5a14cea93e42137302eb1d1f07a Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 4 Dec 2003 09:45:29 +0000 Subject: [PATCH] re PR libstdc++/12653 (Resolution of DR 303 (WP) still unimplemented) 2003-12-04 Paolo Carlini PR libstdc++/12653 * include/std/std_bitset.h (operator>>): Implement resolution of DR 303 [WP]: use widen('0') and widen('1'). * docs/html/ext/howto.html: Add an entry for DR 303. * include/std/std_bitset.h (operator>>): Implement the common requirements of formatted input functions (27.6.1.2.1). * include/std/std_bitset.h (operator>>): Set the failbit when nothing was extracted and _Nb != 0. * testsuite/23_containers/bitset/input/1.cc: New. From-SVN: r74276 --- libstdc++-v3/ChangeLog | 14 +++++ libstdc++-v3/docs/html/ext/howto.html | 7 +++ libstdc++-v3/include/std/std_bitset.h | 63 ++++++++++--------- .../testsuite/23_containers/bitset/input/1.cc | 50 +++++++++++++++ 4 files changed, 106 insertions(+), 28 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/bitset/input/1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1a45fef10c3..38a1d2dc9b3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2003-12-04 Paolo Carlini + + PR libstdc++/12653 + * include/std/std_bitset.h (operator>>): Implement resolution + of DR 303 [WP]: use widen('0') and widen('1'). + * docs/html/ext/howto.html: Add an entry for DR 303. + + * include/std/std_bitset.h (operator>>): Implement the common + requirements of formatted input functions (27.6.1.2.1). + + * include/std/std_bitset.h (operator>>): Set the failbit when + nothing was extracted and _Nb != 0. + * testsuite/23_containers/bitset/input/1.cc: New. + 2003-12-03 Paolo Carlini PR libstdc++/12791 diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index c5e3e20d08c..2ce76ee9db3 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -682,6 +682,13 @@
If (this == &x) do nothing.
+
303: + Bitset input operator underspecified +
+
Basically, compare the input character to is.widen(0) + and is.widen(1). +
+
305: Default behavior of codecvt<wchar_t, char, mbstate_t>::length()
diff --git a/libstdc++-v3/include/std/std_bitset.h b/libstdc++-v3/include/std/std_bitset.h index 345affc7750..e6498973e83 100644 --- a/libstdc++-v3/include/std/std_bitset.h +++ b/libstdc++-v3/include/std/std_bitset.h @@ -1155,46 +1155,53 @@ namespace __gnu_norm basic_string<_CharT, _Traits> __tmp; __tmp.reserve(_Nb); - // Skip whitespace + ios_base::iostate __state = ios_base::goodbit; typename basic_istream<_CharT, _Traits>::sentry __sentry(__is); if (__sentry) { - ios_base::iostate __state = ios_base::goodbit; - basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf(); - for (size_t __i = 0; __i < _Nb; ++__i) + try { - static typename _Traits::int_type __eof = _Traits::eof(); - - typename _Traits::int_type __c1 = __buf->sbumpc(); - if (_Traits::eq_int_type(__c1, __eof)) + basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 303. Bitset input operator underspecified + const char_type __zero = __is.widen('0'); + const char_type __one = __is.widen('1'); + for (size_t __i = 0; __i < _Nb; ++__i) { - __state |= ios_base::eofbit; - break; - } - else - { - char_type __c2 = _Traits::to_char_type(__c1); - char_type __c = __is.narrow(__c2, '*'); - - if (__c == '0' || __c == '1') - __tmp.push_back(__c); - else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) + static typename _Traits::int_type __eof = _Traits::eof(); + + typename _Traits::int_type __c1 = __buf->sbumpc(); + if (_Traits::eq_int_type(__c1, __eof)) { - __state |= ios_base::failbit; + __state |= ios_base::eofbit; break; } + else + { + char_type __c2 = _Traits::to_char_type(__c1); + if (__c2 == __zero) + __tmp.push_back('0'); + else if (__c2 == __one) + __tmp.push_back('1'); + else if (_Traits::eq_int_type(__buf->sputbackc(__c2), + __eof)) + { + __state |= ios_base::failbit; + break; + } + } } } - - if (__tmp.empty() && !_Nb) - __state |= ios_base::failbit; - else - __x._M_copy_from_string(__tmp, static_cast(0), _Nb); - - if (__state != ios_base::goodbit) - __is.setstate(__state); // may throw an exception + catch(...) + { __is._M_setstate(ios_base::badbit); } } + if (__tmp.empty() && _Nb) + __state |= ios_base::failbit; + else + __x._M_copy_from_string(__tmp, static_cast(0), _Nb); + if (__state) + __is.setstate(__state); return __is; } diff --git a/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc new file mode 100644 index 00000000000..a9387b65ade --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc @@ -0,0 +1,50 @@ +// 2003-12-03 Paolo Carlini + +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.5.3 bitset operators + +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + bitset<5> b5; + bitset<0> b0; + stringstream ss; + + ss.str("*"); + ss >> b5; + VERIFY( ss.rdstate() == ios_base::failbit ); + + ss.clear(); + ss.str("*"); + ss >> b0; + VERIFY( ss.rdstate() == ios_base::goodbit ); +} + +int main() +{ + test01(); + return 0; +}