220 31906 <BD003722-5383-491F-8D6C-0B560A4D7B2F@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Alberto Barbati <albertobarbati@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: This variable should not be named: an identifier
 (not) to remember
Date: Thu, 30 Mar 2017 19:31:39 +0200
Lines: 64
Approved: news@gmane.org
Message-ID: <BD003722-5383-491F-8D6C-0B560A4D7B2F@gmail.com>
References: <985b9b2a-c734-45eb-95f4-db4dc0d309a1@isocpp.org> <14211602.1P4LjlnQMh@tjmaciei-mobl1> <CAGsORuBepjjTQxa0w+9Z_v+irrc6QwxqmUv98dTRarUCVHHY+A@mail.gmail.com> <2235919.4GAIbDEcRC@tjmaciei-mobl1> <CAF8PYMgi7mk_fHs=cyYhW4rQad6uDLXrFd7Ef2m7g8Q143p2eg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0 (1.0)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1490895108 12988 195.159.176.226 (30 Mar 2017 17:31:48 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 30 Mar 2017 17:31:48 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCPY5DV6RIMBB74B6XDAKGQEXOLELKI@isocpp.org Thu Mar 30 19:31:43 2017
Return-path: <std-proposals+bncBCPY5DV6RIMBB74B6XDAKGQEXOLELKI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f199.google.com ([209.85.128.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCPY5DV6RIMBB74B6XDAKGQEXOLELKI@isocpp.org>)
	id 1ctdv8-0002JW-H7
	for gclcip-std-proposals@m.gmane.org; Thu, 30 Mar 2017 19:31:38 +0200
Original-Received: by mail-wr0-f199.google.com with SMTP id v44sf11608828wrc.9
        for <gclcip-std-proposals@m.gmane.org>; Thu, 30 Mar 2017 10:31:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:content-transfer-encoding:mime-version:date:subject:message-id
         :references:in-reply-to:to: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=7Ktkd0sLGA0WHdKxZP/lB5Yfrkpu3C1FvjqB8P5O/5Y=;
        b=d6XN9XRXgnKYuWXb/Jah7VMR3FRBMU0BCMYrfXW+pKMnEJseAcdWyLi9dUqEPG5aEp
         lGsDlEP43LxS1yXU5dOdP5ZuTSV3OupaO8H2vFY/gK/sHbv3pI73/guUIBnhvc9IFx4k
         U9w1ekvxok5LYOTmEYKS0ORI5YnJ9tykti74u5DgNY/aeBBRSMi/VT7MCE3aoUzq2vYi
         YLdFHMU3oV4T7NDm8Q9pARRzOlb20qLq7JobdlMPT90yXZis09Psoef8aLbgbnYxhGMA
         /Dwoq2CWcSDKWgllMjHM5GYARsZRmbHvrFSfKsv0ZcQCYjvQExCqALbWOLqg3+K9ulfQ
         CcNw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:content-transfer-encoding:mime-version:date
         :subject:message-id:references:in-reply-to:to: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=7Ktkd0sLGA0WHdKxZP/lB5Yfrkpu3C1FvjqB8P5O/5Y=;
        b=ntqm2/dwJNJiFp2Awi9OphHFO5RT2hyhOK6wDmFbUDV3LkaODGtxk/qnuLVEha3PYX
         G6RrRWBQUeX4YKUiUKJF1to1pjBPQELDaP9VD43LliBXQnrKc4+X7euGUPyvbhMPmXKK
         yaX96005LqlnIGPhqhXjWM4hc1EbYDpaIg1V2r9UMnKEIXiFB/9j750qsi8FrxQfHrWB
         MLZeIJXl7FWDgaR/2CoTPWEoW77XuOULQZDWogONwfRTRm8NlkUDQYA1jWSvewEzYv1r
         cxYL/kll9psl8np67scDzDLZDpNR8+XoPnwFUQbUc8wEx+TbEl9On/Btg+/QGJ0H9KfH
         YUk 
X-Gm-Message-State: AFeK/H1ueO9Iac6vuO5XuKHSPO/OHG++Kav7D/l/1kCdij+hvR9b5xZ7hp9MmLl7BQwlTA==
X-Received: by 10.28.46.20 with SMTP id u20mr279238wmu.14.1490895104664;
        Thu, 30 Mar 2017 10:31:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.0.208 with SMTP id 199ls483178wma.0.gmail; Thu, 30 Mar 2017
 10:31:43 -0700 (PDT)
X-Received: by 10.28.11.130 with SMTP id 124mr1508089wml.3.1490895103390;
        Thu, 30 Mar 2017 10:31:43 -0700 (PDT)
Original-Received: from mail-wr0-x230.google.com (mail-wr0-x230.google.com. [2a00:1450:400c:c0c::230])
        by mx.google.com with ESMTPS id c58si4396299wrc.176.2017.03.30.10.31.43
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 30 Mar 2017 10:31:43 -0700 (PDT)
Received-SPF: pass (google.com: domain of albertobarbati@gmail.com designates 2a00:1450:400c:c0c::230 as permitted sender) client-ip=2a00:1450:400c:c0c::230;
Original-Received: by mail-wr0-x230.google.com with SMTP id w11so69229301wrc.3
        for <std-proposals@isocpp.org>; Thu, 30 Mar 2017 10:31:43 -0700 (PDT)
X-Received: by 10.28.132.130 with SMTP id g124mr4781160wmd.60.1490895102739;
        Thu, 30 Mar 2017 10:31:42 -0700 (PDT)
Original-Received: from [172.20.10.6] ([91.252.253.48])
        by smtp.gmail.com with ESMTPSA id i7sm3985210wmg.30.2017.03.30.10.31.41
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 30 Mar 2017 10:31:41 -0700 (PDT)
In-Reply-To: <CAF8PYMgi7mk_fHs=cyYhW4rQad6uDLXrFd7Ef2m7g8Q143p2eg@mail.gmail.com>
X-Mailer: iPad Mail (14D27)
X-Original-Sender: AlbertoBarbati@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 albertobarbati@gmail.com designates 2a00:1450:400c:c0c::230 as permitted
 sender) smtp.mailfrom=albertobarbati@gmail.com;       dmarc=pass (p=NONE
 sp=NONE dis=NONE) header.from=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: <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:31906
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31906>


> Il giorno 30 mar 2017, alle ore 05:41, Vitali Lovich <vlovich@gmail.com> =
ha scritto:
>=20
> If a function returns a Shared_ptr of a string and string_view that refer=
ences the string, if you do:
>=20
>     auto __ =3D getstr()
>     auto [__, view] =3D getstr()
>=20
> The behavior is observably different between the two cases depending on w=
hether the compiler elides the get(0).  If you elide the get(0) in the seco=
nd example isn't view going to point potentially freed memory?=20

Why would view point to potentially freed memory? Decomposition declaration=
 works like this:

1) initialize a hidden "main" object using the initializer
2) bind "element" names to subobjects of the main objects

The elements are guaranteed not to outlive the main object. Point 2) can be=
 obtained differently according to the type of the main object. In the most=
 general case, get<>() may be invoked. The Standard does not mandate that g=
et<>() function shall have no side effects, but, really, the intent should =
be to get hold of a reference of a subobject of the main object, no signifi=
cant task should be performed.

> It seems like there needs to be a distinction for structured binding betw=
een "don't care about name but keep alive for RAII" vs "don't care about va=
lue at all".

In the case of a decomposition declaration, all RAII logic should performed=
 by the main object itself, since it's guaranteed to be destroyed after the=
 elements. Having an element perform RAII logic is a misuse of the feature.=
 Remember that you are not required to always decompose the object with thi=
s syntax.

> Personally I think the "ignore" semantic is not as interesting - if perfo=
rmance is a concern then you'll have to be slightly more explicit or if it'=
s common enough a separate mechanism can be developed.

I believe it is interesting. However, I understand what you mean. For regul=
ar declarations we definitely want the "keep" semantic, I guess we agree on=
 that. For decomposition declarations we might get either a "keep" or "igno=
re" semantic. In most cases (e.g.: aggregates, arrays and objects whose get=
() functions have no side effect) the result is the same. In the remaining =
corner case, I expect the "ignore" semantic to be more useful, but this is =
a personal opinion. It's a fact, however that if we mandate the "ignore" se=
mantic, the programmer might easily get the "keep" by just providing any id=
entifier different from __. However if we mandate the "keep" semantic, ther=
e's no way to get the other one.

A.

--=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/BD003722-5383-491F-8D6C-0B560A4D7B2F%40gmail.com=
..

.
