|
And another version of the same to show that there is an unbounded set of specializations of the replace() member function template whose arguments may reference elements in *this.
#include <cassert> int main () typedef const unsigned char UChar; assert ("babc" == s); The regression test is attached.
Corrected patch is attached.
I'm not sure we can introduce a string_type local typedef into <string>. Unless there already is a typedef with that name in some scope the name should be private (e.g., _C_string_type).
@ -476,6 +476,8 @@
typedef _Alloc allocator_type;
typedef _TYPENAME allocator_type::size_type size_type;
+ typedef _STD::basic_string<_CharT, _Traits, _Alloc> string_type;
Can you explain the reinterpret_cast in the hunk below? @@ -638,14 +653,40 @@
}
else {
// Current reference has enough room.
- if (__rem)
+ pointer __tmp = 0;
+
+ if (__n2) {
+ const_reference __ref =
+ _RWSTD_REINTERPRET_CAST (const_reference, *__first2);
+ const const_pointer __ptr =
+ _RWSTD_VALUE_ALLOC (_C_value_alloc_type, __s,
+ address (__ref));
+ if (__s.data () <= __ptr && __s.data () + __ssize > __ptr) {
+ __tmp = _RWSTD_VALUE_ALLOC (_C_value_alloc_type, __s,
+ allocate (__n2));
+ for (__d = 0; __d < __n2; __d++)
+ traits_type::assign (*(__tmp + __d), *__first2++);
+ }
+ }
+
+ if (__rem)
The *__first2 expression can be of different type than const_reference.
I.e. from the third example (see comment at 27/Apr/06 12:01 AM), the const_reference is const char&, but *__first2 is unsigned char&. The allocator<>::address() method accept allocator<>::const_reference type, and to avoid of making the temporary object of char type, assigned with a result of *__first2, and passing the reference to this temporary object in address() method I've used the reinterpret_cast. The using address() method is not necessary and the following code
const_reference __ref =
_RWSTD_REINTERPRET_CAST (const_reference, *__first2);
const const_pointer __ptr =
_RWSTD_VALUE_ALLOC (_C_value_alloc_type, __s,
address (__ref));
could be replaced to
const const_pointer __ptr =
&_RWSTD_REINTERPRET_CAST (const_reference, *__first2);
The patch committed in trunk thus: http://svn.apache.org/viewvc?rev=629550&view=rev
The regression test added in trunk thus: http://svn.apache.org/viewvc?rev=629551&view=rev The issue will be closed after passing the nightly builds and merging into the 4.2.x branch.
The patch merged in 4.2.x branch thus: http://svn.apache.org/viewvc?rev=630259&view=rev
The regression test merged in 4.2.x branch thus: http://svn.apache.org/viewvc?rev=630257&view=rev The current patch causing problems. The issue should be fixed using type traits templates and adding overloads for existing methods. This is not binary compatible changes and issue is deferred to 4.3 release.
The patch partially reverted from trunk thus: http://svn.apache.org/viewvc?rev=637897&view=rev Attaching patch for review.
The patch stdcxx-170.patch is suitable for 4.2.2. If the range being copied from is a pointer type and overlaps or IterType is not a pointer type, then we make a copy of the source range and then replace using the temporary. I could create an additional patch that would allow us to avoid creating unnecessary copies of the src range when the iterators are std::string::iterator or std::string::const_iterator types. This would only provide a benefit in debug builds, so I don't see it as being extremely useful. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$ cat t.cpp && make t && ./t
#include <cassert>
#include <string>
int main ()
{
std::string s ("abc");
s.replace (s.begin (), s.begin (), s.rbegin () + 1, s.rbegin () + 2);
assert ("babc" == s);
}
gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG -pthreads -D_RWSTD_USE_CONFIG -I/build/sebor/gcc-4.1.0-15s/include -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest -I/build/sebor/dev/stdlib/../rwtest/include -I/build/sebor/dev/stdlib/tests/include -pedantic -nostdinc++ -g -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long t.cpp
gcc t.o -o t -L/build/sebor/gcc-4.1.0-15s/rwtest -lrwtest15s -pthreads -L/build/sebor/gcc-4.1.0-15s/lib -lstd15s -lsupc++ -lm
Assertion failed: "babc" == s, file t.cpp, line 10
Abort (core dumped)