From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48098 invoked by alias); 24 Nov 2016 00:08:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 48067 invoked by uid 89); 24 Nov 2016 00:08:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.2 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=baldwin, Baldwin, assigning, HX-PHP-Originating-Script:rcube.php X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 00:08:03 +0000 Received: by simark.ca (Postfix, from userid 33) id 28CFD1E141; Wed, 23 Nov 2016 19:08:02 -0500 (EST) To: John Baldwin Subject: Re: [PATCH 3/3] Do not use std::move when assigning an anonymous object to a unique_ptr. X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 24 Nov 2016 00:08:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: <1950124.hOhKlgFiTt@ralph.baldwin.cx> References: <20161123200652.89209-1-jhb@FreeBSD.org> <20161123200652.89209-4-jhb@FreeBSD.org> <1950124.hOhKlgFiTt@ralph.baldwin.cx> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.2 X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00738.txt.bz2 On 2016-11-23 18:31, John Baldwin wrote: > On Wednesday, November 23, 2016 04:19:29 PM Simon Marchi wrote: >> On 2016-11-23 15:06, John Baldwin wrote: >> > Using std::move forces an extra copy of the object. These changes fix >> > -Wpessimizing-move warnings from clang. >> >> For those who, like me, do not quite understand what is happening >> here, >> I suggest the following read: >> >> https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/RVO_V_S_std_move?lang=en > > My head also hurts. I think what clang is warning about is that the > std::move() in these lines breaks RVO for the function being called, > not the function that the modified line belongs to. That is: > > foo = bar (); > > Is able to do RVO if bar() does the right things for RVO to work. > However: > > foo = std::move (bar ()); > > forces an extra copy of the object since the return value of bar > can't use the storge of 'foo' directly, it has to be copied into > an anonymous object (I think) for std::move to consume. > > The commit log for the warning is here: > > http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20150427/128053.html > > I think these instances fall under the "using a move to create a new > object > from a temporary object" case. That's what I understand. Without the move, the object is constructed directly in the caller's stack, so no move/copy is required at all. It seems like the warning works as intended and is useful.