From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99833 invoked by alias); 24 Nov 2016 16:52:45 -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 99824 invoked by uid 89); 24 Nov 2016 16:52:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=blogs, callers X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 16:52:34 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 809CFC054900; Thu, 24 Nov 2016 16:52:33 +0000 (UTC) Received: from [127.0.0.1] (ovpn03.gateway.prod.ext.phx2.redhat.com [10.5.9.3]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAOGqVlG016488; Thu, 24 Nov 2016 11:52:32 -0500 Subject: Re: [PATCH 3/3] Do not use std::move when assigning an anonymous object to a unique_ptr. To: Simon Marchi , John Baldwin References: <20161123200652.89209-1-jhb@FreeBSD.org> <20161123200652.89209-4-jhb@FreeBSD.org> <1950124.hOhKlgFiTt@ralph.baldwin.cx> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Thu, 24 Nov 2016 16:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-11/txt/msg00768.txt.bz2 On 11/24/2016 12:08 AM, Simon Marchi wrote: > 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 I'd recommend as well: https://en.wikipedia.org/wiki/Return_value_optimization http://en.cppreference.com/w/cpp/language/copy_elision Note that C++17 has much stronger copy-elision guarantees. >>> >> >> 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. I've been harping on exploring RVO in several patches/reviews, so I'm surprised I added those std::move calls in the first place. :-P Maybe something to do with an earlier version of gdb::unique_ptr. Anyway, removing them is really right thing to do. Patch is OK, but please drop the leading "gdb/" in filenames in the ChangeLog. Thanks, Pedro Alves