220 36093 <c14fe13b-a658-e295-40a6-1465638d18db@technion.ac.il> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Eyal Rozenberg <eyalroz@technion.ac.il>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Sub-objects and their copy ellision
Date: Tue, 19 Dec 2017 23:09:25 +0100
Lines: 76
Approved: news@gmane.org
Message-ID: <c14fe13b-a658-e295-40a6-1465638d18db@technion.ac.il>
References: <caca241d-3498-b79b-fbf3-e57d8b7c3518@technion.ac.il>
 <1c6eff77-d71f-4dd7-8c13-f609460a03f0@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1513721257 14329 195.159.176.226 (19 Dec 2017 22:07:37 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 19 Dec 2017 22:07:37 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101
 Thunderbird/57.0
To: std-proposals@isocpp.org, Nicol Bolas <jmckesson@gmail.com>
Original-X-From: std-proposals+bncBDHKZN7LR4ARBHE443IQKGQEWKVX5AA@isocpp.org Tue Dec 19 23:07:33 2017
Return-path: <std-proposals+bncBDHKZN7LR4ARBHE443IQKGQEWKVX5AA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f71.google.com ([74.125.82.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDHKZN7LR4ARBHE443IQKGQEWKVX5AA@isocpp.org>)
	id 1eRQ2s-0003Jx-VS
	for gclcip-std-proposals@m.gmane.org; Tue, 19 Dec 2017 23:07:31 +0100
Original-Received: by mail-wm0-f71.google.com with SMTP id e70sf1767711wmc.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 19 Dec 2017 14:09:33 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1513721373; cv=pass;
        d=google.com; s=arc-20160816;
        b=Ia0Ijh+D9OslvOodRpSV01VWOQvDKVFUPf5nQhs5a+QWcyDXf2orL9KZOZjAXV5T/M
         ylbPW72HykV6oDMwahNr19It3El549DDlQ+Q3Q+QonBvCtUsqKqeoAAgFJF4uARxNOM9
         SH9snnVB0QT5k8RwGX9Dmh7U8YKevzsrKPlSaPcPZSY6ee4Up4mLNEyBDvsck0dHizu8
         jc1eIqHtRcVnrkdzdf8gTIDmHovtHFCh/1TFNH/GsaH08P4TLf38ZyuRurlu2JRyeXFy
         AOt1QMUJ2Ntce8xPVY6UDbho+JwSHznLb4hxhbtvnB66XO2S18KIGOYamEN3aBrhqruQ
         rhjw==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-transfer-encoding
         :content-language:in-reply-to:mime-version:user-agent:date
         :message-id:openpgp:from:references:to:subject
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=628599VBg8az86nLZ1ZC05zFCUrzimnuUERK9hP/VYM=;
        b=Ra2fg50RU4npDVnpH5YBe6RTC4prCJfSgspeCb/8cxjqjp23bmcb0F1ZxViDUEphB7
         WfwcZXBTcOqHewSt9VbgVRSDdcuYzWRsGn1dlbMaejpajDSxX3KZjb/Zw2Nk/wpJlVgq
         6ZK0RDD4AgwEtc+3Wn8yQil0vRjRinQyUprsKees82cxf8/aFrh7SG2n9lTvY+/eOjas
         zzuWbSF83QAG0IwN7FTmIte+/h8IEEOQLTO/T7otn45FA6dldjH67sTOx+oV7EgFlO0V
         lpLoxLpBGUZFti47iyya4jSwLjzdo3OS+VCsnvbgZrCC 
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of srs0=kaojp=dp=technion.ac.il=eyalroz@cwi.nl designates 192.16.191.27 as permitted sender) smtp.mailfrom=SRS0=KAOJP=DP=technion.ac.il=eyalroz@cwi.nl;
       dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=technion.ac.il
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:openpgp:message-id:date:user-agent
         :mime-version:in-reply-to:content-language:content-transfer-encoding
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=628599VBg8az86nLZ1ZC05zFCUrzimnuUERK9hP/VYM=;
        b=qrbwrvunh//VQ1Ci/cVJ1nmoYzEKn+Vn88JQelW4mNsjuqAQcGBT9Nz97vgkF6Ds16
         nF+/txodMG13qtyIe3Th/DBbqoa6GW1SPa+AM+gbxGFM2MibbUyXD7vjVBrszCRB7Zbs
         OJCpYxNIXQzXoNPAtBYupgoH+/LdRTwmYgv/6i2bi3nugL70/x6KwSOULdmSTLoSRnto
         cZrut7O9hnwDmLYgYmTETiLr6bw606SuEGb0VSw0k+djsGMhTot0tjeLMXEld3WQ0r/Z
         viUTvHuvPb0xi09hVkmD1WaIDO75mpdqO5INqDhrHIn5w4o4VAoQ+OYkhB91YeZE9HuU
     
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:openpgp:message-id
         :date:user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=628599VBg8az86nLZ1ZC05zFCUrzimnuUERK9hP/VYM=;
        b=NCW+j4xP+umqZJCbOffVTOOZvcqD16pjHxAhoZBIb22UIcynFXaSuQakVZYzt1r+Jl
         0LaORA/zGMKVgQDXYtBcNGRwfMZhYLU4hIGb+JnIcesTjTyVD0LF6uuBFu/XHGTN5iFa
         HZZUwHa5ym/Xmio4Pj6YpymeTQDNRpp/KSjUEe+fD4nAzAEuC6BJbMyKIXVQVsAlQO/H
         Phy+lKqlS/rMUImr4IjY+qbWQO7K2TR89kay69aPGxsmTBcHJytFHMn8pCGtjiOFLIl1
         zMh2cpNoziyFb97ers4ZXsQE4Kv8v6BRJbP 
X-Gm-Message-State: AKGB3mL/CYrfP3hv6kERROfaCq2NCsyW+y/cIQVJX08rCaIWqTRWqwo6
	90WoP1Y77Ouo3G3m0U1lAL4=
X-Google-Smtp-Source: ACJfBosENKuAwNGTEJrpwvcTBBkJ4MrvveQsp4YO5c99WEAmxTNVuzTs0jmJBhB4euJlKg26kO9QhQ==
X-Received: by 10.80.230.25 with SMTP id y25mr618079edm.9.1513721373638;
        Tue, 19 Dec 2017 14:09:33 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.80.144.196 with SMTP id d4ls7066099eda.4.gmail; Tue, 19 Dec
 2017 14:09:32 -0800 (PST)
X-Received: by 10.80.215.89 with SMTP id i25mr2532459edj.274.1513721372214;
        Tue, 19 Dec 2017 14:09:32 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1513721372; cv=none;
        d=google.com; s=arc-20160816;
        b=gpufkwWgw1uPQMGcGJfuggn2o+MpthOM39oJifNln8hyVc8SpQOrjbc6wdbGkf5ULi
         0ZDdfyyjvV0lqQb1aLgKdnR3bbMRU9OUGwImtHHgn3+p0EpQB9dzq5/gd8Ib+tQD+5Bs
         ACrCVGSG7ci4uvap+QYN50NvqGRByxWrkcghtZ2L7ZJaBHZUmnUWzQkXn0VCzZaSd4z5
         YAOC+DD+egUJt4Pa5jzZKdNRBWMzn2DBeKXoBYR3I87cNxL6qDj2lkhj0stQASCoeVLB
         5h9enqIlfihUEj28E7Spx+jgi+xgdMj8QwDtTf+QbqV+VNTT9ttUVX6IADeo7xxZqoAZ
         OMbg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:content-language:in-reply-to:mime-version
         :user-agent:date:message-id:openpgp:from:references:to:subject
         :arc-authentication-results;
        bh=h254oSMyOYB7tAfOSiyhUOE4mRa4COB1dt2HRO4TeCQ=;
        b=PzjLllLZ1rTCXxZoV92Tb39He1TzpLd0g/TgUT7VTVHXY+MMJZPbU+H1IUSSC/g1pk
         6eBIsObqU+WjrUNUCjqLdLZ2Jxq3M/RSSGfdmmkfMLCbyO4CUOQDyBsmXNqQ7QprcuvB
         nNZliY6wwNTL3eKdWur67PIML/ps+5UMR/YMJCWPJKXEOqUZkztm2rU6pnm0oBe0QGej
         5euaLJY53eYqoSIgUjp6EyO1jAYBhKnNDm9gdNk7yLKnMUAMacqwOvcSHFVX7Sr0rztA
         GXTZBCfn8AGxp6VqDXKUV6pM8ZtIw8D2GMIcOyIwDgF0A/uZExPf7WaN+QjZ/CaF68H8
         LNIQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of srs0=kaojp=dp=technion.ac.il=eyalroz@cwi.nl designates 192.16.191.27 as permitted sender) smtp.mailfrom=SRS0=KAOJP=DP=technion.ac.il=eyalroz@cwi.nl;
       dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=technion.ac.il
