220 29574 <591447c7-38cd-4ad4-83aa-fc1326c1829e@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: "A Proposal to Relax Constexpr Restrictions for
 some Reinterpret Casts" ?
Date: Mon, 28 Nov 2016 18:07:57 -0800 (PST)
Lines: 133
Approved: news@gmane.org
Message-ID: <591447c7-38cd-4ad4-83aa-fc1326c1829e@isocpp.org>
References: <afbaf79e-305d-4408-98ab-5b35cfb11f27@isocpp.org>
 <CALnjya_VWQUMYGGd9tYy_cJWiwvsyUF2joMuCMPsPy=T6e15XA@mail.gmail.com>
 <CAJwqTS9XiyDK+7wWCRTCTjcnFnKQk6WudsrRTidgf4Ygoc0yng@mail.gmail.com>
 <14dc989b-7a2f-478b-b16e-b9297fb1782f@isocpp.org> <CAJwqTS_OGEOUiUE6rSRrREV6Yx9+4Sj5gA8CDHeYgXnPwErW6Q@mail.gmail.com>
 <CAJnLdOaJRPtdnHPX0=L89Pip2GC90aXrEYtJdUYxaHw1vwNJ=w@mail.gmail.com>
 <CAOfiQqk4ce1==kUKZYH3ZLUVKMAG94vpQoYu9Bhh3Mc_zC7=eg@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_13345_1176416860.1480385277639"
