This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
this implements the resolution and fixes that small problem with the failbit I have noticed on the way. Also implements the common requirements of formatted input functions, whiche were not met.
2003-12-03 Paolo Carlini <pcarlini@suse.de> 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.
diff -prN libstdc++-v3-orig/docs/html/ext/howto.html libstdc++-v3/docs/html/ext/howto.html *** libstdc++-v3-orig/docs/html/ext/howto.html Mon Dec 1 16:34:07 2003 --- libstdc++-v3/docs/html/ext/howto.html Wed Dec 3 18:17:40 2003 *************** *** 682,687 **** --- 682,694 ---- <dd>If <code>(this == &x)</code> do nothing. </dd> + <dt><a href="lwg-defects.html#303">303</a>: + <em>Bitset input operator underspecified</em> + </dt> + <dd>Basically, compare the input character to <code>is.widen(0)</code> + and <code>is.widen(1)</code>. + </dd> + <dt><a href="lwg-defects.html#305">305</a>: <em>Default behavior of codecvt<wchar_t, char, mbstate_t>::length()</em> </dt> diff -prN libstdc++-v3-orig/include/std/std_bitset.h libstdc++-v3/include/std/std_bitset.h *** libstdc++-v3-orig/include/std/std_bitset.h Tue Nov 11 21:09:09 2003 --- libstdc++-v3/include/std/std_bitset.h Wed Dec 3 18:22:41 2003 *************** namespace __gnu_norm *** 1155,1200 **** basic_string<_CharT, _Traits> __tmp; __tmp.reserve(_Nb); ! // Skip whitespace 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) { ! 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::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)) { ! __state |= ios_base::failbit; break; } } } ! ! if (__tmp.empty() && !_Nb) ! __state |= ios_base::failbit; ! else ! __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb); ! ! if (__state != ios_base::goodbit) ! __is.setstate(__state); // may throw an exception } return __is; } --- 1155,1207 ---- basic_string<_CharT, _Traits> __tmp; __tmp.reserve(_Nb); ! ios_base::iostate __state = ios_base::goodbit; typename basic_istream<_CharT, _Traits>::sentry __sentry(__is); if (__sentry) { ! try { ! 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) { ! 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::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; + } + } } } ! catch(...) ! { __is._M_setstate(ios_base::badbit); } } + if (__tmp.empty() && _Nb) + __state |= ios_base::failbit; + else + __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb); + if (__state) + __is.setstate(__state); return __is; } diff -prN libstdc++-v3-orig/testsuite/23_containers/bitset/input/1.cc libstdc++-v3/testsuite/23_containers/bitset/input/1.cc *** libstdc++-v3-orig/testsuite/23_containers/bitset/input/1.cc Thu Jan 1 01:00:00 1970 --- libstdc++-v3/testsuite/23_containers/bitset/input/1.cc Wed Dec 3 19:00:15 2003 *************** *** 0 **** --- 1,50 ---- + // 2003-12-03 Paolo Carlini <pcarlini@suse.de> + + // 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 <bitset> + #include <sstream> + #include <testsuite_hooks.h> + + 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; + }
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |