diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 438183b36fd..2fd8c5de9be 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,4 +1,14 @@ -2001-10-30 Jakub Jelinek +2001-10-30 Paolo Carlini + Benjamin Kosnik + + * include/bits/basic_string.h: Tweaks. + * include/bits/basic_string.tcc (string::_M_replace(iterator, + iterator, _ForwardIter, _ForwardIter, forward_iterator_tag): Fix. + * src/string-inst.cc: Tweaks, add instantiation. + * testsuite/21_strings/replace.cc (test02): Add test. + * testsuite/21_strings/assign.cc (test01): New file. + +001-10-30 Jakub Jelinek * include/bits/stl_deque.h (_M_new_elements_at_front): Use __throw_exception_again. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index dc62a542e5e..a2fb1e0932d 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -40,7 +40,6 @@ namespace std { - // Documentation? What's that? // Nathan Myers . // @@ -284,7 +283,7 @@ namespace std _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) { for (; __k1 != __k2; ++__k1, ++__p) - traits_type::assign(*__p, *__k1); //these types are off + traits_type::assign(*__p, *__k1); // These types are off. } static void @@ -337,7 +336,7 @@ namespace std basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); template - basic_string(_InputIterator __begin, _InputIterator __end, + basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a = _Alloc()); ~basic_string() diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 7190e2ea943..84ec0cfc132 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -130,7 +130,7 @@ namespace std template template _CharT* - basic_string<_CharT,_Traits,_Alloc>:: + basic_string<_CharT, _Traits, _Alloc>:: _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a, forward_iterator_tag) { @@ -156,7 +156,7 @@ namespace std template _CharT* - basic_string<_CharT,_Traits, _Alloc>:: + basic_string<_CharT, _Traits, _Alloc>:: _S_construct(size_type __n, _CharT __c, const _Alloc& __a) { if (__n == 0 && __a == _Alloc()) @@ -446,18 +446,24 @@ namespace std _M_replace(iterator __i1, iterator __i2, _ForwardIter __k1, _ForwardIter __k2, forward_iterator_tag) { + size_type __dnew = static_cast(distance(__k1, __k2)); size_type __dold = __i2 - __i1; size_type __dmax = this->max_size(); - size_type __dnew = static_cast(distance(__k1, __k2)); if (__dmax <= __dnew) __throw_length_error("basic_string::_M_replace"); size_type __off = __i1 - _M_ibegin(); + + // Save concerned source string data in a temporary. + basic_string __temp(__k1, __k2); _M_mutate(__off, __dold, __dnew); - // Invalidated __i1, __i2 - if (__dnew) - _S_copy_chars(_M_data() + __off, __k1, __k2); + // Invalidated __i1, __i2 (and clobbered original source string + // data when destination string == source string and the string + // is unshared). + if (__dnew) + _S_copy_chars(_M_data() + __off, __temp.begin(), __temp.end()); + return *this; } @@ -473,8 +479,8 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc>& - basic_string<_CharT,_Traits,_Alloc>:: + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: append(const basic_string& __str) { // Iff appending itself, string needs to pre-reserve the @@ -489,8 +495,8 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc>& - basic_string<_CharT,_Traits,_Alloc>:: + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: append(const basic_string& __str, size_type __pos, size_type __n) { // Iff appending itself, string needs to pre-reserve the @@ -504,8 +510,8 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc>& - basic_string<_CharT,_Traits,_Alloc>:: + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: append(const _CharT* __s, size_type __n) { size_type __len = __n + this->size(); @@ -515,8 +521,8 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc>& - basic_string<_CharT,_Traits,_Alloc>:: + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: append(size_type __n, _CharT __c) { size_type __len = __n + this->size(); @@ -526,11 +532,11 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc> + basic_string<_CharT, _Traits, _Alloc> operator+(const _CharT* __lhs, - const basic_string<_CharT,_Traits,_Alloc>& __rhs) + const basic_string<_CharT, _Traits, _Alloc>& __rhs) { - typedef basic_string<_CharT,_Traits,_Alloc> __string_type; + typedef basic_string<_CharT, _Traits, _Alloc> __string_type; typedef typename __string_type::size_type __size_type; __size_type __len = _Traits::length(__lhs); __string_type __str; @@ -541,10 +547,10 @@ namespace std } template - basic_string<_CharT,_Traits,_Alloc> - operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) + basic_string<_CharT, _Traits, _Alloc> + operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) { - typedef basic_string<_CharT,_Traits,_Alloc> __string_type; + typedef basic_string<_CharT, _Traits, _Alloc> __string_type; typedef typename __string_type::size_type __size_type; __string_type __str; __size_type __len = __rhs.size(); @@ -627,7 +633,7 @@ namespace std size_type __size = this->size(); if (__n <= __size) { - __pos = std::min(__size - __n ,__pos); + __pos = std::min(__size - __n, __pos); const _CharT* __data = _M_data(); do { @@ -811,7 +817,7 @@ namespace std template int - basic_string <_CharT,_Traits,_Alloc>:: + basic_string <_CharT, _Traits, _Alloc>:: compare(size_type __pos, size_type __n1, const _CharT* __s) const { size_type __size = this->size(); @@ -829,7 +835,7 @@ namespace std template int - basic_string <_CharT,_Traits,_Alloc>:: + basic_string <_CharT, _Traits, _Alloc>:: compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const { diff --git a/libstdc++-v3/src/string-inst.cc b/libstdc++-v3/src/string-inst.cc index 3d7c127847f..05f6d54257a 100644 --- a/libstdc++-v3/src/string-inst.cc +++ b/libstdc++-v3/src/string-inst.cc @@ -56,22 +56,6 @@ namespace std // Only one template keyword allowed here. // See core issue #46 (NAD) // http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#46 - template - S& - S::_M_replace - (S::iterator, S::iterator, S::iterator, S::iterator, forward_iterator_tag); - - template - S& - S::_M_replace - (S::iterator, S::iterator, - S::const_iterator, S::const_iterator, forward_iterator_tag); - - template - C* - S::_S_construct - (S::iterator, S::iterator, const allocator&, forward_iterator_tag); - template S::basic_string(C*, C*, const allocator&); @@ -81,24 +65,46 @@ namespace std template S::basic_string(S::iterator, S::iterator, const allocator&); + template + S::basic_string(S::const_iterator, S::const_iterator, const allocator&); + + template + S& + S::_M_replace(S::iterator, S::iterator, S::iterator, S::iterator, + forward_iterator_tag); + + template + S& + S::_M_replace(S::iterator, S::iterator, S::const_iterator, + S::const_iterator, forward_iterator_tag); + template S& - S::_M_replace(S::iterator, S::iterator, C*, C*, forward_iterator_tag); + S::_M_replace(S::iterator, S::iterator, C*, C*, forward_iterator_tag); template S& S::_M_replace(S::iterator, S::iterator, const C*, const C*, forward_iterator_tag); - template - C* - S::_S_construct(const C*, const C*, const allocator&, - forward_iterator_tag); + template + C* + S::_S_construct(S::iterator, S::iterator, + const allocator&, forward_iterator_tag); + + template + C* + S::_S_construct(S::const_iterator, S::const_iterator, + const allocator&, forward_iterator_tag); template C* - S::_S_construct (C*, C*, const allocator&, - forward_iterator_tag); + S::_S_construct(C*, C*, const allocator&, forward_iterator_tag); + + template + C* + S::_S_construct(const C*, const C*, const allocator&, + forward_iterator_tag); template void diff --git a/libstdc++-v3/testsuite/21_strings/assign.cc b/libstdc++-v3/testsuite/21_strings/assign.cc new file mode 100644 index 00000000000..271ef65ca78 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/assign.cc @@ -0,0 +1,46 @@ +// 2001-10-30 Benjamin Kosnik + +// Copyright (C) 2001 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. + +// 21.3.5 string modifiers + +#include +#include +#include + +void +test01() +{ + bool test = true; + + using namespace std; + + const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii"; + string aux = strlit; + string::size_type i = aux.rfind("/"); + if (i != string::npos) + aux.assign(aux, i + 1, string::npos); + VERIFY(aux == "Hawaii"); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/replace.cc b/libstdc++-v3/testsuite/21_strings/replace.cc index b4aac625ea1..b42ae8d3fa6 100644 --- a/libstdc++-v3/testsuite/21_strings/replace.cc +++ b/libstdc++-v3/testsuite/21_strings/replace.cc @@ -52,7 +52,6 @@ bool test01(void) // template // string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2) -#if 1 // with mods, from tstring.cc, from jason merrill, et. al. std::string X = "Hello"; std::string x = X; @@ -75,7 +74,6 @@ bool test01(void) std::find(x.rbegin(), x.rend(), 'l').base(), ar, ar + sizeof(ar) / sizeof(ar[0])); VERIFY( x == "jeHelloo" ); -#endif #ifdef DEBUG_ASSERT assert(test); @@ -83,8 +81,24 @@ bool test01(void) return test; } +void +test02() +{ + const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii"; + std::string aux = strlit; + aux.replace(aux.begin()+5, aux.begin()+20, + aux.begin()+10, aux.begin()+15); + VERIFY(aux == "../thg piealei Bay/Kauai/Hawaii"); + + aux = strlit; + aux.replace(aux.begin() + 10, aux.begin() + 15, + aux.begin() + 5, aux.begin() + 20); + VERIFY(aux == "../the lone long pier/Hanr/Hanalei Bay/Kauai/Hawaii"); +} + int main() { test01(); + test02(); return 0; }