Topic: Extending copy elision rules


Author: m.cencora@gmail.com
Date: Mon, 13 Aug 2018 07:30:39 -0700 (PDT)
Raw View
------=_Part_1540_288998635.1534170639995
Content-Type: multipart/alternative;
 boundary="----=_Part_1541_730488694.1534170639995"

------=_Part_1541_730488694.1534170639995
Content-Type: text/plain; charset="UTF-8"

Hi,

can we update copy elision rules so it is allowed in all of following
cases, and not just in 'concat1':

myclass concat1(const myclass& lhs, const myclass& rhs){
    myclass copy(lhs);
    copy += rhs;
    return copy;}


myclass concat2(const myclass& lhs, const myclass& rhs){
    myclass copy(lhs);
    return copy += rhs;}

myclass concat3(const myclass& lhs, const myclass& rhs){
    return myclass(lhs) += rhs;}


Reasoning: given that we are gaining Assignable concept in C++20, compiler
must be able to verify that addressof(lhs) == addressof(lhs = rhs),
so he should be able to verify it for other similar cases (e.g. operator+=).

With this knowledge compiler sees that we are actually returning an
automatic variable and eliding copy should be possible.

Regards,
Maciej

--
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/36582556-c727-4f86-b1cb-44d14b553fe7%40isocpp.org.

------=_Part_1541_730488694.1534170639995
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<div><br></div><div>can we update copy elision rules so=
 it is allowed in all of following cases, and not just in &#39;concat1&#39;=
:</div><div><br></div><div><pre class=3D"lang-cpp prettyprint prettyprinted=
" style=3D"padding: 5px; font-variant-numeric: inherit; font-variant-east-a=
sian: inherit; font-stretch: inherit; line-height: inherit; font-family: Co=
nsolas, Menlo, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&qu=
ot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &q=
uot;Courier New&quot;, monospace, sans-serif; vertical-align: baseline; box=
-sizing: inherit; width: auto; max-height: 600px; overflow: auto; backgroun=
d-color: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;"><c=
ode style=3D"font-style: inherit; font-variant: inherit; font-weight: inher=
it; font-stretch: inherit; line-height: inherit; font-family: Consolas, Men=
lo, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;=
DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier=
 New&quot;, monospace, sans-serif; vertical-align: baseline; box-sizing: in=
herit; white-space: inherit;"><span class=3D"pln" style=3D"font-style: inhe=
rit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; li=
ne-height: inherit; font-family: inherit; vertical-align: baseline; box-siz=
ing: inherit; color: rgb(48, 51, 54);">myclass concat1</span><span class=3D=
"pun" style=3D"font-style: inherit; font-variant: inherit; font-weight: inh=
erit; font-stretch: inherit; line-height: inherit; font-family: inherit; ve=
rtical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">(</sp=
an><span class=3D"kwd" style=3D"font-style: inherit; font-variant: inherit;=
 font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fa=
mily: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(16=
, 16, 148);">const</span><span class=3D"pln" style=3D"font-style: inherit; =
font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-he=
ight: inherit; font-family: inherit; vertical-align: baseline; box-sizing: =
inherit; color: rgb(48, 51, 54);"> myclass</span><span class=3D"pun" style=
=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font-=
stretch: inherit; line-height: inherit; font-family: inherit; vertical-alig=
n: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">&amp;</span><spa=
n class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-w=
eight: inherit; font-stretch: inherit; line-height: inherit; font-family: i=
nherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 5=
4);"> lhs</span><span class=3D"pun" style=3D"font-style: inherit; font-vari=
ant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inh=
erit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; =
color: rgb(48, 51, 54);">,</span><span class=3D"pln" style=3D"font-style: i=
nherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;=
 line-height: inherit; font-family: inherit; vertical-align: baseline; box-=
sizing: inherit; color: rgb(48, 51, 54);"> </span><span class=3D"kwd" style=
=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font-=
stretch: inherit; line-height: inherit; font-family: inherit; vertical-alig=
n: baseline; box-sizing: inherit; color: rgb(16, 16, 148);">const</span><sp=
an class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-=
weight: inherit; font-stretch: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, =
54);"> myclass</span><span class=3D"pun" style=3D"font-style: inherit; font=
-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height=
: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inhe=
rit; color: rgb(48, 51, 54);">&amp;</span><span class=3D"pln" style=3D"font=
-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch:=
 inherit; line-height: inherit; font-family: inherit; vertical-align: basel=
ine; box-sizing: inherit; color: rgb(48, 51, 54);"> rhs</span><span class=
=3D"pun" style=3D"font-style: inherit; font-variant: inherit; font-weight: =
inherit; font-stretch: inherit; line-height: inherit; font-family: inherit;=
 vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">)<=
/span><span class=3D"pln" style=3D"font-style: inherit; font-variant: inher=
it; font-weight: inherit; font-stretch: inherit; line-height: inherit; font=
-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb=
(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">{</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">
    myclass copy</span><span class=3D"pun" style=3D"font-style: inherit; fo=
nt-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heig=
ht: inherit; font-family: inherit; vertical-align: baseline; box-sizing: in=
herit; color: rgb(48, 51, 54);">(</span><span class=3D"pln" style=3D"font-s=
tyle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: i=
nherit; line-height: inherit; font-family: inherit; vertical-align: baselin=
e; box-sizing: inherit; color: rgb(48, 51, 54);">lhs</span><span class=3D"p=
un" style=3D"font-style: inherit; font-variant: inherit; font-weight: inher=
it; font-stretch: inherit; line-height: inherit; font-family: inherit; vert=
ical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">);</spa=
n><span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; =
font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fam=
ily: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48,=
 51, 54);">
    copy </span><span class=3D"pun" style=3D"font-style: inherit; font-vari=
