re PR libstdc++/14320 (istreambuf_iterator::difference_type is not a signed integral type)

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
This commit is contained in:
Paolo Carlini 2004-03-03 00:22:05 +00:00 committed by Paolo Carlini
parent 0eadce5226
commit 0b1d67d23b
8 changed files with 281 additions and 127 deletions

View 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):

View 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>

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View 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()