mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-22 16:37:40 +08:00
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:
@@ -178,4 +178,21 @@ int main()
|
||||
test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test appending to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.append(s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.append(s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.append(s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.append(s_long.begin(), s_long.end());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -61,4 +61,20 @@ int main()
|
||||
S("1234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test appending to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.append(s_short.c_str());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.append(s_short.c_str());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.append(s_short.c_str());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.append(s_long.c_str());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
}
|
||||
|
@@ -70,4 +70,20 @@ int main()
|
||||
S("1234567890123456789012345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test appending to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.append(s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/");
|
||||
s_short.append(s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/123/123/");
|
||||
s_short.append(s_short.data(), s_short.size());
|
||||
assert(s_short == "123/123/123/123/123/123/123/123/");
|
||||
|
||||
s_long.append(s_long.data(), s_long.size());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
|
||||
}
|
||||
}
|
||||
|
@@ -179,4 +179,21 @@ int main()
|
||||
test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test assigning to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.assign(s_short.begin(), s_short.end());
|
||||
assert(s_short == "123/");
|
||||
s_short.assign(s_short.begin() + 2, s_short.end());
|
||||
assert(s_short == "3/");
|
||||
|
||||
s_long.assign(s_long.begin(), s_long.end());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
|
||||
|
||||
s_long.assign(s_long.begin() + 30, s_long.end());
|
||||
assert(s_long == "nsectetur/");
|
||||
}
|
||||
}
|
||||
|
@@ -61,4 +61,18 @@ int main()
|
||||
S("12345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
|
||||
{ // test assignment to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.assign(s_short.c_str());
|
||||
assert(s_short == "123/");
|
||||
s_short.assign(s_short.c_str() + 2);
|
||||
assert(s_short == "3/");
|
||||
|
||||
s_long.assign(s_long.c_str() + 30);
|
||||
assert(s_long == "nsectetur/");
|
||||
}
|
||||
}
|
||||
|
@@ -70,4 +70,20 @@ int main()
|
||||
S("12345678901234567890"));
|
||||
}
|
||||
#endif
|
||||
{ // test assign to self
|
||||
typedef std::string S;
|
||||
S s_short = "123/";
|
||||
S s_long = "Lorem ipsum dolor sit amet, consectetur/";
|
||||
|
||||
s_short.assign(s_short.data(), s_short.size());
|
||||
assert(s_short == "123/");
|
||||
s_short.assign(s_short.data() + 2, s_short.size() - 2);
|
||||
assert(s_short == "3/");
|
||||
|
||||
s_long.assign(s_long.data(), s_long.size());
|
||||
assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
|
||||
|
||||
s_long.assign(s_long.data() + 2, 8 );
|
||||
assert(s_long == "rem ipsu");
|
||||
}
|
||||
}
|
||||
|
@@ -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/");
|
||||
}
|
||||
}
|
||||
|
@@ -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/");
|
||||
}
|
||||
}
|
||||
|
@@ -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/");
|
||||
}
|
||||
}
|
||||
|
@@ -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/");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user