Skip to content

Commit 2c5aee9

Browse files
danakjCommit bot
authored and
Commit bot
committed
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}
1 parent 87ba57a commit 2c5aee9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

styleguide/c++/c++11.html

+19-10
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ <h2 id="whitelist"><a name="core-whitelist"></a>C++11 Allowed Features</h2>
244244
<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. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc">Discussion thread</a></td>
245245
</tr>
246246

247+
<tr>
248+
<td>Rvalue References</td>
249+
<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</code><br/><br/>
250+
<code>template &lt;typename T&gt;<br/>void Function(T&& t) { ... }</code></td>
251+
<td>Reference that only binds to a temporary object</td>
252+
<td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_references">
253+
Rvalue references</a></td>
254+
<td>As per the <a href="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. <a href="https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a> and <a href="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>
261+
</ul>
262+
</td>
263+
</tr>
264+
247265
<tr>
248266
<td>Standard Integers</td>
249267
<td>Typedefs within <code>&lt;stdint.h&gt;</code>
@@ -355,7 +373,7 @@ <h2 id="whitelist"><a name="library-whitelist"></a>C++11 Allowed Library Feature
355373
<td><code>std::move()</code></td>
356374
<td>Facilitates efficient move operations</td>
357375
<td><a href="http://en.cppreference.com/w/cpp/utility/move"><code>std::move</code> reference</a></td>
358-
<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)'. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
376+
<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
359377
</tr>
360378

361379
<tr>
@@ -460,15 +478,6 @@ <h3 id="blacklist_banned"><a name="core-blacklist"></a>C++11 Banned Features</h3
460478
<td>Causes incorrect line numbers in MSVS2013 and gcc. Reevaluate once that works. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
461479
</tr>
462480

463-
<tr>
464-
<td>Rvalue References (and Move Semantics)</td>
465-
<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</code></td>
466-
<td>Reference that only binds to a temporary object</td>
467-
<td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_references">
468-
Rvalue references</a></td>
469-
<td>To be revisited in the future. Allowed in exceptional cases where approved by the OWNERS of src/styleguide/c++/. <a href="https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a></td>
470-
</tr>
471-
472481
<tr>
473482
<td>(Uniform) Initialization Syntax</td>
474483
<td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></td>

0 commit comments

Comments
 (0)