220 38486 <8365b751-0310-4199-8be7-d6222b078aff@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Restricting the valid use of certain methods upon
 temporary objects
Date: Mon, 4 Jun 2018 21:30:58 -0700 (PDT)
Lines: 184
Approved: news@gmane.org
Message-ID: <8365b751-0310-4199-8be7-d6222b078aff@isocpp.org>
References: <f3abea5e-9d3a-407f-be79-48cc5cfd3ddc@isocpp.org>
 <CANh8DEnPS+FMpWpAp1WLe-9H1twSc30w7bQph_MgBMK0FM0t8A@mail.gmail.com>
 <81b39e17-fe78-41ab-b9c9-3b830e32dbf5@isocpp.org> <709f2ceb-5059-4217-8475-288a8f4ecd44@isocpp.org>
 <48ae754e-18c0-4350-922b-8b6faac0df16@isocpp.org> <73c26f59-2aa0-4d89-b783-ebf73282a0bf@isocpp.org>
 <a3608611-17e4-4210-8734-9918c3210b0f@isocpp.org> <1ff61a56-191f-49c2-849d-b3bb47b52930@isocpp.org>
 <CANgTfEgedZZj1=3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5X8e1w@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_38184_1693041824.1528173058786"
X-Trace: blaine.gmane.org 1528172957 12790 195.159.176.226 (5 Jun 2018 04:29:17 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 5 Jun 2018 04:29:17 +0000 (UTC)
Cc: florian.csdt@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBA5E3DMAKGQEB5YIP4I@isocpp.org Tue Jun 05 06:29:13 2018
Return-path: <std-proposals+bncBCEKFTV6ZUMBBA5E3DMAKGQEB5YIP4I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f198.google.com ([209.85.213.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBA5E3DMAKGQEB5YIP4I@isocpp.org>)
	id 1fQ3ap-0003CE-Lm
	for gclcip-std-proposals@m.gmane.org; Tue, 05 Jun 2018 06:29:11 +0200
Original-Received: by mail-yb0-f198.google.com with SMTP id h29-v6sf843131ybj.22
        for <gclcip-std-proposals@m.gmane.org>; Mon, 04 Jun 2018 21:31:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=xXTqVCwZ/uuT7pLlNQQSnihzpJNZun2ueWyR1zOM7Og=;
        b=XUIk9pyW1UtaJ5YoGukUGbN1BKmnsEGRyPHZiLqG48eBnqDbpI7Rj6GhPuL9hNpGlS
         JrCKPgq0CT84hDP7+xxDcXBe7wyCUh0E1sshSGHqmw9Q+7iuXDDyflxRyjHwOS9Sjplg
         bPVuQDyr96tOPaUlyEHGDCYwEZbk/mQ9en3MZ7AOOSOCkz+iRkdcqOQ2mCrClNg038bQ
         Xe3XrXG5YJFXUOTrA9j1zrlgwvPqzOqKtL7MweHh1ULpx4Nk6o9iXA9a4YHWQVfFe9Vp
         VghA53/8HwxaRTOkuHPyjloVmU0M57Uo4Nqz1GywmXR6jBqV2ugm7x4jCUq3ZVNz0FVb
         dwLw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=xXTqVCwZ/uuT7pLlNQQSnihzpJNZun2ueWyR1zOM7Og=;
        b=ZNXQRTRSc6MzbVA2wtQAezYrlUIdilYImXiIFaHrLR7OQG5zTmDF1R4uV8qBTdOOqQ
         QB1nw7QnfnzR5UW9t49Xxj3phUrtbnPPDB7dMamzWxCGm6Nzc4LgN2Pbn/BWRgYKTvUP
         WjdTHaalVPRnfU4DfLH9xXcpHWa4Xm29YYkAer8E6rt5n7julhC2pTKlY00dTQeNULsk
         Z2ATjPJKjUqww/G8WZuB6Fxzzc/cywxNQ6oXaJ7Aqq/xsw8CfcB7nEVR72oguP0rO6AJ
         Jc5nvorHAvV3jeTRw+FZkYPg2GCq+j2t8FfKcs4d9ZVe/s5G3/+5D/xxwqbQrpaBjeUh
         wv2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=xXTqVCwZ/uuT7pLlNQQSnihzpJNZun2ueWyR1zOM7Og=;
        b=XLma8Tu7RK46n/fnPGCnnwHzo8cEQqQAn72ZJNb3A6GL4TV7EISEII6yQ3omgFxCiO
         8vkV56bqYTj1I0MmMmludKEjMz73ZI11LlKEuEvjbAXxus5zQkBssm4tXZqXRajHTt9e
         M8mlAfM/KQwqrpXAU5dXmFFdJ8j/qwm6IhwLsM/bKJTxIfcdY861dCBaVVxu+vGwzy/r
         BTkx4WwxDEd06R8UuDpYiOCoEznNYv6OypYegvxtMaPY5LI+hcKEzjG1x04Jehe70JY0
         iULO8XdwulGc/os/6tY1Mv4i3tX9YMSlc3y1ffA9tVnLwsk7N+B9bNttUdvEoGEDGrSb
         8rQQ==
X-Gm-Message-State: APt69E24MUjBHIFT19IyT3nzGb7r163rSeBMi1rKtbIAE8OQaXmHxAKa
	4hY+12BI06/7Ge8M//tpsBCDzw==
X-Google-Smtp-Source: ADUXVKLlG3VtCUDBjq1U3nlOsRysK85DgsuvHhWvDam+6B+x2XRro68P2R+W/2kotWUtw76mdNaguA==
X-Received: by 2002:a81:ed10:: with SMTP id k16-v6mr1244384ywm.68.1528173082434;
        Mon, 04 Jun 2018 21:31:22 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:c0cf:: with SMTP id c198-v6ls2511118ybf.16.gmail; Mon,
 04 Jun 2018 21:30:59 -0700 (PDT)
X-Received: by 2002:a25:aaa1:: with SMTP id t30-v6mr65244ybi.13.1528173059334;
        Mon, 04 Jun 2018 21:30:59 -0700 (PDT)
In-Reply-To: <CANgTfEgedZZj1=3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5X8e1w@mail.gmail.com>
X-Original-Sender: jmckesson@gmail.com
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:38486
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/38486>

------=_Part_38184_1693041824.1528173058786
Content-Type: multipart/alternative; 
	boundary="----=_Part_38185_1761327257.1528173058787"

------=_Part_38185_1761327257.1528173058787
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Monday, June 4, 2018 at 8:29:41 PM UTC-4, Gareth Lloyd wrote:
>
> So after a long walk today I finally have been able to point at what make=
s=20
> me uneasy about the lifetime extension approach. In short, if we depend=
=20
> upon more than one lifetimebound object which are temporaries, then as it=
=20
> currently stands they are unsequenced. Consider the following example:
> =E2=80=8B=20
>
> #include <string>#include <iostream>
> struct Foo
> {
>     static int counter;
>    =20
>     std::string s;
>    =20
>     Foo(std::string const & _s) : s{_s + std::to_string(counter++)}=20
>     {=20
>         std::cout << "ctr " << s << '\n';
>     }
>     ~Foo(){std::cout << "dtr " << s << '\n';}
> };
> int Foo::counter =3D 0;
> auto f0(Foo const & foo1 /*lifetimebound*/, Foo const & foo2 /*lifetimebo=
und*/)
> {
>     return [&](){std::cout << foo1.s << '-' << foo2.s << '\n';};
> }
> int main()
> {
>     using namespace std::string_literals;
>     auto x =3D f0("a"s, "b"s);
>     x();
> }
>
> With or without lifetime extension, the temporaries that foo1 and foo2 ar=
e bound to have undefined sequence of construction. This is a=20
> problem for temporaries as it currently is, but if we enhance lifetime ex=
tension and encourage the use of temporaries then this will=20
> possibly be a common pitfall.
>
>
I don't see how this would be any more of a problem in the future than it=
=20
is now. If `f0` didn't store those temporaries in the return value, they=20
would still "have undefined sequence of construction" relative to one=20
another. Yet people write code that constructs multiple temporaries in=20
function parameters *all the time*. So I fail to see how the possibility of=
=20
such faults will be significantly raised by lifetime extension.

--=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/8365b751-0310-4199-8be7-d6222b078aff%40isocpp.or=
g.

------=_Part_38185_1761327257.1528173058787
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Monday, June 4, 2018 at 8:29:41 PM UTC-4, Gareth Lloyd =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">So afte=
r a long walk today I finally have been able to point at what makes me unea=
sy about the lifetime extension approach. In short, if we depend upon more =
than one lifetimebound=20

object which are temporaries, then as it currently stands they are unsequen=
ced. Consider the following example:<br><div>=E2=80=8B
<pre style=3D"margin:0px;line-height:125%"><span style=3D"color:rgb(85,119,=
153)">#include &lt;string&gt;</span>
<span style=3D"color:rgb(85,119,153)">#include &lt;iostream&gt;</span>

<span style=3D"color:rgb(0,136,0);font-weight:bold">struct</span> Foo
{
    <span style=3D"color:rgb(0,136,0);font-weight:bold">static</span> <span=
 style=3D"color:rgb(51,51,153);font-weight:bold">int</span> counter;
   =20
    std<span style=3D"color:rgb(51,51,51)">::</span>string s;
   =20
    Foo(std<span style=3D"color:rgb(51,51,51)">::</span>string <span style=
=3D"color:rgb(0,136,0);font-weight:bold">const</span> <span style=3D"color:=
rgb(51,51,51)">&amp;</span> _s) <span style=3D"color:rgb(51,51,51)">:</span=
> s{_s <span style=3D"color:rgb(51,51,51)">+</span> std<span style=3D"color=
:rgb(51,51,51)">::</span>to_string(counter<span style=3D"color:rgb(51,51,51=
)">++</span>)}=20
    {=20
        std<span style=3D"color:rgb(51,51,51)">::</span>cout <span style=3D=
"color:rgb(51,51,51)">&lt;&lt;</span> <span style=3D"background-color:rgb(2=
55,240,240)">&quot;ctr &quot;</span> <span style=3D"color:rgb(51,51,51)">&l=
t;&lt;</span> s <span style=3D"color:rgb(51,51,51)">&lt;&lt;</span> <span s=
tyle=3D"color:rgb(0,68,221)">&#39;\n&#39;</span>;
    }
    <span style=3D"color:rgb(51,51,51)">~</span>Foo(){std<span style=3D"col=
or:rgb(51,51,51)">::</span>cout <span style=3D"color:rgb(51,51,51)">&lt;&lt=
;</span> <span style=3D"background-color:rgb(255,240,240)">&quot;dtr &quot;=
</span> <span style=3D"color:rgb(51,51,51)">&lt;&lt;</span> s <span style=
=3D"color:rgb(51,51,51)">&lt;&lt;</span> <span style=3D"color:rgb(0,68,221)=
">&#39;\n&#39;</span>;}
};

<span style=3D"color:rgb(51,51,153);font-weight:bold">int</span> Foo<span s=
tyle=3D"color:rgb(51,51,51)">::</span>counter <span style=3D"color:rgb(51,5=
1,51)">=3D</span> <span style=3D"color:rgb(0,0,221);font-weight:bold">0</sp=
an>;

<span style=3D"color:rgb(0,136,0);font-weight:bold">auto</span> <span style=
=3D"color:rgb(0,102,187);font-weight:bold">f0</span>(Foo <span style=3D"col=
or:rgb(0,136,0);font-weight:bold">const</span> <span style=3D"color:rgb(51,=
51,51)">&amp;</span> foo1 <span style=3D"color:rgb(136,136,136)">/*lifetime=
bound*/</span>, Foo <span style=3D"color:rgb(0,136,0);font-weight:bold">con=
st</span> <span style=3D"color:rgb(51,51,51)">&amp;</span> foo2 <span style=
=3D"color:rgb(136,136,136)">/*lifetimebound*/</span>)
{
    <span style=3D"color:rgb(0,136,0);font-weight:bold">return</span> [<spa=
n style=3D"color:rgb(51,51,51)">&amp;</span>](){std<span style=3D"color:rgb=
(51,51,51)">::</span>cout <span style=3D"color:rgb(51,51,51)">&lt;&lt;</spa=
n> foo1.s <span style=3D"color:rgb(51,51,51)">&lt;&lt;</span> <span style=
=3D"color:rgb(0,68,221)">&#39;-&#39;</span> <span style=3D"color:rgb(51,51,=
51)">&lt;&lt;</span> foo2.s <span style=3D"color:rgb(51,51,51)">&lt;&lt;</s=
pan> <span style=3D"color:rgb(0,68,221)">&#39;\n&#39;</span>;};
}

<span style=3D"color:rgb(51,51,153);font-weight:bold">int</span> <span styl=
e=3D"color:rgb(0,102,187);font-weight:bold">main</span>()
{
    <span style=3D"color:rgb(0,136,0);font-weight:bold">using</span> <span =
style=3D"color:rgb(0,136,0);font-weight:bold">namespace</span> std<span sty=
le=3D"color:rgb(51,51,51)">::</span>string_literals;
    <span style=3D"color:rgb(0,136,0);font-weight:bold">auto</span> x <span=
 style=3D"color:rgb(51,51,51)">=3D</span> f0(<span style=3D"background-colo=
r:rgb(255,240,240)">&quot;a&quot;</span>s, <span style=3D"background-color:=
rgb(255,240,240)">&quot;b&quot;</span>s);
    x();
}<br><br>
</pre><pre style=3D"margin:0px;line-height:125%"><font face=3D"arial,helvet=
ica,sans-serif">With or without lifetime extension, the temporaries that fo=
o1 and foo2 are bound to have undefined sequence of construction. This is a=
 <br>problem for temporaries as it currently is, but if we enhance lifetime=
 extension and encourage the use of temporaries then this will <br>possibly=
 be a common pitfall.</font></pre></div></div></blockquote><div><br></div><=
div>I don&#39;t see how this would be any more of a problem in the future t=
han it is now. If `f0` didn&#39;t store those temporaries in the return val=
ue, they would still &quot;have undefined sequence of construction&quot; re=
lative to one another. Yet people write code that constructs multiple tempo=
raries in function parameters <i>all the time</i>. So I fail to see how the=
 possibility of such faults will be significantly raised by lifetime extens=
ion.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/8365b751-0310-4199-8be7-d6222b078aff%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8365b751-0310-4199-8be7-d6222b078aff=
%40isocpp.org</a>.<br />

------=_Part_38185_1761327257.1528173058787--

------=_Part_38184_1693041824.1528173058786--

.
