]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/14320 (istreambuf_iterator::difference_type is not a signed integral...
authorPaolo Carlini <pcarlini@suse.de>
Wed, 3 Mar 2004 00:22:05 +0000 (00:22 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 3 Mar 2004 00:22:05 +0000 (00:22 +0000)
2004-03-02  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/14320
* include/bits/postypes.h (class streamoff): Remove, now
streamoff is just typedef a 64 bit signed integer type.
(class fpos): Tweak consistently.
* testsuite/27_io/fpos/14320-1.cc: New.
* testsuite/27_io/fpos/14320-2.cc: New.
* testsuite/27_io/fpos/14320-3.cc: New.
* testsuite/27_io/fpos/14320-4.cc: New.
* testsuite/27_io/fpos/14320-5.cc: New.
* testsuite/27_io/fpos/mbstate_t/4_neg.cc: xfail for now.

From-SVN: r78799

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/postypes.h
libstdc++-v3/testsuite/27_io/fpos/14320-1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/fpos/14320-2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/fpos/14320-3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/fpos/14320-4.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/fpos/14320-5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc

index cbe40379d3af37d5d589ef453559b76437ecfcae..e6c8a2ee4f0967864647d994ec8b44c0db07e7cb 100644 (file)
@@ -1,3 +1,16 @@
+2004-03-02  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/14320
+       * include/bits/postypes.h (class streamoff): Remove, now
+       streamoff is just typedef a 64 bit signed integer type.
+       (class fpos): Tweak consistently.
+       * testsuite/27_io/fpos/14320-1.cc: New.
+       * testsuite/27_io/fpos/14320-2.cc: New.
+       * testsuite/27_io/fpos/14320-3.cc: New.
+       * testsuite/27_io/fpos/14320-4.cc: New.
+       * testsuite/27_io/fpos/14320-5.cc: New.
+       * testsuite/27_io/fpos/mbstate_t/4_neg.cc: xfail for now.
+
 2004-03-02  Paolo Carlini  <pcarlini@suse.de>
 
        * include/bits/locale_facets.tcc (money_get<>::_M_extract):
index b82b36e817fb751200a055314321a775b754958c..0cfb61b2df2e99b8d920591a4facf3f3e7986fc9 100644 (file)
@@ -58,10 +58,20 @@ namespace std
   // unspecified. The behaviour in this implementation is as noted
   // below.
 
+  /**
+   *  @brief  Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
+   *
+   *  @if maint
+   *  In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
+   *  implementation defined type.
+   *  Note: In versions of GCC up to and including GCC 3.3, streamoff
+   *  was typedef long.
+   *  @endif
+  */  
 #ifdef _GLIBCXX_HAVE_INT64_T
-  typedef int64_t       __streamoff_base_type;
+  typedef int64_t       streamoff;
 #else
-  typedef long long     __streamoff_base_type;
+  typedef long long     streamoff;
 #endif
 
   /// Integral type for I/O operation counts and buffer sizes.
@@ -70,107 +80,6 @@ namespace std
   template<typename _StateT>
     class fpos;
 
-  // Class streamoff is an implementation defined type that meets the
-  // requirements for streamoff. It stores an offset as a signed
-  // integer.  Note: this class is an implementation detail.
-  class streamoff
-  {
-  private:
-    __streamoff_base_type _M_off;
-
-  public:
-    // Nothing in the standard requires that streamoff can be default
-    // constructed. In this implementation a default constructor that
-    // stores the value 0 is provided.
-    streamoff()
-    : _M_off(0) { }
-
-    // The standard only requires that streamoff can be constructed
-    // from streamsize using the constructor syntax. This
-    // implementation also allows implicit conversion from integer
-    // types to streamoff.
-    streamoff(__streamoff_base_type __off)
-    : _M_off(__off) { }
-
-    // The standard requires that streamoff can be constructed from
-    // instances of fpos using the constructor syntax, but gives no
-    // semantics for this construction. In this implementation it
-    // extracts the offset stored by the fpos object.
-    // Note: In versions of GCC up to and including GCC 3.3, implicit
-    // conversion from fpos to streamoff was allowed. This constructor
-    // has now been made explicit to improve type safety.
-    template<typename _StateT>
-      explicit
-      streamoff(const fpos<_StateT>&);
-
-    // The standard requires that streamsize can be constructed from
-    // streamoff using the constructor syntax. This implementation
-    // also allows implicit conversion. This allows streamoff objects
-    // to be used in arithmetic expressions and to be compared against
-    // each other and integer types.
-    operator __streamoff_base_type() const
-    { return _M_off; }
-
-    // This implementation allows the use of operators +=, -=, ++ and
-    // -- on streamoff objects.
-    streamoff&
-    operator+=(__streamoff_base_type __off)
-    {
-      _M_off += __off;
-      return *this;
-    }
-
-    streamoff&
-    operator-=(__streamoff_base_type __off)
-    {
-      _M_off -= __off;
-      return *this;
-    }
-
-    streamoff&
-    operator++()
-    {
-      ++_M_off;
-      return *this;
-    }
-
-    streamoff
-    operator++(int)
-    {
-      const streamoff __tmp(*this);
-      ++_M_off;
-      return __tmp;
-    }
-
-    streamoff&
-    operator--()
-    {
-      --_M_off;
-      return *this;
-    }
-
-    streamoff
-    operator--(int)
-    {
-      const streamoff __tmp(*this);
-      --_M_off;
-      return __tmp;
-    }
-  };
-
-  /**
-   *  @brief  Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
-   *
-   *  @if maint
-   *  In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
-   *  implementation defined type. In this implementation it is a
-   *  distinct class type.
-   *  Note: In versions of GCC up to and including GCC 3.3, streamoff
-   *  was typedef long.
-   *  @endif
-  */
-  typedef class streamoff streamoff;
-
   /**
    *  @brief  Class representing stream positions.
    *
@@ -186,9 +95,7 @@ namespace std
     class fpos
     {
     private:
-      friend class streamoff;
-
-      __streamoff_base_type    _M_off;
+      streamoff                        _M_off;
       _StateT                  _M_state;
 
     public:
@@ -199,14 +106,6 @@ namespace std
       fpos()
       : _M_off(0), _M_state() { }
 
-      // The standard requires implicit conversion from integers to
-      // fpos, but gives no meaningful semantics for this
-      // conversion. In this implementation this constructor stores
-      // the integer as the offset and default constructs the state.
-      /// Construct position from integer.
-      fpos(__streamoff_base_type __off)
-      : _M_off(__off), _M_state() { }
-
       // The standard requires that fpos objects can be constructed
       // from streamoff objects using the constructor syntax, and
       // fails to give any meaningful semantics. In this
@@ -214,9 +113,12 @@ namespace std
       // constructor stores the streamoff as the offset and default
       // constructs the state.
       /// Construct position from offset.
-      fpos(const streamoff& __off)
+      fpos(streamoff __off)
       : _M_off(__off), _M_state() { }
 
+      /// Convert to streamoff.
+      operator streamoff() const { return _M_off; }
+
       /// Remember the value of @a st.
       void
       state(_StateT __st)
@@ -246,7 +148,7 @@ namespace std
       // argument to the stored offset and returns *this.
       /// Add offset to this position.
       fpos&
-      operator+=(const streamoff& __off)
+      operator+=(streamoff __off)
       {
        _M_off += __off;
        return *this;
@@ -257,7 +159,7 @@ namespace std
       // it's argument from the stored offset and returns *this.
       /// Subtract offset from this position.
       fpos&
-      operator-=(const streamoff& __off)
+      operator-=(streamoff __off)
       {
        _M_off -= __off;
        return *this;
@@ -270,7 +172,7 @@ namespace std
       // copy.
       /// Add position and offset.
       fpos
-      operator+(const streamoff& __off) const
+      operator+(streamoff __off) const
       {
        fpos __pos(*this);
        __pos += __off;
@@ -284,7 +186,7 @@ namespace std
       // copy.
       /// Subtract offset from position.
       fpos
-      operator-(const streamoff& __off) const
+      operator-(streamoff __off) const
       {
        fpos __pos(*this);
        __pos -= __off;
@@ -301,12 +203,6 @@ namespace std
       { return _M_off - __other._M_off; }
     };
 
-  /// Construct offset from position.
-  template<typename _StateT>
-    inline
-    streamoff::streamoff(const fpos<_StateT>& __pos)
-    : _M_off(__pos._M_off) { }
-
   // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
   // as implementation defined types, but clause 27.2 requires that
   // they must both be typedefs for fpos<mbstate_t>
diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc
new file mode 100644 (file)
index 0000000..71a4d7a
--- /dev/null
@@ -0,0 +1,61 @@
+// 2004-03-02  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2004 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.
+
+// 27.4.3 fpos
+
+// { dg-do run { xfail *-*-* } }
+
+#include <typeinfo>
+#include <limits>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// libstdc++/14320
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef istreambuf_iterator<char>::difference_type Distance;
+
+  bool found = false;
+  if (typeid(Distance) == typeid(long int))
+    found = true;
+  if (typeid(Distance) == typeid(int))
+    found = true;
+  if (typeid(Distance) == typeid(short int))
+    found = true;
+  if (typeid(Distance) == typeid(signed char))
+    found = true;
+  if (numeric_limits<char>::is_signed &&
+      typeid(Distance) == typeid(char))
+    found = true;
+  if (numeric_limits<wchar_t>::is_signed &&
+      typeid(Distance) == typeid(wchar_t))
+    found = true;
+  
+  VERIFY( found );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc
new file mode 100644 (file)
index 0000000..a60daf9
--- /dev/null
@@ -0,0 +1,44 @@
+// 2004-03-02  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2004 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.
+
+// 27.4.3 fpos
+
+// { dg-do run { xfail *-*-* } } 
+
+#include <iterator>
+#include <limits>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;  
+
+  typedef istreambuf_iterator<char>::difference_type Distance;
+  typedef numeric_limits<Distance> Limits;
+
+  VERIFY( Limits::is_specialized );
+  VERIFY( Limits::is_signed );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc
new file mode 100644 (file)
index 0000000..19c839e
--- /dev/null
@@ -0,0 +1,43 @@
+// 2004-03-02  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2004 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.
+
+// 27.4.3 fpos
+
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// libstdc++/14320
+int test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef std::istreambuf_iterator<char>::difference_type Distance;
+  Distance d = 2;
+  Distance e = 3;
+  d *= e;
+  VERIFY( static_cast<int>(d) == 6 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc
new file mode 100644 (file)
index 0000000..591bb4f
--- /dev/null
@@ -0,0 +1,52 @@
+// 2004-03-02  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2004 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.
+
+// 27.4.3 fpos
+
+#include <iterator>
+#include <testsuite_hooks.h>
+
+class Fred
+{
+public:
+  Fred(bool)
+  { }
+};
+
+void barney(Fred)
+{ }
+
+// libstdc++/14320
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef istreambuf_iterator<char>::difference_type Distance;
+  
+  Distance d = 0;
+  barney(d);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc
new file mode 100644 (file)
index 0000000..7c15620
--- /dev/null
@@ -0,0 +1,45 @@
+// 2004-03-02  Petur Runolfsson  <peturr02@ru.is>
+
+// Copyright (C) 2004 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.
+
+// 27.4.3 fpos
+
+#include <iterator>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/14320
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef istreambuf_iterator<char>::difference_type Distance;
+       
+  Distance d;
+  istringstream in("5");
+  in >> d;
+  VERIFY( d == 5 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index ace81eb2669734dddcd00717a16872771c1fe5e0..0db4772acd7e50c173ef4ca8bd3fce242aed0ea5 100644 (file)
@@ -29,10 +29,10 @@ void test04()
   long n;
 
   // Implicit conversion
-  n = pos; // { dg-error "cannot convert" }
+  n = pos; // { dg-error "cannot convert" "" { xfail *-*-* } }
 
   // Explicit conversion
-  n = static_cast<long>(pos); // { dg-error "invalid static_cast" }
+  n = static_cast<long>(pos); // { dg-error "invalid static_cast" "" { xfail *-*-* } }
 }
 
 int main()