summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-04 09:45:29 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-04 09:45:29 +0000
commitc8c50a9af25bca1cd1c8a377d057222e5de6b5bc (patch)
tree250dede730eb4985abd87e33372b147b0426c7ff
parent32b8be602c57be08754138660b9706939dd5fea4 (diff)
downloadgcc-c8c50a9af25bca1cd1c8a377d057222e5de6b5bc.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74276 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/docs/html/ext/howto.html7
-rw-r--r--libstdc++-v3/include/std/std_bitset.h63
-rw-r--r--libstdc++-v3/testsuite/23_containers/bitset/input/1.cc50
4 files changed, 106 insertions, 28 deletions
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 <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
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 @@
<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>
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))
- {
- __state |= ios_base::eofbit;
- break;
- }
- else
+ 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)
{
- 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;
}
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 <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;
+}