ant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inh=
erit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; =
color: rgb(48, 51, 54);">+=3D</span><span class=3D"pln" style=3D"font-style=
: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inher=
it; line-height: inherit; font-family: inherit; vertical-align: baseline; b=
ox-sizing: inherit; color: rgb(48, 51, 54);"> rhs</span><span class=3D"pun"=
 style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
 font-stretch: inherit; line-height: inherit; font-family: inherit; vertica=
l-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">;</span><s=
pan class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
 inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51,=
 54);">
    </span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: =
inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;=
 font-family: inherit; vertical-align: baseline; box-sizing: inherit; color=
: rgb(16, 16, 148);">return</span><span class=3D"pln" style=3D"font-style: =
inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit=
; line-height: inherit; font-family: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(48, 51, 54);"> copy</span><span class=3D"pun" =
style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; =
font-stretch: inherit; line-height: inherit; font-family: inherit; vertical=
-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">;</span><sp=
an class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-=
weight: inherit; font-stretch: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, =
54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">}</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">


myclass concat2</span><span class=3D"pun" style=3D"font-style: inherit; fon=
t-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heigh=
t: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inh=
erit; color: rgb(48, 51, 54);">(</span><span class=3D"kwd" style=3D"font-st=
yle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: in=
herit; line-height: inherit; font-family: inherit; vertical-align: baseline=
; box-sizing: inherit; color: rgb(16, 16, 148);">const</span><span class=3D=
"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight: inh=
erit; font-stretch: inherit; line-height: inherit; font-family: inherit; ve=
rtical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);"> mycl=
ass</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: i=
nherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; =
font-family: inherit; vertical-align: baseline; box-sizing: inherit; color:=
 rgb(48, 51, 54);">&amp;</span><span class=3D"pln" style=3D"font-style: inh=
erit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; l=
ine-height: inherit; font-family: inherit; vertical-align: baseline; box-si=
zing: inherit; color: rgb(48, 51, 54);"> lhs</span><span class=3D"pun" styl=
e=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font=
-stretch: inherit; line-height: inherit; font-family: inherit; vertical-ali=
gn: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">,</span><span c=
lass=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weig=
ht: inherit; font-stretch: inherit; line-height: inherit; font-family: inhe=
rit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);=
"> </span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: i=
nherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; =
font-family: inherit; vertical-align: baseline; box-sizing: inherit; color:=
 rgb(16, 16, 148);">const</span><span class=3D"pln" style=3D"font-style: in=
herit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; =
line-height: inherit; font-family: inherit; vertical-align: baseline; box-s=
izing: inherit; color: rgb(48, 51, 54);"> myclass</span><span class=3D"pun"=
 style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
 font-stretch: inherit; line-height: inherit; font-family: inherit; vertica=
l-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">&amp;</spa=
n><span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; =
font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fam=
ily: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48,=
 51, 54);"> rhs</span><span class=3D"pun" style=3D"font-style: inherit; fon=
t-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heigh=
t: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inh=
erit; color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"font-st=
yle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: in=
herit; line-height: inherit; font-family: inherit; vertical-align: baseline=
; box-sizing: inherit; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">{</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">
    myclass copy</span><span class=3D"pun" style=3D"font-style: inherit; fo=
nt-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heig=
ht: inherit; font-family: inherit; vertical-align: baseline; box-sizing: in=
herit; color: rgb(48, 51, 54);">(</span><span class=3D"pln" style=3D"font-s=
tyle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: i=
nherit; line-height: inherit; font-family: inherit; vertical-align: baselin=
e; box-sizing: inherit; color: rgb(48, 51, 54);">lhs</span><span class=3D"p=
un" style=3D"font-style: inherit; font-variant: inherit; font-weight: inher=
it; font-stretch: inherit; line-height: inherit; font-family: inherit; vert=
ical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">);</spa=
n><span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; =
font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fam=
ily: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48,=
 51, 54);">
    </span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: =
inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;=
 font-family: inherit; vertical-align: baseline; box-sizing: inherit; color=
: rgb(16, 16, 148);">return</span><span class=3D"pln" style=3D"font-style: =
inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit=
; line-height: inherit; font-family: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(48, 51, 54);"> copy </span><span class=3D"pun"=
 style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
 font-stretch: inherit; line-height: inherit; font-family: inherit; vertica=
l-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">+=3D</span=
><span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, =
51, 54);"> rhs</span><span class=3D"pun" style=3D"font-style: inherit; font=
-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height=
: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inhe=
rit; color: rgb(48, 51, 54);">;</span><span class=3D"pln" style=3D"font-sty=
le: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inh=
erit; line-height: inherit; font-family: inherit; vertical-align: baseline;=
 box-sizing: inherit; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">}</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">

myclass concat3</span><span class=3D"pun" style=3D"font-style: inherit; fon=
t-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heigh=
t: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inh=
erit; color: rgb(48, 51, 54);">(</span><span class=3D"kwd" style=3D"font-st=
yle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: in=
herit; line-height: inherit; font-family: inherit; vertical-align: baseline=
; box-sizing: inherit; color: rgb(16, 16, 148);">const</span><span class=3D=
"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight: inh=
erit; font-stretch: inherit; line-height: inherit; font-family: inherit; ve=
rtical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);"> mycl=
ass</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: i=
nherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; =
font-family: inherit; vertical-align: baseline; box-sizing: inherit; color:=
 rgb(48, 51, 54);">&amp;</span><span class=3D"pln" style=3D"font-style: inh=
