220 38484 <CANgTfEgedZZj1=3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5X8e1w@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Gareth Lloyd <gareth@ignition-web.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Restricting the valid use of certain methods upon
 temporary objects
Date: Tue, 5 Jun 2018 01:29:38 +0100
Lines: 153
Approved: news@gmane.org
Message-ID: <CANgTfEgedZZj1=3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5X8e1w@mail.gmail.com>
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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="000000000000489c8a056dda257a"
X-Trace: blaine.gmane.org 1528158454 24688 195.159.176.226 (5 Jun 2018 00:27:34 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 5 Jun 2018 00:27:34 +0000 (UTC)
Cc: florian.csdt@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCTJTSELJQIPJMWX3ACRUBG7HCR2Y@isocpp.org Tue Jun 05 02:27:30 2018
Return-path: <std-proposals+bncBCTJTSELJQIPJMWX3ACRUBG7HCR2Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f197.google.com ([209.85.128.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCTJTSELJQIPJMWX3ACRUBG7HCR2Y@isocpp.org>)
	id 1fPzov-0006Km-OA
	for gclcip-std-proposals@m.gmane.org; Tue, 05 Jun 2018 02:27:29 +0200
Original-Received: by mail-wr0-f197.google.com with SMTP id h12-v6sf298024wrq.2
        for <gclcip-std-proposals@m.gmane.org>; Mon, 04 Jun 2018 17:29:41 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1528158581; cv=pass;
        d=google.com; s=arc-20160816;
        b=ccDeO0YJVDxMzPFZwdwgFvv3cF3o+muK1M/Ua/Nm7i/fPgoeqdat/PCQvQ7VviH0ww
         1NzT2T8ouKVAw0Dz7hTSnhTx/2Zn52XA0vGZRdKrHfmubmme2GH9mOYQ3u1o2yxMTyGR
         9N7sp+l1iBDkvlcfTJaKpFVdAmytDc4aXmzGu+9ygge+LtUScG+oaI1VOBtVsxhIu8kX
         4ZKaPrM2pIXnWr0rXyWo3fBO4iCrp3W432oQM8Sl1MkYDzvVoZ3YM8j1jp1NmDQN2Bfp
         92+AYSsxaSu2n52NUd65TWkKtY3lM3+K6JT30mKmPmksAE8tjd9+G5KxmMJlsdpdV+02
         jdIg==
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:cc:to:subject:message-id
         :date:from:references:in-reply-to:sender:mime-version
         :arc-authentication-results:arc-message-signature
         :arc-authentication-results;
        bh=73Faz8mhNzWKLvt63Y8NmWAnyYhRupQ/t5QGzRXrlqM=;
        b=JGfT6Bq2Teu8M6uT63v9FAgVMRIslNXAfgdqZ15VbiorkX2rxCCSONBscw87KAWUJZ
         EF1/6jYtbSebCCGTG8ALKKI4eU1bkfCLQeeG6DEY/KQgJe+EDa7VaEaoK7fWiFUJnu20
         OpOuxQtDntXryr06q+dGaMLv7QnRzv8NwFxuStTOYCsr75RHIlqLimUMUWTF7iUwvswr
         EFT3oLkPk/tl4rlqbilRQ3l4s6suuXUewI2D/frcBk+FkYsQWNq5bekg0qvmvtXccii1
         euqnNtt2ztj6tKu4MqT1ETZGPbkxvyQOIlNTZQCqwntU7QkkMu29ffqv10y4g853sExD
         mVlA==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=TICKrWbS;
       spf=pass (google.com: domain of gareth.andrew.lloyd@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=gareth.andrew.lloyd@gmail.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc: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=73Faz8mhNzWKLvt63Y8NmWAnyYhRupQ/t5QGzRXrlqM=;
        b=pAhuhQZDtWUy4nz8emr+xQstaufWhmPKJopHeVLaVh+013JjSykLviyZjDmMgRzpFC
         +Zyoo08aEBxVLcibg4mQoZB0dR2IRVXA1XC3oApmbWLuKyVPD7x2A2keZe/LoitXoL9s
         5aPXTa76dAgtqEa/HSKWbq5iJAR+cZEMHrxC1FzJeslCg+/NYpBC+Dvo0Dc6pR1dgJ1s
         bCkOPtZmC9aAekgbK7DpE9itpgx5WzL5Kv8Cm4Qh8xVJ+Ucz+tK2DEF2VZwfQmuAE9Dn
         Z0qHKIK+DTwMAhUfF7RZxcbPmovisTj0hNIqcCkPq10ULVtRlPaHfD/uM5kZwhzN7zOj
         T74Q==
X-Gm-Message-State: ALKqPwcAzkY4xfq7EYIpdxPBVdFiDYfuu2O3CwGwQb44sCGmHrdT9Gbs
	wwoiVqzuIPiJX6J0eKQYWCA=
X-Google-Smtp-Source: ADUXVKJ08kpyYi4l7/oNsRAaTlLNEHQu5iNFZvSNnncH/WdNKKI5QKhkF0td8o1K6C5TSerIMiO91w==
X-Received: by 2002:a1c:ec42:: with SMTP id k63-v6mr1807256wmh.29.1528158580926;
        Mon, 04 Jun 2018 17:29:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:adf:e44e:: with SMTP id t14-v6ls15334275wrm.4.gmail; Mon, 04
 Jun 2018 17:29:39 -0700 (PDT)
X-Received: by 2002:adf:f112:: with SMTP id r18-v6mr16961965wro.134.1528158579879;
        Mon, 04 Jun 2018 17:29:39 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1528158579; cv=none;
        d=google.com; s=arc-20160816;
        b=dddiJXNIZSwru3GpXuyT6UpgvraRY0L3m59owTBxbQDHkpuRSDf6aynkwD8swQCRvu
         cnQK7C7iMiyfP3IGrE0clemIsoM/3mbf4Z4k6Zt8sZUthPtuk7FBf+r1IqfVxvDq+43X
         GCo3AsmZtM35BqrmsM3nLIvYgRXlkj/WHXXwjoCV9KH9BHAcvJhi99KL4Z0b5pziaenP
         tyy7HoL4DQND5BcEvjqf/QG+YJU3+sEuuCpFzjwUaIAYsKUf62UNGuRkA/2GfiJj3Wb+
         MTBjRqJNK9j7QpGjoJsSUnkjYtodfjYM3+1X+n1P9DActpFfQEaU++vVqHKwSfu8BMUe
         qEeA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=cc:to:subject:message-id:date:from:references:in-reply-to:sender
         :mime-version:dkim-signature:arc-authentication-results;
        bh=o6ufUbWTTDvuWkSejyIob8WYWSVTtH1gZC/eKd/kYOU=;
        b=PkWyf9XDjGcA6JMnhtVr8hc5cHO52zAqbVBE9y8nVZd/mvIsP+lNt83+8TgVSc5pfx
         CWrJRhvM5Qp1dFuL8qPsAWNpP2JKGamJeF+XR8TyVBpVfi6LERAW8EOvuAPkY9j80hTu
         tP+qEsh0EQuXG57BGxjkNXNhC9tO/Q3P1667XQ3BHG6tIYljLDB50h3nwWn4+Z8EkfIK
         Iqm2jPyWgsJaB25xDtPQiDK6XZzF6BZ/NHUjEhTQM7rTnItXJDpq3nlLy2WlsdTfSEF5
         LBBgYdVOPb38gR81ya2LPuPA4m14OzaAzFYFbdiwF2d0oJHOrOxQljcOOqDAUx6OI2hf
         NefA==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=TICKrWbS;
       spf=pass (google.com: domain of gareth.andrew.lloyd@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=gareth.andrew.lloyd@gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id f4-v6sor63084wmh.82.2018.06.04.17.29.39
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Mon, 04 Jun 2018 17:29:39 -0700 (PDT)
Received-SPF: pass (google.com: domain of gareth.andrew.lloyd@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 2002:a1c:1588:: with SMTP id 130-v6mr4269332wmv.35.1528158579365;
 Mon, 04 Jun 2018 17:29:39 -0700 (PDT)
Original-Sender: gareth.andrew.lloyd@gmail.com
Original-Received: by 2002:adf:8e57:0:0:0:0:0 with HTTP; Mon, 4 Jun 2018 17:29:38 -0700 (PDT)
In-Reply-To: <1ff61a56-191f-49c2-849d-b3bb47b52930@isocpp.org>
X-Original-Sender: gareth@ignition-web.co.uk
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=TICKrWbS;       spf=pass
 (google.com: domain of gareth.andrew.lloyd@gmail.com designates 209.85.220.41
 as permitted sender) smtp.mailfrom=gareth.andrew.lloyd@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:38484
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/38484>

--000000000000489c8a056dda257a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

So after a long walk today I finally have been able to point at what makes
me uneasy about the lifetime extension approach. In short, if we depend
upon more than one lifetimebound object which are temporaries, then as it
currently stands they are unsequenced. Consider the following example:
=E2=80=8B

#include <string>#include <iostream>
struct Foo
{
    static int counter;

    std::string s;

    Foo(std::string const & _s) : s{_s + std::to_string(counter++)}
    {
        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 /*lifetimeboun=
d*/)
{
    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
are bound to have undefined sequence of construction. This is a
problem for temporaries as it currently is, but if we enhance lifetime
extension and encourage the use of temporaries then this will
possibly be a common pitfall.

--=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/CANgTfEgedZZj1%3D3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5=
X8e1w%40mail.gmail.com.

--000000000000489c8a056dda257a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">So after a long walk today I finally have been able to poi=
nt at what makes me uneasy 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>

<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/CANgTfEgedZZj1%3D3ydxBcZf9AMNNZvXG4Nd=
k6zTFxBNUU5X8e1w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANgTfEgedZZj1%=
3D3ydxBcZf9AMNNZvXG4Ndk6zTFxBNUU5X8e1w%40mail.gmail.com</a>.<br />

--000000000000489c8a056dda257a--

.