Original-Received: from fester.cwi.nl (fester.cwi.nl. [192.16.191.27])
        by mx.google.com with ESMTPS id 93si453015ede.482.2017.12.19.14.09.32
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 19 Dec 2017 14:09:32 -0800 (PST)
Received-SPF: pass (google.com: domain of srs0=kaojp=dp=technion.ac.il=eyalroz@cwi.nl designates 192.16.191.27 as permitted sender) client-ip=192.16.191.27;
Original-Received: from fester.cwi.nl (fester.cwi.nl [192.16.191.27])
	by fester.cwi.nl (8.14.4/8.12.3) with ESMTP id vBJM9V2a018192;
	Tue, 19 Dec 2017 23:09:31 +0100
Original-Received: from [192.168.2.1] (ip565d4370.direct-adsl.nl [86.93.67.112] (may be forged))
	(authenticated bits=0)
	by fester.cwi.nl (8.14.4/8.12.3) with ESMTP id vBJM9UUj018184
	(version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO);
	Tue, 19 Dec 2017 23:09:31 +0100
Openpgp: preference=signencrypt
In-Reply-To: <1c6eff77-d71f-4dd7-8c13-f609460a03f0@isocpp.org>
Content-Language: en-US
X-Original-Sender: eyalroz@technion.ac.il
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of srs0=kaojp=dp=technion.ac.il=eyalroz@cwi.nl designates
 192.16.191.27 as permitted sender) smtp.mailfrom=SRS0=KAOJP=DP=technion.ac.il=eyalroz@cwi.nl;
       dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=technion.ac.il
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:36093
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/36093>