erit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; l=
ine-height: inherit; font-family: inherit; vertical-align: baseline; box-si=
zing: inherit; color: rgb(48, 51, 54);"> lhs</span><span class=3D"pun" styl=
e=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font=
-stretch: inherit; line-height: inherit; font-family: inherit; vertical-ali=
gn: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">,</span><span c=
lass=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weig=
ht: inherit; font-stretch: inherit; line-height: inherit; font-family: inhe=
rit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);=
"> </span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: i=
nherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; =
font-family: inherit; vertical-align: baseline; box-sizing: inherit; color:=
 rgb(16, 16, 148);">const</span><span class=3D"pln" style=3D"font-style: in=
herit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; =
line-height: inherit; font-family: inherit; vertical-align: baseline; box-s=
izing: inherit; color: rgb(48, 51, 54);"> myclass</span><span class=3D"pun"=
 style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
 font-stretch: inherit; line-height: inherit; font-family: inherit; vertica=
l-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">&amp;</spa=
n><span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; =
font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fam=
ily: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48,=
 51, 54);"> rhs</span><span class=3D"pun" style=3D"font-style: inherit; fon=
t-variant: inherit; font-weight: inherit; font-stretch: inherit; line-heigh=
t: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inh=
erit; color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"font-st=
yle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: in=
herit; line-height: inherit; font-family: inherit; vertical-align: baseline=
; box-sizing: inherit; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">{</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">
    </span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: =
inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;=
 font-family: inherit; vertical-align: baseline; box-sizing: inherit; color=
: rgb(16, 16, 148);">return</span><span class=3D"pln" style=3D"font-style: =
inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit=
; line-height: inherit; font-family: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(48, 51, 54);"> myclass</span><span class=3D"pu=
n" style=3D"font-style: inherit; font-variant: inherit; font-weight: inheri=
t; font-stretch: inherit; line-height: inherit; font-family: inherit; verti=
cal-align: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">(</span>=
<span class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; fo=
nt-weight: inherit; font-stretch: inherit; line-height: inherit; font-famil=
y: inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 5=
1, 54);">lhs</span><span class=3D"pun" style=3D"font-style: inherit; font-v=
ariant: inherit; font-weight: inherit; font-stretch: inherit; line-height: =
inherit; font-family: inherit; vertical-align: baseline; box-sizing: inheri=
t; color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"font-style=
: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inher=
it; line-height: inherit; font-family: inherit; vertical-align: baseline; b=
ox-sizing: inherit; color: rgb(48, 51, 54);"> </span><span class=3D"pun" st=
yle=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; fo=
nt-stretch: inherit; line-height: inherit; font-family: inherit; vertical-a=
lign: baseline; box-sizing: inherit; color: rgb(48, 51, 54);">+=3D</span><s=
pan class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
 inherit; vertical-align: baseline; box-sizing: inherit; color: rgb(48, 51,=
 54);"> rhs</span><span class=3D"pun" style=3D"font-style: inherit; font-va=
riant: inherit; font-weight: inherit; font-stretch: inherit; line-height: i=
nherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit=
; color: rgb(48, 51, 54);">;</span><span class=3D"pln" style=3D"font-style:=
 inherit; font-variant: inherit; font-weight: inherit; font-stretch: inheri=
t; line-height: inherit; font-family: inherit; vertical-align: baseline; bo=
x-sizing: inherit; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; box-sizing: inherit; color: rg=
b(48, 51, 54);">}</span><span class=3D"pln" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; font-family: inherit; vertical-align: baseline; box-sizing: i=
nherit; color: rgb(48, 51, 54);">
</span></code></pre></div><div><br></div><div>Reasoning: given that we are =
gaining Assignable concept in C++20, compiler must be able to verify that a=
ddressof(lhs) =3D=3D addressof(lhs =3D rhs),</div><div>so he should be able=
 to verify it for other similar cases (e.g. operator+=3D).</div><div><br></=
div><div>With this knowledge compiler sees that we are actually=C2=A0return=
ing an automatic variable and eliding copy should be possible.</div><div><b=
r></div><div>Regards,<br></div><div>Maciej<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/36582556-c727-4f86-b1cb-44d14b553fe7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/36582556-c727-4f86-b1cb-44d14b553fe7=
%40isocpp.org</a>.<br />

------=_Part_1541_730488694.1534170639995--

------=_Part_1540_288998635.1534170639995--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 13 Aug 2018 08:11:15 -0700 (PDT)
Raw View
------=_Part_1569_1771381350.1534173075473
Content-Type: multipart/alternative;
 boundary="----=_Part_1570_1097872696.1534173075473"

------=_Part_1570_1097872696.1534173075473
Content-Type: text/plain; charset="UTF-8"

On Monday, August 13, 2018 at 10:30:40 AM UTC-4, m.ce...@gmail.com wrote:
>
> Hi,
>
> can we update copy elision rules so it is allowed in all of following
> cases, and not just in 'concat1':
>
> myclass concat1(const myclass& lhs, const myclass& rhs){
>     myclass copy(lhs);
>     copy += rhs;
>     return copy;}
>
>
> myclass concat2(const myclass& lhs, const myclass& rhs){
>     myclass copy(lhs);
>     return copy += rhs;}
>
> myclass concat3(const myclass& lhs, const myclass& rhs){
>     return myclass(lhs) += rhs;}
>
>
>
Reasoning: given that we are gaining Assignable concept in C++20, compiler
> must be able to verify that addressof(lhs) == addressof(lhs = rhs),
>

`Assignable` as a concept does not have this requirement at the language
level. It has this requirement implicitly, but this is not a requirement
that can be spelled out in a `requires` expression.

So the compiler does not have to be able to verify this at all. The
compiler may *assume* it for a type which is given to an
`Assignable`-constrained parameter (with UB resulting if you screw up).
That is, you are expected to abide by it for any types you give to such a
parameter. But the compiler does not have to be able to detect when you're
violating that implicit requirement.

