2009-07-16 Paolo Carlini <paolo.carlini@oracle.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jul 2009 12:41:03 +0000 (12:41 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jul 2009 12:41:03 +0000 (12:41 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149704 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/doc/xml/manual/intro.xml
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/include/tr1_impl/regex
libstdc++-v3/src/compatibility.cc
libstdc++-v3/src/istream.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc [new file with mode: 0644]

index 97a165d..346349d 100644 (file)
@@ -1,3 +1,25 @@
+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
index dca08c2..45a7c6b 100644 (file)
@@ -736,6 +736,12 @@ requirements of the license of GCC.
     <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&gt;&gt;(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>
index 5d60791..d005f73 100644 (file)
@@ -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<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>::
@@ -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<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;
     }
@@ -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)
        {
index e2cbb58..1147212 100644 (file)
@@ -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())
index 9352bc1..6f76a98 100644 (file)
@@ -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
index 6b3c19b..7343268 100644 (file)
@@ -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();
index 6b06df2..7b7f0bf 100644 (file)
@@ -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)
        {
index b2c3336..ac5533a 100644 (file)
@@ -58,8 +58,8 @@ void test13()
   i = 0;
   iss2.str(digits);
   iss2.clear();
-  iss2 >> i; 
-  VERIFY( i == 0 );
+  iss2 >> i;
+  VERIFY( i == numeric_limits<int>::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 (file)
index 0000000..a1a71cc
--- /dev/null
@@ -0,0 +1,101 @@
+// 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;
+}
index ed8f57e..0a44b1f 100644 (file)
@@ -56,7 +56,7 @@ void test13()
   iss2.str(digits);
   iss2.clear();
   iss2 >> i;
-  VERIFY( i == 0 );
+  VERIFY( i == numeric_limits<int>::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 (file)
index 0000000..2ed5b30
--- /dev/null
@@ -0,0 +1,101 @@
+// 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;
+}