[libcxx] r300397 - Fix PR32642 - string::insert and string::append don't work with move_iterator.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 14 23:49:03 PDT 2017
Author: ericwf
Date: Sat Apr 15 01:49:02 2017
New Revision: 300397
URL: http://llvm.org/viewvc/llvm-project?rev=300397&view=rev
Log:
Fix PR32642 - string::insert and string::append don't work with move_iterator.
Modified:
libcxx/trunk/include/string
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=300397&r1=300396&r2=300397&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Sat Apr 15 01:49:02 2017
@@ -2276,7 +2276,9 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n)
{
- if ( __ptr_in_range(&*__first, data(), data() + size()))
+ typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
+ _CharRef __tmp_ref = *__first;
+ if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
{
const basic_string __temp (__first, __last, __alloc());
append(__temp.data(), __temp.size());
@@ -2440,7 +2442,9 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n)
{
- if ( __ptr_in_range(&*__first, data(), data() + size()))
+ typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
+ _CharRef __tmp_char = *__first;
+ if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
{
const basic_string __temp(__first, __last, __alloc());
return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp?rev=300397&r1=300396&r2=300397&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp Sat Apr 15 01:49:02 2017
@@ -204,4 +204,20 @@ int main()
assert(s == "ABCD");
}
+ { // test with a move iterator that returns char&&
+ typedef forward_iterator<const char*> It;
+ typedef std::move_iterator<It> MoveIt;
+ const char p[] = "ABCD";
+ std::string s;
+ s.append(MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
+ assert(s == "ABCD");
+ }
+ { // test with a move iterator that returns char&&
+ typedef const char* It;
+ typedef std::move_iterator<It> MoveIt;
+ const char p[] = "ABCD";
+ std::string s;
+ s.append(MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
+ assert(s == "ABCD");
+ }
}
Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp?rev=300397&r1=300396&r2=300397&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp Sat Apr 15 01:49:02 2017
@@ -188,10 +188,35 @@ int main()
{ // test assigning a different type
typedef std::string S;
- const uint8_t p[] = "ABCD";
+ const uint8_t p[] = "ABCD";
- S s;
- s.insert(s.begin(), p, p + 4);
- assert(s == "ABCD");
+ S s;
+ s.insert(s.begin(), p, p + 4);
+ assert(s == "ABCD");
}
+
+ { // test with a move iterator that returns char&&
+ typedef input_iterator<const char*> It;
+ typedef std::move_iterator<It> MoveIt;
+ const char p[] = "ABCD";
+ std::string s;
+ s.insert(s.begin(), MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
+ assert(s == "ABCD");
+ }
+ { // test with a move iterator that returns char&&
+ typedef forward_iterator<const char*> It;
+ typedef std::move_iterator<It> MoveIt;
+ const char p[] = "ABCD";
+ std::string s;
+ s.insert(s.begin(), MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
+ assert(s == "ABCD");
+ }
+ { // test with a move iterator that returns char&&
+ typedef const char* It;
+ typedef std::move_iterator<It> MoveIt;
+ const char p[] = "ABCD";
+ std::string s;
+ s.insert(s.begin(), MoveIt(It(std::begin(p))), MoveIt(It(std::end(p) - 1)));
+ assert(s == "ABCD");
+ }
}
More information about the cfe-commits
mailing list