In terms of whether the basic feature (find some way to make these work) is
a good idea, I don't much like the implications that `concat3` makes.
There, you're effectively creating the return value object as a prvalue,
giving it a name (passing it to a function), modifying it, and then
returning it as a prvalue to the caller. That is, you have this
prvalue->lvalue->prvalue conversion for an object. Doing all that in a
single expression just seems... disconcerting to me.

With `concat1`, what you have is a single lvalue->prvalue conversion.

Also, teaching people to use assignment operators and other
`this&`-returning functions on prvalues is just destined for trouble. Not
until we get the lifetime issues for these things sorted out.

`concat2` is more palatable, but I think this sort of thing just
over-complicates the rules for elision. As it currently stands, everyone
can say that "return <lvalue>;", where `lvalue` is a local variable of the
exact type of the function's return type is eligible for copy elision. A
`return` statement of any other form is not eligible for elision.

If we start expanding that to more complex expressions, it becomes more
difficult to look at a piece of code and know when elision is happening. In
the example you give here, I have to track down `myclass` and look at its
`+=` operator to know whether elision could happen.

so he should be able to verify it for other similar cases (e.g. operator+=).
>
> With this knowledge compiler sees that we are actually returning an
> automatic variable and eliding copy should be possible.
>
> Regards,
> Maciej
>

--
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/a5da7012-fd38-4cd2-8eaf-5151afbf175f%40isocpp.org.

------=_Part_1570_1097872696.1534173075473
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Monday, August 13, 2018 at 10:30:40 AM UTC-4, m.ce...@g=
mail.com 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=
">Hi,<div><br></div><div>can we update copy elision rules so it is allowed =
in all of following cases, and not just in &#39;concat1&#39;:</div><div><br=
></div><div><pre style=3D"padding:5px;font-stretch:inherit;line-height:inhe=
rit;font-family:Consolas,Menlo,Monaco,&quot;Lucida Console&quot;,&quot;Libe=
ration Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mo=
no&quot;,&quot;Courier New&quot;,monospace,sans-serif;vertical-align:baseli=
ne;width:auto;max-height:600px;overflow:auto;background-color:rgb(239,240,2=
41);color:rgb(57,51,24);word-wrap:normal"><code style=3D"font-style:inherit=
;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:=
inherit;font-family:Consolas,Menlo,Monaco,&quot;Lucida Console&quot;,&quot;=
Liberation Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera San=
s Mono&quot;,&quot;Courier New&quot;,monospace,sans-serif;vertical-align:ba=
seline;white-space:inherit"><span style=3D"font-style:inherit;font-variant:=
inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-f=
amily:inherit;vertical-align:baseline;color:rgb(48,51,54)">myclass concat1<=
/span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:in=
herit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical=
-align:baseline;color:rgb(48,51,54)">(</span><span style=3D"font-style:inhe=
rit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heig=
ht:inherit;font-family:inherit;vertical-align:baseline;color:rgb(16,16,148)=
">const</span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(48,51,54)"> myclass</span><span style=3D"=
font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:in=
herit;line-height:inherit;font-family:inherit;vertical-align:baseline;color=
:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inherit;font-variant:=
inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-f=
amily:inherit;vertical-align:baseline;color:rgb(48,51,54)"> lhs</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">,</span><span style=3D"font-style:inherit;font-va=
riant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;=
font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><s=
pan style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:b=
aseline;color:rgb(16,16,148)">const</span><span style=3D"font-style:inherit=
;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:=
inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> m=
yclass</span><span style=3D"font-style:inherit;font-variant:inherit;font-we=
ight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    copy </span><span style=3D"font-style:inherit;font-variant:inherit;font=
-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inheri=
t;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy</span><span style=3D"font-style:inherit;font-variant:inhe=
rit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-famil=
y:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">


myclass concat2</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy </span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;line-height:inherit;font-family:inherit;vertical-align:baselin=
e;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-va=
riant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;=
font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><s=
pan style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:b=
aseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">

myclass concat3</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant:i=
nherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span sty=
le=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stre=
tch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline=
;color:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-vari=
ant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;fo=
nt-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><spa=
n style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font=
-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(48,51,54)"> </span><span style=3D"font-style:inherit;font-v=
ariant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit=
;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</spa=
n><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inheri=
t;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
;</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:=
inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
</span></code></pre></div><div>=C2=A0</div></div></blockquote><blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
 #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><div>Reasoning:=
 given that we are gaining Assignable concept in C++20, compiler must be ab=
le to verify that addressof(lhs) =3D=3D addressof(lhs =3D rhs),</div></div>=
</blockquote><div><br></div><div>`Assignable` as a concept does not have th=
is requirement at the language level. It has this requirement implicitly, b=
ut this is not a requirement that can be spelled out in a `requires` expres=
sion.</div><div><br></div><div>So the compiler does not have to be able to =
verify this at all. The compiler may <i>assume</i> it for a type which is g=
iven to an `Assignable`-constrained parameter (with UB resulting if you scr=
ew up). That is, you are expected to abide by it for any types you give to =
such a parameter. But the compiler does not have to be able to detect when =
you&#39;re violating that implicit requirement.</div><div><br></div><div>In=
 terms of whether the basic feature (find some way to make these work) is a=
 good idea, I don&#39;t much like the implications that `concat3` makes. Th=
