From 8832296b8668d361081fe45a3d89482967f2483f Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 3 Mar 2004 00:22:05 +0000 Subject: [PATCH] 2004-03-02 Paolo Carlini 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@78799 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 13 ++ libstdc++-v3/include/bits/postypes.h | 146 +++------------------ libstdc++-v3/testsuite/27_io/fpos/14320-1.cc | 61 +++++++++ libstdc++-v3/testsuite/27_io/fpos/14320-2.cc | 44 +++++++ libstdc++-v3/testsuite/27_io/fpos/14320-3.cc | 43 ++++++ libstdc++-v3/testsuite/27_io/fpos/14320-4.cc | 52 ++++++++ libstdc++-v3/testsuite/27_io/fpos/14320-5.cc | 45 +++++++ .../testsuite/27_io/fpos/mbstate_t/4_neg.cc | 4 +- 8 files changed, 281 insertions(+), 127 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/fpos/14320-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/fpos/14320-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/fpos/14320-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/fpos/14320-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/fpos/14320-5.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cbe4037..e6c8a2e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,18 @@ 2004-03-02 Paolo Carlini + 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 + * include/bits/locale_facets.tcc (money_get<>::_M_extract): Reorganize a bit the main parsing loop, thus early detecting an empty value component. diff --git a/libstdc++-v3/include/bits/postypes.h b/libstdc++-v3/include/bits/postypes.h index b82b36e..0cfb61b 100644 --- a/libstdc++-v3/include/bits/postypes.h +++ b/libstdc++-v3/include/bits/postypes.h @@ -58,10 +58,20 @@ namespace std // unspecified. The behaviour in this implementation is as noted // below. + /** + * @brief Type used by fpos, char_traits, and char_traits. + * + * @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 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 - 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, and char_traits. - * - * @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 - 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 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 index 0000000..71a4d7a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc @@ -0,0 +1,61 @@ +// 2004-03-02 Petur Runolfsson + +// 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 +#include +#include +#include + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator::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::is_signed && + typeid(Distance) == typeid(char)) + found = true; + if (numeric_limits::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 index 0000000..a60daf9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc @@ -0,0 +1,44 @@ +// 2004-03-02 Petur Runolfsson + +// 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 +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator::difference_type Distance; + typedef numeric_limits 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 index 0000000..19c839e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc @@ -0,0 +1,43 @@ +// 2004-03-02 Petur Runolfsson + +// 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 +#include + +// libstdc++/14320 +int test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef std::istreambuf_iterator::difference_type Distance; + Distance d = 2; + Distance e = 3; + d *= e; + VERIFY( static_cast(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 index 0000000..591bb4f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc @@ -0,0 +1,52 @@ +// 2004-03-02 Petur Runolfsson + +// 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 +#include + +class Fred +{ +public: + Fred(bool) + { } +}; + +void barney(Fred) +{ } + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator::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 index 0000000..7c15620 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc @@ -0,0 +1,45 @@ +// 2004-03-02 Petur Runolfsson + +// 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 +#include +#include + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator::difference_type Distance; + + Distance d; + istringstream in("5"); + in >> d; + VERIFY( d == 5 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc index ace81eb..0db4772 100644 --- a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc @@ -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(pos); // { dg-error "invalid static_cast" } + n = static_cast(pos); // { dg-error "invalid static_cast" "" { xfail *-*-* } } } int main() -- 2.7.4