From patchwork Tue Feb 12 22:20:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 557 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91515610BB for ; Tue, 12 Feb 2019 23:20:11 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 85C35100002; Tue, 12 Feb 2019 22:20:10 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Feb 2019 23:20:21 +0100 Message-Id: <20190212222021.28517-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212222021.28517-1-jacopo@jmondi.org> References: <20190212222021.28517-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] Documentation: coding-style: Discourage move on shared_ptr<> X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 22:20:11 -0000 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 Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Documentation/coding-style.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index 51afef27e9c1..065fbe0ab07b 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.