ere, you&#39;re effectively creating the return value object as a prvalue, =
giving it a name (passing it to a function), modifying it, and then returni=
ng it as a prvalue to the caller. That is, you have this prvalue-&gt;lvalue=
-&gt;prvalue conversion for an object. Doing all that in a single expressio=
n just seems... disconcerting to me.</div><div><br></div><div>With `concat1=
`, what you have is a single lvalue-&gt;prvalue conversion.</div><div><br><=
/div><div>Also, teaching people to use assignment operators and other `this=
&amp;`-returning functions on prvalues is just destined for trouble. Not un=
til we get the lifetime issues for these things sorted out.<br></div><div><=
br></div><div>`concat2` is more palatable, but I think this sort of thing j=
ust over-complicates the rules for elision. As it currently stands, everyon=
e can say that &quot;return &lt;lvalue&gt;;&quot;, where `lvalue` is a loca=
l variable of the exact type of the function&#39;s return type is eligible =
for copy elision. A `return` statement of any other form is not eligible fo=
r elision.</div><div><br></div><div>If we start expanding that to more comp=
lex expressions, it becomes more difficult to look at a piece of code and k=
now when elision is happening. In the example you give here, I have to trac=
k down `myclass` and look at its `+=3D` operator to know whether elision co=
uld happen.<br></div><div><br></div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div dir=3D"ltr"><div>so he should be able to verify it for other sim=
ilar cases (e.g. operator+=3D).</div><div><br></div><div>With this knowledg=
e compiler sees that we are actually=C2=A0returning an automatic variable a=
nd eliding copy should be possible.</div><div><br></div><div>Regards,<br></=
div><div>Maciej<br></div></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a5da7012-fd38-4cd2-8eaf-5151afbf175f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a5da7012-fd38-4cd2-8eaf-5151afbf175f=
%40isocpp.org</a>.<br />

------=_Part_1570_1097872696.1534173075473--

------=_Part_1569_1771381350.1534173075473--

.


Author: m.cencora@gmail.com
Date: Mon, 13 Aug 2018 08:42:15 -0700 (PDT)
Raw View
------=_Part_1484_220559834.1534174935530
Content-Type: multipart/alternative;
 boundary="----=_Part_1485_1877160999.1534174935531"

------=_Part_1485_1877160999.1534174935531
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hmm, then what if the rule is changed like this: if compiler can prove that=
=20
result of expresion inside return statement is a reference to automatic=20
variable, then copy elision can be performed as well.

With regard on whether it is a good idea, or not - it is not about whether=
=20
you like functions returning this& or not (as we are not going to get rid=
=20
of them), it is about consistency and teachability.
If all of the concat functions are doing the same thing, then why only=20
first of them can be better optimized (language pessimizes the concat2 and=
=20
concat3 implementation).

I find your argument about complex expressions moot, since we are not=20
talking about complex expression, but very simple ones.
If people must be aware of such issues to write efficient code (even=20
one-liners), then no wonder C++ is considered experts only.
But then even experts sometimes seem to forget them:
https://gcc.gnu.org/ml/libstdc++/2018-05/txtc2I3IxLCfn.txt




W dniu poniedzia=C5=82ek, 13 sierpnia 2018 17:11:15 UTC+2 u=C5=BCytkownik N=
icol Bolas=20
napisa=C5=82:
>
> On Monday, August 13, 2018 at 10:30:40 AM UTC-4, m.ce...@gmail.com wrote:
>>
>> Hi,
>>
>> can we update copy elision rules so it is allowed in all of following=20
>> cases, and not just in 'concat1':
>>
>> myclass concat1(const myclass& lhs, const myclass& rhs){
>>     myclass copy(lhs);
>>     copy +=3D rhs;
>>     return copy;}
>>
>>
>> myclass concat2(const myclass& lhs, const myclass& rhs){
>>     myclass copy(lhs);
>>     return copy +=3D rhs;}
>>
>> myclass concat3(const myclass& lhs, const myclass& rhs){
>>     return myclass(lhs) +=3D rhs;}
>>
>> =20
>>
> Reasoning: given that we are gaining Assignable concept in C++20, compile=
r=20
>> must be able to verify that addressof(lhs) =3D=3D addressof(lhs =3D rhs)=
,
>>
>
> `Assignable` as a concept does not have this requirement at the language=
=20
> level. It has this requirement implicitly, but this is not a requirement=
=20
> that can be spelled out in a `requires` expression.
>
> So the compiler does not have to be able to verify this at all. The=20
> compiler may *assume* it for a type which is given to an=20
> `Assignable`-constrained parameter (with UB resulting if you screw up).=
=20
> That is, you are expected to abide by it for any types you give to such a=
=20
> parameter. But the compiler does not have to be able to detect when you'r=
e=20
> violating that implicit requirement.
>
> In terms of whether the basic feature (find some way to make these work)=
=20
> is a good idea, I don't much like the implications that `concat3` makes.=
=20
> There, you're effectively creating the return value object as a prvalue,=
=20
> giving it a name (passing it to a function), modifying it, and then=20
> returning it as a prvalue to the caller. That is, you have this=20
> prvalue->lvalue->prvalue conversion for an object. Doing all that in a=20
> single expression just seems... disconcerting to me.
>
> With `concat1`, what you have is a single lvalue->prvalue conversion.
>
> Also, teaching people to use assignment operators and other=20
> `this&`-returning functions on prvalues is just destined for trouble. Not=
=20
> until we get the lifetime issues for these things sorted out.
>
> `concat2` is more palatable, but I think this sort of thing just=20
> over-complicates the rules for elision. As it currently stands, everyone=
=20
> can say that "return <lvalue>;", where `lvalue` is a local variable of th=
e=20
> exact type of the function's return type is eligible for copy elision. A=
=20
> `return` statement of any other form is not eligible for elision.
>
> If we start expanding that to more complex expressions, it becomes more=
=20
> difficult to look at a piece of code and know when elision is happening. =
In=20
> the example you give here, I have to track down `myclass` and look at its=
=20
> `+=3D` operator to know whether elision could happen.
>
> so he should be able to verify it for other similar cases (e.g.=20
>> operator+=3D).
>>
>> With this knowledge compiler sees that we are actually returning an=20
>> automatic variable and eliding copy should be possible.
>>
>> Regards,
>> Maciej
>>
>

