[llvm-bugs] [Bug 30240] New: std::string: append(first, last) error when aliasing
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 1 08:59:03 PDT 2016
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: unassignedclangbugs at nondot.org
Reporter: llvm-bugs at daryl.haresign.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160901/ec0bdbf7/attachment-0001.html>
More information about the llvm-bugs
mailing list