This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Fix libstdc++/14320


Hi,

I'm committing the below to mainline and, soon, 3_4 too, since
fixes a serious regression wrt 3.3.x.

Tested x86-linux.

Paolo.

//////////////////
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.
diff -urN libstdc++-v3-orig/include/bits/postypes.h libstdc++-v3/include/bits/postypes.h
--- libstdc++-v3-orig/include/bits/postypes.h	2004-02-24 22:20:33.000000000 +0100
+++ libstdc++-v3/include/bits/postypes.h	2004-03-02 23:31:10.000000000 +0100
@@ -58,10 +58,20 @@
   // 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 @@
   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 @@
     class fpos
     {
     private:
-      friend class streamoff;
-
-      __streamoff_base_type	_M_off;
+      streamoff	                _M_off;
       _StateT			_M_state;
 
     public:
@@ -199,14 +106,6 @@
       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 @@
       // 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 @@
       // 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 @@
       // 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 @@
       // copy.
       /// Add position and offset.
       fpos
-      operator+(const streamoff& __off) const
+      operator+(streamoff __off) const
       {
 	fpos __pos(*this);
 	__pos += __off;
@@ -284,7 +186,7 @@
       // copy.
       /// Subtract offset from position.
       fpos
-      operator-(const streamoff& __off) const
+      operator-(streamoff __off) const
       {
 	fpos __pos(*this);
 	__pos -= __off;
@@ -301,12 +203,6 @@
       { 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 -urN libstdc++-v3-orig/testsuite/27_io/fpos/14320-1.cc libstdc++-v3/testsuite/27_io/fpos/14320-1.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14320-1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14320-1.cc	2004-03-02 23:29:05.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/fpos/14320-2.cc libstdc++-v3/testsuite/27_io/fpos/14320-2.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14320-2.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14320-2.cc	2004-03-02 23:29:05.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/fpos/14320-3.cc libstdc++-v3/testsuite/27_io/fpos/14320-3.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14320-3.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14320-3.cc	2004-03-02 23:29:05.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/fpos/14320-4.cc libstdc++-v3/testsuite/27_io/fpos/14320-4.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14320-4.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14320-4.cc	2004-03-02 23:29:05.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/fpos/14320-5.cc libstdc++-v3/testsuite/27_io/fpos/14320-5.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14320-5.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14320-5.cc	2004-03-02 23:29:05.000000000 +0100
@@ -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;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/fpos/mbstate_t/4_neg.cc libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/mbstate_t/4_neg.cc	2003-10-17 00:37:53.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc	2004-03-03 00:51:03.000000000 +0100
@@ -29,10 +29,10 @@
   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()

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]