--=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/3049c92e-8890-4a96-bf06-ab9bb199ff6e%40isocpp.or=
g.

------=_Part_1485_1877160999.1534174935531
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hmm, then what if the rule is changed like this: if compil=
er can prove that result of expresion inside return statement is a referenc=
e to automatic variable, then copy elision can be performed as well.<div><b=
r></div><div>With regard on whether it is a good idea, or not - it is not a=
bout whether you like functions returning this&amp; or not (as we are not g=
oing to get rid of them), it is about consistency and teachability.</div><d=
iv>If all of the concat functions are doing the same thing, then why only f=
irst of them can be better optimized (language pessimizes the concat2 and c=
oncat3 implementation).</div><div><br></div><div>I find your argument about=
 complex expressions moot, since we are not talking about complex expressio=
n, but very simple ones.</div><div>If people must be aware of such issues t=
o write efficient code (even one-liners), then no wonder C++ is considered =
experts only.</div><div>But then even experts sometimes seem to forget them=
:</div><div>https://gcc.gnu.org/ml/libstdc++/2018-05/txtc2I3IxLCfn.txt<br><=
/div><div><br></div><div><br></div><div><br><br>W dniu poniedzia=C5=82ek, 1=
3 sierpnia 2018 17:11:15 UTC+2 u=C5=BCytkownik Nicol Bolas napisa=C5=82:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Monday, Augus=
t 13, 2018 at 10:30:40 AM UTC-4, <a>m.ce...@gmail.com</a> 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">Hi,<div><br></div><div>can we=
 update copy elision rules so it is allowed in all of following cases, and =
not just in &#39;concat1&#39;:</div><div><br></div><div><pre style=3D"paddi=
ng:5px;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,=
Monaco,&quot;Lucida Console&quot;,&quot;Liberation Mono&quot;,&quot;DejaVu =
Sans Mono&quot;,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&quot=
;,monospace,sans-serif;vertical-align:baseline;width:auto;max-height:600px;=
overflow:auto;background-color:rgb(239,240,241);color:rgb(57,51,24);word-wr=
ap:normal"><code style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Me=
nlo,Monaco,&quot;Lucida Console&quot;,&quot;Liberation Mono&quot;,&quot;Dej=
aVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&=
quot;,monospace,sans-serif;vertical-align:baseline;white-space:inherit"><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)">myclass concat1</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)">(</span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> lhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">,</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-style:inherit=
;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:=
inherit;font-family:inherit;vertical-align:baseline;color:rgb(16,16,148)">c=
onst</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)"> myclass</span><span style=3D"fon=
t-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inher=
it;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rg=
b(48,51,54)">&amp;</span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)"> rhs</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;line-height:inherit;font-family:inherit;vertical-align:baselin=
e;color:rgb(48,51,54)">)</span><span style=3D"font-style:inherit;font-varia=
nt:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;fon=
t-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    copy </span><span style=3D"font-style:inherit;font-variant:inherit;font=
-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inheri=
t;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy</span><span style=3D"font-style:inherit;font-variant:inhe=
rit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-famil=
y:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">


myclass concat2</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy </span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;line-height:inherit;font-family:inherit;vertical-align:baselin=
e;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-va=
riant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;=
font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><s=
pan style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:b=
aseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">

myclass concat3</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant:i=
nherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span sty=
le=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stre=
tch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline=
;color:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-vari=
ant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;fo=
nt-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><spa=
n style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font=
-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(48,51,54)"> </span><span style=3D"font-style:inherit;font-v=
ariant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit=
;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</spa=
n><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inheri=
t;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
;</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:=
inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
</span></code></pre></div><div>=C2=A0</div></div></blockquote><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div></div><div>Reasoning: give=
n that we are gaining Assignable concept in C++20, compiler must be able to=
 verify that addressof(lhs) =3D=3D addressof(lhs =3D rhs),</div></div></blo=
ckquote><div><br></div><div>`Assignable` as a concept does not have this re=
quirement at the language level. It has this requirement implicitly, but th=
is is not a requirement that can be spelled out in a `requires` expression.=
</div><div><br></div><div>So the compiler does not have to be able to verif=
y this at all. The compiler may <i>assume</i> it for a type which is given =
to an `Assignable`-constrained parameter (with UB resulting if you screw up=
). That is, you are expected to abide by it for any types you give to such =
a parameter. But the compiler does not have to be able to detect when you&#=
39;re violating that implicit requirement.</div><div><br></div><div>In term=
s of whether the basic feature (find some way to make these work) is a good=
 idea, I don&#39;t much like the implications that `concat3` makes. There, =
you&#39;re effectively creating the return value object as a prvalue, givin=
g it a name (passing it to a function), modifying it, and then returning it=
 as a prvalue to the caller. That is, you have this prvalue-&gt;lvalue-&gt;=
prvalue conversion for an object. Doing all that in a single expression jus=
t seems... disconcerting to me.</div><div><br></div><div>With `concat1`, wh=
at you have is a single lvalue-&gt;prvalue conversion.</div><div><br></div>=
<div>Also, teaching people to use assignment operators and other `this&amp;=
`-returning functions on prvalues is just destined for trouble. Not until w=
e get the lifetime issues for these things sorted out.<br></div><div><br></=
div><div>`concat2` is more palatable, but I think this sort of thing just o=
ver-complicates the rules for elision. As it currently stands, everyone can=
 say that &quot;return &lt;lvalue&gt;;&quot;, where `lvalue` is a local var=
