Fix Bug 30240 - std::string: append(first, last) error when aliasing. Add test cases for append/insert/assign/replace while we're at it, and fix a similar bug in insert.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280643 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2016-09-05 01:54:30 +00:00
parent 4dbd4fcf86
commit d979eed766
13 changed files with 226 additions and 13 deletions

View File

@@ -1007,4 +1007,20 @@ int main()
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 6, TIter::TAComparison), TIter());
}
#endif
{ // test replacing into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
assert(s_short == "123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
assert(s_short == "123/123/123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
assert(s_short == "123/123/123/123/123/123/123/123/");
s_long.replace(s_long.begin(), s_long.begin(), s_long.begin(), s_long.end());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}

View File

@@ -282,4 +282,20 @@ int main()
test2<S>();
}
#endif
{ // test replacing into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
assert(s_short == "123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
assert(s_short == "123/123/123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
assert(s_short == "123/123/123/123/123/123/123/123/");
s_long.replace(s_long.begin(), s_long.begin(), s_long.c_str());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}

View File

@@ -972,4 +972,20 @@ int main()
test8<S>();
}
#endif
{ // test replacing into self
typedef std::string S;
S s_short = "123/";
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
assert(s_short == "123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
assert(s_short == "123/123/123/123/");
s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
assert(s_short == "123/123/123/123/123/123/123/123/");
s_long.replace(s_long.begin(), s_long.begin(), s_long.data(), s_long.size());
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
}
}