You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move Rvalue references to the allowed section of the C++11 styleguide.
They were in the library area, but they are a language feature, so
moved to the language area.
R=Nico
Review URL: https://codereview.chromium.org/1499293002
Cr-Commit-Position: refs/heads/master@{#363568}
<td>As a rule of thumb, use <code>for (const auto& ...)</code>, <code>for (auto& ...)</code>, or <code>for (<i>concrete type</i> ...)</code>. For pointers, use <code>for (auto* ...)</code> to make clear that the copy of the loop variable is intended, and only a pointer is copied. <ahref="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc">Discussion thread</a></td>
245
245
</tr>
246
246
247
+
<tr>
248
+
<td>Rvalue References</td>
249
+
<td><code>T(T&& t)</code> and <code>T& operator=(T&& t)</code><br/><br/>
<td>As per the <ahref="https://google.github.io/styleguide/cppguide.html#Rvalue_references">Google style guide</a>: Only use these to define move constructors and move assignment operators, and for perfect forwarding.<br/>Most classes should not be copyable, even if movable. Continue to use DISALLOW_COPY_AND_ASSIGN (or DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND if needed) in most cases. <ahref="https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a> and <ahref="https://groups.google.com/a/chromium.org/d/topic/cxx/Q526tkruXpM">discussion thread</a>.
255
+
<br/><br/>
256
+
MSVC 2013 has some known bugs with rvalue references:
257
+
<ul>
258
+
<li>Exported classes generate copy constructors even if they are not used, which tries to use copy constructors on members. Use DISALLOW_COPY_AND_ASSIGN on the exported class to resolve it.</li>
259
+
<li>The compiler chooses a T::(T&) constructor before T::(T&&). However copy constructors should be written as T::T(const T&) and these are prioritized correctly.</li>
260
+
<li>The compiler does not create default move constructors, either implicitly or with the =default keyword. You must provide such constructors explicitly to create them.</li>
<td>Note: std::move() is allowed but writing your own move constructors is still only allowed in exceptional cases for now, see 'Rvalue References (and Move Semantics)'. <ahref='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
<td>Causes incorrect line numbers in MSVS2013 and gcc. Reevaluate once that works. <ahref="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
461
479
</tr>
462
480
463
-
<tr>
464
-
<td>Rvalue References (and Move Semantics)</td>
465
-
<td><code>T(T&& t)</code> and <code>T& operator=(T&& t)</code></td>
466
-
<td>Reference that only binds to a temporary object</td>
<td>To be revisited in the future. Allowed in exceptional cases where approved by the OWNERS of src/styleguide/c++/. <ahref="https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a></td>
0 commit comments