diff options
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp')
| -rw-r--r-- | libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp index d6112601f2e0..8c0d3d78ab8f 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp @@ -28,6 +28,8 @@ test(S s, It first, It last, S expected) } #ifndef TEST_HAS_NO_EXCEPTIONS +struct Widget { operator char() const { throw 42; } }; + template <class S, class It> void test_exceptions(S s, It first, It last) @@ -176,6 +178,9 @@ int main(int, char**) test_exceptions(S(), TIter(s, s+10, 4, TIter::TAIncrement), TIter()); test_exceptions(S(), TIter(s, s+10, 5, TIter::TADereference), TIter()); test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter()); + + Widget w[100]; + test_exceptions(S(), w, w+100); } #endif @@ -204,6 +209,23 @@ int main(int, char**) assert(s == "ABCD"); } + { // regression-test appending to self in sneaky ways + std::string s_short = "hello"; + std::string s_long = "Lorem ipsum dolor sit amet, consectetur/"; + std::string s_othertype = "hello"; + const unsigned char *first = reinterpret_cast<const unsigned char*>(s_othertype.data()); + std::string s_sneaky = "hello"; + + test(s_short, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1, + std::string("hello\0", 6)); + test(s_long, s_long.data() + s_long.size(), s_long.data() + s_long.size() + 1, + std::string("Lorem ipsum dolor sit amet, consectetur/\0", 41)); + test(s_othertype, first + 2, first + 5, std::string("hellollo")); + + s_sneaky.reserve(12); + test(s_sneaky, s_sneaky.data(), s_sneaky.data() + 6, std::string("hellohello\0", 11)); + } + { // test with a move iterator that returns char&& typedef forward_iterator<const char*> It; typedef std::move_iterator<It> MoveIt; |
