220 5202 <CAOfiQq=fMN9C3RdQLGhGBsNRvd1W2qaqSpPVomGYdm68Hd2Vbg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Teachability problems with std::move
Date: Mon, 24 Jun 2013 14:30:48 -0700
Lines: 116
Approved: news@gmane.org
Message-ID: <CAOfiQq=fMN9C3RdQLGhGBsNRvd1W2qaqSpPVomGYdm68Hd2Vbg@mail.gmail.com>
References: <CA+cyFgsYFbjG1M98PJS-XVzuJYbQmt7=4GOqS5_V5-WVJ0caLg@mail.gmail.com>
	<CAOfiQq==HeEUmRGhashVO2486N+XCkH25dJY9xxEPc87w0omBQ@mail.gmail.com>
	<8e156cc1-8136-48e6-96f2-8dca72fee7d4@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1372109452 32702 80.91.229.3 (24 Jun 2013 21:30:52 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 24 Jun 2013 21:30:52 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDVNBJG4YAIBBCPVUKHAKGQEIJK2UAY@isocpp.org Mon Jun 24 23:30:53 2013
Return-path: <std-proposals+bncBDVNBJG4YAIBBCPVUKHAKGQEIJK2UAY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vb0-f69.google.com ([209.85.212.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBBCPVUKHAKGQEIJK2UAY@isocpp.org>)
	id 1UrELa-0008Lm-Qm
	for gclcip-std-proposals@m.gmane.org; Mon, 24 Jun 2013 23:30:51 +0200
Original-Received: by mail-vb0-f69.google.com with SMTP id w16sf15650561vbb.4
        for <gclcip-std-proposals@m.gmane.org>; Mon, 24 Jun 2013 14:30:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-beenthere:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=s9t/agq1iseoKJVTiUqPeEFSmVhjo+ikYGkhGaZsRFc=;
        b=pL8YrpcfOFF9a7rZKlDG4P/nRrlADIP3RhmxytED0hGppeZvNkvYS6Tp+W21fcW+rm
         UnX5UjgXIzbK71nR9zwQkfO1eU+yGanQrDIldQ8x6cFAaYD88oMqMs8xGPr102qxnL95
         DBLcC8DywxifyxCmMgzr585xjwo9s4py2HOAEmnNK+6411VrTOJRfXBUafE+rlBpM02f
         1epNqMFF215ULBiGdGEl848SIxiyNIDLN//1Yb4O97lTe4q4oqxKQhXQ828oDenpQM2K
         wNIcMBqxtEZ0CNGIxr+M4+g5LglYebttxTc4/HcxgsSpVVdO7F8CTUW1613ZOUttFWiu
         vYJg==
X-Received: by 10.236.45.4 with SMTP id o4mr14620376yhb.6.1372109449868;
        Mon, 24 Jun 2013 14:30:49 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.116.197 with SMTP id jy5ls2264215qeb.10.gmail; Mon, 24 Jun
 2013 14:30:49 -0700 (PDT)
X-Received: by 10.52.163.67 with SMTP id yg3mr10799222vdb.14.1372109449185;
        Mon, 24 Jun 2013 14:30:49 -0700 (PDT)
Original-Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f])
        by mx.google.com with ESMTPS id f8si5412233vec.47.2013.06.24.14.30.49
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 24 Jun 2013 14:30:49 -0700 (PDT)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400c:c01::22f as permitted sender) client-ip=2607:f8b0:400c:c01::22f;
Original-Received: by mail-ve0-f175.google.com with SMTP id da11so9359553veb.34
        for <std-proposals@isocpp.org>; Mon, 24 Jun 2013 14:30:49 -0700 (PDT)
X-Received: by 10.52.69.177 with SMTP id f17mr10898110vdu.48.1372109448970;
 Mon, 24 Jun 2013 14:30:48 -0700 (PDT)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.58.125.73 with HTTP; Mon, 24 Jun 2013 14:30:48 -0700 (PDT)