On 12/19/17 9:10 PM, Nicol Bolas wrote:
> look at what [class.copy.elision]/1.1 says:
>=20
>> when the expression is the name of a non-volatile automatic object
> (other than a function parameter or a variable introduced by the
> exception-declaration of a handler (18.3))
>=20
> The expression `v.first` is not "the name of a non-volatile automatic
> object". `first` is not an automatic object; it is a member subobject of
> `v`. And `v.first` is not its name; `first` is its name. `v.first` is an
> expression that accesses a subobject from an object.

Ah. Indeed, it seems only variables can have "automatic storage
duration", even though their sub-objects have the same storage behavior
as them. Ok.

> Now, consider this:
>=20
> |
> stringfoo()
> {
> =C2=A0 pair<string,string>pr;
> =C2=A0 pr.first =3D...;
> =C2=A0 returnpr.first;
> }
> |
>=20
> The layout of `pair<string, string>` is fixed.

But when optimizing, the compiler is not committed to using that layout.
In fact, in the example you've given it can completely drop pr, and just
construct the returned string at the area where a string is supposed to
end up. It will be "as if" the pr was used and the first element was copied=
..

> But the/caller/ doesn't know that. The caller is the one who provides
> memory for the return value object. And as far as the caller can tell,
> all it needs to provide is `sizeof(string)` bytes.

.... which is good enough with your specific example. Now, it's true that
there could be code in foo() which depends on the layout being as it is
that a compiler's optimizer will not be able to clear away; but there
could also not be such code. And since, like you pointed out at the
beginning of your reply, elision is just an option - why not give that
option?

> Not to mention, this creates a problem for the entire object model. To
> make this work, `pr.first` would have to be able to outlive the object
> it is stored within. But the object model doesn't allow that; if you
> destroy a complete object, you destroy its subobjects too. That's require=
d.

Under certain assumptions, which std::pair meets, that should not be a
problem. I guess a defaulted destructor would be one of those.

> No, this is not gonna happen. Not unless someone comes up with a really
> novel way of allowing it.

Would you not say there's some leeway for what I describe (i.e. break
up objects that are not necessary) rather than what you ruled out
(negotiations over who destroys an object)? Under the "as if" rule?

Eyal

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/c14fe13b-a658-e295-40a6-1465638d18db%40technion.=
ac.il.

.