X-Trace: blaine.gmane.org 1480385287 16920 195.159.176.226 (29 Nov 2016 02:08:07 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 29 Nov 2016 02:08:07 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB7WF6PAQKGQERJHVLAY@isocpp.org Tue Nov 29 03:08:03 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBB7WF6PAQKGQERJHVLAY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f200.google.com ([209.85.223.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB7WF6PAQKGQERJHVLAY@isocpp.org>)
	id 1cBXpw-0002NL-GW
	for gclcip-std-proposals@m.gmane.org; Tue, 29 Nov 2016 03:08:00 +0100
Original-Received: by mail-io0-f200.google.com with SMTP id r101sf274897692ioi.3
        for <gclcip-std-proposals@m.gmane.org>; Mon, 28 Nov 2016 18:07:59 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=DgCOvif3oc4Bv4oCR3tyQlJIDjaf/uaedUdtTERS8T8=;
        b=SAIoX8XP0k/g7RWpAI1XorwbMnTX6rG2yhEAbaoAFY9ksjusXkcZh3VJmS/u/1ApxF
         voxt0uoIiXdoVucy/XWcyn8FKLkcE4v4ueTcWj5FntrrOTtIyFShkb0tDKp2Hg8nod8v
         F+GIt6CEGag/IKgj+BUMm2o7RhwUEuVMcCIUcyLscGYS/zZDVrBo7i1+/hZr/eMzStg9
         n310phaIC+qmu/wuJWqTNfgn6bE+WJMKDBRzs7QGRlx2C8q6bUQmqqlcMqa+3yOBXVXv
         b0ryChN8A2Vh9Ywj2ggMcTsuV2f1HJRStph5PTAYE2YbF2dsdnFgJ3oR0sWEgXt8YN05
         69LA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.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
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=DgCOvif3oc4Bv4oCR3tyQlJIDjaf/uaedUdtTERS8T8=;
        b=VTaAnH2yQk69hKaPrJJsMXObHPL2ZpWDNqbWio/cRVllfEWoinOhtxcvfVzky8xrB4
         BE1pms7HUPsxVRPRi2JQS+g85MDOT2ZfBTIx1ARJJTnmN2SEyRnjF83AR1VdRHS1UzWA
         mUX1kaz+n7XlAJcLbAlrqiduqmynyPHBr+5zvWJfMaNyQYgmpD/j8vc7Hc0NWUc1utDe
         N9Q2MXXhmsJFIGwEGy1ETVGoPwKDRvtPESOLS971cT4zYTa+aPMM8xBacWnSFHBER2eP
         2gvCn/GVa+vkQmDAK8Zla/61yl3oUyLGA1e1Ssq2mwZEnAzZihiolsdV5JZQWxUFWdSI
         DxVQ==
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:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=DgCOvif3oc4Bv4oCR3tyQlJIDjaf/uaedUdtTERS8T8=;
        b=lSgeLQLizFf5XTMkAWkiNimwuptz1V4N4uGjEULiCVU7CxDQEk14uIO0ZB2a+eyk48
         8uBiI/RJa/yJiQZPTymSkzjpuCId4C9BssuaQGPL/JSnGw2RlSLqClIpe0TtIRxrGf04
         R+Rtq6unFxffeSlHyclMSgdf40AzyenbGr8iX3rHJzXgFplDBhoFvXKZ35vPU5e5Ey//
         fhgoQGQxkb+Q75zmbZCJtlT3vLiUUhWi99RPs4T/Kd0XRIzozOnvYuSSBiVwDswhsgGl
         6OXHe1s2joNdYPBOMWUDtMQiRlDSUuyRtKLsYaAqzqEdd2G0pIKeujK9TG3Kv7Vft2vt
         BR7A==
X-Gm-Message-State: AKaTC02T+Iw3FCysSrk8KjCcxtqFhA6SfVxxSx1Xj4RM91WZykFPSmwfIiJxLaJfLcA0ig==
X-Received: by 10.107.162.69 with SMTP id l66mr4790354ioe.70.1480385278958;
        Mon, 28 Nov 2016 18:07:58 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.3.145 with SMTP id f17ls12304713otf.27.gmail; Mon, 28 Nov
 2016 18:07:58 -0800 (PST)
X-Received: by 10.157.17.3 with SMTP id g3mr781845ote.8.1480385278251;
        Mon, 28 Nov 2016 18:07:58 -0800 (PST)
In-Reply-To: <CAOfiQqk4ce1==kUKZYH3ZLUVKMAG94vpQoYu9Bhh3Mc_zC7=eg@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-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:29574
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29574>

------=_Part_13345_1176416860.1480385277639
Content-Type: multipart/alternative; 
	boundary="----=_Part_13346_2096209644.1480385277640"

------=_Part_13346_2096209644.1480385277640
Content-Type: text/plain; charset=UTF-8



On Monday, November 28, 2016 at 7:01:39 PM UTC-5, Richard Smith wrote:
>
> On 28 November 2016 at 15:00, 'Edward Catmur' via ISO C++ Standard - 
> Future Proposals <std-pr...@isocpp.org <javascript:>> wrote:
>
>> On 28 Nov 2016 22:50, "Peet Nick" <peet...@gmail.com <javascript:>> 
>> wrote:
>> >
>> > Ah, I understand. Although I understand this now, I am not entirely 
>> sure how it will be actually implemented. How would someone implement 
>> bit_cast as a constexpr without having std::memcpy constexpr?
>>
>> They'd have to use a compiler intrinsic; according to [1] llvm already 
>> has a suitable opcode,
>>
> That doesn't help at all. Constant expression evaluation happens at a 
> completely different layer from LLVM.
>
> memcpy is fundamentally not possible to support in general within constant 
> expression evaluation; consider:
>
>   int n;
>   constexpr int *p = &n; // ok
>   constexpr intptr_t q = bit_cast<intptr_t>(p); // ok?
>   static_assert(q > 0x1234567); // ok?!
>
> Clearly this example must be ill-formed. But either that means you can't 
> do the bit_cast in a constant expression or that you can evaluate an 
> integer as part of a constant expression that you then can't do basic 
> integer operations on.
>

This is *precisely* why `bit_cast` is a good thing. Because it's a function 
which knows both the source and destination types, we would be able to say 
that it is `constexpr` when doing certain conversions and not `constexpr` 
when doing others. For example, any conversion of a pointer to anything 
other than a pointer would not be `constexpr`. This would include within 
various types, so you couldn't have a `struct{int *p};` that you `bit_cast` 
to a `struct{intptr_t q};`.

The OP asked specifically about converting integers to their 
bit-representation to do hashing and so forth. `bit_cast` could be 
`constexpr` for such operations.

So there's no problem.

-- 
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/591447c7-38cd-4ad4-83aa-fc1326c1829e%40isocpp.org.

------=_Part_13346_2096209644.1480385277640
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, November 28, 2016 at 7:01:39 PM UTC-5, =
Richard Smith wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote">On 28 November 2016 at 15:00, &#39=
;Edward Catmur&#39; via ISO C++ Standard - Future Proposals <span dir=3D"lt=
r">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"I=
ZKh3UQBBQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#=
39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;=
">std-pr...@isocpp.org</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><span><p dir=3D"ltr"></p>
<p dir=3D"ltr">On 28 Nov 2016 22:50, &quot;Peet Nick&quot; &lt;<a href=3D"j=
avascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"IZKh3UQBBQAJ" rel=3D=
"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" o=
nclick=3D"this.href=3D&#39;javascript:&#39;;return true;">peet...@gmail.com=
</a>&gt; wrote:<br>
&gt;<br>
&gt; Ah, I understand. Although I understand this now, I am not entirely su=
re how it will be actually implemented. How would someone implement bit_cas=
t as a constexpr without having std::memcpy constexpr?</p>
</span><p dir=3D"ltr">They&#39;d have to use a compiler intrinsic; accordin=
g to [1] llvm already has a suitable opcode,</p></blockquote><div>That does=
n&#39;t help at all. Constant expression evaluation happens at a completely=
 different layer from LLVM.</div><div><br></div><div>memcpy is fundamentall=
y not possible to support in general within constant expression evaluation;=
 consider:<br></div><div><br></div><div>=C2=A0 int n;</div><div>=C2=A0 cons=
texpr int *p =3D &amp;n; // ok</div><div>=C2=A0 constexpr intptr_t q =3D bi=
t_cast&lt;intptr_t&gt;(p); // ok?</div><div>=C2=A0 static_assert(q &gt; 0x1=
234567); // ok?!</div><div><br></div></div></div></div></blockquote><div></=
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"><div><div=
 class=3D"gmail_quote"><div></div><div>Clearly this example must be ill-for=
med. But either that means you can&#39;t do the bit_cast in a constant expr=
ession or that you can evaluate an integer as part of a constant expression=
 that you then can&#39;t do basic integer operations on.</div></div></div><=
/div></blockquote><div><br>This is <i>precisely</i> why `bit_cast` is a goo=
d thing. Because it&#39;s a function which knows both the source and destin=
ation types, we would be able to say that it is `constexpr` when doing=20
certain conversions and not `constexpr` when doing others. For example,=20
any conversion of a pointer to anything other than a pointer would not=20
be `constexpr`. This would include within various types, so you couldn&#39;=
t
 have a `struct{int *p};` that you `bit_cast` to a `struct{intptr_t=20
q};`.<br><br>The OP asked specifically about converting integers to=20
their bit-representation to do hashing and so forth. `bit_cast` could be
 `constexpr` for such operations.<br><br>So there&#39;s no problem.<br></di=
v></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/591447c7-38cd-4ad4-83aa-fc1326c1829e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/591447c7-38cd-4ad4-83aa-fc1326c1829e=
%40isocpp.org</a>.<br />

------=_Part_13346_2096209644.1480385277640--

------=_Part_13345_1176416860.1480385277639--

.
