From d978d656d8017e71fe4d2802766c4ceda99bccbf Mon Sep 17 00:00:00 2001 From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri, 13 Oct 2006 09:00:31 +0000 Subject: [PATCH] 2006-10-13 Paolo Carlini <pcarlini@suse.de> PR libstdc++/28277 (partial: ostream bits 2) * include/std/std_ostream.h (basic_ostream<>::_M_insert(const char_type*, streamsize)): New. (basic_ostream<>::_M_write(char_type, streamsize)): Likewise. (operator<<(basic_ostream<>&, _CharT), operator<<(basic_ostream<>&, char), operator<<(basic_ostream<>&, const _CharT*), operator<<(basic_ostream<>&, const char*)): Use the latter. * include/bits/ostream.tcc (basic_ostream<>::_M_insert(const char_type*, streamsize)): Define. (operator<<(basic_ostream<>&, const char*)): Use the latter. (operator<<(basic_ostream<>&, _CharT), operator<<(basic_ostream<>&, char), operator<<(basic_ostream<>&, const _CharT*), operator<<(basic_ostream<>&, const char*), operator<<(basic_ostream<>&, const basic_string<>&)): Remove. * include/bits/basic_string.h (operator<<(basic_ostream<>&, const basic_string<>&)): Use the latter, implement DR 586. * config/abi/pre/gnu.ver: Adjust, export the new _M_insert. * docs/html/ext/howto.html: Add an entry for DR 586. * testsuite/21_strings/basic_string/inserters_extractors/char/ 28277.cc: New. * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/ 28277.cc: Likewise. * testsuite/27_io/basic_ostream/inserters_character/char/ 28277-3.cc: Likewise. * testsuite/27_io/basic_ostream/inserters_character/char/ 28277-4.cc: Likewise. * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ 28277-2.cc: Likewise. * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ 28277-3.cc: Likewise. * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ 28277-4.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117689 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 35 +++ libstdc++-v3/config/abi/pre/gnu.ver | 7 +- libstdc++-v3/docs/html/ext/howto.html | 6 + libstdc++-v3/include/bits/basic_string.h | 7 +- libstdc++-v3/include/bits/ostream.tcc | 201 +++--------------- libstdc++-v3/include/std/std_ostream.h | 50 ++++- .../inserters_extractors/char/28277.cc | 49 +++++ .../inserters_extractors/wchar_t/28277.cc | 49 +++++ .../inserters_character/char/28277-3.cc | 48 +++++ .../inserters_character/char/28277-4.cc | 49 +++++ .../inserters_character/wchar_t/28277-2.cc | 49 +++++ .../inserters_character/wchar_t/28277-3.cc | 48 +++++ .../inserters_character/wchar_t/28277-4.cc | 49 +++++ 13 files changed, 463 insertions(+), 184 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/28277.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/28277.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 44bf10317633..c42aba17c4f9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,38 @@ +2006-10-13 Paolo Carlini <pcarlini@suse.de> + + PR libstdc++/28277 (partial: ostream bits 2) + * include/std/std_ostream.h (basic_ostream<>::_M_insert(const + char_type*, streamsize)): New. + (basic_ostream<>::_M_write(char_type, streamsize)): Likewise. + (operator<<(basic_ostream<>&, _CharT), operator<<(basic_ostream<>&, + char), operator<<(basic_ostream<>&, const _CharT*), + operator<<(basic_ostream<>&, const char*)): Use the latter. + * include/bits/ostream.tcc (basic_ostream<>::_M_insert(const + char_type*, streamsize)): Define. + (operator<<(basic_ostream<>&, const char*)): Use the latter. + (operator<<(basic_ostream<>&, _CharT), operator<<(basic_ostream<>&, + char), operator<<(basic_ostream<>&, const _CharT*), + operator<<(basic_ostream<>&, const char*), + operator<<(basic_ostream<>&, const basic_string<>&)): Remove. + * include/bits/basic_string.h (operator<<(basic_ostream<>&, + const basic_string<>&)): Use the latter, implement DR 586. + * config/abi/pre/gnu.ver: Adjust, export the new _M_insert. + * docs/html/ext/howto.html: Add an entry for DR 586. + * testsuite/21_strings/basic_string/inserters_extractors/char/ + 28277.cc: New. + * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/ + 28277.cc: Likewise. + * testsuite/27_io/basic_ostream/inserters_character/char/ + 28277-3.cc: Likewise. + * testsuite/27_io/basic_ostream/inserters_character/char/ + 28277-4.cc: Likewise. + * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ + 28277-2.cc: Likewise. + * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ + 28277-3.cc: Likewise. + * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ + 28277-4.cc: Likewise. + 2006-10-11 Paolo Carlini <pcarlini@suse.de> * docs/html/ext/lwg-active.html, lwg-defects.html: Import Revision 44. diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 384ad35e26c9..dd6854c80f75 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -285,7 +285,7 @@ GLIBCXX_3.4 { _ZNSoC*; _ZNSoD*; _ZNKSo6sentrycvbEv; - _ZNSo8_M_write*; + _ZNSo8_M_writeEPKc[il]; _ZNSo[0-9][a-z]*; _ZNSolsE*[^g]; @@ -299,7 +299,7 @@ GLIBCXX_3.4 { _ZNSt13basic_ostreamIwSt11char_traitsIwEE5tellpEv; _ZNSt13basic_ostreamIwSt11char_traitsIwEE5writeEPKw*; _ZNSt13basic_ostreamIwSt11char_traitsIwEE6sentry*; - _ZNSt13basic_ostreamIwSt11char_traitsIwEE8_M_write*; + _ZNSt13basic_ostreamIwSt11char_traitsIwEE8_M_writeEPKw[il]; _ZNSt13basic_ostreamIwSt11char_traitsIwEElsE*[^g]; # std::ostream operators and inserters @@ -659,6 +659,9 @@ GLIBCXX_3.4.9 { _ZNSt13basic_istreamIwSt11char_traitsIwEE10_M_extractI[^g]*; _ZSt21__copy_streambufs_eofI[cw]St11char_traitsI[cw]EE[il]PSt15basic_streambuf*; + + _ZNSo9_M_insertEPKc[il]; + _ZNSt13basic_ostreamIwSt11char_traitsIwEE9_M_insertEPKw[il]; } GLIBCXX_3.4.8; diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index 7a9e4ef15a61..a39e0fbf9154 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -593,6 +593,12 @@ <dd>In case of input_iterator/output_iterator rely on Assignability of input_iterator' value_type. </dd> + + <dt><a href="lwg-active.html#586">586</a>: + <em>string inserter not a formatted function</em> + </dt> + <dd>Change it to be a formatted output function (i.e. catch exceptions). + </dd> <!-- <dt><a href="lwg-defects.html#"></a>: <em></em> diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 56c3fe6097af..da6ef1c2d196 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -2396,7 +2396,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _CharT, typename _Traits, typename _Alloc> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const basic_string<_CharT, _Traits, _Alloc>& __str); + const basic_string<_CharT, _Traits, _Alloc>& __str) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 586. string inserter not a formatted function + return __os._M_insert(__str.data(), __str.size()); + } /** * @brief Read a line from stream into a string. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index d53cd07579d0..a52eb4e3a00b 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -315,209 +315,60 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } - // 27.6.2.5.4 Character inserters. template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb) - { - try - { - const streamsize __w = __out.width(); - streamsize __len = 1; - _CharT* __cs = &__c; - if (__w > __len) - { - __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __w)); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - &__c, __w, __len, false); - __len = __w; - } - __out._M_write(__cs, __len); - __out.width(0); - } - catch(...) - { __out._M_setstate(ios_base::badbit); } - } - return __out; - } - - // Specializations. - template <class _Traits> - basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, char __c) + basic_ostream<_CharT, _Traits>:: + _M_insert(const char_type* __s, streamsize __n) { - typedef basic_ostream<char, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); + sentry __cerb(*this); if (__cerb) { try { - const streamsize __w = __out.width(); - streamsize __len = 1; - char* __cs = &__c; - if (__w > __len) + const streamsize __w = this->width(); + if (__w > __n) { - __cs = static_cast<char*>(__builtin_alloca(__w)); - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, - &__c, __w, __len, false); - __len = __w; + const bool __left = ((this->flags() & ios_base::adjustfield) + == ios_base::left); + if (!__left) + _M_write(this->fill(), __w - __n); + if (this->good()) + _M_write(__s, __n); + if (__left && this->good()) + _M_write(this->fill(), __w - __n); } - __out._M_write(__cs, __len); - __out.width(0); + else + _M_write(__s, __n); + this->width(0); } catch(...) - { __out._M_setstate(ios_base::badbit); } - } - return __out; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) - { - try - { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(_Traits::length(__s)); - if (__w > __len) - { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) - * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - __s, __w, __len, false); - __s = __cs; - __len = __w; - } - __out._M_write(__s, __len); - __out.width(0); - } - catch(...) - { __out._M_setstate(ios_base::badbit); } + { this->_M_setstate(ios_base::badbit); } } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; + return *this; } template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 167. Improper use of traits_type::length() - // Note that this is only in 'Review' status. - typedef char_traits<char> __traits_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) + if (!__s) + __out.setstate(ios_base::badbit); + else { - _CharT* __ws = 0; try { - const size_t __clen = __traits_type::length(__s); - __ws = new _CharT[__clen]; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 167. Improper use of traits_type::length() + const size_t __clen = char_traits<char>::length(__s); + _CharT* __ws = new _CharT[__clen]; for (size_t __i = 0; __i < __clen; ++__i) __ws[__i] = __out.widen(__s[__i]); - _CharT* __str = __ws; - - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(__clen); - if (__w > __len) - { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) - * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - __ws, __w, __len, false); - __str = __cs; - __len = __w; - } - __out._M_write(__str, __len); - __out.width(0); - + __out._M_insert(__ws, __clen); delete [] __ws; } - catch(...) - { - delete [] __ws; - __out._M_setstate(ios_base::badbit); - } - } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; - } - - // Partial specializations. - template<class _Traits> - basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, const char* __s) - { - typedef basic_ostream<char, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) - { - try - { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(_Traits::length(__s)); - if (__w > __len) - { - char* __cs = static_cast<char*>(__builtin_alloca(__w)); - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, - __s, __w, __len, false); - __s = __cs; - __len = __w; - } - __out._M_write(__s, __len); - __out.width(0); - } catch(...) { __out._M_setstate(ios_base::badbit); } } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; - } - - // 21.3.7.9 basic_string::operator<< - template<typename _CharT, typename _Traits, typename _Alloc> - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, - const basic_string<_CharT, _Traits, _Alloc>& __str) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb) - { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(__str.size()); - const _CharT* __s = __str.data(); - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 25. String operator<< uses width() value wrong - if (__w > __len) - { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, - __w, __len, false); - __s = __cs; - __len = __w; - } - __out._M_write(__s, __len); - __out.width(0); - } return __out; } diff --git a/libstdc++-v3/include/std/std_ostream.h b/libstdc++-v3/include/std/std_ostream.h index 23a19c98d32b..6b4d389ac1fa 100644 --- a/libstdc++-v3/include/std/std_ostream.h +++ b/libstdc++-v3/include/std/std_ostream.h @@ -92,6 +92,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) friend basic_ostream<_CharT2, _Traits2>& operator<<(basic_ostream<_CharT2, _Traits2>&, const char*); + template<typename _CharT2, typename _Traits2, typename _Alloc> + friend basic_ostream<_CharT2, _Traits2>& + operator<<(basic_ostream<_CharT2, _Traits2>&, + const basic_string<_CharT2, _Traits2, _Alloc>&); + // [27.6.2.2] constructor/destructor /** * @brief Base constructor. @@ -288,11 +293,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void _M_write(const char_type* __s, streamsize __n) { - streamsize __put = this->rdbuf()->sputn(__s, __n); + const streamsize __put = this->rdbuf()->sputn(__s, __n); if (__put != __n) this->setstate(ios_base::badbit); } + void + _M_write(char_type __c, streamsize __n) + { + for (; __n > 0; --__n) + { + const int_type __put = this->rdbuf()->sputc(__c); + if (traits_type::eq_int_type(__put, traits_type::eof())) + { + this->setstate(ios_base::badbit); + break; + } + } + } + /** * @brief Character string insertion. * @param s The array to insert. @@ -366,6 +385,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _ValueT> __ostream_type& _M_insert(_ValueT __v); + + __ostream_type& + _M_insert(const char_type* __s, streamsize __n); }; /** @@ -448,7 +470,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) */ template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c); + operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) + { return __out._M_insert(&__c, 1); } template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& @@ -458,7 +481,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Specialization template <class _Traits> basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, char __c); + operator<<(basic_ostream<char, _Traits>& __out, char __c) + { return __out._M_insert(&__c, 1); } // Signed and unsigned template<class _Traits> @@ -488,7 +512,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) */ template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s); + operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) + { + if (!__s) + __out.setstate(ios_base::badbit); + else + __out._M_insert(__s, static_cast<streamsize>(_Traits::length(__s))); + return __out; + } template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits> & @@ -497,8 +528,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Partial specializationss template<class _Traits> basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, const char* __s); - + operator<<(basic_ostream<char, _Traits>& __out, const char* __s) + { + if (!__s) + __out.setstate(ios_base::badbit); + else + __out._M_insert(__s, static_cast<streamsize>(_Traits::length(__s))); + return __out; + } + // Signed and unsigned template<class _Traits> basic_ostream<char, _Traits>& diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/28277.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/28277.cc new file mode 100644 index 000000000000..f67582c5f26c --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/28277.cc @@ -0,0 +1,49 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.3.7.9 inserters and extractors + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(20000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/28277.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/28277.cc new file mode 100644 index 000000000000..ff6228f12408 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/28277.cc @@ -0,0 +1,49 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.3.7.9 inserters and extractors + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const wstring str_01(50, L'a'); + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc new file mode 100644 index 000000000000..f79fb064ccc9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc @@ -0,0 +1,48 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + + oss_01.width(20000000); + const streamsize width = oss_01.width(); + + oss_01 << 'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc new file mode 100644 index 000000000000..cc02979cb5ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc @@ -0,0 +1,49 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(20000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc new file mode 100644 index 000000000000..736c8a8ae94f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc @@ -0,0 +1,49 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc new file mode 100644 index 000000000000..ae13c5267e38 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc @@ -0,0 +1,48 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << L'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc new file mode 100644 index 000000000000..1a13e04fc409 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc @@ -0,0 +1,49 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006 Free Software Foundation +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const wstring str_01(50, L'a'); + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == width ); +} + +int main() +{ + test01(); + return 0; +} -- GitLab