https://llvm.org/bugs/show_bug.cgi?id=30240
Bug ID: 30240
Summary: std::string: append(first, last) error when aliasing
Product: libc++
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
The standard says:
| template<class InputIterator>
| basic_string& append(InputIterator first, InputIterator last);
|
| Requires: [first, last) is a valid range.
|
| Effects: Equivalent to append(basic_string(first, last)).
|
| Returns: *this.
http://eel.is/c++draft/string::append#20
Given that, I would expect the following to work:
| std::string str("hello world//");
|
| str.append(str.begin(), str.end());
| str.append(str.begin(), str.end());
And I should end up with 'str' containing:
| hello world//hello world//hello world//hello world//
libcxx, however, appears to try to avoid creating a temporary string if it can:
https://github.com/llvm-mirror/libcxx/blob/master/include/string#L2159
If the capacity is not enough for the new string, it will resize the storage:
https://github.com/llvm-mirror/libcxx/blob/master/include/string#L2175
Unfortunately '__grow_by()' destroys the old storage before the string is
copied.
This means the above code doesn't work as expected. You can see the result
of calling the above code here, compiled against libcxx and libstdc++:
http://coliru.stacked-crooked.com/a/b099fd5dada88798
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs