220 11020 <b32d8970-dc34-4b74-9613-c6e4dc6c871b@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Thibaut Lutz <thibaut.lutz@googlemail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Protect Lambda functions against reflection
Date: Mon, 2 Jun 2014 07:30:15 -0700 (PDT)
Lines: 167
Approved: news@gmane.org
Message-ID: <b32d8970-dc34-4b74-9613-c6e4dc6c871b@isocpp.org>
References: <108c47a2-d952-4f84-a347-923b2ab742ad@isocpp.org>
 <CAFk2RUaPcXONmVug7-_t+imouCVQv9LQ3Hos-yRo=0X-HBQZKQ@mail.gmail.com>
 <CAB+4KHL3MvqYR3s=grM7t8imKHmnjj8s4PAYO01Z+rtq8sivnw@mail.gmail.com>
 <CAFk2RUasQdm4U+w393wqaD-J_6km+xOHhmd_sRyBx7ESy5Eyjw@mail.gmail.com>
 <CAB+4KH+eoF=PcS1pTg+neNA60bcbyZZXJsUenud4Md5RAk+MKw@mail.gmail.com>
 <CAFk2RUacOGaupA6+4JnYMt9ADv4vLOnXL6Ye4ef6crmOB7p78w@mail.gmail.com>
 <CAB+4KHJa1_OoQ5fevDztHYUJDz=uoW5BgzOAiNX19ArNyQhCvg@mail.gmail.com>
 <CAFk2RUbRbXCCETeD=PC3yCHJSigqiCqaCYM8NUx57tugnw4m7w@mail.gmail.com>
 <CANh-dXm+2BcZr-2mcoK_sjOnPgZoczN29A1ZBxQ5xvnOpnwL0A@mail.gmail.com>
 <CAB+4KHJJG=M7PbGJrconmROoOSJPt3hK7CpnD9BWYeSOrEUTXA@mail.gmail.com>
 <7ef3d3da-0c1d-443c-88d2-656b91937170@isocpp.org>
 <68f98b78-8bd4-48e0-9e1d-47cfc0492764@isocpp.org>
 <CAGg_6+MbbEPCW8mxyDDCZJhrhDKideb_UBvQ42De46w-WRGhjw@mail.gmail.com>
 <af9ceb0c-e51e-446e-8f56-bc58a2144896@isocpp.org>
 <CAGg_6+OHgQvWR3g+K1ShNESOefrmj1BaNQ6F5CXmnyEOiS01Zw@mail.gmail.com>
 <CAArVCkT6xGs7B2ZaUj3WTRuW6TffTt9S8PCDWBekM5jiHzf1fw@mail.gmail.com>
 <c3204801-96d1-4131-af31-609e7103124c@isocpp.org>
 <CAB+4KHJ_RtaEW9qNYFbbmp1gXXYGW5A3D60V18amciid7J91rw@mail.gmail.com>
 <2960c77b-fd52-4052-b50c-c8e2aa829cf7@isocpp.org>
 <1dd683e4-5728-41f2-9a7d-b8d604dbcf8b@isocpp.org>
 <e4d5bd14-5a01-47e9-95a1-413709507097@isocpp.org>
 <1c28d0af-7252-4828-a25a-b34794051883@isocpp.org>
 <d35ff094-23a1-42cc-868a-5ea6ef846697@isocpp.org>
 <ecd313ca-def0-4ace-9969-a2bc156087d6@isocpp.org>
 <10f413fd-5c55-412e-a791-7ae07b94b8ed@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_196_14608244.1401719415169"
X-Trace: ger.gmane.org 1401719425 7713 80.91.229.3 (2 Jun 2014 14:30:25 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 2 Jun 2014 14:30:25 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC66PHON7ACRB6EUWKOAKGQEAF57IZY@isocpp.org Mon Jun 02 16:30:19 2014
Return-path: <std-proposals+bncBC66PHON7ACRB6EUWKOAKGQEAF57IZY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f197.google.com ([209.85.192.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC66PHON7ACRB6EUWKOAKGQEAF57IZY@isocpp.org>)
	id 1WrTFh-00080N-RL
	for gclcip-std-proposals@m.gmane.org; Mon, 02 Jun 2014 16:30:18 +0200
Original-Received: by mail-pd0-f197.google.com with SMTP id y10sf16002633pdj.8
        for <gclcip-std-proposals@m.gmane.org>; Mon, 02 Jun 2014 07:30:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=googlemail.com; s=20120113;
        h=date:from:to: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
         :content-type;
        bh=qv7xqJHnHr48UiMUwIPinazVs4UEek2L+Si8WnW4l28=;
        b=lRmxGpGXXdiuVftUCbRGhhy2c62Bfe1qYkuk8bAORx+fQ5lmvCBovNPwDxEYK3sKln
         ZZhMMHrqxUgSrjIveKOVPrr5KQK0pSBmwZxK7IjrmAO8IE5fAN2KL4zLNmtdYTL3EnS1
         pbRCEbxE4FrhppV+u83TTgVyudEuh5ZI5X9ZpjgINdHvCBIeLD7rPWgd2GzYND64a/YZ
         nhm5qh1+tSRIQ9ZLEyX/4n/RTIW1+4MdXM0a9XiXEWQm6Zu46Q6dM3sIbcM2eV77MUaV
         7HSfSk5OJlWrEYVJPXCtJArBqplLgZ48/99he+IvTWYcaJ+wia7FNrxtsz3/J1QVbR34
         +qfA==
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: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:content-type;
        bh=qv7xqJHnHr48UiMUwIPinazVs4UEek2L+Si8WnW4l28=;
        b=FDrTELNlJoGui/o4HLSlbpOnST5s9mjKNnF0k2qwWIq1glJqo3/ON1odOdjPRkb1tm
         e7CI6DQkCDQXn/RIqUhLEKYs57rgYzag3DMaFiBWrwY+0JQFeCNJN97kwUAz+YceCaji
         yTHVwViCC1nbO/DQU3Ycl2o6sW3iQ2lK1y6z9HKuZNasnfRw04oITHFRjzlvxYXONjb0
         /PWUW4MlHXnJOo5SdjBaWt+r8ndGvxeM3LWm9c/ezBgwgW5PrY2ptKl/iFB7+aZgkjW3
         MW/EDkPrFWDxtG9oL8HvWhpah3F+wDk613FcnEz+nRV/fK1X/tNSWpVujSCZtZFZSXjR
         xgeA==
X-Gm-Message-State: ALoCoQlLBPNb4w/QYsopiwyN2Rm7VA/LNRgSLHShm9+U+bhj7A2EvX8J1TRdQODQfW+YD6w9lcbo
X-Received: by 10.66.222.129 with SMTP id qm1mr14007035pac.6.1401719416782;
        Mon, 02 Jun 2014 07:30:16 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.85.138 with SMTP id n10ls2111127qgd.4.gmail; Mon, 02 Jun
 2014 07:30:16 -0700 (PDT)
X-Received: by 10.140.48.241 with SMTP id o104mr8951qga.38.1401719416067;
        Mon, 02 Jun 2014 07:30:16 -0700 (PDT)
In-Reply-To: <10f413fd-5c55-412e-a791-7ae07b94b8ed@isocpp.org>
X-Original-Sender: thibaut.lutz@googlemail.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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11020
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11020>

------=_Part_196_14608244.1401719415169
Content-Type: text/plain; charset=UTF-8

Thanks for the comments.

- If construction of lambdas is ever allowed through reflection, then it 
> should create a new type of lambda, constructing an existing type should 
> only be possible via copy or move, this avoids the problem you mentioned 
> with references.
>

This is a bit tricky. A Lambda declaration is implicitly a constructor 
call, so the constructor does exist and is accessible. Moreover the type of 
the newly created object might be explicitly the same as the lambda's:

  auto test = [](){return 0;};

  using Lambda = decltype(test);

  Lambda closure = std::reflect<Lambda>::construct();


Also, creating new types on the fly introduces transitive oddities:

  auto test = [](){return 0;};

  auto closure = std::reflect<decltype(test)>::construct();

  static_assert<is_same<decltype(test),decltype(closure)>::value>(); // this fails

  test = closure; // this fails

 

> - Maybe it's worth at least having a function which just returns the types 
> and names of captured variables: this would make it possible for a portable 
> higher level interface to lambdas to be added to the standard library at a 
> later time without any additional compiler support (the standard library 
> can 'know' exactly what the layout of a lambda looks like given a capture 
> list because it can be aware of the inner workings of the compiler).
>

This might be one possibility, but it looks to me like it would be more of 
an extension of the current lambda capabilities rather than a feature of 
reflection. Another possibility would be to enforce that identifiers are 
the same in the capture list and the closure type, instead of being 
unnamed. It would be interesting to know why they decided the members 
should be unnamed in the first place, my guess it they don't want them to 
be accessible, which is something reflection would expose.

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_196_14608244.1401719415169
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thanks for the comments.<div><br><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr">- If construction of lambdas is ever a=
llowed through reflection, then it should create a new type of lambda, cons=
tructing an existing type should only be possible via copy or move, this av=
oids the problem you mentioned with references.<br></div></blockquote><div>=
<br></div><div>This is a bit tricky. A Lambda declaration is implicitly a c=
onstructor call, so the constructor does exist and is accessible. Moreover =
the type of the newly created object might be explicitly the same as the la=
mbda's:</div><div><pre><pre><!--StartFragment--><span style=3D" color:#c0c0=
c0;">  </span><span style=3D" color:#808000;">auto</span><span style=3D" co=
lor:#c0c0c0;"> </span><span style=3D" color:#000000;">test</span><span styl=
e=3D" color:#c0c0c0;"> </span><span style=3D" color:#000000;">=3D</span><sp=
an style=3D" color:#c0c0c0;"> </span><span style=3D" color:#000000;">[](){<=
/span><span style=3D" color:#808000;">return</span><span style=3D" color:#c=
0c0c0;"> </span><span style=3D" color:#000080;">0</span><span style=3D" col=
or:#000000;">;};</span><!--EndFragment--></pre></pre>
<pre><span style=3D" color:#c0c0c0;">  </span><span style=3D" color:#808000=
;">using</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" colo=
r:#800080;">Lambda</span><span style=3D" color:#c0c0c0;"> </span><span styl=
e=3D" color:#000000;">=3D</span><span style=3D" color:#c0c0c0;"> </span><sp=
an style=3D" color:#808000;">decltype</span><span style=3D" color:#000000;"=
>(</span><span style=3D" color:#000000;">test</span><span style=3D" color:#=
000000;">);</span></pre>
<pre><span style=3D" color:#c0c0c0;">  </span><span style=3D" color:#800080=
;">Lambda</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" col=
or:#000000;">closure</span><span style=3D" color:#c0c0c0;"> </span><span st=
yle=3D" color:#000000;">=3D</span><span style=3D" color:#c0c0c0;"> </span>s=
td<span style=3D" color:#000000;">::</span>reflect<span style=3D" color:#00=
0000;">&lt;</span><span style=3D" color:#800080;">Lambda</span><span style=
=3D" color:#000000;">&gt;::</span>construct<span style=3D" color:#000000;">=
(</span><span style=3D" color:#000000;">);</span><!--EndFragment--></pre></=
div><div><br></div><div>Also, creating new types on the fly introduces tran=
sitive oddities:</div><div>
<pre><!--StartFragment--><span style=3D" color:#c0c0c0;">  </span><span sty=
le=3D" color:#808000;">auto</span><span style=3D" color:#c0c0c0;"> </span><=
span style=3D" color:#000000;">test</span><span style=3D" color:#c0c0c0;"> =
</span><span style=3D" color:#000000;">=3D</span><span style=3D" color:#c0c=
0c0;"> </span><span style=3D" color:#000000;">[](){</span><span style=3D" c=
olor:#808000;">return</span><span style=3D" color:#c0c0c0;"> </span><span s=
tyle=3D" color:#000080;">0</span><span style=3D" color:#000000;">;};</span>=
</pre>
<pre><span style=3D" color:#c0c0c0;">  </span><span style=3D" color:#808000=
;">auto</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" color=
:#000000;">closure</span><span style=3D" color:#c0c0c0;"> </span><span styl=
e=3D" color:#000000;">=3D</span><span style=3D" color:#c0c0c0;"> </span>std=
<span style=3D" color:#000000;">::</span>reflect<span style=3D" color:#0000=
00;">&lt;</span><span style=3D" color:#808000;">decltype</span><span style=
=3D" color:#000000;">(</span><span style=3D" color:#000000;">test</span><sp=
an style=3D" color:#000000;">)&gt;::</span>construct<span style=3D" color:#=
000000;">();</span></pre>
<pre><span style=3D" color:#c0c0c0;">  </span><span style=3D" color:#808000=
;">static_assert</span><span style=3D" color:#000000;">&lt;</span>is_same<s=
pan style=3D" color:#000000;">&lt;</span><span style=3D" color:#808000;">de=
cltype</span><span style=3D" color:#000000;">(</span><span style=3D" color:=
#000000;">test</span><span style=3D" color:#000000;">),</span><span style=
=3D" color:#808000;">decltype</span><span style=3D" color:#000000;">(</span=
><span style=3D" color:#000000;">closure</span><span style=3D" color:#00000=
0;">)&gt;::</span>value<span style=3D" color:#000000;">&gt;();</span><span =
style=3D" color:#c0c0c0;"> </span><span style=3D" color:#008000;">//</span>=
<span style=3D" color:#c0c0c0;"> </span><span style=3D" color:#008000;">thi=
s</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" color:#0080=
00;">fails</span></pre><pre><pre><!--StartFragment--><span style=3D" color:=
#000000;">  test</span><span style=3D" color:#c0c0c0;"> </span><span style=
=3D" color:#000000;">=3D</span><span style=3D" color:#c0c0c0;"> </span><spa=
n style=3D" color:#000000;">closure</span><span style=3D" color:#000000;">;=
</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" color:#00800=
0;">//</span><span style=3D" color:#c0c0c0;"> </span><span style=3D" color:=
#008000;">this</span><span style=3D" color:#c0c0c0;"> </span><span style=3D=
" color:#008000;">fails</span><!--EndFragment--></pre></pre></div><div>&nbs=
p;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">- May=
be it's worth at least having a function which just returns the types and n=
ames of captured variables: this would make it possible for a portable high=
er level interface to lambdas to be added to the standard library at a late=
r time without any additional compiler support (the standard library can 'k=
now' exactly what the layout of a lambda looks like given a capture list be=
cause it can be aware of the inner workings of the compiler).<br></div></bl=
ockquote><div><br></div><div>This might be one possibility, but it looks to=
 me like it would be more of an extension of the current lambda capabilitie=
s rather than a feature of reflection. Another possibility would be to enfo=
rce that identifiers are the same in the capture list and the closure type,=
 instead of being unnamed. It would be interesting to know why they decided=
 the members should be unnamed in the first place, my guess it they don't w=
ant them to be accessible, which is something reflection would expose.</div=
></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_196_14608244.1401719415169--

.
