mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 10:07:41 +08:00
Fix PR#25973 : 'basic_string::assign(InputIt, InputIt) doesn't provide the strong exception safety guarantee'. This turned out to be a pervasive problem in <string>, which required a fair amount of rework. Add in an optimization for when iterators provide noexcept increment/comparison/assignment/dereference (which covers many of the iterators in libc++). Reviewed as http://reviews.llvm.org/D15862
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@257682 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -24,7 +24,7 @@ int main()
|
||||
s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
|
||||
assert(s == "123abc456");
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
S s("123def456");
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class S, class It>
|
||||
void
|
||||
@@ -34,6 +35,22 @@ test(S s, typename S::size_type pos1, typename S::size_type n1, It f, It l, S ex
|
||||
assert(s.size() == old_size - xlen + rlen);
|
||||
}
|
||||
|
||||
template <class S, class It>
|
||||
void
|
||||
test_exceptions(S s, typename S::size_type pos1, typename S::size_type n1, It f, It l)
|
||||
{
|
||||
typename S::const_iterator first = s.begin() + pos1;
|
||||
typename S::const_iterator last = s.begin() + pos1 + n1;
|
||||
S aCopy = s;
|
||||
try {
|
||||
s.replace(first, last, f, l);
|
||||
assert(false);
|
||||
}
|
||||
catch (...) {}
|
||||
assert(s.__invariants());
|
||||
assert(s == aCopy);
|
||||
}
|
||||
|
||||
const char* str = "12345678901234567890";
|
||||
|
||||
template <class S>
|
||||
@@ -959,7 +976,7 @@ int main()
|
||||
test7<S>();
|
||||
test8<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
@@ -973,4 +990,17 @@ int main()
|
||||
test8<S>();
|
||||
}
|
||||
#endif
|
||||
{ // test iterator operations that throw
|
||||
typedef std::string S;
|
||||
typedef ThrowingIterator<char> TIter;
|
||||
typedef input_iterator<TIter> IIter;
|
||||
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, IIter(TIter(s, s+10, 4, TIter::TAIncrement)), IIter());
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, IIter(TIter(s, s+10, 5, TIter::TADereference)), IIter());
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, IIter(TIter(s, s+10, 6, TIter::TAComparison)), IIter());
|
||||
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 4, TIter::TAIncrement), TIter());
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 5, TIter::TADereference), TIter());
|
||||
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 6, TIter::TAComparison), TIter());
|
||||
}
|
||||
}
|
||||
|
@@ -274,7 +274,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -959,7 +959,7 @@ int main()
|
||||
test7<S>();
|
||||
test8<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -275,7 +275,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -274,7 +274,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -365,7 +365,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -1308,7 +1308,7 @@ int main()
|
||||
test10<S>();
|
||||
test11<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -364,7 +364,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -362,7 +362,7 @@ int main()
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
@@ -5903,7 +5903,7 @@ int main()
|
||||
test54<S>();
|
||||
test55<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
|
Reference in New Issue
Block a user