iable of the exact type of the function&#39;s return type is eligible for c=
opy elision. A `return` statement of any other form is not eligible for eli=
sion.</div><div><br></div><div>If we start expanding that to more complex e=
xpressions, it becomes more difficult to look at a piece of code and know w=
hen elision is happening. In the example you give here, I have to track dow=
n `myclass` and look at its `+=3D` operator to know whether elision could h=
appen.<br></div><div><br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
 dir=3D"ltr"><div>so he should be able to verify it for other similar cases=
 (e.g. operator+=3D).</div><div><br></div><div>With this knowledge compiler=
 sees that we are actually=C2=A0returning an automatic variable and eliding=
 copy should be possible.</div><div><br></div><div>Regards,<br></div><div>M=
aciej<br></div></div></blockquote></div></blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3049c92e-8890-4a96-bf06-ab9bb199ff6e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3049c92e-8890-4a96-bf06-ab9bb199ff6e=
%40isocpp.org</a>.<br />

------=_Part_1485_1877160999.1534174935531--

------=_Part_1484_220559834.1534174935530--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 13 Aug 2018 17:04:57 -0700 (PDT)
Raw View
------=_Part_1822_1141593148.1534205097737
Content-Type: multipart/alternative;
 boundary="----=_Part_1823_1636203972.1534205097738"

------=_Part_1823_1636203972.1534205097738
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Monday, August 13, 2018 at 7:30:40 AM UTC-7, m.ce...@gmail.com wrote:
>
> Hi,
>
> can we update copy elision rules so it is allowed in all of following=20
> cases, and not just in 'concat1':
>
> myclass concat1(const myclass& lhs, const myclass& rhs){
>     myclass copy(lhs);
>     copy +=3D rhs;
>     return copy;}
>
>
> myclass concat2(const myclass& lhs, const myclass& rhs){
>     myclass copy(lhs);
>     return copy +=3D rhs;}
>
> myclass concat3(const myclass& lhs, const myclass& rhs){
>     return myclass(lhs) +=3D rhs;}
>
>
> Reasoning: given that we are gaining Assignable concept in C++20, compile=
r=20
> must be able to verify that addressof(lhs) =3D=3D addressof(lhs =3D rhs),
> so he should be able to verify it for other similar cases (e.g.=20
> operator+=3D).
>

Unfortunately, `Assignable` is a library-level concept (specified in the=20
<concepts> header of e.g. libc++); it's not "built in" at any level where=
=20
the compiler itself (e.g. Clang) could understand its ramifications.

It is also extremely unclear (at least to me, at least right now) whether=
=20
it would be legitimate for the compiler to optimize based on `Assignable`=
=20
in general. Because of fundamental limitations (I would say horrible=20
defects) in the C++2a approach to Concepts, `Assignable<T> =3D=3D true`=20
basically any time `T` has an assignment operator, regardless of what that=
=20
assignment operator actually does. So for example it would be `true` for=20
`std::vector<bool>::reference`, even though `std::vector<bool>::reference`=
=20
doesn't model the *semantic* concept of Assignable (AFAIK =E2=80=94 and if =
I'm=20
wrong, let's just pretend for the sake of this example that I'm right ;)).

I believe that there are at least three more-promising avenues to explore=
=20
in the core language itself:

- Some variety of [[clang::lifetimebound]], as proposed in P0936=20
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0936r0.pdf>,=20
could allow us to express the invariant that `operator=3D` returns a=20
reference to its first parameter. Elision could theoretically be guaranteed=
=20
in this case, I think, although it would be a huge hack.

- Contracts could express the same thing =E2=80=94 [[ensures return(x): &x =
=3D=3D=20
this]] =E2=80=94 although it would be hecka hard for the compiler to actual=
ly parse=20
out and *use* that information in practice; we certainly couldn't=20
*guarantee* elision in this case.

- The core language could simply specify as a special case that `return x =
=3D=20
expr;` should be treated exactly the same as `x =3D expr; return x;` for=20
elision purposes. This would be the cleanest, simplest-to-implement,=20
simplest-to-specify approach; but it would also be the least general.

P.S., my recent request for comment on P1155 "More implicit moves"=20
<https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/eeLS8vI=
05nM>=20
may be relevant to your interests, although it will not solve this=20
particular problem at all.

=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/313b5423-8eea-4095-8416-38b8199985c4%40isocpp.or=
g.

------=_Part_1823_1636203972.1534205097738
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Monday, August 13, 2018 at 7:30:40 AM UTC-7, m.ce...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Hi,<div><br></div><div>can we update copy elision rules so it is allowed i=
n all of following cases, and not just in &#39;concat1&#39;:</div><div><br>=
</div><div><pre style=3D"padding:5px;font-stretch:inherit;line-height:inher=
it;font-family:Consolas,Menlo,Monaco,&quot;Lucida Console&quot;,&quot;Liber=
ation Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans Mon=
o&quot;,&quot;Courier New&quot;,monospace,sans-serif;vertical-align:baselin=
e;width:auto;max-height:600px;overflow:auto;background-color:rgb(239,240,24=
1);color:rgb(57,51,24);word-wrap:normal"><code style=3D"font-style:inherit;=
font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:i=
nherit;font-family:Consolas,Menlo,Monaco,&quot;Lucida Console&quot;,&quot;L=
iberation Mono&quot;,&quot;DejaVu Sans Mono&quot;,&quot;Bitstream Vera Sans=
 Mono&quot;,&quot;Courier New&quot;,monospace,sans-serif;vertical-align:bas=