In-Reply-To: <8e156cc1-8136-48e6-96f2-8dca72fee7d4@isocpp.org>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of metafoo@gmail.com designates 2607:f8b0:400c:c01::22f as permitted
 sender) smtp.mail=metafoo@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5202
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5202>

On Mon, Jun 24, 2013 at 1:08 PM, Xeo <hivemaster@hotmail.de> wrote:
> I remember sending you and Mike a reminder about that some months ago, and
> was wondering, did you actually talk about this at the Bristol meeting?

No. For CWG, the Bristol meeting was almost entirely occupied by
reviewing C++14 feature wording. I don't recall seeing this on the
issues list, either, but perhaps I just missed it.

> On Monday, June 24, 2013 9:14:17 PM UTC+2, Richard Smith wrote:
>>
>> On Mon, Jun 24, 2013 at 11:42 AM, Geoffrey Romer <gro...@google.com>
>> wrote:
>> > It's surprisingly hard to come up with a good, teachable set of rules
>> > for
>> > when to use std::move. For example, it would be nice to be able to say
>> > "you
>> > can leave out std::move when returning a named local variable", but this
>> > is
>> > not always the case. Consider:
>> >
>> > std::unique_ptr<const Foo> FooFactory() {
>> >   std::unique_ptr<Foo> result(new Foo);
>> >   // ...
>> >   return std::move(result);
>> > }
>> >
>> > The "std::move" is mandatory here, because an lvalue can only be
>> > implicitly
>> > treated as an rvalue during copy operations, and in "return result;",
>> > 'result' is not copied, but used as the input for an implicit
>> > conversion. It
>> > seems like this should be fixable, perhaps by expanding the
>> > implicit-rvalue
>> > rules, but I'm not sure what all the consequences would be (at a
>> > minimum,
>> > this could change the behavior of existing code that has separate rvalue
>> > and
>> > lvalue overloads for an implicit conversion operation).
>>
>> Yes, for NRVO, I think the "same cv-unqualified type as the function
>> return type" restriction only needs to apply to copy-elision and not
>> to implicit move. That is, I think we should treat 'result' as an
>> xvalue here:
>>
>> T f() {
>>   U result;
>>   return result;
>> }
>>
>> ... independent of the types of T and U, but we should only be
>> permitted to perform copy-elision of they're the same cv-unqualified
>> type. Most generalizations of the implicit-rvalue rules are fraught
>> with peril, but this one seems relatively safe.
>>
>> > Conversely, it would be nice to be able to say "When in doubt, just use
>> > std::move if you want move semantics, because it never hurts", but
>> > std::move
>> > can in fact be a pessimization:
>> >
>> > std::array<Foo, 10000> MakeHugeArray() {
>> >   std::array<Foo, 10000> result;
>> >   // ...
>> >   return std::move(result);
>> > }
>>
>> I suggest you talk to your compiler vendor (Hi!) and ask for a warning
>> for this case.
>>
>> > As written, the return statement incurs 10,000 invocations of Foo's move
>> > constructor (or, worse, its copy constructor), but if std::move is
>> > eliminated, the return statement becomes effectively free, because it's
>> > an
>> > elidable copy/move. In this case it's not at all clear to me how to fix
>> > the
>> > problem; it seems like a fix would either require special-casing
>> > std::move
>> > (which seems like a hack, and breaks the convention that the
>> > core-language
>> > standard tries not to refer to the library standard), or require the
>> > implementation to 'see into' the implementation of a function called in
>> > a
>> > return statement (which seems impractical).
>> >
>> > I think it's worth trying to fix these issues, despite the difficulties,
>> > because being able to provide reliable "rules of thumb" would
>> > substantially
>> > improve the learning curve for std::move. Can anyone suggest how these
>> > issues could be fixed?
>>
>> Per the above, I think we can make "you can leave out std::move when
>> returning a named local variable" be the right advice, with the added
>> bonus of a compiler warning if you put in a pessimizing std::move.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.
