Topic: Proposal: After the lifetime of an object data
Author: Nicolas Lesser <blitzrakete@gmail.com>
Date: Tue, 17 Apr 2018 12:55:23 +0000
Raw View
--000000000000ab701d056a0ada21
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tue, Apr 17, 2018, 1:47 PM <christopher.hite.work@gmail.com> wrote:
> Godbolt to compile code
> <https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,sou=
rce:'%23include+%3Cexperimental/optional%3E%0A%0A%23if+0%0Ausing+O+%3D+std:=
:experimental::optional%3Cint%3E%3B%0A%23else%0A%0Astruct+O+%7B%0A++++bool+=
inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++~O()+%7B%0A++++++++if(init=
ed)%0A++++++++++++inited+%3D+false%3B%0A++++%7D%0A%7D%3B%0A%0A%23endif%0A%0=
Avoid+destruct_optional_int(O%26+o)+%7B%0A++++o.~O()%3B++//+should+be+noop+=
%3F!!%0A%7D%0A%0Avoid+more_optional_int()+%7B%0A++++O+o%3B+++//+address+doe=
s+not+leak%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.3333333=
33333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang600,=
filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execu=
te:'1',intel:'0',trim:'0'),lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B1z+=
-O3',source:1),l:'5',n:'0',o:'x86-64+clang+6.0.0+(Editor+%231,+Compiler+%23=
1)+C%2B%2B',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((=
h:output,i:(compiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+with+x86-64+c=
lang+6.0.0',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',=
n:'0',o:'',t:'0')),version:4>
> .
> #include <experimental/optional>
>
> struct O {
> bool inited =3D false;
> int value;
>
> ~O() {
> if(inited)
> inited =3D false;
> }
> };
>
> void destruct_optional_int(O& o) {
> o.~O(); // should be noop ?!
> }
>
> void more_optional_int() {
> O o; // address does not leak
> }
>
> A few years ago I noticed boost::optional<int> deconstructing with a
> branch. One could argue such containers should be coded to have trivial
> construction. It seems the container std::optional that ships with gcc a=
nd
> clang have fixed the issue.
>
> I always thought there was room in the language spec to help
> optimization. I'd like to propose something like this:
>
> *After the lifetime of an object has ended data within its layout has
> undefined value.*
>
>
But this is already the case. See [basic.life]p1.3 that says that the
lifetime of an (class) object ends when the destructor is called and
[basic.life]p6.2 which says that non-static member access after the
lifetime of the object has ended is undefined behavior.
>
>
> Often the compiler can figure out that operations on such an object's
> memory are undefined anyway, if the object existed on the stack or a dele=
te
> expression releases it to the heap. However in cases where the memory is
> from a pool or container are or the address leaks out of compilation scop=
e,
> it may not be able to prove this.
>
That's why it's UB.
>
> Note that the implementation can optimize further. Once it is known the
> memory of an object is undefined at a certain point, any previous stores =
to
> that memory may be elided as long as they can be shown to have no side
> effects up until that point.
>
True.
>
> It looks like gcc is assuming this is in the standard already. Clang and
> ICC do not. Does anyone know if gcc is right?
>
Yes. gcc just has another definition of UB in this case, or rather, it can
prove that the object was destructed, while clang and icc cannot. This is a
QoI issue, not a standard's one.
--=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/CALmDwq0o%2B%2Bxdnu%3DGSbNfr5MajrvC%2BfuncdpH%3D=
ksQWBCzM%3DC6%3Dg%40mail.gmail.com.
--000000000000ab701d056a0ada21
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, =
Apr 17, 2018, 1:47 PM <<a href=3D"mailto:christopher.hite.work@gmail.co=
m" target=3D"_blank" rel=3D"noreferrer">christopher.hite.work@gmail.com</a>=
> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><a hre=
f=3D"https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,s=
ource:'%23include+%3Cexperimental/optional%3E%0A%0A%23if+0%0Ausing+O+%3=
D+std::experimental::optional%3Cint%3E%3B%0A%23else%0A%0Astruct+O+%7B%0A+++=
+bool+inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++~O()+%7B%0A++++++++i=
f(inited)%0A++++++++++++inited+%3D+false%3B%0A++++%7D%0A%7D%3B%0A%0A%23endi=
f%0A%0Avoid+destruct_optional_int(O%26+o)+%7B%0A++++o.~O()%3B++//+should+be=
+noop+%3F!!%0A%7D%0A%0Avoid+more_optional_int()+%7B%0A++++O+o%3B+++//+addre=
ss+does+not+leak%0A%7D'),l:'5',n:'0',o:'C%2B%2B+sou=
rce+%231',t:'0')),k:33.333333333333336,l:'4',n:'0&#=
39;,o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang600,f=
ilters:(b:'0',binary:'1',commentOnly:'0',demangle:&=
#39;0',directives:'0',execute:'1',intel:'0',tri=
m:'0'),lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B1z+-O3'=
,source:1),l:'5',n:'0',o:'x86-64+clang+6.0.0+(Editor+%2=
31,+Compiler+%231)+C%2B%2B',t:'0')),k:33.333333333333336,l:'=
;4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(com=
piler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+=
with+x86-64+clang+6.0.0',t:'0')),k:33.33333333333333,l:'4&#=
39;,n:'0',o:'',s:0,t:'0')),l:'2',n:'0&#=
39;,o:'',t:'0')),version:4" rel=3D"noreferrer noreferrer" t=
arget=3D"_blank">Godbolt to compile code</a>.=C2=A0=C2=A0<div><div class=3D=
"m_-4276847239778310674m_-7471231613853773024prettyprint" style=3D"backgrou=
nd-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;=
border-width:1px;word-wrap:break-word"><code class=3D"m_-427684723977831067=
4m_-7471231613853773024prettyprint"><div class=3D"m_-4276847239778310674m_-=
7471231613853773024subprettyprint"><div><div><span style=3D"color:#0000ff">=
<span style=3D"color:#800" class=3D"m_-4276847239778310674m_-74712316138537=
73024styled-by-prettify">#include</span></span><span style=3D"color:#000" c=
lass=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify"> </=
span><span style=3D"color:#660" class=3D"m_-4276847239778310674m_-747123161=
3853773024styled-by-prettify"><</span><span style=3D"color:#000" class=
=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">experim=
ental</span><span style=3D"color:#660" class=3D"m_-4276847239778310674m_-74=
71231613853773024styled-by-prettify">/</span><span style=3D"color:#000" cla=
ss=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">optio=
nal</span><span style=3D"color:#660" class=3D"m_-4276847239778310674m_-7471=
231613853773024styled-by-prettify">></span></div><span style=3D"color:#0=
00" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify=
"><br></span><div><span style=3D"color:#0000ff"><span style=3D"color:#008" =
class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">st=
ruct</span></span><span style=3D"color:#000" class=3D"m_-427684723977831067=
4m_-7471231613853773024styled-by-prettify"> O </span><span style=3D"color:#=
660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettif=
y">{</span></div><div><span style=3D"color:#000" class=3D"m_-42768472397783=
10674m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0</span><span s=
tyle=3D"color:#0000ff"><span style=3D"color:#008" class=3D"m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify">bool</span></span><span sty=
le=3D"color:#000" class=3D"m_-4276847239778310674m_-7471231613853773024styl=
ed-by-prettify"> inited </span><span style=3D"color:#660" class=3D"m_-42768=
47239778310674m_-7471231613853773024styled-by-prettify">=3D</span><span sty=
le=3D"color:#000" class=3D"m_-4276847239778310674m_-7471231613853773024styl=
ed-by-prettify"> </span><span style=3D"color:#0000ff"><span style=3D"color:=
#008" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-pretti=
fy">false</span></span><span style=3D"color:#660" class=3D"m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify">;</span></div><div><span st=
yle=3D"color:#000" class=3D"m_-4276847239778310674m_-7471231613853773024sty=
led-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color:#0000ff"><span s=
tyle=3D"color:#008" class=3D"m_-4276847239778310674m_-7471231613853773024st=
yled-by-prettify">int</span></span><span style=3D"color:#000" class=3D"m_-4=
276847239778310674m_-7471231613853773024styled-by-prettify"> =C2=A0value</s=
pan><span style=3D"color:#660" class=3D"m_-4276847239778310674m_-7471231613=
853773024styled-by-prettify">;</span></div><span style=3D"color:#000" class=
=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify"><br></s=
pan><div><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-74712=
31613853773024styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color=
:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prett=
ify">~</span><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-7=
471231613853773024styled-by-prettify">O</span><span style=3D"color:#660" cl=
ass=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">()</=
span><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-747123161=
3853773024styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m=
_-4276847239778310674m_-7471231613853773024styled-by-prettify">{</span></di=
v><div><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-7471231=
613853773024styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span st=
yle=3D"color:#0000ff"><span style=3D"color:#008" class=3D"m_-42768472397783=
10674m_-7471231613853773024styled-by-prettify">if</span></span><span style=
=3D"color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled=
-by-prettify">(</span><span style=3D"color:#000" class=3D"m_-42768472397783=
10674m_-7471231613853773024styled-by-prettify">inited</span><span style=3D"=
color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-=
prettify">)</span></div><div><span style=3D"color:#000" class=3D"m_-4276847=
239778310674m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0inited </span><span style=3D"color:#660" class=3D"m_-4=
276847239778310674m_-7471231613853773024styled-by-prettify">=3D</span><span=
style=3D"color:#000" class=3D"m_-4276847239778310674m_-7471231613853773024=
styled-by-prettify"> </span><span style=3D"color:#0000ff"><span style=3D"co=
lor:#008" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-pr=
ettify">false</span></span><span style=3D"color:#660" class=3D"m_-427684723=
9778310674m_-7471231613853773024styled-by-prettify">;</span></div><div><spa=
n style=3D"color:#000" class=3D"m_-4276847239778310674m_-747123161385377302=
4styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color:#660" class=
=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">}</span=
></div><div><span style=3D"color:#660" class=3D"m_-4276847239778310674m_-74=
71231613853773024styled-by-prettify">};</span></div><span style=3D"color:#0=
00" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify=
"><br></span><div><span style=3D"color:#0000ff"><span style=3D"color:#008" =
class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">vo=
id</span></span><span style=3D"color:#000" class=3D"m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify"> destruct_optional_int</span><span=
style=3D"color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024=
styled-by-prettify">(</span><span style=3D"color:#000" class=3D"m_-42768472=
39778310674m_-7471231613853773024styled-by-prettify">O</span><span style=3D=
"color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by=
-prettify">&</span><span style=3D"color:#000" class=3D"m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify"> o</span><span style=3D"col=
or:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-pre=
ttify">)</span><span style=3D"color:#000" class=3D"m_-4276847239778310674m_=
-7471231613853773024styled-by-prettify"> </span><span style=3D"color:#660" =
class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">{<=
/span></div><div><span style=3D"color:#000" class=3D"m_-4276847239778310674=
m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0o</span><span style=
=3D"color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled=
-by-prettify">.~</span><span style=3D"color:#000" class=3D"m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify">O</span><span style=3D"colo=
r:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-pret=
tify">();</span><span style=3D"color:#000" class=3D"m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify"> </span><span style=3D"color:#0080=
00"><span style=3D"color:#800" class=3D"m_-4276847239778310674m_-7471231613=
853773024styled-by-prettify">// should be noop ?!</span></span></div><div><=
span style=3D"color:#800" class=3D"m_-4276847239778310674m_-747123161385377=
3024styled-by-prettify">}</span></div><span style=3D"color:#000" class=3D"m=
_-4276847239778310674m_-7471231613853773024styled-by-prettify"><br></span><=
div><span style=3D"color:#0000ff"><span style=3D"color:#008" class=3D"m_-42=
76847239778310674m_-7471231613853773024styled-by-prettify">void</span></spa=
n><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-747123161385=
3773024styled-by-prettify"> more_optional_int</span><span style=3D"color:#6=
60" class=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify=
">()</span><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-747=
1231613853773024styled-by-prettify"> </span><span style=3D"color:#660" clas=
s=3D"m_-4276847239778310674m_-7471231613853773024styled-by-prettify">{</spa=
n></div><div><span style=3D"color:#000" class=3D"m_-4276847239778310674m_-7=
471231613853773024styled-by-prettify"> =C2=A0 =C2=A0O o</span><span style=
=3D"color:#660" class=3D"m_-4276847239778310674m_-7471231613853773024styled=
-by-prettify">;</span><span style=3D"color:#000" class=3D"m_-42768472397783=
10674m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0</span><span s=
tyle=3D"color:#008000"><span style=3D"color:#800" class=3D"m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify">// address does not leak</s=
pan></span></div><div><span style=3D"color:#800" class=3D"m_-42768472397783=
10674m_-7471231613853773024styled-by-prettify">}</span></div></div></div></=
code></div><br><div>A few years ago I noticed boost::optional<int> de=
constructing with a branch.=C2=A0 One could argue such containers should be=
coded to have trivial construction.=C2=A0 It seems the container std::opti=
onal that ships with gcc and clang have fixed the issue.<br></div><div><div=
><br></div><div>I always thought there was room in the language spec to hel=
p optimization.=C2=A0 I'd like to propose something like this:</div><di=
v><br></div><div><blockquote style=3D"margin:0 0 0 40px;border:none;padding=
:0px"><div><b>After the lifetime of an object has ended data within its lay=
out has undefined value.</b></div></blockquote></div></div></div></div></bl=
ockquote></div></div><div dir=3D"auto"><br></div><div dir=3D"auto">But this=
is already the case. See [basic.life]p1.3 that says that the lifetime of a=
n (class) object ends when the destructor is called and [basic.life]p6.2 wh=
ich says that non-static member access after the lifetime of the object has=
ended is undefined behavior.</div><div dir=3D"auto"><div class=3D"gmail_qu=
ote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><blockq=
uote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div><br></div></b=
lockquote></div><div><br></div><div>Often the compiler can figure out that =
operations on such an object's memory are undefined anyway, if the obje=
ct existed on the stack or a delete expression releases it to the heap.=C2=
=A0 However in cases where the memory is from a pool or container are or th=
e address leaks out of compilation scope, it may not be able to prove this.=
</div></div></div></div></blockquote></div></div><div dir=3D"auto">That'=
;s why it's UB.</div><div dir=3D"auto"><div class=3D"gmail_quote"><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><br></div><div>No=
te that the implementation can optimize further.=C2=A0 Once it is known the=
memory of an object is undefined at a certain point, any previous stores t=
o that memory may be elided as long as they can be shown to have no side ef=
fects up until that point.</div></div></div></div></blockquote></div></div>=
<div dir=3D"auto">True.</div><div dir=3D"auto"><div class=3D"gmail_quote"><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
#ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><br></div><di=
v>It looks like gcc is assuming this is in the standard already.=C2=A0 Clan=
g and ICC do not.=C2=A0 Does anyone know if gcc is right?<br></div></div></=
div></div></blockquote></div></div><div dir=3D"auto">Yes. gcc just has anot=
her definition of UB in this case, or rather, it can prove that the object =
was destructed, while clang and icc cannot. This is a QoI issue, not a stan=
dard's one.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CALmDwq0o%2B%2Bxdnu%3DGSbNfr5MajrvC%2=
BfuncdpH%3DksQWBCzM%3DC6%3Dg%40mail.gmail.com?utm_medium=3Demail&utm_source=
=3Dfooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAL=
mDwq0o%2B%2Bxdnu%3DGSbNfr5MajrvC%2BfuncdpH%3DksQWBCzM%3DC6%3Dg%40mail.gmail=
..com</a>.<br />
--000000000000ab701d056a0ada21--
.
Author: Hyman Rosen <hyman.rosen@gmail.com>
Date: Tue, 17 Apr 2018 09:28:58 -0400
Raw View
--001a1142de805b1394056a0b53de
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tue, Apr 17, 2018 at 8:55 AM, Nicolas Lesser <blitzrakete@gmail.com>
wrote:
> On Tue, Apr 17, 2018, 1:47 PM <christopher.hite.work@gmail.com> wrote:
>
>> Godbolt to compile code
>> <https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,so=
urce:'%23include+%3Cexperimental/optional%3E%0A%0A%23if+0%0Ausing+O+%3D+std=
::experimental::optional%3Cint%3E%3B%0A%23else%0A%0Astruct+O+%7B%0A++++bool=
+inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++~O()+%7B%0A++++++++if(ini=
ted)%0A++++++++++++inited+%3D+false%3B%0A++++%7D%0A%7D%3B%0A%0A%23endif%0A%=
0Avoid+destruct_optional_int(O%26+o)+%7B%0A++++o.~O()%3B++//+should+be+noop=
+%3F!!%0A%7D%0A%0Avoid+more_optional_int()+%7B%0A++++O+o%3B+++//+address+do=
es+not+leak%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.333333=
333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang600=
,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',exec=
ute:'1',intel:'0',trim:'0'),lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B1z=
+-O3',source:1),l:'5',n:'0',o:'x86-64+clang+6.0.0+(Editor+%231,+Compiler+%2=
31)+C%2B%2B',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!(=
(h:output,i:(compiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+with+x86-64+=
clang+6.0.0',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2'=
,n:'0',o:'',t:'0')),version:4>
>> .
>> #include <experimental/optional>
>>
>> struct O {
>> bool inited =3D false;
>> int value;
>>
>> ~O() {
>> if(inited)
>> inited =3D false;
>> }
>> };
>>
>> void destruct_optional_int(O& o) {
>> o.~O(); // should be noop ?!
>> }
>>
>> void more_optional_int() {
>> O o; // address does not leak
>> }
>>
>> A few years ago I noticed boost::optional<int> deconstructing with a
>> branch. One could argue such containers should be coded to have trivial
>> construction. It seems the container std::optional that ships with gcc =
and
>> clang have fixed the issue.
>>
>> I always thought there was room in the language spec to help
>> optimization. I'd like to propose something like this:
>>
>> *After the lifetime of an object has ended data within its layout has
>> undefined value.*
>>
>>
> But this is already the case. See [basic.life]p1.3 that says that the
> lifetime of an (class) object ends when the destructor is called and
> [basic.life]p6.2 which says that non-static member access after the
> lifetime of the object has ended is undefined behavior.
>
>>
>>
>> Often the compiler can figure out that operations on such an object's
>> memory are undefined anyway, if the object existed on the stack or a del=
ete
>> expression releases it to the heap. However in cases where the memory i=
s
>> from a pool or container are or the address leaks out of compilation sco=
pe,
>> it may not be able to prove this.
>>
> That's why it's UB.
>
>>
>> Note that the implementation can optimize further. Once it is known the
>> memory of an object is undefined at a certain point, any previous stores=
to
>> that memory may be elided as long as they can be shown to have no side
>> effects up until that point.
>>
> True.
>
>>
>> It looks like gcc is assuming this is in the standard already. Clang an=
d
>> ICC do not. Does anyone know if gcc is right?
>>
> Yes. gcc just has another definition of UB in this case, or rather, it ca=
n
> prove that the object was destructed, while clang and icc cannot. This is=
a
> QoI issue, not a standard's one.
>
The fundamental question is whether the side effect of modifying an object
must
also modify the storage of the object. If the compiler elides the
assignment in
destruct_optional_int, the following code will fail:
alignas(O) unsigned char buf1[sizeof(O)], buf2[sizeof(O)];
O *o =3D new(buf1) O;
o->inited =3D true;
o->value =3D 0;
memcpy(buf2, buf1, sizeof(O));
destruct_optional_int(*o);
assert(memcmp(buf1, buf2, sizeof(O)) !=3D 0);
This explains the compiled code. The destruct_optional_int function canno=
t
know
the underlying storage of its parameter, so it must do the side effect.
The more_optional_int function does know that the underlying storage is not
used
after the destructor, so the side effect can be elided.
--=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/CAHSYqdZJ%2ByR5-mc_AOJ7_hHimQw0baN5dv%2BYw0Gdb%2=
BY2KS%2BGXA%40mail.gmail.com.
--001a1142de805b1394056a0b53de
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Apr 17, 2018 at 8:55 AM, Nicolas Lesser <span dir=3D"ltr"><<a href=
=3D"mailto:blitzrakete@gmail.com" target=3D"_blank">blitzrakete@gmail.com</=
a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><s=
pan class=3D""><div><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Apr=
17, 2018, 1:47 PM <<a href=3D"mailto:christopher.hite.work@gmail.com" =
rel=3D"noreferrer" target=3D"_blank">christopher.hite.work@gmail.<wbr>com</=
a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><a h=
ref=3D"https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B=
,source:'%23include+%3Cexperimental/optional%3E%0A%0A%23if+0%0Ausing+O+=
%3D+std::experimental::optional%3Cint%3E%3B%0A%23else%0A%0Astruct+O+%7B%0A+=
+++bool+inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++~O()+%7B%0A+++++++=
+if(inited)%0A++++++++++++inited+%3D+false%3B%0A++++%7D%0A%7D%3B%0A%0A%23en=
dif%0A%0Avoid+destruct_optional_int(O%26+o)+%7B%0A++++o.~O()%3B++//+should+=
be+noop+%3F!!%0A%7D%0A%0Avoid+more_optional_int()+%7B%0A++++O+o%3B+++//+add=
ress+does+not+leak%0A%7D'),l:'5',n:'0',o:'C%2B%2B+s=
ource+%231',t:'0')),k:33.333333333333336,l:'4',n:'0=
',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang600=
,filters:(b:'0',binary:'1',commentOnly:'0',demangle=
:'0',directives:'0',execute:'1',intel:'0',t=
rim:'0'),lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B1z+-O3=
9;,source:1),l:'5',n:'0',o:'x86-64+clang+6.0.0+(Editor+=
%231,+Compiler+%231)+C%2B%2B',t:'0')),k:33.333333333333336,l:&#=
39;4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(c=
ompiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%23=
1+with+x86-64+clang+6.0.0',t:'0')),k:33.33333333333333,l:'4=
',n:'0',o:'',s:0,t:'0')),l:'2',n:'0=
',o:'',t:'0')),version:4" rel=3D"noreferrer noreferrer"=
target=3D"_blank">Godbolt to compile code</a>.=C2=A0=C2=A0<div><div class=
=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024pretty=
print" style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px;word-wrap:break-word"><code class=
=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024pretty=
print"><div class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316=
13853773024subprettyprint"><div><div><span style=3D"color:#0000ff"><span st=
yle=3D"color:#800" class=3D"m_6595411318958702833m_-4276847239778310674m_-7=
471231613853773024styled-by-prettify">#include</span></span><span style=3D"=
color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316=
13853773024styled-by-prettify"> </span><span style=3D"color:#660" class=3D"=
m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by-=
prettify"><</span><span style=3D"color:#000" class=3D"m_6595411318958702=
833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">experime=
ntal</span><span style=3D"color:#660" class=3D"m_6595411318958702833m_-4276=
847239778310674m_-7471231613853773024styled-by-prettify">/</span><span styl=
e=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-747=
1231613853773024styled-by-prettify">optional</span><span style=3D"color:#66=
0" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316138537730=
24styled-by-prettify">></span></div><span style=3D"color:#000" class=3D"=
m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by-=
prettify"><br></span><div><span style=3D"color:#0000ff"><span style=3D"colo=
r:#008" class=3D"m_6595411318958702833m_-4276847239778310674m_-747123161385=
3773024styled-by-prettify">struct</span></span><span style=3D"color:#000" c=
lass=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024st=
yled-by-prettify"> O </span><span style=3D"color:#660" class=3D"m_659541131=
8958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">{=
</span></div><div><span style=3D"color:#000" class=3D"m_6595411318958702833=
m_-4276847239778310674m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=
=A0</span><span style=3D"color:#0000ff"><span style=3D"color:#008" class=3D=
"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by=
-prettify">bool</span></span><span style=3D"color:#000" class=3D"m_65954113=
18958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">=
inited </span><span style=3D"color:#660" class=3D"m_6595411318958702833m_-=
4276847239778310674m_-7471231613853773024styled-by-prettify">=3D</span><spa=
n style=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674=
m_-7471231613853773024styled-by-prettify"> </span><span style=3D"color:#000=
0ff"><span style=3D"color:#008" class=3D"m_6595411318958702833m_-4276847239=
778310674m_-7471231613853773024styled-by-prettify">false</span></span><span=
style=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify">;</span></div><div><span style=3D"=
color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316=
13853773024styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color:#0=
000ff"><span style=3D"color:#008" class=3D"m_6595411318958702833m_-42768472=
39778310674m_-7471231613853773024styled-by-prettify">int</span></span><span=
style=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify"> =C2=A0value</span><span style=3D"=
color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316=
13853773024styled-by-prettify">;</span></div><span style=3D"color:#000" cla=
ss=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styl=
ed-by-prettify"><br></span><div><span style=3D"color:#000" class=3D"m_65954=
11318958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettif=
y">=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_6595411318958=
702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">~</sp=
an><span style=3D"color:#000" class=3D"m_6595411318958702833m_-427684723977=
8310674m_-7471231613853773024styled-by-prettify">O</span><span style=3D"col=
or:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316138=
53773024styled-by-prettify">()</span><span style=3D"color:#000" class=3D"m_=
6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by-pr=
ettify"> </span><span style=3D"color:#660" class=3D"m_6595411318958702833m_=
-4276847239778310674m_-7471231613853773024styled-by-prettify">{</span></div=
><div><span style=3D"color:#000" class=3D"m_6595411318958702833m_-427684723=
9778310674m_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color:#0000ff"><span style=3D"color:#008" class=
=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled=
-by-prettify">if</span></span><span style=3D"color:#660" class=3D"m_6595411=
318958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify"=
>(</span><span style=3D"color:#000" class=3D"m_6595411318958702833m_-427684=
7239778310674m_-7471231613853773024styled-by-prettify">inited</span><span s=
tyle=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-=
7471231613853773024styled-by-prettify">)</span></div><div><span style=3D"co=
lor:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613=
853773024styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0init=
ed </span><span style=3D"color:#660" class=3D"m_6595411318958702833m_-42768=
47239778310674m_-7471231613853773024styled-by-prettify">=3D</span><span sty=
le=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-74=
71231613853773024styled-by-prettify"> </span><span style=3D"color:#0000ff">=
<span style=3D"color:#008" class=3D"m_6595411318958702833m_-427684723977831=
0674m_-7471231613853773024styled-by-prettify">false</span></span><span styl=
e=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-747=
1231613853773024styled-by-prettify">;</span></div><div><span style=3D"color=
:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853=
773024styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color:#660" c=
lass=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024st=
yled-by-prettify">}</span></div><div><span style=3D"color:#660" class=3D"m_=
6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by-pr=
ettify">};</span></div><span style=3D"color:#000" class=3D"m_65954113189587=
02833m_-4276847239778310674m_-7471231613853773024styled-by-prettify"><br></=
span><div><span style=3D"color:#0000ff"><span style=3D"color:#008" class=3D=
"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by=
-prettify">void</span></span><span style=3D"color:#000" class=3D"m_65954113=
18958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">=
destruct_optional_int</span><span style=3D"color:#660" class=3D"m_65954113=
18958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">=
(</span><span style=3D"color:#000" class=3D"m_6595411318958702833m_-4276847=
239778310674m_-7471231613853773024styled-by-prettify">O</span><span style=
=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-7471=
231613853773024styled-by-prettify">&</span><span style=3D"color:#000" c=
lass=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024st=
yled-by-prettify"> o</span><span style=3D"color:#660" class=3D"m_6595411318=
958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">)<=
/span><span style=3D"color:#000" class=3D"m_6595411318958702833m_-427684723=
9778310674m_-7471231613853773024styled-by-prettify"> </span><span style=3D"=
color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m_-74712316=
13853773024styled-by-prettify">{</span></div><div><span style=3D"color:#000=
" class=3D"m_6595411318958702833m_-4276847239778310674m_-747123161385377302=
4styled-by-prettify"> =C2=A0 =C2=A0o</span><span style=3D"color:#660" class=
=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled=
-by-prettify">.~</span><span style=3D"color:#000" class=3D"m_65954113189587=
02833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">O</spa=
n><span style=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778=
310674m_-7471231613853773024styled-by-prettify">();</span><span style=3D"co=
lor:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-7471231613=
853773024styled-by-prettify"> </span><span style=3D"color:#008000"><span st=
yle=3D"color:#800" class=3D"m_6595411318958702833m_-4276847239778310674m_-7=
471231613853773024styled-by-prettify">// should be noop ?!</span></span></d=
iv><div><span style=3D"color:#800" class=3D"m_6595411318958702833m_-4276847=
239778310674m_-7471231613853773024styled-by-prettify">}</span></div><span s=
tyle=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m_-=
7471231613853773024styled-by-prettify"><br></span><div><span style=3D"color=
:#0000ff"><span style=3D"color:#008" class=3D"m_6595411318958702833m_-42768=
47239778310674m_-7471231613853773024styled-by-prettify">void</span></span><=
span style=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310=
674m_-7471231613853773024styled-by-prettify"> more_optional_int</span><span=
style=3D"color:#660" class=3D"m_6595411318958702833m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify">()</span><span style=3D"color:#000=
" class=3D"m_6595411318958702833m_-4276847239778310674m_-747123161385377302=
4styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_65954113=
18958702833m_-4276847239778310674m_-7471231613853773024styled-by-prettify">=
{</span></div><div><span style=3D"color:#000" class=3D"m_659541131895870283=
3m_-4276847239778310674m_-7471231613853773024styled-by-prettify"> =C2=A0 =
=C2=A0O o</span><span style=3D"color:#660" class=3D"m_6595411318958702833m_=
-4276847239778310674m_-7471231613853773024styled-by-prettify">;</span><span=
style=3D"color:#000" class=3D"m_6595411318958702833m_-4276847239778310674m=
_-7471231613853773024styled-by-prettify"> =C2=A0 =C2=A0</span><span style=
=3D"color:#008000"><span style=3D"color:#800" class=3D"m_659541131895870283=
3m_-4276847239778310674m_-7471231613853773024styled-by-prettify">// address=
does not leak</span></span></div><div><span style=3D"color:#800" class=3D"=
m_6595411318958702833m_-4276847239778310674m_-7471231613853773024styled-by-=
prettify">}</span></div></div></div></code></div><br><div>A few years ago I=
noticed boost::optional<int> deconstructing with a branch.=C2=A0 One=
could argue such containers should be coded to have trivial construction.=
=C2=A0 It seems the container std::optional that ships with gcc and clang h=
ave fixed the issue.<br></div><div><div><br></div><div>I always thought the=
re was room in the language spec to help optimization.=C2=A0 I'd like t=
o propose something like this:</div><div><br></div><div><blockquote style=
=3D"margin:0 0 0 40px;border:none;padding:0px"><div><b>After the lifetime o=
f an object has ended data within its layout has undefined value.</b></div>=
</blockquote></div></div></div></div></blockquote></div></div><div dir=3D"a=
uto"><br></div></span><div dir=3D"auto">But this is already the case. See [=
basic.life]p1.3 that says that the lifetime of an (class) object ends when =
the destructor is called and [basic.life]p6.2 which says that non-static me=
mber access after the lifetime of the object has ended is undefined behavio=
r.</div><span class=3D""><div dir=3D"auto"><div class=3D"gmail_quote"><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><blockquote style=
=3D"margin:0 0 0 40px;border:none;padding:0px"><div><br></div></blockquote>=
</div><div><br></div><div>Often the compiler can figure out that operations=
on such an object's memory are undefined anyway, if the object existed=
on the stack or a delete expression releases it to the heap.=C2=A0 However=
in cases where the memory is from a pool or container are or the address l=
eaks out of compilation scope, it may not be able to prove this.</div></div=
></div></div></blockquote></div></div></span><div dir=3D"auto">That's w=
hy it's UB.</div><span class=3D""><div dir=3D"auto"><div class=3D"gmail=
_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><br>=
</div><div>Note that the implementation can optimize further.=C2=A0 Once it=
is known the memory of an object is undefined at a certain point, any prev=
ious stores to that memory may be elided as long as they can be shown to ha=
ve no side effects up until that point.</div></div></div></div></blockquote=
></div></div></span><div dir=3D"auto">True.</div><span class=3D""><div dir=
=3D"auto"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr"><div><div><div><br></div><div>It looks like gcc is assuming this =
is in the standard already.=C2=A0 Clang and ICC do not.=C2=A0 Does anyone k=
now if gcc is right?<br></div></div></div></div></blockquote></div></div></=
span><div dir=3D"auto">Yes. gcc just has another definition of UB in this c=
ase, or rather, it can prove that the object was destructed, while clang an=
d icc cannot. This is a QoI issue, not a standard's one.</div></div></b=
lockquote><div><br>The fundamental question is whether the side effect of m=
odifying an object must<br>also modify the storage of the object.=C2=A0 If =
the compiler elides the assignment in<br><font face=3D"monospace, monospace=
">destruct_optional_int</font>, the following code will fail:<br><br><font =
face=3D"monospace, monospace">alignas(O) unsigned char buf1[sizeof(O)], buf=
2[sizeof(O)];</font><br><font face=3D"monospace, monospace">O *o =3D new(bu=
f1) O;</font><br><font face=3D"monospace, monospace">o->inited =3D true;=
</font><br><font face=3D"monospace, monospace">o->value =3D 0;</font><br=
><font face=3D"monospace, monospace">memcpy(buf2, buf1, sizeof(O));</font><=
br><font face=3D"monospace, monospace">destruct_optional_int(*o);</font><br=
><font face=3D"monospace, monospace">assert(memcmp(buf1, buf2, sizeof(O)) !=
=3D 0);</font><br><br><font face=3D"arial, helvetica, sans-serif">This expl=
ains the compiled code.=C2=A0 The=C2=A0</font>
<span style=3D"font-family:monospace,monospace;color:rgb(34,34,34);font-siz=
e:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:n=
ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px;background-color:=
rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initia=
l;float:none;display:inline">destruct_optional_int</span><span style=3D"fon=
t-family:arial,helvetica,sans-serif;color:rgb(34,34,34);font-size:small;fon=
t-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-=
weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tran=
sform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255=
,255);text-decoration-style:initial;text-decoration-color:initial;float:non=
e;display:inline"> function=C2=A0</span><span style=3D"color:rgb(34,34,34);=
font-size:small;font-style:normal;font-variant-ligatures:normal;font-varian=
t-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i=
ndent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgroun=
d-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-colo=
r:initial;float:none;display:inline"><font face=3D"arial, helvetica, sans-s=
erif">cannot know</font><br><font face=3D"arial, helvetica, sans-serif">the=
underlying storage of its parameter, so it must do the side effect.<br><br=
>The </font><font face=3D"monospace, monospace">more_optional_int</font><fo=
nt face=3D"arial, helvetica, sans-serif">=C2=A0function does know that the =
underlying storage is not used<br>after the destructor, so the side=C2=A0</=
font><font face=3D"arial, helvetica, sans-serif">effect can be elided.</fon=
t></span></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAHSYqdZJ%2ByR5-mc_AOJ7_hHimQw0baN5dv=
%2BYw0Gdb%2BY2KS%2BGXA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdZJ=
%2ByR5-mc_AOJ7_hHimQw0baN5dv%2BYw0Gdb%2BY2KS%2BGXA%40mail.gmail.com</a>.<br=
/>
--001a1142de805b1394056a0b53de--
.
Author: christopher.hite.work@gmail.com
Date: Tue, 17 Apr 2018 13:55:28 -0700 (PDT)
Raw View
------=_Part_28674_933858064.1523998528630
Content-Type: multipart/alternative;
boundary="----=_Part_28675_1669802900.1523998528630"
------=_Part_28675_1669802900.1523998528630
Content-Type: text/plain; charset="UTF-8"
On Tuesday, 17 April 2018 13:55:36 UTC+1, Nicolas Lesser wrote:
>
> On Tue, Apr 17, 2018, 1:47 PM <christophe...@gmail.com <javascript:>>
> wrote:
>
>>
>> I always thought there was room in the language spec to help
>> optimization. I'd like to propose something like this:
>>
>> *After the lifetime of an object has ended data within its layout has
>> undefined value.*
>>
>>
> But this is already the case. See [basic.life]p1.3 that says that the
> lifetime of an (class) object ends when the destructor is called and
> [basic.life]p6.2 which says that non-static member access after the
> lifetime of the object has ended is undefined behavior.
>
Oh, my bad there it is. It's also more explicit in [class.cdtor]
For an object with a non-trivial destructor, referring to any non-static
member or base class of the object after the destructor finishes execution
results in undefined behavior.
The non-trivial destructor clause raises an issue though. Consider these
cases:
void vector_int(std::vector<int>& v) {
v.back() *= 0xDEADBEEF; // can't be removed
v.pop_back();
}
void vector_O(std::vector<O>& v) {
v.back().value *= 0xDEADBEEF;
v.pop_back();
}
void vector_optional(std::vector<std::optional<int>>& v) {
*(v.back()) *= 0xDEADBEEF;
v.pop_back();
}
Only vector_O is optimized away. I assume the issue is trivial
deconstruction. The vector_optional case is especially annoying since the
implementer of optional worked hard to give it trivial deconstruction.
I'm pretty sure the spec for vector says referencing beyond end is
undefined. Is there a way for the container implementer to tell the
compiler data is undefined? I've wondered if someone has proposed
something like that.
I've thought about a set_undefined(T&) function that at least for trivial
types overwrites them with uninitialized memory and/or
calls VALGRIND_MAKE_MEM_UNDEFINED or ASAN_UNPOISON_MEMORY_REGION. If I did
this in my code though, there's still the risk that some compiler would
actually feel obligated to overwrite the data with junk instead of just
taking the hint that this is undefined.
--
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/4b4425b4-15e4-4ad4-9889-e444eaf89064%40isocpp.org.
------=_Part_28675_1669802900.1523998528630
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, 17 April 2018 13:55:36 UTC+1, Nicolas Lesser =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"auto"><div><=
div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Apr 17, 2018, 1:47 PM &=
lt;<a href=3D"javascript:" rel=3D"nofollow" target=3D"_blank" gdf-obfuscate=
d-mailto=3D"0eQ6nVnVCQAJ" onmousedown=3D"this.href=3D'javascript:';=
return true;" onclick=3D"this.href=3D'javascript:';return true;">ch=
ristophe...@gmail.<wbr>com</a>> wrote:</div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><div><div><div><br></div><div>I always thought there wa=
s room in the language spec to help optimization.=C2=A0 I'd like to pro=
pose something like this:</div><div><br></div><div><blockquote style=3D"mar=
gin:0 0 0 40px;border:none;padding:0px"><div><b>After the lifetime of an ob=
ject has ended data within its layout has undefined value.</b></div></block=
quote></div></div></div></div></blockquote></div></div><div dir=3D"auto"><b=
r></div><div dir=3D"auto">But this is already the case. See [basic.life]p1.=
3 that says that the lifetime of an (class) object ends when the destructor=
is called and [basic.life]p6.2 which says that non-static member access af=
ter the lifetime of the object has ended is undefined behavior.</div></div>=
</blockquote><div>Oh, my bad there it is.=C2=A0 It's also more explicit=
in=C2=A0[class.cdtor]</div><div><blockquote style=3D"margin: 0 0 0 40px; b=
order: none; padding: 0px;"><div>For an object with a non-trivial destructo=
r, referring to any non-static member or base class of the object after the=
destructor finishes execution results in undefined behavior.<br></div></bl=
ockquote><div><br></div><div>The non-trivial destructor clause raises an is=
sue though.=C2=A0 Consider these cases:</div><div><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><div style=3D"color:=
#000000;background-color: #fffffe;font-family: Consolas, " liberation=3D""=
mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D=
"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div><span styl=
e=3D"color: #0000ff;"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span></span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> vector_int</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">vector</span><spa=
n style=3D"color: #080;" class=3D"styled-by-prettify"><</span><span styl=
e=3D"color: #0000ff;"><span style=3D"color: #080;" class=3D"styled-by-prett=
ify">int</span></span><span style=3D"color: #080;" class=3D"styled-by-prett=
ify">></span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> v</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span></div><div><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0v</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">back</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">*=3D</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #3030c0;"><span style=3D"color:=
#066;" class=3D"styled-by-prettify">0xDEADBEEF</span></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> =C2=A0</span><span style=3D"color: #008=
000;"><span style=3D"color: #800;" class=3D"styled-by-prettify">// can'=
t be removed</span></span></div><div><span style=3D"color: #800;" class=3D"=
styled-by-prettify"> =C2=A0 =C2=A0v.pop_back();</span></div><div><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">}</span></div><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><div><span style=
=3D"color: #0000ff;"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> vector_O</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">vector</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">O</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">>&</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> v</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span></div><div><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> =C2=A0 =C2=A0v</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">back</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">().</span><span style=3D"color: #000;" class=3D"styled-by-prettify">valu=
e </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #3030c0;"><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">0xDEADBEEF</span></span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span></div><div><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> =C2=A0 =C2=A0v</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">pop_back</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">();</span></div><div><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span></div><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><div><span style=3D"color: #0000ff;"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> vector_optional</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">vector</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">optional</span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify"><</span><span style=3D"color: #0000ff;"><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">int</span></span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">>&</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> v</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span></div><div><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> =C2=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">*(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">v<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">back</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">())</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">*=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #3030c0;"><span st=
yle=3D"color: #066;" class=3D"styled-by-prettify">0xDEADBEEF</span></span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div><div=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0v<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">pop_back</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">();</span></div><div><=
span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></di=
v></div></code></div>Only=C2=A0<span style=3D"color: rgb(0, 0, 0); font-fam=
ily: monospace; background-color: rgb(255, 255, 254);">vector_O is optimize=
d away.=C2=A0 I assume the issue is trivial deconstruction.=C2=A0 The=C2=A0=
</span><span style=3D"background-color: rgb(255, 255, 254); color: rgb(0, 0=
, 0); font-family: monospace;">vector_optional case is especially annoying =
since the implementer of optional worked hard to give it trivial deconstruc=
tion.=C2=A0=C2=A0</span></div><div><span style=3D"background-color: rgb(255=
, 255, 254); color: rgb(0, 0, 0); font-family: monospace;"><br></span></div=
><div><span style=3D"background-color: rgb(255, 255, 254); color: rgb(0, 0,=
0); font-family: monospace;">I'm pretty sure the spec for vector says =
referencing beyond end is undefined.=C2=A0 Is there a way for the container=
implementer to tell the compiler data is undefined?=C2=A0 I've wondere=
d if someone has proposed something like that.</span></div><div><br></div><=
/div><div>I've thought about a set_undefined(T&) function that at l=
east for trivial types overwrites them with uninitialized memory and/or cal=
ls=C2=A0VALGRIND_MAKE_MEM_UNDEFINED or ASAN_UNPOISON_MEMORY_REGION.=C2=A0 I=
f I did this in my code though, there's still the risk that some compil=
er would actually feel obligated to overwrite the data with junk instead of=
just taking the hint that this is undefined.</div><div><br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left:=
1px #ccc solid;padding-left: 1ex;">
</blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/4b4425b4-15e4-4ad4-9889-e444eaf89064%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4b4425b4-15e4-4ad4-9889-e444eaf89064=
%40isocpp.org</a>.<br />
------=_Part_28675_1669802900.1523998528630--
------=_Part_28674_933858064.1523998528630--
.
Author: Hyman Rosen <hyman.rosen@gmail.com>
Date: Tue, 17 Apr 2018 17:04:37 -0400
Raw View
--f4f5e80a1b14dc1647056a11b07e
Content-Type: text/plain; charset="UTF-8"
On Tue, Apr 17, 2018 at 4:55 PM, <christopher.hite.work@gmail.com> wrote:
>
> I've thought about a set_undefined(T&) function that at least for trivial
> types overwrites them with uninitialized memory and/or
> calls VALGRIND_MAKE_MEM_UNDEFINED or ASAN_UNPOISON_MEMORY_REGION. If I
> did this in my code though, there's still the risk that some compiler would
> actually feel obligated to overwrite the data with junk instead of just
> taking the hint that this is undefined.
>
Optimizationism is a curse. C++ doesn't need more ways for the compiler
to eliminate code that the programmer wrote. It needs coherent and simple
design so that everyone, human and machine, who looks at a piece of code
knows what that code does.
--
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/CAHSYqdbn-N-LCqk_%3DyPx%2B43g_Z_MzB4vQk0oYax7uD7O%3DKv1Xg%40mail.gmail.com.
--f4f5e80a1b14dc1647056a11b07e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Apr 17, 2018 at 4:55 PM, <span dir=3D"ltr"><<a href=3D"mailto:chris=
topher.hite.work@gmail.com" target=3D"_blank">christopher.hite.work@gmail.c=
om</a>></span> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><di=
v>I've thought about a set_undefined(T&) function that at least for=
trivial types overwrites them with uninitialized memory and/or calls=C2=A0=
VALGRIND_MAKE_MEM_<wbr>UNDEFINED or ASAN_UNPOISON_MEMORY_REGION.=C2=A0 If I=
did this in my code though, there's still the risk that some compiler =
would actually feel obligated to overwrite the data with junk instead of ju=
st taking the hint that this is undefined.</div></div></blockquote><div><br=
>Optimizationism is a curse.=C2=A0 C++ doesn't need more ways for the c=
ompiler<br>to eliminate code that the programmer wrote.=C2=A0 It needs cohe=
rent and simple<br>design so that everyone, human and machine, who looks at=
a piece of code<br>knows what that code does.=C2=A0</div></div></div></div=
>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAHSYqdbn-N-LCqk_%3DyPx%2B43g_Z_MzB4v=
Qk0oYax7uD7O%3DKv1Xg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdbn-N=
-LCqk_%3DyPx%2B43g_Z_MzB4vQk0oYax7uD7O%3DKv1Xg%40mail.gmail.com</a>.<br />
--f4f5e80a1b14dc1647056a11b07e--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 17 Apr 2018 15:41:38 -0700 (PDT)
Raw View
------=_Part_5126_1417467411.1524004898760
Content-Type: multipart/alternative;
boundary="----=_Part_5127_816189327.1524004898760"
------=_Part_5127_816189327.1524004898760
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tuesday, April 17, 2018 at 1:55:28 PM UTC-7, christophe...@gmail.com=20
wrote:
>
>
> Only vector_O is optimized away. I assume the issue is trivial=20
> deconstruction. The vector_optional case is especially annoying since=20
> the implementer of optional worked hard to give it trivial deconstruction=
.. =20
>
Wow, that's a neat case! Here it is reduced to its essence:
https://godbolt.org/g/uVjdrW
=20
> I'm pretty sure the spec for vector says referencing beyond end is=20
> undefined. Is there a way for the container implementer to tell the=20
> compiler data is undefined? I've wondered if someone has proposed=20
> something like that.
>
I can't think of any such mechanism currently.
It wouldn't work to create *just* a std::unbless() mechanism, either,=20
because just as the vector is currently skipping the destructor call, it=20
might also skip a *constructor* call when it starts using that element's=20
memory again (after a push_back, or let's say if you're concatenating=20
another vector onto this vector and we decide to use memcpy for the=20
concatenation, so we skip calling the constructors of the new elements).=20
So if the vector calls "unbless" when it skips a destructor, it would also=
=20
have to call "bless" when it skips a constructor.
There is lots of talk about std::bless (and std::launder, which is related=
=20
but distinct, I think). I don't know what the active proposals are, if any.=
=20
I don't know if any of them include support for std::unbless /=20
std::curse... but I'm pretty sure I've heard people bikeshedding those=20
names before! ;)
=E2=80=93Arthur
>
--=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/7fede9fa-ebf9-43d3-9d13-80833c5189a3%40isocpp.or=
g.
------=_Part_5127_816189327.1524004898760
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, April 17, 2018 at 1:55:28 PM UTC-7, christophe=
....@gmail.com 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"><br><div><div>Only=C2=A0<span style=3D"color:rgb(0,0,0);font-famil=
y:monospace;background-color:rgb(255,255,254)">vector_O is optimized away.=
=C2=A0 I assume the issue is trivial deconstruction.=C2=A0 The=C2=A0</span>=
<span style=3D"background-color:rgb(255,255,254);color:rgb(0,0,0);font-fami=
ly:monospace">vector_optional case is especially annoying since the impleme=
nter of optional worked hard to give it trivial deconstruction. =C2=A0</spa=
n></div></div></div></blockquote><div><br></div><div>Wow, that's a neat=
case! =C2=A0Here it is reduced to its essence:</div><div><a href=3D"https:=
//godbolt.org/g/uVjdrW">https://godbolt.org/g/uVjdrW</a><br></div><div><br>=
</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div><div><span style=3D"background-color:rgb(255,255,254);color:=
rgb(0,0,0);font-family:monospace"></span></div><div><span style=3D"backgrou=
nd-color:rgb(255,255,254);color:rgb(0,0,0);font-family:monospace">I'm p=
retty sure the spec for vector says referencing beyond end is undefined.=C2=
=A0 Is there a way for the container implementer to tell the compiler data =
is undefined?=C2=A0 I've wondered if someone has proposed something lik=
e that.</span></div></div></div></blockquote><div><br></div><div>I can'=
t think of any such mechanism currently.</div><div><br></div><div>It wouldn=
't work to create <i>just</i> a std::unbless() mechanism, either, becau=
se just as the vector is currently skipping the destructor call, it might a=
lso skip a <i>constructor</i> call when it starts using that element's =
memory again (after a push_back, or let's say if you're concatenati=
ng another vector onto this vector and we decide to use memcpy for the conc=
atenation, so we skip calling the constructors of the new elements). =C2=A0=
So if the vector calls "unbless" when it skips a destructor, it w=
ould also have to call "bless" when it skips a constructor.</div>=
<div><br></div><div>There is lots of talk about std::bless (and std::launde=
r, which is related but distinct, I think). I don't know what the activ=
e proposals are, if any. I don't know if any of them include support fo=
r std::unbless / std::curse... but I'm pretty sure I've heard peopl=
e bikeshedding those names before! ;)</div><div><br></div><div>=E2=80=93Art=
hur</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"><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex">
</blockquote></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/7fede9fa-ebf9-43d3-9d13-80833c5189a3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7fede9fa-ebf9-43d3-9d13-80833c5189a3=
%40isocpp.org</a>.<br />
------=_Part_5127_816189327.1524004898760--
------=_Part_5126_1417467411.1524004898760--
.
Author: Ren Industries <renindustries@gmail.com>
Date: Tue, 17 Apr 2018 21:16:36 -0400
Raw View
--94eb2c0efc8edc02e5056a15340a
Content-Type: text/plain; charset="UTF-8"
Optimizations are why we use C++ for games. We absolutely need more ways
for the compiler to eliminate code, assuming those mechanisms are well
specified and clear.
On Tue, Apr 17, 2018 at 5:04 PM, Hyman Rosen <hyman.rosen@gmail.com> wrote:
> On Tue, Apr 17, 2018 at 4:55 PM, <christopher.hite.work@gmail.com> wrote:
>>
>> I've thought about a set_undefined(T&) function that at least for trivial
>> types overwrites them with uninitialized memory and/or
>> calls VALGRIND_MAKE_MEM_UNDEFINED or ASAN_UNPOISON_MEMORY_REGION. If I
>> did this in my code though, there's still the risk that some compiler would
>> actually feel obligated to overwrite the data with junk instead of just
>> taking the hint that this is undefined.
>>
>
> Optimizationism is a curse. C++ doesn't need more ways for the compiler
> to eliminate code that the programmer wrote. It needs coherent and simple
> design so that everyone, human and machine, who looks at a piece of code
> knows what that code does.
>
> --
> 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/CAHSYqdbn-N-LCqk_%3DyPx%2B43g_Z_
> MzB4vQk0oYax7uD7O%3DKv1Xg%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdbn-N-LCqk_%3DyPx%2B43g_Z_MzB4vQk0oYax7uD7O%3DKv1Xg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAMD6iD-3RY-rKHxFHpB6PQ_L5uCu_nPYG-byBbDGtRaPznPNuQ%40mail.gmail.com.
--94eb2c0efc8edc02e5056a15340a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Optimizations are why we use C++ for games. We absolutely =
need more ways for the compiler to eliminate code, assuming those mechanism=
s are well specified and clear.</div><div class=3D"gmail_extra"><br><div cl=
ass=3D"gmail_quote">On Tue, Apr 17, 2018 at 5:04 PM, Hyman Rosen <span dir=
=3D"ltr"><<a href=3D"mailto:hyman.rosen@gmail.com" target=3D"_blank">hym=
an.rosen@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><spa=
n class=3D"">On Tue, Apr 17, 2018 at 4:55 PM, <span dir=3D"ltr"><<a hre=
f=3D"mailto:christopher.hite.work@gmail.com" target=3D"_blank">christopher.=
hite.work@gmail.<wbr>com</a>></span> wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><div>I've thought about a set_undefined(T&) func=
tion that at least for trivial types overwrites them with uninitialized mem=
ory and/or calls=C2=A0VALGRIND_MAKE_MEM_UNDEFI<wbr>NED or ASAN_UNPOISON_MEM=
ORY_REGION.=C2=A0 If I did this in my code though, there's still the ri=
sk that some compiler would actually feel obligated to overwrite the data w=
ith junk instead of just taking the hint that this is undefined.</div></div=
></blockquote></span><div><br>Optimizationism is a curse.=C2=A0 C++ doesn&#=
39;t need more ways for the compiler<br>to eliminate code that the programm=
er wrote.=C2=A0 It needs coherent and simple<br>design so that everyone, hu=
man and machine, who looks at a piece of code<br>knows what that code does.=
=C2=A0</div></div></div></div><span class=3D"">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAHSYqdbn-N-LCqk_%3DyPx%2B43g_Z_MzB4v=
Qk0oYax7uD7O%3DKv1Xg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/msgi=
d/std-<wbr>proposals/CAHSYqdbn-N-LCqk_%<wbr>3DyPx%2B43g_Z_<wbr>MzB4vQk0oYax=
7uD7O%3DKv1Xg%<wbr>40mail.gmail.com</a>.<br>
</blockquote></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAMD6iD-3RY-rKHxFHpB6PQ_L5uCu_nPYG-by=
BbDGtRaPznPNuQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMD6iD-3RY-rKHxF=
HpB6PQ_L5uCu_nPYG-byBbDGtRaPznPNuQ%40mail.gmail.com</a>.<br />
--94eb2c0efc8edc02e5056a15340a--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 17 Apr 2018 18:34:35 -0700 (PDT)
Raw View
------=_Part_30290_1780604166.1524015275198
Content-Type: multipart/alternative;
boundary="----=_Part_30291_1232612866.1524015275198"
------=_Part_30291_1232612866.1524015275198
Content-Type: text/plain; charset="UTF-8"
On Tuesday, April 17, 2018 at 9:16:40 PM UTC-4, Ren Industries wrote:
>
> Optimizations are why we use C++ for games. We absolutely need more ways
> for the compiler to eliminate code, assuming those mechanisms are well
> specified and clear.
>
Normally, I disagree with Hyman about thinks like this. But in this
particular case, I have to agree. Or at least partially; it's crazy to
*expect* the compiler to recognize cases like this. And it's even worse to
start adding functions and other unnecessary bits to *help* the compiler
detect such occurrences.
That's not to say that I think that the compiler shouldn't be able to
eliminate it. After all, it's impossible for anyone to tell the difference,
so compilers are free to do so. But I don't think anyone should look at
that code and assume that the compiler will catch it. And I certainly don't
think we should start necessitating special functions like `std::unbless`
or whatever just to tell the compiler something.
Reliance on the omniscience of the compiler is not always a good idea.
Better to learn to write good code yourself than to assume the compiler
will catch you.
--
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/6c291874-b9e6-47e4-a1f2-cf32cacc30bd%40isocpp.org.
------=_Part_30291_1232612866.1524015275198
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, April 17, 2018 at 9:16:40 PM UTC-4, Ren Indust=
ries wrote:<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">Op=
timizations are why we use C++ for games. We absolutely need more ways for =
the compiler to eliminate code, assuming those mechanisms are well specifie=
d and clear.</div></blockquote><div><br>Normally, I disagree with Hyman abo=
ut thinks like this. But in this particular case, I have to agree. Or at le=
ast partially; it's crazy to <i>expect</i> the compiler to recognize ca=
ses like this. And it's even worse to start adding functions and other =
unnecessary bits to <i>help</i> the compiler detect such occurrences.<br><b=
r>That's not to say that I think that the compiler shouldn't be abl=
e to eliminate it. After all, it's impossible for anyone to tell the di=
fference, so compilers are free to do so. But I don't think anyone shou=
ld look at that code and assume that the compiler will catch it. And I cert=
ainly don't think we should start necessitating special functions like =
`std::unbless` or whatever just to tell the compiler something.<br><br>Reli=
ance on the omniscience of the compiler is not always a good idea. Better t=
o learn to write good code yourself than to assume the compiler will catch =
you.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/6c291874-b9e6-47e4-a1f2-cf32cacc30bd%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6c291874-b9e6-47e4-a1f2-cf32cacc30bd=
%40isocpp.org</a>.<br />
------=_Part_30291_1232612866.1524015275198--
------=_Part_30290_1780604166.1524015275198--
.
Author: Avi Kivity <avi@scylladb.com>
Date: Wed, 18 Apr 2018 11:45:50 +0300
Raw View
This is a multi-part message in MIME format.
--------------0E2B4BE8D2EA664F80A60FBB
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable
Related gcc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61982
On 2018-04-17 14:47, christopher.hite.work@gmail.com wrote:
> Godbolt to compile code=20
> <https://godbolt.org/#g:%21%28%28g:%21%28%28g:%21%28%28h:codeEditor,i:%28=
j:1,lang:c%2B%2B,source:%27%23include+%3Cexperimental/optional%3E%0A%0A%23i=
f+0%0Ausing+O+%3D+std::experimental::optional%3Cint%3E%3B%0A%23else%0A%0Ast=
ruct+O+%7B%0A++++bool+inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++%7EO=
%28%29+%7B%0A++++++++if%28inited%29%0A++++++++++++inited+%3D+false%3B%0A+++=
+%7D%0A%7D%3B%0A%0A%23endif%0A%0Avoid+destruct_optional_int%28O%26+o%29+%7B=
%0A++++o.%7EO%28%29%3B++//+should+be+noop+%3F%21%21%0A%7D%0A%0Avoid+more_op=
tional_int%28%29+%7B%0A++++O+o%3B+++//+address+does+not+leak%0A%7D%27%29,l:=
%275%27,n:%270%27,o:%27C%2B%2B+source+%231%27,t:%270%27%29%29,k:33.33333333=
3333336,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:compi=
ler,i:%28compiler:clang600,filters:%28b:%270%27,binary:%271%27,commentOnly:=
%270%27,demangle:%270%27,directives:%270%27,execute:%271%27,intel:%270%27,t=
rim:%270%27%29,lang:c%2B%2B,libs:%21%28%29,options:%27-std%3Dc%2B%2B1z+-O3%=
27,source:1%29,l:%275%27,n:%270%27,o:%27x86-64+clang+6.0.0+%28Editor+%231,+=
Compiler+%231%29+C%2B%2B%27,t:%270%27%29%29,k:33.333333333333336,l:%274%27,=
n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:output,i:%28compiler:1,=
editor:1,wrap:%271%27%29,l:%275%27,n:%270%27,o:%27%231+with+x86-64+clang+6.=
0.0%27,t:%270%27%29%29,k:33.33333333333333,l:%274%27,n:%270%27,o:%27%27,s:0=
,t:%270%27%29%29,l:%272%27,n:%270%27,o:%27%27,t:%270%27%29%29,version:4>.=
=20
>
> |
> #include<experimental/optional>
>
> structO {
> boolinited =3Dfalse;
> int=C2=A0value;
>
> ~O(){
> if(inited)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0inited =3Dfalse;
> }
> };
>
> voiddestruct_optional_int(O&o){
> =C2=A0 =C2=A0o.~O();// should be noop ?!
> }
>
> voidmore_optional_int(){
> =C2=A0 =C2=A0O o;// address does not leak
> }
> |
>
> A few years ago I noticed boost::optional<int> deconstructing with a=20
> branch.=C2=A0 One could argue such containers should be coded to have=20
> trivial construction.=C2=A0 It seems the container std::optional that shi=
ps=20
> with gcc and clang have fixed the issue.
>
> I always thought there was room in the language spec to help=20
> optimization.=C2=A0 I'd like to propose something like this:
>
> *After the lifetime of an object has ended data within its layout
> has undefined value.*
>
>
> Often the compiler can figure out that operations on such an object's=20
> memory are undefined anyway, if the object existed on the stack or a=20
> delete expression releases it to the heap.=C2=A0 However in cases where t=
he=20
> memory is from a pool or container are or the address leaks out of=20
> compilation scope, it may not be able to prove this.
>
> Note that the implementation can optimize further. Once it is known=20
> the memory of an object is undefined at a certain point, any previous=20
> stores to that memory may be elided as long as they can be shown to=20
> have no side effects up until that point.
>
> It looks like gcc is assuming this is in the standard already.=C2=A0 Clan=
g=20
> and ICC do not.=C2=A0 Does anyone know if gcc is right?
>
>
> --=20
> You received this message because you are subscribed to the Google=20
> Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send=20
> an email to std-proposals+unsubscribe@isocpp.org=20
> <mailto:std-proposals+unsubscribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org=20
> <mailto:std-proposals@isocpp.org>.
> To view this discussion on the web visit=20
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5da=
1-4dec-af26-a2f0184543c3%40isocpp.org=20
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5d=
a1-4dec-af26-a2f0184543c3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>.
--=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/65d05993-861a-a3b5-3a4b-4f441e6784b1%40scylladb.=
com.
--------------0E2B4BE8D2EA664F80A60FBB
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8=
">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<p>Related gcc bug:</p>
<p><br>
</p>
<p><a class=3D"moz-txt-link-freetext" href=3D"https://gcc.gnu.org/bugzi=
lla/show_bug.cgi?id=3D61982">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=
=3D61982</a><br>
</p>
<br>
<div class=3D"moz-cite-prefix">On 2018-04-17 14:47,
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:christopher.hite=
..work@gmail.com">christopher.hite.work@gmail.com</a> wrote:<br>
</div>
<blockquote type=3D"cite"
cite=3D"mid:1abb061a-5da1-4dec-af26-a2f0184543c3@isocpp.org">
<div dir=3D"ltr"><a
href=3D"https://godbolt.org/#g:%21%28%28g:%21%28%28g:%21%28%28h:codeEditor,=
i:%28j:1,lang:c%2B%2B,source:%27%23include+%3Cexperimental/optional%3E%0A%0=
A%23if+0%0Ausing+O+%3D+std::experimental::optional%3Cint%3E%3B%0A%23else%0A=
%0Astruct+O+%7B%0A++++bool+inited+%3D+false%3B%0A++++int++value%3B%0A%0A+++=
+%7EO%28%29+%7B%0A++++++++if%28inited%29%0A++++++++++++inited+%3D+false%3B%=
0A++++%7D%0A%7D%3B%0A%0A%23endif%0A%0Avoid+destruct_optional_int%28O%26+o%2=
9+%7B%0A++++o.%7EO%28%29%3B++//+should+be+noop+%3F%21%21%0A%7D%0A%0Avoid+mo=
re_optional_int%28%29+%7B%0A++++O+o%3B+++//+address+does+not+leak%0A%7D%27%=
29,l:%275%27,n:%270%27,o:%27C%2B%2B+source+%231%27,t:%270%27%29%29,k:33.333=
333333333336,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:=
compiler,i:%28compiler:clang600,filters:%28b:%270%27,binary:%271%27,comment=
Only:%270%27,demangle:%270%27,directives:%270%27,execute:%271%27,intel:%270=
%27,trim:%270%27%29,lang:c%2B%2B,libs:%21%28%29,options:%27-std%3Dc%2B%2B1z=
+-O3%27,source:1%29,l:%275%27,n:%270%27,o:%27x86-64+clang+6.0.0+%28Editor+%=
231,+Compiler+%231%29+C%2B%2B%27,t:%270%27%29%29,k:33.333333333333336,l:%27=
4%27,n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:output,i:%28compil=
er:1,editor:1,wrap:%271%27%29,l:%275%27,n:%270%27,o:%27%231+with+x86-64+cla=
ng+6.0.0%27,t:%270%27%29%29,k:33.33333333333333,l:%274%27,n:%270%27,o:%27%2=
7,s:0,t:%270%27%29%29,l:%272%27,n:%270%27,o:%27%27,t:%270%27%29%29,version:=
4"
moz-do-not-send=3D"true">Godbolt to compile code</a>.=C2=A0=C2=A0
<div>
<div class=3D"prettyprint" style=3D"background-color: rgb(250,
250, 250); border-color: rgb(187, 187, 187); border-style:
solid; border-width: 1px; word-wrap: break-word;"><code
class=3D"prettyprint">
<div class=3D"subprettyprint">
<div style=3D"color: #000000;background-color:
#fffffe;font-family: Consolas, " liberation=3D""
mono",=3D"" courier,=3D"" monospace;font-weight:=3D""
normal;font-size:=3D"" 14px;line-height:=3D""
19px;white-space:=3D"" pre;"=3D"">
<div><span style=3D"color: #0000ff;"><span style=3D"color=
:
#800;" class=3D"styled-by-prettify">#include</span>=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">e=
xperimental</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">/=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">o=
ptional</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span></div>
<span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>
</span>
<div><span style=3D"color: #0000ff;"><span style=3D"color=
:
#008;" class=3D"styled-by-prettify">struct</span></=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
O
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">{</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><sp=
an
style=3D"color: #0000ff;"><span style=3D"color: #008;=
"
class=3D"styled-by-prettify">bool</span></span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify">
inited </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">=3D</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #0000ff;"><span style=3D"color: #008;=
"
class=3D"styled-by-prettify">false</span></span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><sp=
an
style=3D"color: #0000ff;"><span style=3D"color: #008;=
"
class=3D"styled-by-prettify">int</span></span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
=C2=A0value</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span></div>
<span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>
</span>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">~=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">O=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(=
)</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =
=C2=A0</span><span
style=3D"color: #0000ff;"><span style=3D"color: #008;=
"
class=3D"styled-by-prettify">if</span></span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">i=
nited</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0inited </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #0000ff;"><span style=3D"color: #008;=
"
class=3D"styled-by-prettify">false</span></span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span></div>
<div><span style=3D"color: #660;"
class=3D"styled-by-prettify">};</span></div>
<span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>
</span>
<div><span style=3D"color: #0000ff;"><span style=3D"color=
:
#008;" class=3D"styled-by-prettify">void</span></sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify">
destruct_optional_int</span><span style=3D"color:
#660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">O=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
o</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0o</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">.=
~</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">O=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(=
);</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #008000;"><span style=3D"color: #800;=
"
class=3D"styled-by-prettify">// should be noop ?!</=
span></span></div>
<div><span style=3D"color: #800;"
class=3D"styled-by-prettify">}</span></div>
<span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>
</span>
<div><span style=3D"color: #0000ff;"><span style=3D"color=
:
#008;" class=3D"styled-by-prettify">void</span></sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify">
more_optional_int</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">()</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0O o</span>=
<span
style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0
=C2=A0</span><span style=3D"color: #008000;"><span
style=3D"color: #800;" class=3D"styled-by-prettify"=
>//
address does not leak</span></span></div>
<div><span style=3D"color: #800;"
class=3D"styled-by-prettify">}</span></div>
</div>
</div>
</code></div>
<br>
<div>A few years ago I noticed boost::optional<int>
deconstructing with a branch.=C2=A0 One could argue such
containers should be coded to have trivial construction.=C2=A0 =
It
seems the container std::optional that ships with gcc and
clang have fixed the issue.<br>
</div>
<div>
<div><br>
</div>
<div>I always thought there was room in the language spec to
help optimization.=C2=A0 I'd like to propose something like
this:</div>
<div><br>
</div>
<div>
<blockquote style=3D"margin: 0 0 0 40px; border: none;
padding: 0px;">
<div><b>After the lifetime of an object has ended data
within its layout has undefined value.</b><br>
</div>
</blockquote>
</div>
<div><br>
</div>
<div>Often the compiler can figure out that operations on
such an object's memory are undefined anyway, if the
object existed on the stack or a delete expression
releases it to the heap.=C2=A0 However in cases where the
memory is from a pool or container are or the address
leaks out of compilation scope, it may not be able to
prove this.</div>
<div><br>
</div>
<div>Note that the implementation can optimize further.=C2=A0
Once it is known the memory of an object is undefined at a
certain point, any previous stores to that memory may be
elided as long as they can be shown to have no side
effects up until that point.</div>
<div><br>
</div>
<div>It looks like gcc is assuming this is in the standard
already.=C2=A0 Clang and ICC do not.=C2=A0 Does anyone know i=
f gcc
is right?<br>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
-- <br>
You received this message because you are subscribed to the Google
Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it,
send an email to <a
href=3D"mailto:std-proposals+unsubscribe@isocpp.org"
moz-do-not-send=3D"true">std-proposals+unsubscribe@isocpp.org</a>.<=
br>
To post to this group, send email to <a
href=3D"mailto:std-proposals@isocpp.org" moz-do-not-send=3D"true">s=
td-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a
href=3D"https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1abb06=
1a-5da1-4dec-af26-a2f0184543c3%40isocpp.org?utm_medium=3Demail&utm_sour=
ce=3Dfooter"
moz-do-not-send=3D"true">https://groups.google.com/a/isocpp.org/d/m=
sgid/std-proposals/1abb061a-5da1-4dec-af26-a2f0184543c3%40isocpp.org</a>.<b=
r>
</blockquote>
<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/65d05993-861a-a3b5-3a4b-4f441e6784b1%=
40scylladb.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.googl=
e.com/a/isocpp.org/d/msgid/std-proposals/65d05993-861a-a3b5-3a4b-4f441e6784=
b1%40scylladb.com</a>.<br />
--------------0E2B4BE8D2EA664F80A60FBB--
.
Author: "T. C." <rs2740@gmail.com>
Date: Wed, 18 Apr 2018 15:34:57 -0700 (PDT)
Raw View
------=_Part_28880_1779970723.1524090897203
Content-Type: multipart/alternative;
boundary="----=_Part_28881_116450056.1524090897204"
------=_Part_28881_116450056.1524090897204
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Currently, a destructor call does not end the lifetime of a trivially=20
destructible object. See [basic.life]/p1. Core issue 2256 is going to=20
change that.
On Wednesday, April 18, 2018 at 4:45:56 AM UTC-4, Avi Kivity wrote:
>
> Related gcc bug:
>
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61982
>
> On 2018-04-17 14:47, christophe...@gmail.com <javascript:> wrote:
>
> Godbolt to compile code=20
> <https://godbolt.org/#g:%21%28%28g:%21%28%28g:%21%28%28h:codeEditor,i:%28=
j:1,lang:c%2B%2B,source:%27%23include+%3Cexperimental/optional%3E%0A%0A%23i=
f+0%0Ausing+O+%3D+std::experimental::optional%3Cint%3E%3B%0A%23else%0A%0Ast=
ruct+O+%7B%0A++++bool+inited+%3D+false%3B%0A++++int++value%3B%0A%0A++++%7EO=
%28%29+%7B%0A++++++++if%28inited%29%0A++++++++++++inited+%3D+false%3B%0A+++=
+%7D%0A%7D%3B%0A%0A%23endif%0A%0Avoid+destruct_optional_int%28O%26+o%29+%7B=
%0A++++o.%7EO%28%29%3B++//+should+be+noop+%3F%21%21%0A%7D%0A%0Avoid+more_op=
tional_int%28%29+%7B%0A++++O+o%3B+++//+address+does+not+leak%0A%7D%27%29,l:=
%275%27,n:%270%27,o:%27C%2B%2B+source+%231%27,t:%270%27%29%29,k:33.33333333=
3333336,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:compi=
ler,i:%28compiler:clang600,filters:%28b:%270%27,binary:%271%27,commentOnly:=
%270%27,demangle:%270%27,directives:%270%27,execute:%271%27,intel:%270%27,t=
rim:%270%27%29,lang:c%2B%2B,libs:%21%28%29,options:%27-std%3Dc%2B%2B1z+-O3%=
27,source:1%29,l:%275%27,n:%270%27,o:%27x86-64+clang+6.0.0+%28Editor+%231,+=
Compiler+%231%29+C%2B%2B%27,t:%270%27%29%29,k:33.333333333333336,l:%274%27,=
n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21%28%28h:output,i:%28compiler:1,=
editor:1,wrap:%271%27%29,l:%275%27,n:%270%27,o:%27%231+with+x86-64+clang+6.=
0.0%27,t:%270%27%29%29,k:33.33333333333333,l:%274%27,n:%270%27,o:%27%27,s:0=
,t:%270%27%29%29,l:%272%27,n:%270%27,o:%27%27,t:%270%27%29%29,version:4>. =
=20
>
> #include <experimental/optional>
>
> struct O {
> bool inited =3D false;
> int value;
>
> ~O() {
> if(inited)
> inited =3D false;
> }
> };
>
> void destruct_optional_int(O& o) {
> o.~O(); // should be noop ?!
> }
>
> void more_optional_int() {
> O o; // address does not leak
> }
>
> A few years ago I noticed boost::optional<int> deconstructing with a=20
> branch. One could argue such containers should be coded to have trivial=
=20
> construction. It seems the container std::optional that ships with gcc a=
nd=20
> clang have fixed the issue.
>
> I always thought there was room in the language spec to help=20
> optimization. I'd like to propose something like this:
>
> *After the lifetime of an object has ended data within its layout has=20
> undefined value.*
>
>
> Often the compiler can figure out that operations on such an object's=20
> memory are undefined anyway, if the object existed on the stack or a dele=
te=20
> expression releases it to the heap. However in cases where the memory is=
=20
> from a pool or container are or the address leaks out of compilation scop=
e,=20
> it may not be able to prove this.
>
> Note that the implementation can optimize further. Once it is known the=
=20
> memory of an object is undefined at a certain point, any previous stores =
to=20
> that memory may be elided as long as they can be shown to have no side=20
> effects up until that point.
>
> It looks like gcc is assuming this is in the standard already. Clang and=
=20
> ICC do not. Does anyone know if gcc is right?
>
>
> --=20
> You received this message because you are subscribed to the Google Groups=
=20
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
=20
> email to std-proposal...@isocpp.org <javascript:>.
> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
> To view this discussion on the web visit=20
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5da=
1-4dec-af26-a2f0184543c3%40isocpp.org=20
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5d=
a1-4dec-af26-a2f0184543c3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
>
>
--=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/c16d4fb6-dd44-4450-9964-9e9e678d681b%40isocpp.or=
g.
------=_Part_28881_116450056.1524090897204
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently, a destructor call does not end the lifetime of =
a trivially destructible object. See [basic.life]/p1. Core issue 2256 is go=
ing to change that.<div><div><br>On Wednesday, April 18, 2018 at 4:45:56 AM=
UTC-4, Avi Kivity wrote:<blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div text=3D"#000000" bgcolor=3D"#FFFFFF">
<p>Related gcc bug:</p>
<p><br>
</p>
<p><a href=3D"https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61982" tar=
get=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://www=
..google.com/url?q\x3dhttps%3A%2F%2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3F=
id%3D61982\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEy3JptblTzZT8_5M4ssvGesT=
Kxug';return true;" onclick=3D"this.href=3D'https://www.google.com/=
url?q\x3dhttps%3A%2F%2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D61982\x=
26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEy3JptblTzZT8_5M4ssvGesTKxug';re=
turn true;">https://gcc.gnu.org/bugzilla/<wbr>show_bug.cgi?id=3D61982</a><b=
r>
</p>
<br>
<div>On 2018-04-17 14:47,
<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Ny=
-ySk4WCgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:=
9;;return true;" onclick=3D"this.href=3D'javascript:';return true;"=
>christophe...@gmail.<wbr>com</a> wrote:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr"><a href=3D"https://godbolt.org/#g:%21%28%28g:%21%28%=
28g:%21%28%28h:codeEditor,i:%28j:1,lang:c%2B%2B,source:%27%23include+%3Cexp=
erimental/optional%3E%0A%0A%23if+0%0Ausing+O+%3D+std::experimental::optiona=
l%3Cint%3E%3B%0A%23else%0A%0Astruct+O+%7B%0A++++bool+inited+%3D+false%3B%0A=
++++int++value%3B%0A%0A++++%7EO%28%29+%7B%0A++++++++if%28inited%29%0A++++++=
++++++inited+%3D+false%3B%0A++++%7D%0A%7D%3B%0A%0A%23endif%0A%0Avoid+destru=
ct_optional_int%28O%26+o%29+%7B%0A++++o.%7EO%28%29%3B++//+should+be+noop+%3=
F%21%21%0A%7D%0A%0Avoid+more_optional_int%28%29+%7B%0A++++O+o%3B+++//+addre=
ss+does+not+leak%0A%7D%27%29,l:%275%27,n:%270%27,o:%27C%2B%2B+source+%231%2=
7,t:%270%27%29%29,k:33.333333333333336,l:%274%27,n:%270%27,o:%27%27,s:0,t:%=
270%27%29,%28g:%21%28%28h:compiler,i:%28compiler:clang600,filters:%28b:%270=
%27,binary:%271%27,commentOnly:%270%27,demangle:%270%27,directives:%270%27,=
execute:%271%27,intel:%270%27,trim:%270%27%29,lang:c%2B%2B,libs:%21%28%29,o=
ptions:%27-std%3Dc%2B%2B1z+-O3%27,source:1%29,l:%275%27,n:%270%27,o:%27x86-=
64+clang+6.0.0+%28Editor+%231,+Compiler+%231%29+C%2B%2B%27,t:%270%27%29%29,=
k:33.333333333333336,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27%29,%28g:%21=
%28%28h:output,i:%28compiler:1,editor:1,wrap:%271%27%29,l:%275%27,n:%270%27=
,o:%27%231+with+x86-64+clang+6.0.0%27,t:%270%27%29%29,k:33.33333333333333,l=
:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27%29%29,l:%272%27,n:%270%27,o:%27%2=
7,t:%270%27%29%29,version:4" target=3D"_blank" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fgodbolt.=
org%2F%23g%3A%2521%2528%2528g%3A%2521%2528%2528g%3A%2521%2528%2528h%3AcodeE=
ditor%2Ci%3A%2528j%3A1%2Clang%3Ac%252B%252B%2Csource%3A%2527%2523include%2B=
%253Cexperimental%2Foptional%253E%250A%250A%2523if%2B0%250Ausing%2BO%2B%253=
D%2Bstd%3A%3Aexperimental%3A%3Aoptional%253Cint%253E%253B%250A%2523else%250=
A%250Astruct%2BO%2B%257B%250A%2B%2B%2B%2Bbool%2Binited%2B%253D%2Bfalse%253B=
%250A%2B%2B%2B%2Bint%2B%2Bvalue%253B%250A%250A%2B%2B%2B%2B%257EO%2528%2529%=
2B%257B%250A%2B%2B%2B%2B%2B%2B%2B%2Bif%2528inited%2529%250A%2B%2B%2B%2B%2B%=
2B%2B%2B%2B%2B%2B%2Binited%2B%253D%2Bfalse%253B%250A%2B%2B%2B%2B%257D%250A%=
257D%253B%250A%250A%2523endif%250A%250Avoid%2Bdestruct_optional_int%2528O%2=
526%2Bo%2529%2B%257B%250A%2B%2B%2B%2Bo.%257EO%2528%2529%253B%2B%2B%2F%2F%2B=
should%2Bbe%2Bnoop%2B%253F%2521%2521%250A%257D%250A%250Avoid%2Bmore_optiona=
l_int%2528%2529%2B%257B%250A%2B%2B%2B%2BO%2Bo%253B%2B%2B%2B%2F%2F%2Baddress=
%2Bdoes%2Bnot%2Bleak%250A%257D%2527%2529%2Cl%3A%25275%2527%2Cn%3A%25270%252=
7%2Co%3A%2527C%252B%252B%2Bsource%2B%25231%2527%2Ct%3A%25270%2527%2529%2529=
%2Ck%3A33.333333333333336%2Cl%3A%25274%2527%2Cn%3A%25270%2527%2Co%3A%2527%2=
527%2Cs%3A0%2Ct%3A%25270%2527%2529%2C%2528g%3A%2521%2528%2528h%3Acompiler%2=
Ci%3A%2528compiler%3Aclang600%2Cfilters%3A%2528b%3A%25270%2527%2Cbinary%3A%=
25271%2527%2CcommentOnly%3A%25270%2527%2Cdemangle%3A%25270%2527%2Cdirective=
s%3A%25270%2527%2Cexecute%3A%25271%2527%2Cintel%3A%25270%2527%2Ctrim%3A%252=
70%2527%2529%2Clang%3Ac%252B%252B%2Clibs%3A%2521%2528%2529%2Coptions%3A%252=
7-std%253Dc%252B%252B1z%2B-O3%2527%2Csource%3A1%2529%2Cl%3A%25275%2527%2Cn%=
3A%25270%2527%2Co%3A%2527x86-64%2Bclang%2B6.0.0%2B%2528Editor%2B%25231%2C%2=
BCompiler%2B%25231%2529%2BC%252B%252B%2527%2Ct%3A%25270%2527%2529%2529%2Ck%=
3A33.333333333333336%2Cl%3A%25274%2527%2Cn%3A%25270%2527%2Co%3A%2527%2527%2=
Cs%3A0%2Ct%3A%25270%2527%2529%2C%2528g%3A%2521%2528%2528h%3Aoutput%2Ci%3A%2=
528compiler%3A1%2Ceditor%3A1%2Cwrap%3A%25271%2527%2529%2Cl%3A%25275%2527%2C=
n%3A%25270%2527%2Co%3A%2527%25231%2Bwith%2Bx86-64%2Bclang%2B6.0.0%2527%2Ct%=
3A%25270%2527%2529%2529%2Ck%3A33.33333333333333%2Cl%3A%25274%2527%2Cn%3A%25=
270%2527%2Co%3A%2527%2527%2Cs%3A0%2Ct%3A%25270%2527%2529%2529%2Cl%3A%25272%=
2527%2Cn%3A%25270%2527%2Co%3A%2527%2527%2Ct%3A%25270%2527%2529%2529%2Cversi=
on%3A4\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFOplH90EjyAfqOTLdgY4KXNIpMiA=
';return true;" onclick=3D"this.href=3D'https://www.google.com/url?=
q\x3dhttps%3A%2F%2Fgodbolt.org%2F%23g%3A%2521%2528%2528g%3A%2521%2528%2528g=
%3A%2521%2528%2528h%3AcodeEditor%2Ci%3A%2528j%3A1%2Clang%3Ac%252B%252B%2Cso=
urce%3A%2527%2523include%2B%253Cexperimental%2Foptional%253E%250A%250A%2523=
if%2B0%250Ausing%2BO%2B%253D%2Bstd%3A%3Aexperimental%3A%3Aoptional%253Cint%=
253E%253B%250A%2523else%250A%250Astruct%2BO%2B%257B%250A%2B%2B%2B%2Bbool%2B=
inited%2B%253D%2Bfalse%253B%250A%2B%2B%2B%2Bint%2B%2Bvalue%253B%250A%250A%2=
B%2B%2B%2B%257EO%2528%2529%2B%257B%250A%2B%2B%2B%2B%2B%2B%2B%2Bif%2528inite=
d%2529%250A%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2Binited%2B%253D%2Bfalse%253B%=
250A%2B%2B%2B%2B%257D%250A%257D%253B%250A%250A%2523endif%250A%250Avoid%2Bde=
struct_optional_int%2528O%2526%2Bo%2529%2B%257B%250A%2B%2B%2B%2Bo.%257EO%25=
28%2529%253B%2B%2B%2F%2F%2Bshould%2Bbe%2Bnoop%2B%253F%2521%2521%250A%257D%2=
50A%250Avoid%2Bmore_optional_int%2528%2529%2B%257B%250A%2B%2B%2B%2BO%2Bo%25=
3B%2B%2B%2B%2F%2F%2Baddress%2Bdoes%2Bnot%2Bleak%250A%257D%2527%2529%2Cl%3A%=
25275%2527%2Cn%3A%25270%2527%2Co%3A%2527C%252B%252B%2Bsource%2B%25231%2527%=
2Ct%3A%25270%2527%2529%2529%2Ck%3A33.333333333333336%2Cl%3A%25274%2527%2Cn%=
3A%25270%2527%2Co%3A%2527%2527%2Cs%3A0%2Ct%3A%25270%2527%2529%2C%2528g%3A%2=
521%2528%2528h%3Acompiler%2Ci%3A%2528compiler%3Aclang600%2Cfilters%3A%2528b=
%3A%25270%2527%2Cbinary%3A%25271%2527%2CcommentOnly%3A%25270%2527%2Cdemangl=
e%3A%25270%2527%2Cdirectives%3A%25270%2527%2Cexecute%3A%25271%2527%2Cintel%=
3A%25270%2527%2Ctrim%3A%25270%2527%2529%2Clang%3Ac%252B%252B%2Clibs%3A%2521=
%2528%2529%2Coptions%3A%2527-std%253Dc%252B%252B1z%2B-O3%2527%2Csource%3A1%=
2529%2Cl%3A%25275%2527%2Cn%3A%25270%2527%2Co%3A%2527x86-64%2Bclang%2B6.0.0%=
2B%2528Editor%2B%25231%2C%2BCompiler%2B%25231%2529%2BC%252B%252B%2527%2Ct%3=
A%25270%2527%2529%2529%2Ck%3A33.333333333333336%2Cl%3A%25274%2527%2Cn%3A%25=
270%2527%2Co%3A%2527%2527%2Cs%3A0%2Ct%3A%25270%2527%2529%2C%2528g%3A%2521%2=
528%2528h%3Aoutput%2Ci%3A%2528compiler%3A1%2Ceditor%3A1%2Cwrap%3A%25271%252=
7%2529%2Cl%3A%25275%2527%2Cn%3A%25270%2527%2Co%3A%2527%25231%2Bwith%2Bx86-6=
4%2Bclang%2B6.0.0%2527%2Ct%3A%25270%2527%2529%2529%2Ck%3A33.33333333333333%=
2Cl%3A%25274%2527%2Cn%3A%25270%2527%2Co%3A%2527%2527%2Cs%3A0%2Ct%3A%25270%2=
527%2529%2529%2Cl%3A%25272%2527%2Cn%3A%25270%2527%2Co%3A%2527%2527%2Ct%3A%2=
5270%2527%2529%2529%2Cversion%3A4\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF=
OplH90EjyAfqOTLdgY4KXNIpMiA';return true;">Godbolt to compile code</a>.=
=C2=A0=C2=A0
<div>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(=
187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><cod=
e>
<div>
<div>
<div><span style=3D"color:#0000ff"><span style=3D"color:#=
800">#include</span></span><span style=3D"color:#000"> </span><span style=
=3D"color:#660"><</span><span style=3D"color:#000">experimental</span><s=
pan style=3D"color:#660">/</span><span style=3D"color:#000">optional</span>=
<span style=3D"color:#660">></span></div>
<span style=3D"color:#000"><br>
</span>
<div><span style=3D"color:#0000ff"><span style=3D"color:#=
008">struct</span></span><span style=3D"color:#000"> O
</span><span style=3D"color:#660">{</span></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0</span><spa=
n style=3D"color:#0000ff"><span style=3D"color:#008">bool</span></span><spa=
n style=3D"color:#000">
inited </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#0000ff"><span style=
=3D"color:#008">false</span></span><span style=3D"color:#660">;</span></div=
>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0</span><spa=
n style=3D"color:#0000ff"><span style=3D"color:#008">int</span></span><span=
style=3D"color:#000">
=C2=A0value</span><span style=3D"color:#660">;</span>=
</div>
<span style=3D"color:#000"><br>
</span>
<div><span style=3D"color:#000">=C2=A0 =C2=A0 </span><spa=
n style=3D"color:#660">~</span><span style=3D"color:#000">O</span><span sty=
le=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=
=A0</span><span style=3D"color:#0000ff"><span style=3D"color:#008">if</span=
></span><span style=3D"color:#660">(</span><span style=3D"color:#000">inite=
d</span><span style=3D"color:#660">)</span></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0inited </span><span style=3D"color:#660">=3D</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#0000ff"><span style=3D"co=
lor:#008">false</span></span><span style=3D"color:#660">;</span></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0</span><spa=
n style=3D"color:#660">}</span></div>
<div><span style=3D"color:#660">};</span></div>
<span style=3D"color:#000"><br>
</span>
<div><span style=3D"color:#0000ff"><span style=3D"color:#=
008">void</span></span><span style=3D"color:#000">
destruct_optional_int</span><span style=3D"color:#660=
">(</span><span style=3D"color:#000">O</span><span style=3D"color:#660">&am=
p;</span><span style=3D"color:#000"> o</span><span style=3D"color:#660">)</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span>=
</div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0o</span><sp=
an style=3D"color:#660">.~</span><span style=3D"color:#000">O</span><span s=
tyle=3D"color:#660">();</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008000"><span style=3D"color:#800">// should be noop ?!</span><=
/span></div>
<div><span style=3D"color:#800">}</span></div>
<span style=3D"color:#000"><br>
</span>
<div><span style=3D"color:#0000ff"><span style=3D"color:#=
008">void</span></span><span style=3D"color:#000">
more_optional_int</span><span style=3D"color:#660">()=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</spa=
n></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0O o</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"> =C2=A0
=C2=A0</span><span style=3D"color:#008000"><span styl=
e=3D"color:#800">//
address does not leak</span></span></div>
<div><span style=3D"color:#800">}</span></div>
</div>
</div>
</code></div>
<br>
<div>A few years ago I noticed boost::optional<int>
deconstructing with a branch.=C2=A0 One could argue such
containers should be coded to have trivial construction.=C2=A0 =
It
seems the container std::optional that ships with gcc and
clang have fixed the issue.<br>
</div>
<div>
<div><br>
</div>
<div>I always thought there was room in the language spec to
help optimization.=C2=A0 I'd like to propose something li=
ke
this:</div>
<div><br>
</div>
<div>
<blockquote style=3D"margin:0 0 0 40px;border:none;padding:0p=
x">
<div><b>After the lifetime of an object has ended data
within its layout has undefined value.</b><br>
</div>
</blockquote>
</div>
<div><br>
</div>
<div>Often the compiler can figure out that operations on
such an object's memory are undefined anyway, if the
object existed on the stack or a delete expression
releases it to the heap.=C2=A0 However in cases where the
memory is from a pool or container are or the address
leaks out of compilation scope, it may not be able to
prove this.</div>
<div><br>
</div>
<div>Note that the implementation can optimize further.=C2=A0
Once it is known the memory of an object is undefined at a
certain point, any previous stores to that memory may be
elided as long as they can be shown to have no side
effects up until that point.</div>
<div><br>
</div>
<div>It looks like gcc is assuming this is in the standard
already.=C2=A0 Clang and ICC do not.=C2=A0 Does anyone know i=
f gcc
is right?<br>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
-- <br>
You received this message because you are subscribed to the Google
Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it,
send an email to <a href=3D"javascript:" target=3D"_blank" gdf-obfusc=
ated-mailto=3D"Ny-ySk4WCgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#=
39;javascript:';return true;" onclick=3D"this.href=3D'javascript:&#=
39;;return true;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"Ny-ySk4WCgAJ" rel=3D"nofollow" onmouse=
down=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.go=
ogle.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5da1-4dec-af26-a2f0184=
543c3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_b=
lank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.googl=
e.com/a/isocpp.org/d/msgid/std-proposals/1abb061a-5da1-4dec-af26-a2f0184543=
c3%40isocpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return tru=
e;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/ms=
gid/std-proposals/1abb061a-5da1-4dec-af26-a2f0184543c3%40isocpp.org?utm_med=
ium\x3demail\x26utm_source\x3dfooter';return true;">https://groups.goog=
le.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/1abb061a-5da1-4dec-<wbr=
>af26-a2f0184543c3%40isocpp.org</a><wbr>.<br>
</blockquote>
<br>
</div>
</blockquote></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/c16d4fb6-dd44-4450-9964-9e9e678d681b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c16d4fb6-dd44-4450-9964-9e9e678d681b=
%40isocpp.org</a>.<br />
------=_Part_28881_116450056.1524090897204--
------=_Part_28880_1779970723.1524090897203--
.
Author: christopher.hite.work@gmail.com
Date: Fri, 20 Apr 2018 15:49:54 -0700 (PDT)
Raw View
------=_Part_11844_170313410.1524264594207
Content-Type: multipart/alternative;
boundary="----=_Part_11845_849844239.1524264594208"
------=_Part_11845_849844239.1524264594208
Content-Type: text/plain; charset="UTF-8"
On Wednesday, 18 April 2018 23:34:57 UTC+1, T. C. wrote:
>
> Currently, a destructor call does not end the lifetime of a trivially
> destructible object. See [basic.life]/p1. Core issue 2256 is going to
> change that.
>
Cool! So does the proposed solution mean that deconstruction of a POD
would invalidate it? I guess the container just needs to keep calling std::
destroy_at <http://en.cppreference.com/w/cpp/memory/destroy_at>(std::
addressof <http://en.cppreference.com/w/cpp/memory/addressof>(thing)).
Theoretically you could do this to a trivially destructible object on the
stack to shorten its lifetime.
Have there been objects when sub-objects reference each other?
volatile int sink=0;
struct A {
int& ir;
~A () { sink += ir++; } // Undefined Behavior?
};
struct B : A{
int i = 3;
B() : A{i} {}
};
void bar() {
B b;
b.i = 7; // May the compiler skip this store?
}
B is being naughty giving A ref to its i, but traditionally this was safe
code. The storage isn't released until the whole object goes.
--
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/312db392-58a1-4ddd-84f5-9da025fd9adc%40isocpp.org.
------=_Part_11845_849844239.1524264594208
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, 18 April 2018 23:34:57 UTC+1, T. C. wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Currently, a d=
estructor call does not end the lifetime of a trivially destructible object=
.. See [basic.life]/p1. Core issue 2256 is going to change that.=C2=A0</div>=
</blockquote><div><br></div><div>Cool!=C2=A0 So does the proposed solution =
mean that deconstruction of a POD would invalidate it?=C2=A0 I guess the co=
ntainer just needs to keep calling=C2=A0<a href=3D"http://en.cppreference.c=
om/w/cpp/memory/destroy_at" style=3D"font-size: 12.8px; color: rgb(0, 48, 1=
28); background: none;"><span class=3D"kw727">std::<span class=3D"me2">dest=
roy_at</span></span></a><span class=3D"br0" style=3D"font-size: 12.8px; col=
or: rgb(0, 128, 0);">(</span><a href=3D"http://en.cppreference.com/w/cpp/me=
mory/addressof" style=3D"font-size: 12.8px; color: rgb(0, 48, 128); backgro=
und: none;"><span class=3D"kw756">std::<span class=3D"me2">addressof</span>=
</span></a><span class=3D"br0" style=3D"font-size: 12.8px; color: rgb(0, 12=
8, 0);">(</span><span class=3D"br0" style=3D"font-size: 12.8px;"><font colo=
r=3D"#000040">thing</font></span><span class=3D"br0" style=3D"font-size: 12=
..8px; color: rgb(0, 128, 0);">)</span><span class=3D"br0" style=3D"font-siz=
e: 12.8px; color: rgb(0, 128, 0);">)</span>.</div><div><br></div><div>Theor=
etically you could do this to a trivially destructible object=C2=A0on the s=
tack to shorten its lifetime.</div><div><br></div><div>Have there been obje=
cts when sub-objects reference each other?</div><div><div class=3D"prettypr=
int" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, =
187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;">=
<code class=3D"prettyprint"><div class=3D"subprettyprint"><div style=3D"col=
or: #000000;background-color: #fffffe;font-family: Consolas, " liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div liber=
ation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;fon=
t-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div>=
<span style=3D"color: #0000ff;"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">volatile</span></span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #0000ff;"><span style=3D"=
color: #008;" class=3D"styled-by-prettify">int</span></span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> sink</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0988=
5a;"><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><div><=
span style=3D"color: #0000ff;"><span style=3D"color: #008;" class=3D"styled=
-by-prettify">struct</span></span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> A </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span></div><div><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #0000ff;"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">int</span></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> ir</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span></div><div><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">~</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">A </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
sink </span><span style=3D"color: #660;" class=3D"styled-by-prettify">+=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ir</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">++;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> =C2=A0</span><span style=3D"color: #008000=
;"><span style=3D"color: #800;" class=3D"styled-by-prettify">// Undefined B=
ehavior?</span></span></div><div><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">};</span></div><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><div><span style=3D"color: #0000ff;"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> B </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span></div><div><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #000=
0ff;"><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0i </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #09885a;"><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">3</span></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span></div><div><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> =C2=A0 =C2=A0B</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{}</span></div><div><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span></div><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><div><span style=3D"color: #0000ff;"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span></div><div><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> =C2=A0 =C2=A0B b</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span></div><div><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0b</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">i </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #09885a;"><span style=3D"col=
or: #066;" class=3D"styled-by-prettify">7</span></span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> =C2=A0</span><span style=3D"color: #008000;">=
<span style=3D"color: #800;" class=3D"styled-by-prettify">// May the compil=
er skip this store?</span></span></div><div><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">}</span></div><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></div></div></div></code></div>B is bein=
g naughty giving A ref to its i, but traditionally this was safe code.=C2=
=A0 The storage isn't released until the whole object goes.</div><div><=
br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/312db392-58a1-4ddd-84f5-9da025fd9adc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/312db392-58a1-4ddd-84f5-9da025fd9adc=
%40isocpp.org</a>.<br />
------=_Part_11845_849844239.1524264594208--
------=_Part_11844_170313410.1524264594207--
.