+2009-07-16 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/istream.tcc (basic_istream<>::operator>>(short&),
+ basic_istream<>::operator>>(int&)): Implement resolution of DR 696,
+ [Ready] in Frankfurt.
+ * include/tr1_impl/regex (regex_traits<>::value): Adjust.
+ * testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc:
+ New.
+ * testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc:
+ Likewise.
+ * testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc:
+ Adjust.
+ * testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc:
+ Likewise.
+ * doc/xml/manual/intro.xml: Add an entry for DR 696.
+
+ * include/bits/istream.tcc: Minor clean-up to the initializers of the
+ __err locals.
+ * include/bits/ostream.tcc: Likewise.
+ * src/compatibility.cc: Likewise.
+ * src/istream.cc: Likewise.
+
2009-07-12 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/type_traits (common_type): Remove workaround for
<listitem><para>Make the member functions table and classic_table public.
</para></listitem></varlistentry>
+ <varlistentry><term><ulink url="../ext/lwg-active.html#696">696</ulink>:
+ <emphasis>istream::operator>>(int&) broken</emphasis>
+ </term>
+ <listitem><para>Implement the straightforward resolution.
+ </para></listitem></varlistentry>
+
<varlistentry><term><ulink url="../ext/lwg-defects.html#761">761</ulink>:
<emphasis>unordered_map needs an at() member function</emphasis>
</term>
basic_istream<_CharT, _Traits>::sentry::
sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
if (__in.good())
{
if (__in.tie())
sentry __cerb(*this, false);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const __num_get_type& __ng = __check_facet(this->_M_num_get);
}
__catch(__cxxabiv1::__forced_unwind&)
{
- this->_M_setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions.
- long __l;
- _M_extract(__l);
- if (!this->fail())
+ sentry __cerb(*this, false);
+ if (__cerb)
{
- if (__gnu_cxx::__numeric_traits<short>::__min <= __l
- && __l <= __gnu_cxx::__numeric_traits<short>::__max)
- __n = short(__l);
- else
- this->setstate(ios_base::failbit);
+ ios_base::iostate __err = ios_base::goodbit;
+ __try
+ {
+ long __l;
+ const __num_get_type& __ng = __check_facet(this->_M_num_get);
+ __ng.get(*this, 0, *this, __err, __l);
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 696. istream::operator>>(int&) broken.
+ if (__l < __gnu_cxx::__numeric_traits<short>::__min)
+ {
+ __err |= ios_base::failbit;
+ __n = __gnu_cxx::__numeric_traits<short>::__min;
+ }
+ else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
+ {
+ __err |= ios_base::failbit;
+ __n = __gnu_cxx::__numeric_traits<short>::__max;
+ }
+ else
+ __n = short(__l);
+ }
+ __catch(__cxxabiv1::__forced_unwind&)
+ {
+ this->_M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ if (__err)
+ this->setstate(__err);
}
return *this;
}
-
+
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions.
- long __l;
- _M_extract(__l);
- if (!this->fail())
+ sentry __cerb(*this, false);
+ if (__cerb)
{
- if (__gnu_cxx::__numeric_traits<int>::__min <= __l
- && __l <= __gnu_cxx::__numeric_traits<int>::__max)
- __n = int(__l);
- else
- this->setstate(ios_base::failbit);
+ ios_base::iostate __err = ios_base::goodbit;
+ __try
+ {
+ long __l;
+ const __num_get_type& __ng = __check_facet(this->_M_num_get);
+ __ng.get(*this, 0, *this, __err, __l);
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 696. istream::operator>>(int&) broken.
+ if (__l < __gnu_cxx::__numeric_traits<int>::__min)
+ {
+ __err |= ios_base::failbit;
+ __n = __gnu_cxx::__numeric_traits<int>::__min;
+ }
+ else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
+ {
+ __err |= ios_base::failbit;
+ __n = __gnu_cxx::__numeric_traits<int>::__max;
+ }
+ else
+ __n = int(__l);
+ }
+ __catch(__cxxabiv1::__forced_unwind&)
+ {
+ this->_M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ if (__err)
+ this->setstate(__err);
}
return *this;
}
basic_istream<_CharT, _Traits>::
operator>>(__streambuf_type* __sbout)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, false);
if (__cerb && __sbout)
{
const int_type __eof = traits_type::eof();
int_type __c = __eof;
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
get(char_type& __c)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
get(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
get(__streambuf_type& __sb, char_type __delim)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
getline(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
__c = this->rdbuf()->sgetc();
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
_M_gcount = this->rdbuf()->sgetn(__s, __n);
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
// Cannot compare int_type with streamsize generically.
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
__streambuf_type* __sb = this->rdbuf();
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const __int_type __cb = __in.rdbuf()->sbumpc();
typedef ctype<_CharT> __ctype_type;
streamsize __extracted = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
sentry __cerb(*this);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
basic_ostream<_CharT, _Traits>::
operator<<(__streambuf_type* __sbin)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this);
if (__cerb && __sbin)
{
sentry __cerb(*this);
if (__cerb)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __put = this->rdbuf()->sputc(__c);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// basic_ostream::flush() is *not* an unformatted output function.
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
basic_ostream<_CharT, _Traits>::
seekp(pos_type __pos)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
basic_ostream<_CharT, _Traits>::
seekp(off_type __off, ios_base::seekdir __dir)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
value(_Ch_type __ch, int __radix) const
{
std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
- int __v = -1;
+ int __v;
if (__radix == 8)
__is >> std::oct;
else if (__radix == 16)
__is >> std::hex;
__is >> __v;
- return __v;
+ return __is.fail() ? -1 : __v;
}
// [7.8] Class basic_regex
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
getline(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const char_type __cdelim = traits_type::to_char_type(__delim);
typedef __istream_type::__ctype_type __ctype_type;
streamsize __extracted = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__istream_type::sentry __cerb(__in, false);
if (__cerb)
{
typedef __string_type::size_type __size_type;
__size_type __extracted = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__istream_type::sentry __cerb(__in, false);
if (__cerb)
{
__size_type __extracted = 0;
const __size_type __n = __str.max_size();
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__istream_type::sentry __cerb(__in, true);
if (__cerb)
{
getline(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__try
{
const char_type __cdelim = traits_type::to_char_type(__delim);
__size_type __extracted = 0;
const __size_type __n = __str.max_size();
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ ios_base::iostate __err = ios_base::goodbit;
__istream_type::sentry __cerb(__in, true);
if (__cerb)
{
i = 0;
iss2.str(digits);
iss2.clear();
- iss2 >> i;
- VERIFY( i == 0 );
+ iss2 >> i;
+ VERIFY( i == numeric_limits<int>::max() );
VERIFY( iss2.fail() );
}
--- /dev/null
+// 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2009 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 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
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.2.2 arithmetic extractors
+
+#include <sstream>
+#include <limits>
+#include <testsuite_hooks.h>
+
+// DR 696.
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ short s1 = 0;
+ ostringstream oss1;
+ oss1 << numeric_limits<short>::max();
+ istringstream iss1(oss1.str());
+ iss1 >> s1;
+ VERIFY( s1 == numeric_limits<short>::max() );
+ VERIFY( !iss1.fail() && iss1.eof() );
+
+ short s2 = 0;
+ ostringstream oss2;
+ oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1;
+ istringstream iss2(oss2.str());
+ iss2 >> s2;
+ VERIFY( s2 == numeric_limits<short>::max() );
+ VERIFY( iss2.fail() && iss2.eof() );
+
+ short s3 = 0;
+ ostringstream oss3;
+ oss3 << numeric_limits<short>::min();
+ istringstream iss3(oss3.str());
+ iss3 >> s3;
+ VERIFY( s3 == numeric_limits<short>::min() );
+ VERIFY( !iss3.fail() && iss3.eof() );
+
+ short s4 = 0;
+ ostringstream oss4;
+ oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1;
+ istringstream iss4(oss4.str());
+ iss4 >> s4;
+ VERIFY( s4 == numeric_limits<short>::min() );
+ VERIFY( iss4.fail() && iss4.eof() );
+
+ int i1 = 0;
+ ostringstream oss5;
+ oss5 << numeric_limits<int>::max();
+ istringstream iss5(oss5.str());
+ iss5 >> i1;
+ VERIFY( i1 == numeric_limits<int>::max() );
+ VERIFY( !iss5.fail() && iss5.eof() );
+
+ int i2 = 0;
+ ostringstream oss6;
+ oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1;
+ istringstream iss6(oss6.str());
+ iss6 >> i2;
+ VERIFY( i1 == numeric_limits<int>::max() );
+ VERIFY( iss6.fail() && iss6.eof() );
+
+ int i3 = 0;
+ ostringstream oss7;
+ oss7 << numeric_limits<int>::min();
+ istringstream iss7(oss7.str());
+ iss7 >> i3;
+ VERIFY( i3 == numeric_limits<int>::min() );
+ VERIFY( !iss7.fail() && iss7.eof() );
+
+ int i4 = 0;
+ ostringstream oss8;
+ oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1;
+ istringstream iss8(oss8.str());
+ iss8 >> i4;
+ VERIFY( i4 == numeric_limits<int>::min() );
+ VERIFY( iss8.fail() && iss8.eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
iss2.str(digits);
iss2.clear();
iss2 >> i;
- VERIFY( i == 0 );
+ VERIFY( i == numeric_limits<int>::max() );
VERIFY( iss2.fail() );
}
--- /dev/null
+// 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2009 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 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
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.2.2 arithmetic extractors
+
+#include <sstream>
+#include <limits>
+#include <testsuite_hooks.h>
+
+// DR 696.
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ short s1 = 0;
+ wostringstream oss1;
+ oss1 << numeric_limits<short>::max();
+ wistringstream iss1(oss1.str());
+ iss1 >> s1;
+ VERIFY( s1 == numeric_limits<short>::max() );
+ VERIFY( !iss1.fail() && iss1.eof() );
+
+ short s2 = 0;
+ wostringstream oss2;
+ oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1;
+ wistringstream iss2(oss2.str());
+ iss2 >> s2;
+ VERIFY( s2 == numeric_limits<short>::max() );
+ VERIFY( iss2.fail() && iss2.eof() );
+
+ short s3 = 0;
+ wostringstream oss3;
+ oss3 << numeric_limits<short>::min();
+ wistringstream iss3(oss3.str());
+ iss3 >> s3;
+ VERIFY( s3 == numeric_limits<short>::min() );
+ VERIFY( !iss3.fail() && iss3.eof() );
+
+ short s4 = 0;
+ wostringstream oss4;
+ oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1;
+ wistringstream iss4(oss4.str());
+ iss4 >> s4;
+ VERIFY( s4 == numeric_limits<short>::min() );
+ VERIFY( iss4.fail() && iss4.eof() );
+
+ int i1 = 0;
+ wostringstream oss5;
+ oss5 << numeric_limits<int>::max();
+ wistringstream iss5(oss5.str());
+ iss5 >> i1;
+ VERIFY( i1 == numeric_limits<int>::max() );
+ VERIFY( !iss5.fail() && iss5.eof() );
+
+ int i2 = 0;
+ wostringstream oss6;
+ oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1;
+ wistringstream iss6(oss6.str());
+ iss6 >> i2;
+ VERIFY( i1 == numeric_limits<int>::max() );
+ VERIFY( iss6.fail() && iss6.eof() );
+
+ int i3 = 0;
+ wostringstream oss7;
+ oss7 << numeric_limits<int>::min();
+ wistringstream iss7(oss7.str());
+ iss7 >> i3;
+ VERIFY( i3 == numeric_limits<int>::min() );
+ VERIFY( !iss7.fail() && iss7.eof() );
+
+ int i4 = 0;
+ wostringstream oss8;
+ oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1;
+ wistringstream iss8(oss8.str());
+ iss8 >> i4;
+ VERIFY( i4 == numeric_limits<int>::min() );
+ VERIFY( iss8.fail() && iss8.eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}