re PR libstdc++/12653 (Resolution of DR 303 (WP) still unimplemented)

2003-12-04  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.

From-SVN: r74276
This commit is contained in:
Paolo Carlini 2003-12-04 09:45:29 +00:00 committed by Paolo Carlini
parent 8a89dbd242
commit 7f1156ed35
4 changed files with 106 additions and 28 deletions

View File

@ -1,3 +1,17 @@
2003-12-04 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.
2003-12-03 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/12791

View File

@ -682,6 +682,13 @@
<dd>If <code>(this == &amp;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&lt;wchar_t, char, mbstate_t&gt;::length()</em>
</dt>

View File

@ -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<size_t>(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<size_t>(0), _Nb);
if (__state)
__is.setstate(__state);
return __is;
}

View File

@ -0,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;
}