220 25467 <105d82bc-e1cf-4795-894c-112cd591c3af@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: isocppgroup@denisbider.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Relocation as a solution for the valueless
 variant problem?
Date: Wed, 6 Apr 2016 09:55:11 -0700 (PDT)
Lines: 200
Approved: news@gmane.org
Message-ID: <105d82bc-e1cf-4795-894c-112cd591c3af@isocpp.org>
References: <b4feb52d-4cd0-475f-9f3d-6694564bc1b0@isocpp.org>
 <4187538d-68fa-4582-ba26-f406479abe67@isocpp.org>
 <eafd831f-85d2-430c-9969-7d084e6d28d2@isocpp.org>
 <CALQmNFggBQSADjEqS7pEzcdPSStGJfXkJdX0d2CwW_TmwqA=yQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2136_539717698.1459961711375"
X-Trace: ger.gmane.org 1459961720 18038 80.91.229.3 (6 Apr 2016 16:55:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 6 Apr 2016 16:55:20 +0000 (UTC)
Cc: isocppgroup@denisbider.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD5LNK7YQYJRB4H6SS4AKGQENVKOE3I@isocpp.org Wed Apr 06 18:55:16 2016
Return-path: <std-proposals+bncBD5LNK7YQYJRB4H6SS4AKGQENVKOE3I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qg0-f71.google.com ([209.85.192.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5LNK7YQYJRB4H6SS4AKGQENVKOE3I@isocpp.org>)
	id 1anqja-0002ZC-PG
	for gclcip-std-proposals@m.gmane.org; Wed, 06 Apr 2016 18:55:15 +0200
Original-Received: by mail-qg0-f71.google.com with SMTP id g33sf24020780qgf.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 06 Apr 2016 09:55:14 -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:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=eYYzSro0ZS+k06X86tIJuHnm9FDnC3VwTyA5LmmX2ZA=;
        b=HC43CTjq15zmjhcw2vOGTjaY16pGFXbD26cPDbC69lwpOcWIQUWMgChjlB3OnRs31g
         SOapaVO6hwo/aplRRKEvKxyioyUHjoUAz4im8z8bt/sc3HiN/1ytzbhlWQz2sX2BE5ko
         Uk7iiIZfApE8901wKF5YeAjWyO4A6lKc/e4bk6y7tcdplho1f+Oq/w81WfD9VK159Pff
         wzz6/ZgP2tNguuJlplsCIJJipKOiHn0RdcRYUAJe/DUeexN7+hSfBmBFzwGdse2GCxUI
         5xDGwxhXxbP/Z4fEsd8wdFY0Lo1YCXO82vc6CqFwKu+T23UD342/IT9YQeof/QVzSQyQ
         JiDQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        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=eYYzSro0ZS+k06X86tIJuHnm9FDnC3VwTyA5LmmX2ZA=;
        b=WRpFiVLae4iE0QM3CHz+feQRg924fqVR1JLNssvFkU9QrqxRAiF7gOcoDSzEImXgSq
         zUn6WZ/pbj/7c2kuxtrUKPoRiHJPSYsA6LW/YnY2CrE+bCyXkwWiKM5fhveVdA2h1R+i
         AGdziK6C7NO741sl5pxfFs7TdjOUKa91jyEFPqnGqp2jKfpJVBtwwuvfexUMJ2IwKOCA
         z86w4YyTVVRKaLv4xfcl/+KmrgbuG4JAO9eZmNtIi/2KFgyUhCrqYUJbKZQ6Jl4Uh/PD
         CqZjG+PzqZC+n8195OfsfaIpzQUB+MwRll0goHQlrD5jE6J4fbv3vO5mpsuYjoffDTSA
         82gQ==
X-Gm-Message-State: AD7BkJLEgyGh74YUZpzeRDOmFtXqIJNpFZr/iY+kWIFxRHXfZkFFmz/k1qGn04ouR4fGxA==
X-Received: by 10.31.154.65 with SMTP id c62mr3585877vke.8.1459961713406;
        Wed, 06 Apr 2016 09:55:13 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.142.142 with SMTP id q136ls511851iod.72.gmail; Wed, 06 Apr
 2016 09:55:12 -0700 (PDT)
X-Received: by 10.50.129.97 with SMTP id nv1mr459679igb.7.1459961712345;
        Wed, 06 Apr 2016 09:55:12 -0700 (PDT)
In-Reply-To: <CALQmNFggBQSADjEqS7pEzcdPSStGJfXkJdX0d2CwW_TmwqA=yQ@mail.gmail.com>
X-Original-Sender: isocppgroup@denisbider.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:25467
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/25467>

------=_Part_2136_539717698.1459961711375
Content-Type: multipart/alternative; 
	boundary="----=_Part_2137_128809297.1459961711375"

------=_Part_2137_128809297.1459961711375
Content-Type: text/plain; charset=UTF-8



> The committee can mandate that standard library types all have
> relocators added where necessary but it can do no such thing for
> user types. However, the committee _does_ want to allow variant
> to be used with those same problematic user types. 

With respect to variant, it is already a major advantage of relocation that 
it can support:

- exception-safe use of variant with non-nullable standard library types - 
without requiring an existing std::list implementation to be thrown away so 
it can be nothrow_move_constructible;

- exception-safe use of variant with future non-nullable types.

Existing problematic non-library types can of course still be supported, if 
we're willing to lose the strong exception safety guarantee in that case. 
I'm not sure there is a silver bullet that can avoid that.


> With your proposal, it's way too easy to accidentally leave
> some object in an undefined state

I find this logic highly questionable. By this line of reasoning, we should 
remove placement new, C-style casts, and manual memory management, so that 
C++ might become a managed language.

C++ involves low-level tools that have to be used correctly. Relocation is 
one. It is safer than current practice, which is to memcpy objects, which 
invokes undefined behavior and is horrible for static analysis. Relocation 
allows objects to be moved, while allowing static analysis tools to reason 
about the program.


The general advantage of relocation is that it supports future use of 
non-nullable types in C++ at all. If relocation is not implemented, 
non-nullable types will remain fundamentally incompatible with C++ move 
semantics, and will have to go the way of the Dodo.

Forcing all objects to have null states creates another instance of what 
has been called the Billion-Dollar Mistake:

http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare

Except for some reason, we are now doing this with object states.


On Wednesday, April 6, 2016 at 10:07:11 AM UTC-6, Sean Middleditch wrote:
On Wed, Apr 6, 2016 at 8:48 AM,  <eloan...@gmail.com> wrote: 
> Types with throwing move constructors are prime candidates to have a 
> relocator, because it solves a problem specific to them. A relocator can 
be 
> implemented trivially, without changing the design of a non-nullable type 
> like the particular std::list implementation. It would not require 
changing 
> the fundamental design of the type, which implementing a noexcept move 
> constructor would require. 
> 
> For user types, relocators would be implicitly defined by the compiler, 
> under much the same terms as a move constructor. 
> 
> I'm not seeing a plausible usage case where you would want a type to have 
a 
> throwing move constructor, and not implement a relocator. It seems 
plausible 
> this combination could be unsupported. 

Much existing code simply wouldn't support relocation properly until 
someone went in and wrote the relocator functions. You can't generate 
correct relocations for all types, e.g. those with non-trivial move 
constructors that do who-knows-what. Those existing types would become 
incompatible with variants were variant to rely on relocation. That 
level of requirements has so far been a show stopper for suggestions 
to "fix" variant. 

The committee can mandate that standard library types all have 
relocators added where necessary but it can do no such thing for user 
types. However, the committee _does_ want to allow variant to be used 
with those same problematic user types. 


I personally find this relocation proposal currently incomplete and in 
need of a lot more iteration. With your proposal, it's way too easy to 
accidentally leave some object in an undefined state where the 
compiler has no idea and is stuck calling the destructor anyway. All 
it takes is passing an object via pointer to some function and *bam* 
insta-pain, as the caller has no way to know what the function will do 
and the function has no way to know what the caller wanted to allow, 
other than comments and documentation (no compiler support for error 
checking). Standardizable relocation support in C++ is likely to 
require more work on value categories and probably some kind of new 
reference or wrapper type (one that cannot be very easily and 
accidentally bound to sub-objects or glvalues). 

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/105d82bc-e1cf-4795-894c-112cd591c3af%40isocpp.org.

------=_Part_2137_128809297.1459961711375
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><p>&gt; The committee can mandate that standard library ty=
pes all have<br>&gt; relocators added where necessary but it can do no such=
 thing for<br>&gt; user types. However, the committee _does_ want to allow =
variant<br>&gt; to be used with those same problematic user types. </p><div=
><br></div><div>With respect to variant, it is already a major advantage of=
 relocation that it can support:</div><div><br></div><div>- exception-safe =
use of variant with non-nullable standard library types - without requiring=
 an existing std::list implementation to be thrown away so it can be nothro=
w_move_constructible;</div><p>- exception-safe use of variant with future n=
on-nullable types.</p><div><br></div><div>Existing problematic non-library =
types can of course still be supported, if we&#39;re willing to lose the st=
rong exception safety guarantee in that case. I&#39;m not sure there is a s=
ilver bullet that can avoid that.</div><div><br></div><div><br></div><div>&=
gt; With your proposal, it&#39;s way too easy to accidentally leave<br>&gt;=
 some object in an undefined state</div><div><br></div><div>I find this log=
ic highly questionable. By this line of reasoning, we should remove placeme=
nt new, C-style casts, and manual memory management, so that C++ might beco=
me a managed language.</div><div><br></div><div>C++ involves low-level tool=
s that have to be used correctly. Relocation is one.=C2=A0It is safer than =
current practice, which is to memcpy objects, which invokes undefined behav=
ior and is horrible for static analysis. Relocation allows objects to be mo=
ved, while allowing static analysis tools to reason about the program.</div=
><div><br></div><div><br>The general=C2=A0advantage of relocation is that i=
t supports future use of non-nullable types in C++ at all. If relocation is=
 not implemented, non-nullable types will remain fundamentally incompatible=
 with C++ move semantics, and will have to go the way of the Dodo.</div><di=
v><br></div><div>Forcing all objects to have null states creates another in=
stance of what has been called the Billion-Dollar Mistake:</div><div><br></=
div><div><a href=3D"http://www.infoq.com/presentations/Null-References-The-=
Billion-Dollar-Mistake-Tony-Hoare">http://www.infoq.com/presentations/Null-=
References-The-Billion-Dollar-Mistake-Tony-Hoare</a></div><div><br></div><d=
iv>Except for some reason, we are now doing this with object states.</div><=
div><br></div><div><br>On Wednesday, April 6, 2016 at 10:07:11 AM UTC-6, Se=
an Middleditch wrote:<br>On Wed, Apr 6, 2016 at 8:48 AM,=C2=A0 &lt;<a href=
=3D"mailto:eloan...@gmail.com">eloan...@gmail.com</a>&gt; wrote: <br>&gt; T=
ypes with throwing move constructors are prime candidates to have a <br>&gt=
; relocator, because it solves a problem specific to them. A relocator can =
be <br>&gt; implemented trivially, without changing the design of a non-nul=
lable type <br>&gt; like the particular std::list implementation. It would =
not require changing <br>&gt; the fundamental design of the type, which imp=
lementing a noexcept move <br>&gt; constructor would require. <br>&gt; <br>=
&gt; For user types, relocators would be implicitly defined by the compiler=
, <br>&gt; under much the same terms as a move constructor. <br>&gt; <br>&g=
t; I&#39;m not seeing a plausible usage case where you would want a type to=
 have a <br>&gt; throwing move constructor, and not implement a relocator. =
It seems plausible <br>&gt; this combination could be unsupported. </div><p=
>Much existing code simply wouldn&#39;t support relocation properly until <=
br>someone went in and wrote the relocator functions. You can&#39;t generat=
e <br>correct relocations for all types, e.g. those with non-trivial move <=
br>constructors that do who-knows-what. Those existing types would become <=
br>incompatible with variants were variant to rely on relocation. That <br>=
level of requirements has so far been a show stopper for suggestions <br>to=
 &quot;fix&quot; variant. </p><p>The committee can mandate that standard li=
brary types all have <br>relocators added where necessary but it can do no =
such thing for user <br>types. However, the committee _does_ want to allow =
variant to be used <br>with those same problematic user types. </p><p><br>I=
 personally find this relocation proposal currently incomplete and in <br>n=
eed of a lot more iteration. With your proposal, it&#39;s way too easy to <=
br>accidentally leave some object in an undefined state where the <br>compi=
ler has no idea and is stuck calling the destructor anyway. All <br>it take=
s is passing an object via pointer to some function and *bam* <br>insta-pai=
n, as the caller has no way to know what the function will do <br>and the f=
unction has no way to know what the caller wanted to allow, <br>other than =
comments and documentation (no compiler support for error <br>checking). St=
andardizable relocation support in C++ is likely to <br>require more work o=
n value categories and probably some kind of new <br>reference or wrapper t=
ype (one that cannot be very easily and <br>accidentally bound to sub-objec=
ts or glvalues). <br></p></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/105d82bc-e1cf-4795-894c-112cd591c3af%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/105d82bc-e1cf-4795-894c-112cd591c3af=
%40isocpp.org</a>.<br />

------=_Part_2137_128809297.1459961711375--
------=_Part_2136_539717698.1459961711375--

.
