summaryrefslogtreecommitdiffstats
path: root/styleguide
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2015-12-07 12:40:27 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-07 20:41:19 +0000
commit2c5aee92a0e3a40958f69500b563eb590c0df45f (patch)
tree613a0caab26e72e27cb0dc9f47d309c93f5e91e7 /styleguide
parent87ba57a24d6a55f7332d3e07e1fa7300b7cc48b9 (diff)
downloadchromium_src-2c5aee92a0e3a40958f69500b563eb590c0df45f.zip
chromium_src-2c5aee92a0e3a40958f69500b563eb590c0df45f.tar.gz
chromium_src-2c5aee92a0e3a40958f69500b563eb590c0df45f.tar.bz2
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}
Diffstat (limited to 'styleguide')
-rw-r--r--styleguide/c++/c++11.html29
1 files changed, 19 insertions, 10 deletions
diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html
index 85ff363..8b2cb4a 100644
--- a/styleguide/c++/c++11.html
+++ b/styleguide/c++/c++11.html
@@ -245,6 +245,24 @@ Range-based for loop</a></td>
</tr>
<tr>
+<td>Rvalue References</td>
+<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</code><br/><br/>
+ <code>template &lt;typename T&gt;<br/>void Function(T&& t) { ... }</code></td>
+<td>Reference that only binds to a temporary object</td>
+<td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_references">
+Rvalue references</a></td>
+<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>.
+<br/><br/>
+MSVC 2013 has some known bugs with rvalue references:
+<ul>
+<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>
+<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>
+<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>
+</ul>
+</td>
+</tr>
+
+<tr>
<td>Standard Integers</td>
<td>Typedefs within <code>&lt;stdint.h&gt;</code>
and <code>&lt;inttypes&gt;</code></td>
@@ -355,7 +373,7 @@ std::end</a></td>
<td><code>std::move()</code></td>
<td>Facilitates efficient move operations</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/move"><code>std::move</code> reference</a></td>
-<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>
+<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
</tr>
<tr>
@@ -461,15 +479,6 @@ string literal</a></td>
</tr>
<tr>
-<td>Rvalue References (and Move Semantics)</td>
-<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</code></td>
-<td>Reference that only binds to a temporary object</td>
-<td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_references">
-Rvalue references</a></td>
-<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>
-</tr>
-
-<tr>
<td>(Uniform) Initialization Syntax</td>
<td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></td>
<td>Allows any object of primitive, aggregate or class