<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Assign rvalue to self"
href="http://llvm.org/bugs/show_bug.cgi?id=16993">16993</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Assign rvalue to self
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>hhinnant@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ruslan_baratov@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I've found out that some libc++ STL containers works incorrect while
assigning rvalue to self. For example std::vector:
#include <iostream> // std::cout
#include <vector>
int main() {
std::vector<int> a(1000);
std::cout << a.capacity() << std::endl; // 1000
a = std::move(a);
std::cout << a.capacity() << std::endl; // 0
a[100] = 0x0; // Segmentation fault
return EXIT_SUCCESS;
}
And, I think, is right.
>From standard 17.6.4.9 Function arguments [res.on.arguments]:
— If a function argument binds to an rvalue reference parameter, the
implementation may assume that this parameter is a unique reference to this
argument. [ Note: If the parameter is a generic parameter of the form T&& and
an lvalue of type A is bound, the argument binds to an lvalue reference
(14.8.2.1) and thus is not covered by the previous sentence. —end note ] [
Note: If a program casts an lvalue to an xvalue while passing that lvalue to a
library function (e.g. by calling the function with the argument move(x)), the
program is effectively asking that function to treat that lvalue as a
temporary. The implementation is free to optimize away aliasing checks which
might be needed if the argument was an lvalue. —end note ]
1. Am I quoting standard correctly?
2. Is it refer to STL containers only ("evil" optimization) or general C++11
rule (good practice?)
3. Can you provide an assert(_LIBCPP_ASSERT?) in debug mode to check violation
of this rule?
PS MSVC check (this != &ref) and works correcty, libstdc++ not check and
segfaulting too.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>