diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 97a165d7127..346349d4212 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2009-07-16 Paolo Carlini + + * 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 * include/std/type_traits (common_type): Remove workaround for diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index dca08c2b9e1..45a7c6bda4f 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -736,6 +736,12 @@ requirements of the license of GCC. Make the member functions table and classic_table public. + 696: + istream::operator>>(int&) broken + + Implement the straightforward resolution. + + 761: unordered_map needs an at() member function diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 5d60791ec98..d005f736f03 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -46,7 +46,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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()) @@ -89,7 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } __catch(__cxxabiv1::__forced_unwind&) { - this->_M_setstate(ios_base::badbit); + this->_M_setstate(ios_base::badbit); __throw_exception_again; } __catch(...) @@ -115,19 +115,44 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _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::__min <= __l - && __l <= __gnu_cxx::__numeric_traits::__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::__min) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits::__min; + } + else if (__l > __gnu_cxx::__numeric_traits::__max) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits::__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 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: @@ -135,15 +160,40 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _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::__min <= __l - && __l <= __gnu_cxx::__numeric_traits::__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::__min) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits::__min; + } + else if (__l > __gnu_cxx::__numeric_traits::__max) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits::__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; } @@ -153,7 +203,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -188,7 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -222,7 +272,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -259,7 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -306,7 +356,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -350,7 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -413,7 +463,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -446,7 +496,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -508,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -574,7 +624,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -603,7 +653,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -632,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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. @@ -666,7 +716,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -699,7 +749,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -732,7 +782,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -788,7 +838,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _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()) @@ -821,7 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _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()) @@ -858,7 +908,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -891,7 +941,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index e2cbb585a89..1147212aa14 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -66,7 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -119,7 +119,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -157,7 +157,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -213,7 +213,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // _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) @@ -257,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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()) @@ -289,7 +289,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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()) diff --git a/libstdc++-v3/include/tr1_impl/regex b/libstdc++-v3/include/tr1_impl/regex index 9352bc13732..6f76a981419 100644 --- a/libstdc++-v3/include/tr1_impl/regex +++ b/libstdc++-v3/include/tr1_impl/regex @@ -688,13 +688,13 @@ namespace regex_constants 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 diff --git a/libstdc++-v3/src/compatibility.cc b/libstdc++-v3/src/compatibility.cc index 6b3c19b31e4..73432681ecf 100644 --- a/libstdc++-v3/src/compatibility.cc +++ b/libstdc++-v3/src/compatibility.cc @@ -64,7 +64,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); @@ -136,7 +136,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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(); diff --git a/libstdc++-v3/src/istream.cc b/libstdc++-v3/src/istream.cc index 6b06df2594d..7b7f0bf9278 100644 --- a/libstdc++-v3/src/istream.cc +++ b/libstdc++-v3/src/istream.cc @@ -37,7 +37,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -118,7 +118,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -203,7 +203,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -286,7 +286,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -368,7 +368,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __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) { @@ -444,7 +444,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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) { @@ -525,7 +525,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) 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); @@ -614,7 +614,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __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) { diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc index b2c3336a006..ac5533a496e 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc @@ -58,8 +58,8 @@ void test13() i = 0; iss2.str(digits); iss2.clear(); - iss2 >> i; - VERIFY( i == 0 ); + iss2 >> i; + VERIFY( i == numeric_limits::max() ); VERIFY( iss2.fail() ); } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc new file mode 100644 index 00000000000..a1a71cc571f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 Paolo Carlini +// +// 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + ostringstream oss1; + oss1 << numeric_limits::max(); + istringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + ostringstream oss2; + oss2 << static_cast(numeric_limits::max()) + 1; + istringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + ostringstream oss3; + oss3 << numeric_limits::min(); + istringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + ostringstream oss4; + oss4 << static_cast(numeric_limits::min()) - 1; + istringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + ostringstream oss5; + oss5 << numeric_limits::max(); + istringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + ostringstream oss6; + oss6 << static_cast(numeric_limits::max()) + 1; + istringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + ostringstream oss7; + oss7 << numeric_limits::min(); + istringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + ostringstream oss8; + oss8 << static_cast(numeric_limits::min()) - 1; + istringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc index ed8f57eb5f3..0a44b1ffb09 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc @@ -56,7 +56,7 @@ void test13() iss2.str(digits); iss2.clear(); iss2 >> i; - VERIFY( i == 0 ); + VERIFY( i == numeric_limits::max() ); VERIFY( iss2.fail() ); } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc new file mode 100644 index 00000000000..2ed5b309b0e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 Paolo Carlini +// +// 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + wostringstream oss1; + oss1 << numeric_limits::max(); + wistringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + wostringstream oss2; + oss2 << static_cast(numeric_limits::max()) + 1; + wistringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + wostringstream oss3; + oss3 << numeric_limits::min(); + wistringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + wostringstream oss4; + oss4 << static_cast(numeric_limits::min()) - 1; + wistringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + wostringstream oss5; + oss5 << numeric_limits::max(); + wistringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + wostringstream oss6; + oss6 << static_cast(numeric_limits::max()) + 1; + wistringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + wostringstream oss7; + oss7 << numeric_limits::min(); + wistringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + wostringstream oss8; + oss8 << static_cast(numeric_limits::min()) - 1; + wistringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +}