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:
@@ -169,4 +169,21 @@ int main()
|
||||
assert(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test inserting into self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.insert(s_long.begin(), s_long.begin(), s_long.end());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -210,4 +210,20 @@ int main()
|
||||
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test inserting into self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.insert(0, s_short.c_str());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.insert(0, s_short.c_str());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.insert(0, s_short.c_str());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.insert(0, s_long.c_str());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,4 +691,20 @@ int main()
|
||||
test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"));
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test inserting into self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.insert(0, s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.insert(0, s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.insert(0, s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.insert(0, s_long.data(), s_long.size());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user