eline;white-space:inherit"><span style=3D"font-style:inherit;font-variant:i=
nherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">myclass concat1</=
span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inh=
erit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-=
align:baseline;color:rgb(48,51,54)">(</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(16,16,148)"=
>const</span><span style=3D"font-style:inherit;font-variant:inherit;font-we=
ight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)"> myclass</span><span style=3D"f=
ont-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inh=
erit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:=
rgb(48,51,54)">&amp;</span><span style=3D"font-style:inherit;font-variant:i=
nherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)"> lhs</span><span =
style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-s=
tretch:inherit;line-height:inherit;font-family:inherit;vertical-align:basel=
ine;color:rgb(48,51,54)">,</span><span style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;f=
ont-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;=
font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:i=
nherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> my=
class</span><span style=3D"font-style:inherit;font-variant:inherit;font-wei=
ght:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-=
style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit=
;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(=
48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    copy </span><span style=3D"font-style:inherit;font-variant:inherit;font=
-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inheri=
t;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy</span><span style=3D"font-style:inherit;font-variant:inhe=
rit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-famil=
y:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">


myclass concat2</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    myclass copy</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">);</span><span=
 style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> copy </span><span style=3D"font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;line-height:inherit;font-family:inherit;vertical-align:baselin=
e;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;font-va=
riant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;=
font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">;</span><s=
pan style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:b=
aseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">

myclass concat3</span><span style=3D"font-style:inherit;font-variant:inheri=
t;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:=
inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span style=3D=
"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:i=
nherit;line-height:inherit;font-family:inherit;vertical-align:baseline;colo=
r:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-varian=
t:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font=
-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> myclass</span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">&amp;</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
 lhs</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(48,51,54)">,</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit;font-w=
eight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(16,16,148)">const</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:r=
gb(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant=
:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&amp;</span><sp=
an style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</sp=
an><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
    </span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(16,16,148)">return</span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> myclass</span><span style=3D"font-style:inherit;font-variant:i=
nherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">(</span><span sty=
le=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stre=
tch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline=
;color:rgb(48,51,54)">lhs</span><span style=3D"font-style:inherit;font-vari=
ant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;fo=
nt-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">)</span><spa=
n style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font=
-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(48,51,54)"> </span><span style=3D"font-style:inherit;font-v=
ariant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit=
;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">+=3D</spa=
n><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inheri=
t;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-ali=
gn:baseline;color:rgb(48,51,54)"> rhs</span><span style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">=
;</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:=
inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertic=
al-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">}</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-hei=
ght:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)=
">
</span></code></pre></div><div><br></div><div>Reasoning: given that we are =
gaining Assignable concept in C++20, compiler must be able to verify that a=
ddressof(lhs) =3D=3D addressof(lhs =3D rhs),</div><div>so he should be able=
 to verify it for other similar cases (e.g. operator+=3D).</div></div></blo=
ckquote><div><br></div><div>Unfortunately, `Assignable` is a library-level =
concept (specified in the &lt;concepts&gt; header of e.g. libc++); it&#39;s=
 not &quot;built in&quot; at any level where the compiler itself (e.g. Clan=
g) could understand its ramifications.</div><div><br></div><div>It is also =
extremely unclear (at least to me, at least right now) whether it would be =
legitimate for the compiler to optimize based on `Assignable` in general. B=
ecause of fundamental limitations (I would say horrible defects) in the C++=
2a approach to Concepts, `Assignable&lt;T&gt; =3D=3D true` basically any ti=
me `T` has an assignment operator, regardless of what that assignment opera=
tor actually does. So for example it would be `true` for `std::vector&lt;bo=
ol&gt;::reference`, even though `std::vector&lt;bool&gt;::reference` doesn&=
#39;t model the <i>semantic</i> concept of Assignable (AFAIK =E2=80=94 and =
if I&#39;m wrong, let&#39;s just pretend for the sake of this example that =
I&#39;m right ;)).</div><div><br></div><div>I believe that there are at lea=
st three more-promising avenues to explore in the core language itself:</di=
v><div><br></div><div>- Some variety of [[clang::lifetimebound]], as propos=
ed in <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0=
936r0.pdf">P0936</a>, could allow us to express the invariant that `operato=
r=3D` returns a reference to its first parameter. Elision could theoretical=
ly be guaranteed in this case, I think, although it would be a huge hack.</=
div><div><br></div><div>- Contracts could express the same thing =E2=80=94 =
[[ensures return(x): &amp;x =3D=3D this]] =E2=80=94 although it would be he=
cka hard for the compiler to actually parse out and <i>use</i> that informa=
tion in practice; we certainly couldn&#39;t <i>guarantee</i> elision in thi=
s case.</div><div><br></div><div>- The core language could simply specify a=
s a special case that `return x =3D expr;` should be treated exactly the sa=
me as `x =3D expr; return x;` for elision purposes. This would be the clean=
est, simplest-to-implement, simplest-to-specify approach; but it would also=
 be the least general.</div><div><br></div><div>P.S., <a href=3D"https://gr=
oups.google.com/a/isocpp.org/forum/#!topic/std-proposals/eeLS8vI05nM">my re=
cent request for comment on P1155 &quot;More implicit moves&quot;</a> may b=
e relevant to your interests, although it will not solve this particular pr=
oblem at all.</div><div><br></div><div>=E2=80=93Arthur</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/313b5423-8eea-4095-8416-38b8199985c4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/313b5423-8eea-4095-8416-38b8199985c4=
%40isocpp.org</a>.<br />

------=_Part_1823_1636203972.1534205097738--

------=_Part_1822_1141593148.1534205097737--

.