summaryrefslogtreecommitdiff
path: root/Documentation
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-02-12 23:11:09 +0100
committerJacopo Mondi <jacopo@jmondi.org>2019-02-14 05:32:17 +0100
commitfbc67a54f379654b5d785940850cb9f4edb22c62 (patch)
treec71f44999a5f7983346542e410ba9451027b3a98 /Documentation
parentddcd8ebb3de0d5938b59eb62b9cf2e5bc430d820 (diff)
Documentation: coding-style: Discourage move on shared_ptr<>
Using std::move() on return statement of a method or on the its returned value prevents the compiler from implementing copy-elision. Discourage that in the coding style document. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/coding-style.rst4
1 files changed, 4 insertions, 0 deletions
diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst
index 51afef27..065fbe0a 100644
--- a/Documentation/coding-style.rst
+++ b/Documentation/coding-style.rst
@@ -151,6 +151,10 @@ reference for the duration of the operation that borrows it.
never by reference. The caller can decide whether to transfer its ownership
of the std::shared_ptr<> with std::move() or retain it. The callee shall
use std::move() if it needs to store the shared pointer.
+ * Do not over-use std::move(), as it may prevent copy-elision. In particular
+ a function returning a std::shared_ptr<> value shall not use std::move() in
+ its return statements, and its callers shall not wrap the function call
+ with std::move().
* Borrowed references to shared objects are passed as references to the
objects themselves, not to the std::shared_ptr<>, with the same rules as
for single owner objects.