Topic: Generalizing covariant return types
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 05:31:06 -0800 (PST)
Raw View
------=_Part_4139_1750230688.1419341466606
Content-Type: multipart/alternative;
boundary="----=_Part_4140_944489281.1419341466611"
------=_Part_4140_944489281.1419341466611
Content-Type: text/plain; charset=UTF-8
Currently, covariant return types are allowed under the restrictions placed
by [class.virtual]/7. I think these restrictions are unnecessarily severe.
For instance, the following is legal:
struct X { };
struct Y : X { };
struct A
{
virtual void X* foo();
virtual void X& bar();
};
struct B : A
{
virtual void Y* foo() override;
virtual void Y& bar() override;
};
However, replacing raw pointers by unique_ptr or shared_ptr is not allowed.
This makes little sense to me.
Given that B derives from A, I think that a function "T B::foo()" should be
allowed to override a function "U A::foo()" if and only if T is implicitly
convertible to U. Derived-to-base conversion would be just one particular
case of this rule.
What do you think?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4140_944489281.1419341466611
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently, covariant return types are allowed under the re=
strictions placed by [class.virtual]/7. I think these restrictions are unne=
cessarily severe.<br><br>For instance, the following is legal:<br><br><div =
class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><font color=3D"#000088"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span></font><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">X </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> Y =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> X </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> A<br></span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> X<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> fo</span><font colo=
r=3D"#666600"><span style=3D"color: #000;" class=3D"styled-by-prettify">o</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> X</span><font color=3D"#666600"=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span></fo=
nt><span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> B </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">:</span><font color=3D"#000000"><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> A</span></font><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">virtual</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> Y</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fo</sp=
an><font color=3D"#666600" style=3D"font-size: 13.3333330154419px;"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">o</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">override</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span></font><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> Y</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">override</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">};</span></div></code></div><br>However=
, replacing raw pointers by unique_ptr or shared_ptr is not allowed. This m=
akes little sense to me.<br><br>Given that B derives from A, I think that a=
function "T B::foo()" should be allowed to override a function "U A::foo()=
" if and only if T is implicitly convertible to U. Derived-to-base conversi=
on would be just one particular case of this rule.<br><br>What do you think=
?<br><br>Kind regards,<br><br>Andy<br><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4140_944489281.1419341466611--
------=_Part_4139_1750230688.1419341466606--
.
Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Tue, 23 Dec 2014 14:00:22 +0000
Raw View
--part5940-boundary-378279820-909400959
Content-Type: text/plain; charset=UTF-8
In a past post, I wanted to go further by providing some mechanism to allow conversion from const vector<Derived>& to const vector<Base>& (vector being an example). However. This somehow overlaps the domain of concepts and parametric polymorphism.
-----Original Message-----
From: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 05:31:06
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: [std-proposals] Generalizing covariant return types
Currently, covariant return types are allowed under the restrictions placed
by [class.virtual]/7. I think these restrictions are unnecessarily severe.
For instance, the following is legal:
struct X { };
struct Y : X { };
struct A
{
virtual void X* foo();
virtual void X& bar();
};
struct B : A
{
virtual void Y* foo() override;
virtual void Y& bar() override;
};
However, replacing raw pointers by unique_ptr or shared_ptr is not allowed.
This makes little sense to me.
Given that B derives from A, I think that a function "T B::foo()" should be
allowed to override a function "U A::foo()" if and only if T is implicitly
convertible to U. Derived-to-base conversion would be just one particular
case of this rule.
What do you think?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--part5940-boundary-378279820-909400959
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><=
meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type"></h=
ead><body>In a past post, I wanted to go further by providing some mechanis=
m to allow conversion from const vector<Derived>& to const vector<=
Base>& (vector being an example). However. This somehow overlaps the dom=
ain of concepts and parametric polymorphism. <hr/><div><b>From: </b> Andy P=
rowl <andy.prowl@gmail.com>
</div><div><b>Date: </b>Tue, 23 Dec 2014 05:31:06 -0800 (PST)</div><div><b>=
To: </b><std-proposals@isocpp.org></div><div><b>ReplyTo: </b> std-pro=
posals@isocpp.org
</div><div><b>Subject: </b>[std-proposals] Generalizing covariant return ty=
pes</div><div><br/></div><div dir=3D"ltr">Currently, covariant return types=
are allowed under the restrictions placed by [class.virtual]/7. I think th=
ese restrictions are unnecessarily severe.<br><br>For instance, the followi=
ng is legal:<br><br><div class=3D"prettyprint" style=3D"border: 1px solid r=
gb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 2=
50);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font color=
=3D"#000088"><span style=3D"color: #008;" class=3D"styled-by-prettify">stru=
ct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
</font><span style=3D"color: #000;" class=3D"styled-by-prettify">X </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> Y </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> X </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> A<br></span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> X</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> fo</span><font color=3D"#666600"><span style=3D"color: #000;" class=3D"=
styled-by-prettify">o</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></font><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">virtual</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">voi=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> X</span>=
<font color=3D"#666600"><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&</span></font><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> B </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">:</span><font color=3D"#000000"=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span></font>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> Y</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> fo</span><font color=3D"#666600" style=3D"font-size: 13.33=
33330154419px;"><span style=3D"color: #000;" class=3D"styled-by-prettify">o=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">override</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> Y</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> bar</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>override</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span></div><=
/code></div><br>However, replacing raw pointers by unique_ptr or shared_ptr=
is not allowed. This makes little sense to me.<br><br>Given that B derives=
from A, I think that a function "T B::foo()" should be allowed to override=
a function "U A::foo()" if and only if T is implicitly convertible to U. D=
erived-to-base conversion would be just one particular case of this rule.<b=
r><br>What do you think?<br><br>Kind regards,<br><br>Andy<br><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
</body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--part5940-boundary-378279820-909400959--
.
Author: David Krauss <potswa@gmail.com>
Date: Tue, 23 Dec 2014 22:29:12 +0800
Raw View
--Apple-Mail=_8422CFC7-6C81-4D2F-A6E0-CAD8C01CF1D9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2014=E2=80=9312=E2=80=9323, at 10:00 PM, Daniel Gutson <danielgutson@g=
mail.com> wrote:
>=20
> In a past post, I wanted to go further by providing some mechanism to all=
ow conversion from const vector<Derived>& to const vector<Base>& (vector be=
ing an example). However. This somehow overlaps the domain of concepts and =
parametric polymorphism.
Converting to a vector<Base> by value I=E2=80=99d understand, but how could=
you implement such a reference not to be dangling?
Assuming Andy=E2=80=99s rule is based on allowing user-defined conversions,=
you could create your own vector derivative with that functionality, witho=
ut extending the proposal further.
> What do you think?
The idea has been floating around for a while. Are there open questions rem=
aining? Has there been any formal write-up?
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_8422CFC7-6C81-4D2F-A6E0-CAD8C01CF1D9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2014=E2=80=9312=
=E2=80=9323, at 10:00 PM, Daniel Gutson <<a href=3D"mailto:danielgutson@=
gmail.com" class=3D"">danielgutson@gmail.com</a>> wrote:</div><br class=
=3D"Apple-interchange-newline"><div class=3D""><meta content=3D"text/html; =
charset=3Dutf-8" http-equiv=3D"Content-Type" class=3D""><div class=3D"">In =
a past post, I wanted to go further by providing some mechanism to allow co=
nversion from const vector<Derived>& to const vector<Base>&=
amp; (vector being an example). However. This somehow overlaps the domain o=
f concepts and parametric polymorphism. </div></div></blockquote><div><br c=
lass=3D""></div><div>Converting to a <font face=3D"Courier" class=3D"">vect=
or<Base></font> by value I=E2=80=99d understand, but how could you im=
plement such a reference not to be dangling?</div><div><br class=3D""></div=
><div>Assuming Andy=E2=80=99s rule is based on allowing user-defined conver=
sions, you could create your own <font face=3D"Courier" class=3D"">vector</=
font> derivative with that functionality, without extending the proposal fu=
rther.</div><br class=3D""><blockquote type=3D"cite" class=3D""><div class=
=3D""><div class=3D""><div class=3D"">What do you think?</div></div></div><=
/blockquote></div><br class=3D""><div class=3D"">The idea has been floating=
around for a while. Are there open questions remaining? Has there been any=
formal write-up?</div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_8422CFC7-6C81-4D2F-A6E0-CAD8C01CF1D9--
.
Author: Jean-Marc Bourguet <jm.bourguet@gmail.com>
Date: Tue, 23 Dec 2014 06:31:31 -0800 (PST)
Raw View
------=_Part_110_1442140814.1419345091290
Content-Type: multipart/alternative;
boundary="----=_Part_111_1560220856.1419345091290"
------=_Part_111_1560220856.1419345091290
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Le mardi 23 d=C3=A9cembre 2014 14:31:06 UTC+1, Andy Prowl a =C3=A9crit :
>
> Currently, covariant return types are allowed under the restrictions=20
> placed by [class.virtual]/7. I think these restrictions are unnecessarily=
=20
> severe.
>
> For instance, the following is legal:
>
> struct X { };
> struct Y : X { };
>
> struct A
> {
> virtual void X* foo();
> virtual void X& bar();
> };
>
> struct B : A
> {
> virtual void Y* foo() override;
> virtual void Y& bar() override;
> };
>
> However, replacing raw pointers by unique_ptr or shared_ptr is not=20
> allowed. This makes little sense to me.
>
> Given that B derives from A, I think that a function "T B::foo()" should=
=20
> be allowed to override a function "U A::foo()" if and only if T is=20
> implicitly convertible to U. Derived-to-base conversion would be just one=
=20
> particular case of this rule.
>
> What do you think?
>
I see where you are coming from. There are details that have to be=20
considered to be sure that it is implementable with a correct semantic.=20
The issue I see is that with implementation technique I know of covariant=
=20
return, not only T has to be implicitly convertible to U but from a U you=
=20
need to be able to reconstruct the T. Your example is compiled as
struct A
{
void X* foo() { return __foo(); }
void X& bar() { return __bar(); }
virtual X* __foo();
virtual X& __bar();
};
struct B : A
{
virtual X* __foo() override;
virtual X& __bar() override;
Y* foo() { return static_cast<Y*>(this->foo()); }
X& bar() { return static_cast<Y&>(this->bar()); }
};
implicit conversion don't guarantee this round trip. You will at least to=
=20
show that there is a way to compile with the semantic you want.
Yours
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_111_1560220856.1419345091290
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Le mardi 23 d=C3=A9cembre 2014 14:31:06 UTC+1, Andy Prowl =
a =C3=A9crit :<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">Currently, covariant return types are allowed under the restrictions =
placed by [class.virtual]/7. I think these restrictions are unnecessarily s=
evere.<br><br>For instance, the following is legal:<br><br><div style=3D"bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(2=
50,250,250)"><code><div><font color=3D"#000088"><span style=3D"color:#008">=
struct</span><span style=3D"color:#000"> </span></font><span style=3D"color=
:#000">X </span><span style=3D"color:#660">{</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">};</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#008">struct</span><span style=3D"color:#000=
"> Y </span><span style=3D"color:#660">:</span><span style=3D"color:#000"> =
X </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br>=
</span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> =
A<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000"><=
br> </span><span style=3D"color:#008">virtual</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">void</span><span style=
=3D"color:#000"> X</span><span style=3D"color:#660">*</span><span style=3D"=
color:#000"> fo</span><font color=3D"#666600"><span style=3D"color:#000">o<=
/span><span style=3D"color:#660">();</span><span style=3D"color:#000"><br><=
/span></font><span style=3D"color:#000"> </span><span style=3D=
"color:#008">virtual</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">void</span><span style=3D"color:#000"> X</span><font color=
=3D"#666600"><span style=3D"color:#660">&</span></font><span style=3D"c=
olor:#000"> bar</span><span style=3D"color:#660">();</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"co=
lor:#000"><br><br></span><span style=3D"color:#008">struct</span><span styl=
e=3D"color:#000"> B </span><span style=3D"color:#660">:</span><font color=
=3D"#000000"><span style=3D"color:#000"> A</span></font><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br> </span><span style=3D"color:#008">virtual</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">void</span><span=
style=3D"color:#000"> Y</span><span style=3D"color:#660">*</span><span sty=
le=3D"color:#000"> fo</span><font color=3D"#666600" style=3D"font-size:13.3=
333330154419px"><span style=3D"color:#000">o</span><span style=3D"color:#66=
0">()</span><span style=3D"color:#000"> </span><span style=3D"color:#008">o=
verride</span><span style=3D"color:#660">;</span></font><span style=3D"colo=
r:#000"><br> </span><span style=3D"color:#008">virtual</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">void</span><sp=
an style=3D"color:#000"> Y</span><span style=3D"color:#660">&</span><sp=
an style=3D"color:#000"> bar</span><span style=3D"color:#660">()</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">override</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">};</span></div></code></div><br>However, replacing r=
aw pointers by unique_ptr or shared_ptr is not allowed. This makes little s=
ense to me.<br><br>Given that B derives from A, I think that a function "T =
B::foo()" should be allowed to override a function "U A::foo()" if and only=
if T is implicitly convertible to U. Derived-to-base conversion would be j=
ust one particular case of this rule.<br><br>What do you think?<br></div></=
blockquote><div><br></div><div>I see where you are coming from. There=
are details that have to be considered to be sure that it is implementable=
with a correct semantic. The issue I see is that with implementation=
technique I know of covariant return, not only T has to be implicitly conv=
ertible to U but from a U you need to be able to reconstruct the T. Y=
our example is compiled as</div><div><br></div><div class=3D"prettyprint" s=
tyle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgr=
ound-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">s=
truct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A<br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> X</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __=
foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> X</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> bar</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __bar</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> X</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> __foo</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> X</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> __bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> B </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> A<br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">virtual</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> X</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> __foo</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">override</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> X</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> __bar</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">override</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> Y</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">static_cast</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">Y</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*>(</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">this</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">-></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">());</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br> X</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">static_cast</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">Y<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&>(<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">this</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">-></span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">bar</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">());</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></div></code></div><div><div><span style=3D"font-famil=
y: monospace; color: rgb(102, 102, 0); background-color: rgb(250, 250, 250)=
;"><br></span></div></div><div><span style=3D"background-color: rgb(250, 25=
0, 250);"><font color=3D"#666600" face=3D"monospace">implicit conversion do=
n't guarantee this round trip. You will at least to show th=
at there is a way to compile with the semantic you want.</font></span></div=
><div><span style=3D"background-color: rgb(250, 250, 250);"><font color=3D"=
#666600" face=3D"monospace"><br></font></span></div><div><span style=3D"bac=
kground-color: rgb(250, 250, 250);"><font color=3D"#666600" face=3D"monospa=
ce">Yours</font></span></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_111_1560220856.1419345091290--
------=_Part_110_1442140814.1419345091290--
.
Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Tue, 23 Dec 2014 14:33:47 +0000
Raw View
--part5873-boundary-144294060-1626647103
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
My bad, errata: I meant pointers:
Conversion from
const vector<Derived*>&
to
const vector<Base*>&
AFAIK C# has an equivalent facility.
-----Original Message-----
From: David Krauss <potswa@gmail.com>
Date: Tue, 23 Dec 2014 22:29:12=20
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: Re: [std-proposals] Generalizing covariant return types
> On 2014=E2=80=9312=E2=80=9323, at 10:00 PM, Daniel Gutson <danielgutson@g=
mail.com> wrote:
>=20
> In a past post, I wanted to go further by providing some mechanism to all=
ow conversion from const vector<Derived>& to const vector<Base>& (vector be=
ing an example). However. This somehow overlaps the domain of concepts and =
parametric polymorphism.
Converting to a vector<Base> by value I=E2=80=99d understand, but how could=
you implement such a reference not to be dangling?
Assuming Andy=E2=80=99s rule is based on allowing user-defined conversions,=
you could create your own vector derivative with that functionality, witho=
ut extending the proposal further.
> What do you think?
The idea has been floating around for a while. Are there open questions rem=
aining? Has there been any formal write-up?
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--part5873-boundary-144294060-1626647103
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">My bad, errata: I =
meant pointers:<br/> Conversion from<br/><br/> const vector<Derived*&g=
t;&<br/>to<br/> const vector<Base*>&<br/><br/>AFAIK C# has an equiva=
lent facility.<hr/><div><b>From: </b> David Krauss <potswa@gmail.com>
</div><div><b>Date: </b>Tue, 23 Dec 2014 22:29:12 +0800</div><div><b>To: </=
b><std-proposals@isocpp.org></div><div><b>ReplyTo: </b> std-proposals=
@isocpp.org
</div><div><b>Subject: </b>Re: [std-proposals] Generalizing covariant retur=
n types</div><div><br/></div><br class=3D""><div><blockquote type=3D"cite" =
class=3D""><div class=3D"">On 2014=E2=80=9312=E2=80=9323, at 10:00 PM, Dani=
el Gutson <<a href=3D"mailto:danielgutson@gmail.com" class=3D"">danielgu=
tson@gmail.com</a>> wrote:</div><br class=3D"Apple-interchange-newline">=
<div class=3D""><meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"=
Content-Type" class=3D""><div class=3D"">In a past post, I wanted to go fur=
ther by providing some mechanism to allow conversion from const vector<D=
erived>& to const vector<Base>& (vector being an example).=
However. This somehow overlaps the domain of concepts and parametric polym=
orphism. </div></div></blockquote><div><br class=3D""></div><div>Converting=
to a <font face=3D"Courier" class=3D"">vector<Base></font> by value =
I=E2=80=99d understand, but how could you implement such a reference not to=
be dangling?</div><div><br class=3D""></div><div>Assuming Andy=E2=80=99s r=
ule is based on allowing user-defined conversions, you could create your ow=
n <font face=3D"Courier" class=3D"">vector</font> derivative with that func=
tionality, without extending the proposal further.</div><br class=3D""><blo=
ckquote type=3D"cite" class=3D""><div class=3D""><div class=3D""><div class=
=3D"">What do you think?</div></div></div></blockquote></div><br class=3D""=
><div class=3D"">The idea has been floating around for a while. Are there o=
pen questions remaining? Has there been any formal write-up?</div></body></=
html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--part5873-boundary-144294060-1626647103--
.
Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Tue, 23 Dec 2014 14:40:22 +0000
Raw View
--part5895-boundary-1565200514-1748824356
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
FWIW,
http://msdn.microsoft.com/en-us/library/ee207183.aspx
Of course it's completely far in terms of implementation, I just want to sh=
ow what other languages (that I very much dislike) do. Additionally, it see=
ms they only allow this for arrays rather than for generic containers.
I didn't go much further to explore feasibility of a library solution.
-----Original Message-----
From: "Daniel Gutson" <danielgutson@gmail.com>
Date: Tue, 23 Dec 2014 14:33:47=20
To: <std-proposals@isocpp.org>
Reply-To: danielgutson@gmail.com
Subject: Re: [std-proposals] Generalizing covariant return types
My bad, errata: I meant pointers:
Conversion from
const vector<Derived*>&
to
const vector<Base*>&
AFAIK C# has an equivalent facility.
-----Original Message-----
From: David Krauss <potswa@gmail.com>
Date: Tue, 23 Dec 2014 22:29:12=20
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: Re: [std-proposals] Generalizing covariant return types
> On 2014=E2=80=9312=E2=80=9323, at 10:00 PM, Daniel Gutson <danielgutson@g=
mail.com> wrote:
>=20
> In a past post, I wanted to go further by providing some mechanism to all=
ow conversion from const vector<Derived>& to const vector<Base>& (vector be=
ing an example). However. This somehow overlaps the domain of concepts and =
parametric polymorphism.
Converting to a vector<Base> by value I=E2=80=99d understand, but how could=
you implement such a reference not to be dangling?
Assuming Andy=E2=80=99s rule is based on allowing user-defined conversions,=
you could create your own vector derivative with that functionality, witho=
ut extending the proposal further.
> What do you think?
The idea has been floating around for a while. Are there open questions rem=
aining? Has there been any formal write-up?
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--part5895-boundary-1565200514-1748824356
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">FWIW,<br/> http:/=
/msdn.microsoft.com/en-us/library/ee207183.aspx<br/><br/>Of course it's com=
pletely far in terms of implementation, I just want to show what other lang=
uages (that I very much dislike) do. Additionally, it seems they only allow=
this for arrays rather than for generic containers.<br/>I didn't go much f=
urther to explore feasibility of a library solution.<hr/><div><b>From: </b>=
"Daniel Gutson" <danielgutson@gmail.com>
</div><div><b>Date: </b>Tue, 23 Dec 2014 14:33:47 +0000</div><div><b>To: </=
b><std-proposals@isocpp.org></div><div><b>ReplyTo: </b> danielgutson@=
gmail.com
</div><div><b>Subject: </b>Re: [std-proposals] Generalizing covariant retur=
n types</div><div><br/></div>My bad, errata: I meant pointers:<br/> Conver=
sion from<br/><br/> const vector<Derived*>&<br/>to<br/> const vecto=
r<Base*>&<br/><br/>AFAIK C# has an equivalent facility.<hr/><div><b>F=
rom: </b> David Krauss <potswa@gmail.com>
</div><div><b>Date: </b>Tue, 23 Dec 2014 22:29:12 +0800</div><div><b>To: </=
b><std-proposals@isocpp.org></div><div><b>ReplyTo: </b> std-proposals=
@isocpp.org
</div><div><b>Subject: </b>Re: [std-proposals] Generalizing covariant retur=
n types</div><div><br/></div><br class=3D""><div><blockquote type=3D"cite" =
class=3D""><div class=3D"">On 2014=E2=80=9312=E2=80=9323, at 10:00 PM, Dani=
el Gutson <<a href=3D"mailto:danielgutson@gmail.com" class=3D"">danielgu=
tson@gmail.com</a>> wrote:</div><br class=3D"Apple-interchange-newline">=
<div class=3D""><meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"=
Content-Type" class=3D""><div class=3D"">In a past post, I wanted to go fur=
ther by providing some mechanism to allow conversion from const vector<D=
erived>& to const vector<Base>& (vector being an example).=
However. This somehow overlaps the domain of concepts and parametric polym=
orphism. </div></div></blockquote><div><br class=3D""></div><div>Converting=
to a <font face=3D"Courier" class=3D"">vector<Base></font> by value =
I=E2=80=99d understand, but how could you implement such a reference not to=
be dangling?</div><div><br class=3D""></div><div>Assuming Andy=E2=80=99s r=
ule is based on allowing user-defined conversions, you could create your ow=
n <font face=3D"Courier" class=3D"">vector</font> derivative with that func=
tionality, without extending the proposal further.</div><br class=3D""><blo=
ckquote type=3D"cite" class=3D""><div class=3D""><div class=3D""><div class=
=3D"">What do you think?</div></div></div></blockquote></div><br class=3D""=
><div class=3D"">The idea has been floating around for a while. Are there o=
pen questions remaining? Has there been any formal write-up?</div></body></=
html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--part5895-boundary-1565200514-1748824356--
.
Author: Jean-Marc Bourguet <jm.bourguet@gmail.com>
Date: Tue, 23 Dec 2014 06:50:45 -0800 (PST)
Raw View
------=_Part_164_1023439687.1419346245161
Content-Type: multipart/alternative;
boundary="----=_Part_165_1754290586.1419346245161"
------=_Part_165_1754290586.1419346245161
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Le mardi 23 d=C3=A9cembre 2014 15:33:52 UTC+1, dgutson a =C3=A9crit :
>
> My bad, errata: I meant pointers:
> Conversion from
>
> const vector<Derived*>&
> to
> const vector<Base*>&
>
> AFAIK C# has an equivalent facility.
>
This won't work with multiple inheritance. If Derived inherit from B1 and=
=20
B2, you can't have vector<Derived*> be a valid representation for both=20
vector<B1*> and vector<B2*>. The conversion of Derived* to at least one of=
=20
B1* or B2* apply an offset to the pointer.
Yours,=20
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_165_1754290586.1419346245161
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>Le mardi 23 d=C3=A9cembre 2014 15:33:52 UTC+1, dgu=
tson a =C3=A9crit :<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div s=
tyle=3D"word-wrap:break-word">My bad, errata: I meant pointers:<br> Conver=
sion from<br><br> const vector<Derived*>&<br>to<br> const vecto=
r<Base*>&<br><br>AFAIK C# has an equivalent facility.</div></bloc=
kquote><div><br></div><div>This won't work with multiple inheritance.  =
;If Derived inherit from B1 and B2, you can't have vector<Derived*> b=
e a valid representation for both vector<B1*> and vector<B2*>. =
The conversion of Derived* to at least one of B1* or B2* apply an off=
set to the pointer.</div><div><br></div><div>Yours, </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_165_1754290586.1419346245161--
------=_Part_164_1023439687.1419346245161--
.
Author: David Krauss <potswa@gmail.com>
Date: Tue, 23 Dec 2014 23:16:22 +0800
Raw View
--Apple-Mail=_7647509A-1F31-42C3-8FDE-2BDACE31538A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2014=E2=80=9312=E2=80=9323, at 10:31 PM, Jean-Marc Bourguet <jm.bourgu=
et@gmail.com> wrote:
>=20
> Your example is compiled as
If I=E2=80=99m grokking this correctly, current implementations leave the r=
everse conversion to the callee to avoid extra trampoline subroutines. The =
caller knows the correct derived return type, and when it can obtain that f=
rom the base type, the virtual callee doesn=E2=80=99t need to specialize on=
each derived type.
The cost of the extra trampolines is an extra vtable entry and a function c=
ontaining the implicit cast code, per level of covariant overriding. It sou=
nds reasonable to me, in any case users can avoid paying for it by not usin=
g it. Anyway, I don=E2=80=99t think that executing two implicit conversion =
functions is acceptable as a user-visible semantic.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_7647509A-1F31-42C3-8FDE-2BDACE31538A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2014=E2=80=9312=
=E2=80=9323, at 10:31 PM, Jean-Marc Bourguet <<a href=3D"mailto:jm.bourg=
uet@gmail.com" class=3D"">jm.bourguet@gmail.com</a>> wrote:</div><br cla=
ss=3D"Apple-interchange-newline"><div class=3D""><span style=3D"font-family=
: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; fon=
t-weight: normal; letter-spacing: normal; line-height: normal; orphans: aut=
o; text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; fl=
oat: none; display: inline !important;" class=3D"">Your example is compiled=
as</span></div></blockquote></div><br class=3D""><div class=3D"">If I=E2=
=80=99m grokking this correctly, current implementations leave the reverse =
conversion to the callee to avoid extra trampoline subroutines. The caller =
knows the correct derived return type, and when it can obtain that from the=
base type, the virtual callee doesn=E2=80=99t need to specialize on each d=
erived type.</div><div class=3D""><br class=3D""></div><div class=3D"">The =
cost of the extra trampolines is an extra vtable entry and a function conta=
ining the implicit cast code, per level of covariant overriding. It sounds =
reasonable to me, in any case users can avoid paying for it by not using it=
.. Anyway, I don=E2=80=99t think that executing two implicit conversion func=
tions is acceptable as a user-visible semantic.</div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_7647509A-1F31-42C3-8FDE-2BDACE31538A--
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 07:19:11 -0800 (PST)
Raw View
------=_Part_4406_1160056581.1419347951279
Content-Type: multipart/alternative;
boundary="----=_Part_4407_66925754.1419347951279"
------=_Part_4407_66925754.1419347951279
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 3:31:31 PM UTC+1, Jean-Marc Bourguet wrote
I see where you are coming from. There are details that have to be
> considered to be sure that it is implementable with a correct semantic.
> The issue I see is that with implementation technique I know of covariant
> return, not only T has to be implicitly convertible to U but from a U you
> need to be able to reconstruct the T. Your example is compiled as
>
> struct A
> {
> void X* foo() { return __foo(); }
> void X& bar() { return __bar(); }
> virtual X* __foo();
> virtual X& __bar();
> };
>
> struct B : A
> {
> virtual X* __foo() override;
> virtual X& __bar() override;
> Y* foo() { return static_cast<Y*>(this->foo()); }
> X& bar() { return static_cast<Y&>(this->bar()); }
> };
>
> implicit conversion don't guarantee this round trip. You will at least to
> show that there is a way to compile with the semantic you want.
>
I am not a compiler guy, but I thought it would be implemented more or less
this way (borrowing the structure of the example you sketched, and assuming
T is convertible to U):
struct A
{
void U foo() { return __foo(); }
virtual U __foo();
};
struct B : A
{
virtual U __foo() override { return U{foo()}; }
T foo();
};
Thank you for your comments.
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4407_66925754.1419347951279
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 3:31:31 PM UTC+1, Jean-Marc =
Bourguet wrote<div><br><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div>I see where you are coming from. There are details tha=
t have to be considered to be sure that it is implementable with a correct =
semantic. The issue I see is that with implementation technique I kno=
w of covariant return, not only T has to be implicitly convertible to U but=
from a U you need to be able to reconstruct the T. Your example is c=
ompiled as</div><div><br></div><div style=3D"border:1px solid rgb(187,187,1=
87);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><spa=
n style=3D"color:#008">struct</span><span style=3D"color:#000"> A<br></span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br> &=
nbsp; </span><span style=3D"color:#008">void</span><span style=3D"color:#00=
0"> X</span><span style=3D"color:#660">*</span><span style=3D"color:#000"> =
foo</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">return</span><span style=3D"color:#000"> __foo<=
/span><span style=3D"color:#660">();</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#008">void</span><span style=3D"color:#=
000"> X</span><span style=3D"color:#660">&</span><span style=3D"color:#=
000"> bar</span><span style=3D"color:#660">()</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">return</span><span style=3D"color:#000"> =
__bar</span><span style=3D"color:#660">();</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#008">virtual</span><span style=
=3D"color:#000"> X</span><span style=3D"color:#660">*</span><span style=3D"=
color:#000"> __foo</span><span style=3D"color:#660">();</span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#008">virtual=
</span><span style=3D"color:#000"> X</span><span style=3D"color:#660">&=
</span><span style=3D"color:#000"> __bar</span><span style=3D"color:#660">(=
);</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}=
;</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#008=
">struct</span><span style=3D"color:#000"> B </span><span style=3D"color:#6=
60">:</span><span style=3D"color:#000"> A<br></span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"><br> </span><span style=
=3D"color:#008">virtual</span><span style=3D"color:#000"> X</span><span sty=
le=3D"color:#660">*</span><span style=3D"color:#000"> __foo</span><span sty=
le=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">override</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br> </span><span style=3D"color:#008">virtu=
al</span><span style=3D"color:#000"> X</span><span style=3D"color:#660">&am=
p;</span><span style=3D"color:#000"> __bar</span><span style=3D"color:#660"=
>()</span><span style=3D"color:#000"> </span><span style=3D"color:#008">ove=
rride</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br> Y</span><span style=3D"color:#660">*</span><span style=3D"=
color:#000"> foo</span><span style=3D"color:#660">()</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">return</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">static_cast</span><span style=3D"c=
olor:#660"><</span><span style=3D"color:#000">Y</span><span style=3D"col=
or:#660">*>(</span><span style=3D"color:#008">this</span><span style=3D"=
color:#660">-></span><span style=3D"color:#000">foo</span><span style=3D=
"color:#660">());</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">}</span><span style=3D"color:#000"><br> X</span><sp=
an style=3D"color:#660">&</span><span style=3D"color:#000"> bar</span><=
span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">return</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">static_cast</span><span style=3D"color:#660"><</span><s=
pan style=3D"color:#000">Y</span><span style=3D"color:#660">&>(</spa=
n><span style=3D"color:#008">this</span><span style=3D"color:#660">-></s=
pan><span style=3D"color:#000">bar</span><span style=3D"color:#660">());</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">}</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br></span></div></code></div><div><div><span styl=
e=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,25=
0,250)"><br></span></div></div><div><span style=3D"background-color:rgb(250=
,250,250)"><font color=3D"#666600" face=3D"monospace">implicit conversion d=
on't guarantee this round trip. You will at least to show t=
hat there is a way to compile with the semantic you want.</font></span></di=
v></div></blockquote><div><br>I am not a compiler guy, but I thought it wou=
ld be implemented more or less this way (borrowing the structure of the exa=
mple you sketched, and assuming T is convertible to U):</div></div><div><br=
></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, =
187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> A<br></span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> U foo</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> __foo</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> U __foo</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> B </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A<br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> U __foo</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">override</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">foo</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">()};</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> T foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">};</span></div></code></div><div><br></di=
v></div><div>Thank you for your comments.<br><br>Kind regards,<br><br>Andy<=
/div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4407_66925754.1419347951279--
------=_Part_4406_1160056581.1419347951279--
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 07:22:09 -0800 (PST)
Raw View
------=_Part_97_846831165.1419348129458
Content-Type: multipart/alternative;
boundary="----=_Part_98_1317261486.1419348129458"
------=_Part_98_1317261486.1419348129458
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 3:29:21 PM UTC+1, David Krauss wrote:
>
>
> The idea has been floating around for a while. Are there open questions
> remaining? Has there been any formal write-up?
>
I did some quick research before posting here and did not find anything. I
myself haven't written anything formal - I first wanted to get feedback
from expert users.
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_98_1317261486.1419348129458
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 3:29:21 PM UTC+1, David Krau=
ss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wr=
ap:break-word"><br><div>The idea has been floating around for a while. Are =
there open questions remaining? Has there been any formal write-up?</div></=
div></blockquote><div><br>I did some quick research before posting here and=
did not find anything. I myself haven't written anything formal - I first =
wanted to get feedback from expert users.<br><br>Kind regards,<br><br>Andy<=
/div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_98_1317261486.1419348129458--
------=_Part_97_846831165.1419348129458--
.
Author: Farid Mehrabi <farid.mehrabi@gmail.com>
Date: Tue, 23 Dec 2014 18:58:05 +0330
Raw View
--047d7bfcf25a8316fc050ae3d304
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2014-12-23 18:01 GMT+03:30 Jean-Marc Bourguet <jm.bourguet@gmail.com>:
> Le mardi 23 d=C3=A9cembre 2014 14:31:06 UTC+1, Andy Prowl a =C3=A9crit :
>>
>> Currently, covariant return types are allowed under the restrictions
>> placed by [class.virtual]/7. I think these restrictions are unnecessaril=
y
>> severe.
>>
>> For instance, the following is legal:
>>
>> struct X { };
>> struct Y : X { };
>>
>> struct A
>> {
>> virtual void X* foo();
>> virtual void X& bar();
>> };
>>
>> struct B : A
>> {
>> virtual void Y* foo() override;
>> virtual void Y& bar() override;
>> };
>>
>> However, replacing raw pointers by unique_ptr or shared_ptr is not
>> allowed. This makes little sense to me.
>>
>> Given that B derives from A, I think that a function "T B::foo()" should
>> be allowed to override a function "U A::foo()" if and only if T is
>> implicitly convertible to U. Derived-to-base conversion would be just on=
e
>> particular case of this rule.
>>
>> What do you think?
>>
>
> I see where you are coming from. There are details that have to be
> considered to be sure that it is implementable with a correct semantic.
> The issue I see is that with implementation technique I know of covariant
> return, not only T has to be implicitly convertible to U but from a U you
> need to be able to reconstruct the T. Your example is compiled as
>
> struct A
> {
> void X* foo() { return __foo(); }
> void X& bar() { return __bar(); }
> virtual X* __foo();
> virtual X& __bar();
> };
>
> struct B : A
> {
> virtual X* __foo() override;
> virtual X& __bar() override;
> Y* foo() { return static_cast<Y*>(this->foo()); }
> X& bar() { return static_cast<Y&>(this->bar()); }
> };
>
> implicit conversion don't guarantee this round trip. You will at least t=
o
> show that there is a way to compile with the semantic you want.
>
> Yours
>
I think you got it upside down:
struct A
{
X* foo() ;
X& bar() ;
X proposal() ;
//implement virtual:
virtual X* __foo(){ return foo(); }
virtual X& __bar(){ return bar(); }
virtual X& __proposal(){ return proposal(); }
};
struct B : A
{
Y* foo() ;
Y& bar() ;
Y proposal() ;
//implement virtual:
virtual X* __foo() override { return static_cast<X*>(this->foo()); };
virtual X& __bar() override { return static_cast<X&>(this->bar()); };
virtual X __proposal() override { return static_cast<X>(this->proposal
()); };
};
regards,
FM.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--047d7bfcf25a8316fc050ae3d304
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"rtl"><br><div class=3D"gmail_extra"><div dir=3D"ltr"><br><div c=
lass=3D"gmail_quote">2014-12-23 18:01 GMT+03:30 Jean-Marc Bourguet <span di=
r=3D"ltr"><<a href=3D"mailto:jm.bourguet@gmail.com" target=3D"_blank">jm=
..bourguet@gmail.com</a>></span>:<br><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb=
(204,204,204);border-left-style:solid;padding-left:1ex">Le mardi 23 d=C3=A9=
cembre 2014 14:31:06 UTC+1, Andy Prowl a =C3=A9crit=C2=A0:<span class=3D"">=
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr">Currently, covariant return types are all=
owed under the restrictions placed by [class.virtual]/7. I think these rest=
rictions are unnecessarily severe.<br><br>For instance, the following is le=
gal:<br><br><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#000088"=
><span style=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0=
,0,0)"> </span></font><span style=3D"color:rgb(0,0,0)">X </span><span style=
=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,=
0)"><br></span><span style=3D"color:rgb(0,0,136)">struct</span><span style=
=3D"color:rgb(0,0,0)"> Y </span><span style=3D"color:rgb(102,102,0)">:</spa=
n><span style=3D"color:rgb(0,0,0)"> X </span><span style=3D"color:rgb(102,1=
02,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br><br></span>=
<span style=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,=
0,0)"> A<br></span><span style=3D"color:rgb(102,102,0)">{</span><span style=
=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0=
,136)">virtual</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> X</spa=
n><span style=3D"color:rgb(102,102,0)">*</span><span style=3D"color:rgb(0,0=
,0)"> fo</span><font color=3D"#666600"><span style=3D"color:rgb(0,0,0)">o</=
span><span style=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rg=
b(0,0,0)"><br></span></font><span style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 =
</span><span style=3D"color:rgb(0,0,136)">virtual</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">void</span><span s=
tyle=3D"color:rgb(0,0,0)"> X</span><font color=3D"#666600"><span style=3D"c=
olor:rgb(102,102,0)">&</span></font><span style=3D"color:rgb(0,0,0)"> b=
ar</span><span style=3D"color:rgb(102,102,0)">();</span><span style=3D"colo=
r:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">};</span><spa=
n style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,13=
6)">struct</span><span style=3D"color:rgb(0,0,0)"> B </span><span style=3D"=
color:rgb(102,102,0)">:</span><font color=3D"#000000"><span style=3D"color:=
rgb(0,0,0)"> A</span></font><span style=3D"color:rgb(0,0,0)"><br></span><sp=
an style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">virtual</span><=
span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">=
void</span><span style=3D"color:rgb(0,0,0)"> Y</span><span style=3D"color:r=
gb(102,102,0)">*</span><span style=3D"color:rgb(0,0,0)"> fo</span><font col=
or=3D"#666600" style=3D"font-size:13.3333330154419px"><span style=3D"color:=
rgb(0,0,0)">o</span><span style=3D"color:rgb(102,102,0)">()</span><span sty=
le=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">override=
</span><span style=3D"color:rgb(102,102,0)">;</span></font><span style=3D"c=
olor:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)=
">virtual</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> Y</span><span=
style=3D"color:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)=
"> bar</span><span style=3D"color:rgb(102,102,0)">()</span><span style=3D"c=
olor:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">override</span>=
<span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0=
)"><br></span><span style=3D"color:rgb(102,102,0)">};</span></div></code></=
div><br>However, replacing raw pointers by unique_ptr or shared_ptr is not =
allowed. This makes little sense to me.<br><br>Given that B derives from A,=
I think that a function "T B::foo()" should be allowed to overri=
de a function "U A::foo()" if and only if T is implicitly convert=
ible to U. Derived-to-base conversion would be just one particular case of =
this rule.<br><br>What do you think?<br></div></blockquote><div><br></div><=
/span><div>I see where you are coming from.=C2=A0 There are details that ha=
ve to be considered to be sure that it is implementable with a correct sema=
ntic.=C2=A0 The issue I see is that with implementation technique I know of=
covariant return, not only T has to be implicitly convertible to U but fro=
m a U you need to be able to reconstruct the T.=C2=A0 Your example is compi=
led as</div><div><br></div><div style=3D"border:1px solid rgb(187,187,187);=
word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span st=
yle=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> A=
<br></span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"colo=
r:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">v=
oid</span><span style=3D"color:rgb(0,0,0)"> X</span><span style=3D"color:rg=
b(102,102,0)">*</span><span style=3D"color:rgb(0,0,0)"> foo</span><span sty=
le=3D"color:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </sp=
an><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,=
0,0)"> </span><span style=3D"color:rgb(0,0,136)">return</span><span style=
=3D"color:rgb(0,0,0)"> __foo</span><span style=3D"color:rgb(102,102,0)">();=
</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(10=
2,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0=
,0)"> X</span><span style=3D"color:rgb(102,102,0)">&</span><span style=
=3D"color:rgb(0,0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">()</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,1=
02,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> __bar</span>=
<span style=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0=
,0)"> </span><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"co=
lor:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)"=
>virtual</span><span style=3D"color:rgb(0,0,0)"> X</span><span style=3D"col=
or:rgb(102,102,0)">*</span><span style=3D"color:rgb(0,0,0)"> __foo</span><s=
pan style=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0=
)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">virtual</spa=
n><span style=3D"color:rgb(0,0,0)"> X</span><span style=3D"color:rgb(102,10=
2,0)">&</span><span style=3D"color:rgb(0,0,0)"> __bar</span><span style=
=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><br></=
span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb=
(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,136)">struct</span><sp=
an style=3D"color:rgb(0,0,0)"> B </span><span style=3D"color:rgb(102,102,0)=
">:</span><span style=3D"color:rgb(0,0,0)"> A<br></span><span style=3D"colo=
r:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:rgb(0,0,136)">virtual</span><span style=3D"=
color:rgb(0,0,0)"> X</span><span style=3D"color:rgb(102,102,0)">*</span><sp=
an style=3D"color:rgb(0,0,0)"> __foo</span><span style=3D"color:rgb(102,102=
,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(0,0,136)">override</span><span style=3D"color:rgb(102,102,0)">;</span>=
<span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor:rgb(0,0,136)">virtual</span><span style=3D"color:rgb(0,0,0)"> X</span><=
span style=3D"color:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,=
0,0)"> __bar</span><span style=3D"color:rgb(102,102,0)">()</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">override<=
/span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb=
(0,0,0)"><br>=C2=A0 =C2=A0 Y</span><span style=3D"color:rgb(102,102,0)">*</=
span><span style=3D"color:rgb(0,0,0)"> foo</span><span style=3D"color:rgb(1=
02,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D=
"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,0,136)">static_cast</span><span style=
=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">Y</sp=
an><span style=3D"color:rgb(102,102,0)">*>(</span><span style=3D"color:r=
gb(0,0,136)">this</span><span style=3D"color:rgb(102,102,0)">-></span><s=
pan style=3D"color:rgb(0,0,0)">foo</span><span style=3D"color:rgb(102,102,0=
)">());</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0=
X</span><span style=3D"color:rgb(102,102,0)">&</span><span style=3D"co=
lor:rgb(0,0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">()</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)"=
>{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(=
0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,0,136)">static_cast</span><span style=3D"color:rgb(102,102,=
0)"><</span><span style=3D"color:rgb(0,0,0)">Y</span><span style=3D"colo=
r:rgb(102,102,0)">&>(</span><span style=3D"color:rgb(0,0,136)">this<=
/span><span style=3D"color:rgb(102,102,0)">-></span><span style=3D"color=
:rgb(0,0,0)">bar</span><span style=3D"color:rgb(102,102,0)">());</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}=
</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb=
(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br></span></div></c=
ode></div><div><div><span style=3D"font-family:monospace;color:rgb(102,102,=
0);background-color:rgb(250,250,250)"><br></span></div></div><div><span sty=
le=3D"background-color:rgb(250,250,250)"><font color=3D"#666600" face=3D"mo=
nospace">implicit conversion don't=C2=A0guarantee=C2=A0this round trip.=
=C2=A0 You will at least to show that there is a way to compile with the se=
mantic you want.</font></span></div><div><span style=3D"background-color:rg=
b(250,250,250)"><font color=3D"#666600" face=3D"monospace"><br></font></spa=
n></div><div><span style=3D"background-color:rgb(250,250,250)"><font color=
=3D"#666600" face=3D"monospace">Yours</font></span></div></blockquote><div>=
<br></div><div>I think you got it upside down:=C2=A0</div></div><div class=
=3D""><div class=3D"h5">
<p></p></div></div></div><div class=3D"gmail_signature"><div dir=3D"ltr"><b=
r></div><div dir=3D"ltr"><span style=3D"font-family:monospace;color:rgb(0,0=
,136);background-color:rgb(250,250,250)">struct</span><span style=3D"font-f=
amily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0A=
<br></span><span style=3D"font-family:monospace;color:rgb(102,102,0);backgr=
ound-color:rgb(250,250,250)">{</span><span style=3D"font-family:monospace;c=
olor:rgb(0,0,0);background-color:rgb(250,250,250)"><br>=C2=A0 =C2=A0=C2=A0<=
/span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-colo=
r:rgb(250,250,250)">X</span><span style=3D"font-family:monospace;color:rgb(=
102,102,0);background-color:rgb(250,250,250)">*</span><span style=3D"font-f=
amily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0f=
oo</span><span style=3D"font-family:monospace;color:rgb(102,102,0);backgrou=
nd-color:rgb(250,250,250)">()</span><span style=3D"font-family:monospace;co=
lor:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span style=
=3D"font-family:monospace;background-color:rgb(250,250,250)"><font color=3D=
"#666600">;</font></span><span style=3D"font-family:monospace;color:rgb(0,0=
,0);background-color:rgb(250,250,250)"><br></span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0 =C2=
=A0=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backg=
round-color:rgb(250,250,250)">X</span><span style=3D"font-family:monospace;=
color:rgb(102,102,0);background-color:rgb(250,250,250)">&</span><span s=
tyle=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250=
,250)">=C2=A0bar</span><span style=3D"font-family:monospace;color:rgb(102,1=
02,0);background-color:rgb(250,250,250)">()</span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</spa=
n><span style=3D"font-family:monospace;background-color:rgb(250,250,250)"><=
font color=3D"#666600">;</font></span><span style=3D"font-family:monospace;=
color:rgb(0,0,0);background-color:rgb(250,250,250)"><br></span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)">=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-family:monospace;color:rgb=
(0,0,0);background-color:rgb(250,250,250)">X</span><span style=3D"font-fami=
ly:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</sp=
an><span style=3D"background-color:rgb(250,250,250)"><font color=3D"#000000=
" face=3D"monospace">proposal</font><font color=3D"#666600" face=3D"monospa=
ce">()</font></span><span style=3D"font-family:monospace;color:rgb(0,0,0);b=
ackground-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:m=
onospace;background-color:rgb(250,250,250)"><font color=3D"#666600">;</font=
></span></div><div dir=3D"ltr"><span style=3D"font-family:monospace;backgro=
und-color:rgb(250,250,250)"><font color=3D"#666600">//implement virtual:<br=
></font></span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgr=
ound-color:rgb(250,250,250)">=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-=
family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">virt=
ual</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-=
color:rgb(250,250,250)">=C2=A0X</span><span style=3D"font-family:monospace;=
color:rgb(102,102,0);background-color:rgb(250,250,250)">*</span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)">=C2=A0__foo</span><span style=3D"font-family:monospace;color:rgb(102,102=
,0);background-color:rgb(250,250,250)">()</span><span style=3D"font-family:=
monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">{</span><=
span style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(2=
50,250,250)">=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,=
0,136);background-color:rgb(250,250,250)">return</span><span style=3D"font-=
family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0=
foo</span><span style=3D"font-family:monospace;color:rgb(102,102,0);backgro=
und-color:rgb(250,250,250)">();</span><span style=3D"font-family:monospace;=
color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span styl=
e=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,25=
0,250)">}</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backg=
round-color:rgb(250,250,250)"><br></span><span style=3D"font-family:monospa=
ce;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0 =C2=A0=C2=A0<=
/span><span style=3D"font-family:monospace;color:rgb(0,0,136);background-co=
lor:rgb(250,250,250)">virtual</span><span style=3D"font-family:monospace;co=
lor:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0X</span><span style=
=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250=
,250)">&</span><span style=3D"font-family:monospace;color:rgb(0,0,0);ba=
ckground-color:rgb(250,250,250)">=C2=A0__bar</span><span style=3D"font-fami=
ly:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">()</sp=
an><span style=3D"font-family:monospace;color:rgb(102,102,0);background-col=
or:rgb(250,250,250)">{</span><span style=3D"font-family:monospace;color:rgb=
(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font=
-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">ret=
urn=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backg=
round-color:rgb(250,250,250)">bar</span><span style=3D"font-family:monospac=
e;color:rgb(102,102,0);background-color:rgb(250,250,250)">();</span><span s=
tyle=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250=
,250)">=C2=A0</span><span style=3D"font-family:monospace;color:rgb(102,102,=
0);background-color:rgb(250,250,250)">}</span><span style=3D"font-family:mo=
nospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br></span><spa=
n style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,=
250,250)">=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-family:monospace;co=
lor:rgb(0,0,136);background-color:rgb(250,250,250)">virtual</span><span sty=
le=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,2=
50)">=C2=A0X</span><span style=3D"font-family:monospace;color:rgb(102,102,0=
);background-color:rgb(250,250,250)">&</span><span style=3D"font-family=
:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0__</sp=
an><span style=3D"color:rgb(0,0,0);font-family:monospace;background-color:r=
gb(250,250,250)">proposal</span><span style=3D"font-family:monospace;color:=
rgb(102,102,0);background-color:rgb(250,250,250)">()</span><span style=3D"f=
ont-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)=
">{</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-=
color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:monospace;c=
olor:rgb(0,0,136);background-color:rgb(250,250,250)">return</span><span sty=
le=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,2=
50)">=C2=A0</span><span style=3D"color:rgb(0,0,0);font-family:monospace;bac=
kground-color:rgb(250,250,250)">proposal</span><span style=3D"font-family:m=
onospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">();</span>=
<span style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(=
250,250,250)">=C2=A0</span><span style=3D"font-family:monospace;color:rgb(1=
02,102,0);background-color:rgb(250,250,250)">}</span><span style=3D"font-fa=
mily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br></sp=
an><span style=3D"font-family:monospace;color:rgb(102,102,0);background-col=
or:rgb(250,250,250)">};</span><span style=3D"font-family:monospace;color:rg=
b(0,0,0);background-color:rgb(250,250,250)"><br><br></span><span style=3D"f=
ont-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">=
struct</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgrou=
nd-color:rgb(250,250,250)">=C2=A0B=C2=A0</span><span style=3D"font-family:m=
onospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">:</span><s=
pan style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(25=
0,250,250)">=C2=A0A<br></span><span style=3D"font-family:monospace;color:rg=
b(102,102,0);background-color:rgb(250,250,250)">{</span><span style=3D"font=
-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br><=
/span></div><div dir=3D"ltr"><span style=3D"font-family:monospace;color:rgb=
(0,0,0);background-color:rgb(250,250,250)">=C2=A0 =C2=A0 Y</span><span styl=
e=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,25=
0,250)">*</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backg=
round-color:rgb(250,250,250)">=C2=A0foo</span><span style=3D"font-family:mo=
nospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">()</span><s=
pan style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(25=
0,250,250)">=C2=A0</span><span style=3D"font-family:monospace;background-co=
lor:rgb(250,250,250)"><font color=3D"#666600">;</font></span><span style=3D=
"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=
<br>=C2=A0 =C2=A0 Y</span><span style=3D"font-family:monospace;color:rgb(10=
2,102,0);background-color:rgb(250,250,250)">&</span><span style=3D"font=
-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=
=A0bar</span><span style=3D"font-family:monospace;color:rgb(102,102,0);back=
ground-color:rgb(250,250,250)">()</span><span style=3D"font-family:monospac=
e;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span st=
yle=3D"font-family:monospace;background-color:rgb(250,250,250)"><font color=
=3D"#666600">;</font></span><span style=3D"font-family:monospace;color:rgb(=
0,0,0);background-color:rgb(250,250,250)"><br></span><div dir=3D"ltr"><span=
style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,2=
50,250)">=C2=A0 =C2=A0=C2=A0</span><span style=3D"color:rgb(0,0,0);font-fam=
ily:monospace;background-color:rgb(250,250,250)">Y</span><span style=3D"fon=
t-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=
=A0</span><span style=3D"background-color:rgb(250,250,250)"><font color=3D"=
#000000" face=3D"monospace">proposal</font><font color=3D"#666600" face=3D"=
monospace">()</font></span><span style=3D"font-family:monospace;color:rgb(0=
,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-f=
amily:monospace;background-color:rgb(250,250,250)"><font color=3D"#666600">=
;</font></span></div><div dir=3D"ltr"><span style=3D"color:rgb(102,102,0);f=
ont-family:monospace;background-color:rgb(250,250,250)">//implement virtual=
:</span></div><div dir=3D"ltr"><span style=3D"font-family:monospace;color:r=
gb(0,0,0);background-color:rgb(250,250,250)">=C2=A0 =C2=A0=C2=A0</span><spa=
n style=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb(25=
0,250,250)">virtual</span><span style=3D"font-family:monospace;color:rgb(0,=
0,0);background-color:rgb(250,250,250)">=C2=A0X</span><span style=3D"font-f=
amily:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">*</=
span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-color=
:rgb(250,250,250)">=C2=A0__foo</span><span style=3D"font-family:monospace;c=
olor:rgb(102,102,0);background-color:rgb(250,250,250)">()</span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)">=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,136);bac=
kground-color:rgb(250,250,250)">override=C2=A0</span><span style=3D"font-fa=
mily:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">{</s=
pan><span style=3D"font-family:monospace;color:rgb(0,0,0);background-color:=
rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:monospace;color:r=
gb(0,0,136);background-color:rgb(250,250,250)">return</span><span style=3D"=
font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=
=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,136);backgr=
ound-color:rgb(250,250,250)">static_cast</span><span style=3D"font-family:m=
onospace;color:rgb(102,102,0);background-color:rgb(250,250,250)"><</span=
><span style=3D"font-family:monospace;background-color:rgb(250,250,250)"><f=
ont color=3D"#000000">X</font></span><span style=3D"font-family:monospace;c=
olor:rgb(102,102,0);background-color:rgb(250,250,250)">*>(</span><span s=
tyle=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb(250,2=
50,250)">this</span><span style=3D"font-family:monospace;color:rgb(102,102,=
0);background-color:rgb(250,250,250)">-></span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">foo</span><=
span style=3D"font-family:monospace;color:rgb(102,102,0);background-color:r=
gb(250,250,250)">());</span><span style=3D"font-family:monospace;color:rgb(=
0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-=
family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">}<=
/span><span style=3D"color:rgb(102,102,0);font-family:monospace;background-=
color:rgb(250,250,250)">;</span></div><div dir=3D"ltr"><span style=3D"font-=
family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0=
=C2=A0=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,136)=
;background-color:rgb(250,250,250)">virtual</span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0X</sp=
an><span style=3D"font-family:monospace;color:rgb(102,102,0);background-col=
or:rgb(250,250,250)">&</span><span style=3D"font-family:monospace;color=
:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0__bar</span><span styl=
e=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,25=
0,250)">()</span><span style=3D"font-family:monospace;color:rgb(0,0,0);back=
ground-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:mono=
space;color:rgb(0,0,136);background-color:rgb(250,250,250)">override {=C2=
=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,136);backgroun=
d-color:rgb(250,250,250)">return</span><span style=3D"font-family:monospace=
;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><span sty=
le=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250=
,250)">static_cast</span><span style=3D"font-family:monospace;color:rgb(102=
,102,0);background-color:rgb(250,250,250)"><</span><span style=3D"font-f=
amily:monospace;background-color:rgb(250,250,250)"><font color=3D"#000000">=
X</font></span><span style=3D"font-family:monospace;color:rgb(102,102,0);ba=
ckground-color:rgb(250,250,250)">&>(</span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">this</spa=
n><span style=3D"font-family:monospace;color:rgb(102,102,0);background-colo=
r:rgb(250,250,250)">-></span><span style=3D"font-family:monospace;color:=
rgb(0,0,0);background-color:rgb(250,250,250)">bar</span><span style=3D"font=
-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">(=
));</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-=
color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:monospace;c=
olor:rgb(102,102,0);background-color:rgb(250,250,250)">}</span><span style=
=3D"color:rgb(102,102,0);font-family:monospace;background-color:rgb(250,250=
,250)">;</span></div><span style=3D"font-family:monospace;color:rgb(102,102=
,0);background-color:rgb(250,250,250)"></span><div dir=3D"ltr"><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)">=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-family:monospace;color:rgb=
(0,0,136);background-color:rgb(250,250,250)">virtual</span><span style=3D"f=
ont-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">=
=C2=A0X</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgro=
und-color:rgb(250,250,250)">=C2=A0__</span><span style=3D"color:rgb(0,0,0);=
font-family:monospace;background-color:rgb(250,250,250)">proposal</span><sp=
an style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb=
(250,250,250)">()</span><span style=3D"font-family:monospace;color:rgb(0,0,=
0);background-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-fami=
ly:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">override=
{=C2=A0</span><span style=3D"font-family:monospace;color:rgb(0,0,136);back=
ground-color:rgb(250,250,250)">return</span><span style=3D"font-family:mono=
space;color:rgb(0,0,0);background-color:rgb(250,250,250)">=C2=A0</span><spa=
n style=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb(25=
0,250,250)">static_cast</span><span style=3D"font-family:monospace;color:rg=
b(102,102,0);background-color:rgb(250,250,250)"><</span><span style=3D"f=
ont-family:monospace;background-color:rgb(250,250,250)"><font color=3D"#000=
000">X</font></span><span style=3D"font-family:monospace;color:rgb(102,102,=
0);background-color:rgb(250,250,250)">>(</span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">this</spa=
n><span style=3D"font-family:monospace;color:rgb(102,102,0);background-colo=
r:rgb(250,250,250)">-></span><span style=3D"color:rgb(0,0,0);font-family=
:monospace;background-color:rgb(250,250,250)">proposal</span><span style=3D=
"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,25=
0)">());</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgr=
ound-color:rgb(250,250,250)">=C2=A0</span><span style=3D"font-family:monosp=
ace;color:rgb(102,102,0);background-color:rgb(250,250,250)">}</span><span s=
tyle=3D"color:rgb(102,102,0);font-family:monospace;background-color:rgb(250=
,250,250)">;</span></div><span style=3D"font-family:monospace;color:rgb(102=
,102,0);background-color:rgb(250,250,250)"></span><div dir=3D"ltr"><span st=
yle=3D"color:rgb(102,102,0);font-family:monospace;background-color:rgb(250,=
250,250)">};</span><br></div><div dir=3D"ltr"><span style=3D"color:rgb(102,=
102,0);font-family:monospace;background-color:rgb(250,250,250)"><br></span>=
</div><div><span style=3D"color:rgb(102,102,0);font-family:monospace;backgr=
ound-color:rgb(250,250,250)">regards,</span></div><div><span style=3D"color=
:rgb(102,102,0);font-family:monospace;background-color:rgb(250,250,250)">FM=
..</span></div></div></div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7bfcf25a8316fc050ae3d304--
.
Author: Jean-Marc Bourguet <jm.bourguet@gmail.com>
Date: Tue, 23 Dec 2014 08:28:02 -0800 (PST)
Raw View
------=_Part_4239_600274989.1419352082268
Content-Type: multipart/alternative;
boundary="----=_Part_4240_2091050164.1419352082268"
------=_Part_4240_2091050164.1419352082268
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Le mardi 23 d=C3=A9cembre 2014 16:28:30 UTC+1, Farid Mehrabi a =C3=A9crit :
>
>
>
> 2014-12-23 18:01 GMT+03:30 Jean-Marc Bourguet <jm.bo...@gmail.com=20
> <javascript:>>:
>
>> Le mardi 23 d=C3=A9cembre 2014 14:31:06 UTC+1, Andy Prowl a =C3=A9crit :
>>>
>>> Currently, covariant return types are allowed under the restrictions=20
>>> placed by [class.virtual]/7. I think these restrictions are unnecessari=
ly=20
>>> severe.
>>>
>>> For instance, the following is legal:
>>>
>>> struct X { };
>>> struct Y : X { };
>>>
>>> struct A
>>> {
>>> virtual void X* foo();
>>> virtual void X& bar();
>>> };
>>>
>>> struct B : A
>>> {
>>> virtual void Y* foo() override;
>>> virtual void Y& bar() override;
>>> };
>>>
>>> However, replacing raw pointers by unique_ptr or shared_ptr is not=20
>>> allowed. This makes little sense to me.
>>>
>>> Given that B derives from A, I think that a function "T B::foo()" shoul=
d=20
>>> be allowed to override a function "U A::foo()" if and only if T is=20
>>> implicitly convertible to U. Derived-to-base conversion would be just o=
ne=20
>>> particular case of this rule.
>>>
>>> What do you think?
>>>
>>
>> I see where you are coming from. There are details that have to be=20
>> considered to be sure that it is implementable with a correct semantic. =
=20
>> The issue I see is that with implementation technique I know of covarian=
t=20
>> return, not only T has to be implicitly convertible to U but from a U yo=
u=20
>> need to be able to reconstruct the T. Your example is compiled as
>>
>> struct A
>> {
>> void X* foo() { return __foo(); }
>> void X& bar() { return __bar(); }
>> virtual X* __foo();
>> virtual X& __bar();
>> };
>>
>> struct B : A
>> {
>> virtual X* __foo() override;
>> virtual X& __bar() override;
>> Y* foo() { return static_cast<Y*>(this->foo()); }
>> X& bar() { return static_cast<Y&>(this->bar()); }
>> };
>>
>> implicit conversion don't guarantee this round trip. You will at least=
=20
>> to show that there is a way to compile with the semantic you want.
>>
>> Yours
>>
>
> I think you got it upside down:=20
>
>
> struct A
> {
> X* foo() ;
> X& bar() ;
> X proposal() ;
> //implement virtual:
> virtual X* __foo(){ return foo(); }
> virtual X& __bar(){ return bar(); }
> virtual X& __proposal(){ return proposal(); }
> };
>
> struct B : A
> {
> Y* foo() ;
> Y& bar() ;
> Y proposal() ;
> //implement virtual:
> virtual X* __foo() override { return static_cast<X*>(this->foo()); };
> virtual X& __bar() override { return static_cast<X&>(this->bar()); };
> virtual X __proposal() override { return static_cast<X>(this->proposa=
l
> ()); };
> };
>
>
That doesn't work if there is a C inheriting from B which override foo as=
=20
well. This is fixable and as alluded by David, that could be a mean to=20
implement the current proposal, at the cost of adding virtual functions at=
=20
each level were covariant return is used.
struct R1 {};
struct R2: R1 {};
struct R3: R2 {};
struct C1 {
virtual R1* foo();
};
struct C2: C1 {
virtual R1* foo() { return static_cast<R1*>(foo__1()); }; // final=20
descendant overrides instead foo__1
virtual R2* foo__1();
};
struct C3: C2 {
virtual R2* foo__1() { return static_cast<R2*>(foo__2()); }; // final,=
=20
descendant overrides instead foo__2
virtual R3* foo__2();
};
Yours
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_4240_2091050164.1419352082268
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Le mardi 23 d=C3=A9cembre 2014 16:28:30 UTC+1, Farid Mehra=
bi a =C3=A9crit :<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"rtl"><br><div><div dir=3D"ltr"><br><div class=3D"gmail_quote">2014-12-2=
3 18:01 GMT+03:30 Jean-Marc Bourguet <span dir=3D"ltr"><<a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"M_v2ROSt50MJ" onmousedow=
n=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javasc=
ript:';return true;">jm.bo...@gmail.com</a>></span>:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"=
>Le mardi 23 d=C3=A9cembre 2014 14:31:06 UTC+1, Andy Prowl a =C3=A9crit&nbs=
p;:<span><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-styl=
e:solid;padding-left:1ex"><div dir=3D"ltr">Currently, covariant return type=
s are allowed under the restrictions placed by [class.virtual]/7. I think t=
hese restrictions are unnecessarily severe.<br><br>For instance, the follow=
ing is legal:<br><br><div style=3D"border:1px solid rgb(187,187,187);word-w=
rap:break-word;background-color:rgb(250,250,250)"><code><div><font color=3D=
"#000088"><span style=3D"color:rgb(0,0,136)">struct</span><span style=3D"co=
lor:rgb(0,0,0)"> </span></font><span style=3D"color:rgb(0,0,0)">X </span><s=
pan style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"=
> </span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color=
:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">struct</span><sp=
an style=3D"color:rgb(0,0,0)"> Y </span><span style=3D"color:rgb(102,102,0)=
">:</span><span style=3D"color:rgb(0,0,0)"> X </span><span style=3D"color:r=
gb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br><br=
></span><span style=3D"color:rgb(0,0,136)">struct</span><span style=3D"colo=
r:rgb(0,0,0)"> A<br></span><span style=3D"color:rgb(102,102,0)">{</span><sp=
an style=3D"color:rgb(0,0,0)"><br> </span><span style=3D"color=
:rgb(0,0,136)">virtual</span><span style=3D"color:rgb(0,0,0)"> </span><span=
style=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> =
X</span><span style=3D"color:rgb(102,102,0)">*</span><span style=3D"color:r=
gb(0,0,0)"> fo</span><font color=3D"#666600"><span style=3D"color:rgb(0,0,0=
)">o</span><span style=3D"color:rgb(102,102,0)">();</span><span style=3D"co=
lor:rgb(0,0,0)"><br></span></font><span style=3D"color:rgb(0,0,0)"> &=
nbsp; </span><span style=3D"color:rgb(0,0,136)">virtual</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">void</span=
><span style=3D"color:rgb(0,0,0)"> X</span><font color=3D"#666600"><span st=
yle=3D"color:rgb(102,102,0)">&</span></font><span style=3D"color:rgb(0,=
0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">();</span><span style=
=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">};</s=
pan><span style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"color:rg=
b(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> B </span><span s=
tyle=3D"color:rgb(102,102,0)">:</span><font color=3D"#000000"><span style=
=3D"color:rgb(0,0,0)"> A</span></font><span style=3D"color:rgb(0,0,0)"><br>=
</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"><br> </span><span style=3D"color:rgb(0,0,136)">virtu=
al</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(=
0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> Y</span><span style=
=3D"color:rgb(102,102,0)">*</span><span style=3D"color:rgb(0,0,0)"> fo</spa=
n><font color=3D"#666600" style=3D"font-size:13.3333330154419px"><span styl=
e=3D"color:rgb(0,0,0)">o</span><span style=3D"color:rgb(102,102,0)">()</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136=
)">override</span><span style=3D"color:rgb(102,102,0)">;</span></font><span=
style=3D"color:rgb(0,0,0)"><br> </span><span style=3D"color:r=
gb(0,0,136)">virtual</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> Y<=
/span><span style=3D"color:rgb(102,102,0)">&</span><span style=3D"color=
:rgb(0,0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">()</span><span=
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">over=
ride</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"colo=
r:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">};</span></di=
v></code></div><br>However, replacing raw pointers by unique_ptr or shared_=
ptr is not allowed. This makes little sense to me.<br><br>Given that B deri=
ves from A, I think that a function "T B::foo()" should be allowed to overr=
ide a function "U A::foo()" if and only if T is implicitly convertible to U=
.. Derived-to-base conversion would be just one particular case of this rule=
..<br><br>What do you think?<br></div></blockquote><div><br></div></span><di=
v>I see where you are coming from. There are details that have to be =
considered to be sure that it is implementable with a correct semantic.&nbs=
p; The issue I see is that with implementation technique I know of covarian=
t return, not only T has to be implicitly convertible to U but from a U you=
need to be able to reconstruct the T. Your example is compiled as</d=
iv><div><br></div><div style=3D"border:1px solid rgb(187,187,187);word-wrap=
:break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"co=
lor:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> A<br></spa=
n><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0=
,0)"><br> </span><span style=3D"color:rgb(0,0,136)">void</span=
><span style=3D"color:rgb(0,0,0)"> X</span><span style=3D"color:rgb(102,102=
,0)">*</span><span style=3D"color:rgb(0,0,0)"> foo</span><span style=3D"col=
or:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </=
span><span style=3D"color:rgb(0,0,136)">return</span><span style=3D"color:r=
gb(0,0,0)"> __foo</span><span style=3D"color:rgb(102,102,0)">();</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}=
</span><span style=3D"color:rgb(0,0,0)"><br> </span><span styl=
e=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> X</sp=
an><span style=3D"color:rgb(102,102,0)">&</span><span style=3D"color:rg=
b(0,0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">()</span><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</sp=
an><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,13=
6)">return</span><span style=3D"color:rgb(0,0,0)"> __bar</span><span style=
=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"> </spa=
n><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0=
,0)"><br> </span><span style=3D"color:rgb(0,0,136)">virtual</s=
pan><span style=3D"color:rgb(0,0,0)"> X</span><span style=3D"color:rgb(102,=
102,0)">*</span><span style=3D"color:rgb(0,0,0)"> __foo</span><span style=
=3D"color:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><br>&n=
bsp; </span><span style=3D"color:rgb(0,0,136)">virtual</span><span s=
tyle=3D"color:rgb(0,0,0)"> X</span><span style=3D"color:rgb(102,102,0)">&am=
p;</span><span style=3D"color:rgb(0,0,0)"> __bar</span><span style=3D"color=
:rgb(102,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><br></span><spa=
n style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)">=
<br><br></span><span style=3D"color:rgb(0,0,136)">struct</span><span style=
=3D"color:rgb(0,0,0)"> B </span><span style=3D"color:rgb(102,102,0)">:</spa=
n><span style=3D"color:rgb(0,0,0)"> A<br></span><span style=3D"color:rgb(10=
2,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br> </span=
><span style=3D"color:rgb(0,0,136)">virtual</span><span style=3D"color:rgb(=
0,0,0)"> X</span><span style=3D"color:rgb(102,102,0)">*</span><span style=
=3D"color:rgb(0,0,0)"> __foo</span><span style=3D"color:rgb(102,102,0)">()<=
/span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0=
,136)">override</span><span style=3D"color:rgb(102,102,0)">;</span><span st=
yle=3D"color:rgb(0,0,0)"><br> </span><span style=3D"color:rgb(=
0,0,136)">virtual</span><span style=3D"color:rgb(0,0,0)"> X</span><span sty=
le=3D"color:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)"> _=
_bar</span><span style=3D"color:rgb(102,102,0)">()</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">override</span><s=
pan style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"=
><br> Y</span><span style=3D"color:rgb(102,102,0)">*</span><sp=
an style=3D"color:rgb(0,0,0)"> foo</span><span style=3D"color:rgb(102,102,0=
)">()</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> </sp=
an><span style=3D"color:rgb(0,0,136)">static_cast</span><span style=3D"colo=
r:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">Y</span><span=
style=3D"color:rgb(102,102,0)">*>(</span><span style=3D"color:rgb(0,0,1=
36)">this</span><span style=3D"color:rgb(102,102,0)">-></span><span styl=
e=3D"color:rgb(0,0,0)">foo</span><span style=3D"color:rgb(102,102,0)">());<=
/span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102=
,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br> X</span=
><span style=3D"color:rgb(102,102,0)">&</span><span style=3D"color:rgb(=
0,0,0)"> bar</span><span style=3D"color:rgb(102,102,0)">()</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)=
">return</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(0,0,136)">static_cast</span><span style=3D"color:rgb(102,102,0)"><=
</span><span style=3D"color:rgb(0,0,0)">Y</span><span style=3D"color:rgb(10=
2,102,0)">&>(</span><span style=3D"color:rgb(0,0,136)">this</span><s=
pan style=3D"color:rgb(102,102,0)">-></span><span style=3D"color:rgb(0,0=
,0)">bar</span><span style=3D"color:rgb(102,102,0)">());</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}</span>=
<span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,10=
2,0)">};</span><span style=3D"color:rgb(0,0,0)"><br></span></div></code></d=
iv><div><div><span style=3D"font-family:monospace;color:rgb(102,102,0);back=
ground-color:rgb(250,250,250)"><br></span></div></div><div><span style=3D"b=
ackground-color:rgb(250,250,250)"><font color=3D"#666600" face=3D"monospace=
">implicit conversion don't guarantee this round trip. You =
will at least to show that there is a way to compile with the semantic you =
want.</font></span></div><div><span style=3D"background-color:rgb(250,250,2=
50)"><font color=3D"#666600" face=3D"monospace"><br></font></span></div><di=
v><span style=3D"background-color:rgb(250,250,250)"><font color=3D"#666600"=
face=3D"monospace">Yours</font></span></div></blockquote><div><br></div><d=
iv>I think you got it upside down: </div></div><div><div>
<p></p></div></div></div><div><div dir=3D"ltr"><br></div><div dir=3D"ltr"><=
span style=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb=
(250,250,250)">struct</span><span style=3D"font-family:monospace;color:rgb(=
0,0,0);background-color:rgb(250,250,250)"> A<br></span><span style=3D"=
font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250=
)">{</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background=
-color:rgb(250,250,250)"><br> </span><span style=3D"font-=
family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">X</spa=
n><span style=3D"font-family:monospace;color:rgb(102,102,0);background-colo=
r:rgb(250,250,250)">*</span><span style=3D"font-family:monospace;color:rgb(=
0,0,0);background-color:rgb(250,250,250)"> foo</span><span style=3D"fo=
nt-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)"=
>()</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-=
color:rgb(250,250,250)"> </span><span style=3D"font-family:monospace;b=
ackground-color:rgb(250,250,250)"><font color=3D"#666600">;</font></span><s=
pan style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(25=
0,250,250)"><br></span><span style=3D"font-family:monospace;color:rgb(0,0,0=
);background-color:rgb(250,250,250)"> </span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)">X</span><span style=3D"font-family:monospace;color:rgb(102,102,0);backgr=
ound-color:rgb(250,250,250)">&</span><span style=3D"font-family:monospa=
ce;color:rgb(0,0,0);background-color:rgb(250,250,250)"> bar</span><spa=
n style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(=
250,250,250)">()</span><span style=3D"font-family:monospace;color:rgb(0,0,0=
);background-color:rgb(250,250,250)"> </span><span style=3D"font-famil=
y:monospace;background-color:rgb(250,250,250)"><font color=3D"#666600">;</f=
ont></span><span style=3D"font-family:monospace;color:rgb(0,0,0);background=
-color:rgb(250,250,250)"><br></span><span style=3D"font-family:monospace;co=
lor:rgb(0,0,0);background-color:rgb(250,250,250)"> </span=
><span style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb=
(250,250,250)">X</span><span style=3D"font-family:monospace;color:rgb(0,0,0=
);background-color:rgb(250,250,250)"> </span><span style=3D"background=
-color:rgb(250,250,250)"><font color=3D"#000000" face=3D"monospace">proposa=
l</font><font color=3D"#666600" face=3D"monospace">()</font></span><span st=
yle=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,=
250)"> </span><span style=3D"font-family:monospace;background-color:rg=
b(250,250,250)"><font color=3D"#666600">;</font></span></div><div dir=3D"lt=
r"><span style=3D"font-family:monospace;background-color:rgb(250,250,250)">=
<font color=3D"#666600">//implement virtual:<br></font></span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)"> </span><span style=3D"font-family:monospace;color:rgb=
(0,0,136);background-color:rgb(250,250,250)">virtual</span><span style=3D"f=
ont-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">&n=
bsp;X</span><span style=3D"font-family:monospace;color:rgb(102,102,0);backg=
round-color:rgb(250,250,250)">*</span><span style=3D"font-family:monospace;=
color:rgb(0,0,0);background-color:rgb(250,250,250)"> __foo</span><span=
style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(2=
50,250,250)">()</span><span style=3D"font-family:monospace;color:rgb(102,10=
2,0);background-color:rgb(250,250,250)">{</span><span style=3D"font-family:=
monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </span>=
<span style=3D"font-family:monospace;color:rgb(0,0,136);background-color:rg=
b(250,250,250)">return</span><span style=3D"font-family:monospace;color:rgb=
(0,0,0);background-color:rgb(250,250,250)"> <wbr>foo</span><span style=
=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250=
,250)">();</span><span style=3D"font-family:monospace;color:rgb(0,0,0);back=
ground-color:rgb(250,250,250)"> </span><span style=3D"font-family:mono=
space;color:rgb(102,102,0);background-color:rgb(250,250,250)">}</span><span=
style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,2=
50,250)"><br></span><span style=3D"font-family:monospace;color:rgb(0,0,0);b=
ackground-color:rgb(250,250,250)"> </span><span style=3D"=
font-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)"=
>virtual</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgr=
ound-color:rgb(250,250,250)"> X</span><span style=3D"font-family:monos=
pace;color:rgb(102,102,0);background-color:rgb(250,250,250)">&</span><s=
pan style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(25=
0,250,250)"> __bar</span><span style=3D"font-family:monospace;color:rg=
b(102,102,0);background-color:rgb(250,250,250)">()</span><span style=3D"fon=
t-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">=
{</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-co=
lor:rgb(250,250,250)"> </span><span style=3D"font-family:monospace;col=
or:rgb(0,0,136);background-color:rgb(250,250,250)">return </span><span=
style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,2=
50,250)">b<wbr>ar</span><span style=3D"font-family:monospace;color:rgb(102,=
102,0);background-color:rgb(250,250,250)">();</span><span style=3D"font-fam=
ily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </s=
pan><span style=3D"font-family:monospace;color:rgb(102,102,0);background-co=
lor:rgb(250,250,250)">}</span><span style=3D"font-family:monospace;color:rg=
b(0,0,0);background-color:rgb(250,250,250)"><br></span><span style=3D"font-=
family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> =
</span><span style=3D"font-family:monospace;color:rgb(0,0,136)=
;background-color:rgb(250,250,250)">virtual</span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> X</sp=
an><span style=3D"font-family:monospace;color:rgb(102,102,0);background-col=
or:rgb(250,250,250)">&</span><span style=3D"font-family:monospace;color=
:rgb(0,0,0);background-color:rgb(250,250,250)"> __</span><span style=
=3D"color:rgb(0,0,0);font-family:monospace;background-color:rgb(250,250,250=
)">proposal</span><span style=3D"font-family:monospace;color:rgb(102,102,0)=
;background-color:rgb(250,250,250)">()</span><span style=3D"font-family:mon=
ospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">{</span><spa=
n style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,=
250,250)"> </span><span style=3D"font-family:monospace;color:rgb(0,0,1=
36);background-color:rgb(250,250,250)">ret<wbr>urn</span><span style=3D"fon=
t-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">&nbs=
p;</span><span style=3D"color:rgb(0,0,0);font-family:monospace;background-c=
olor:rgb(250,250,250)">proposal</span><span style=3D"font-family:monospace;=
color:rgb(102,102,0);background-color:rgb(250,250,250)">();</span><span sty=
le=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,2=
50)"> </span><span style=3D"font-family:monospace;color:rgb(102,102,0)=
;background-color:rgb(250,250,250)">}</span><span style=3D"font-family:mono=
space;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br></span><span =
style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(25=
0,250,250)">};</span><span style=3D"font-family:monospace;color:rgb(0,0,0);=
background-color:rgb(250,250,250)"><br><br></span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">struct</s=
pan><span style=3D"font-family:monospace;color:rgb(0,0,0);background-color:=
rgb(250,250,250)"> B </span><span style=3D"font-family:monospace;=
color:rgb(102,102,0);background-color:rgb(250,250,250)">:</span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)"> A<br></span><span style=3D"font-family:monospace;color:rgb(102,102=
,0);background-color:rgb(250,250,250)">{</span><span style=3D"font-family:m=
onospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br></span></d=
iv><div dir=3D"ltr"><span style=3D"font-family:monospace;color:rgb(0,0,0);b=
ackground-color:rgb(250,250,250)"> Y</span><span style=3D"font=
-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">*=
</span><span style=3D"font-family:monospace;color:rgb(0,0,0);background-col=
or:rgb(250,250,250)"> foo</span><span style=3D"font-family:monospace;c=
olor:rgb(102,102,0);background-color:rgb(250,250,250)">()</span><span style=
=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250=
)"> </span><span style=3D"font-family:monospace;background-color:rgb(2=
50,250,250)"><font color=3D"#666600">;</font></span><span style=3D"font-fam=
ily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"><br> =
; Y</span><span style=3D"font-family:monospace;color:rgb(102,102,0);=
background-color:rgb(250,250,250)">&</span><span style=3D"font-family:m=
onospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> bar</spa=
n><span style=3D"font-family:monospace;color:rgb(102,102,0);background-colo=
r:rgb(250,250,250)">()</span><span style=3D"font-family:monospace;color:rgb=
(0,0,0);background-color:rgb(250,250,250)"> </span><span style=3D"font=
-family:monospace;background-color:rgb(250,250,250)"><font color=3D"#666600=
">;</font></span><span style=3D"font-family:monospace;color:rgb(0,0,0);back=
ground-color:rgb(250,250,250)"><br></span><div dir=3D"ltr"><span style=3D"f=
ont-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">&n=
bsp; </span><span style=3D"color:rgb(0,0,0);font-family:monospa=
ce;background-color:rgb(250,250,250)">Y</span><span style=3D"font-family:mo=
nospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </span><s=
pan style=3D"background-color:rgb(250,250,250)"><font color=3D"#000000" fac=
e=3D"monospace">proposal</font><font color=3D"#666600" face=3D"monospace">(=
)</font></span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgr=
ound-color:rgb(250,250,250)"> </span><span style=3D"font-family:monosp=
ace;background-color:rgb(250,250,250)"><font color=3D"#666600">;</font></sp=
an></div><div dir=3D"ltr"><span style=3D"color:rgb(102,102,0);font-family:m=
onospace;background-color:rgb(250,250,250)">//implement virtual:</span></di=
v><div dir=3D"ltr"><span style=3D"font-family:monospace;color:rgb(0,0,0);ba=
ckground-color:rgb(250,250,250)"> </span><span style=3D"f=
ont-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">=
virtual</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgro=
und-color:rgb(250,250,250)"> X</span><span style=3D"font-family:monosp=
ace;color:rgb(102,102,0);background-color:rgb(250,250,250)">*</span><span s=
tyle=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250=
,250)"> __foo</span><span style=3D"font-family:monospace;color:rgb(102=
,102,0);background-color:rgb(250,250,250)">()</span><span style=3D"font-fam=
ily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </s=
pan><span style=3D"font-family:monospace;color:rgb(0,0,136);background-colo=
r:rgb(250,250,250)">override </span><span style=3D"font-family:monospa=
ce;color:rgb(102,102,0);background-color:rgb(250,250,250)"><wbr>{</span><sp=
an style=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250=
,250,250)"> </span><span style=3D"font-family:monospace;color:rgb(0,0,=
136);background-color:rgb(250,250,250)">return</span><span style=3D"font-fa=
mily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </=
span><span style=3D"font-family:monospace;color:rgb(0,0,136);background-col=
or:rgb(250,250,250)">static_cast</span><span style=3D"font-family:monospace=
;color:rgb(102,102,0);background-color:rgb(250,250,250)"><</span><span s=
tyle=3D"font-family:monospace;background-color:rgb(250,250,250)"><font colo=
r=3D"#000000">X</font></span><span style=3D"font-family:monospace;color:rgb=
(102,102,0);background-color:rgb(250,250,250)">*>(</span><span style=3D"=
font-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)"=
>this</span><span style=3D"font-family:monospace;color:rgb(102,102,0);backg=
round-color:rgb(250,250,250)">-<wbr>></span><span style=3D"font-family:m=
onospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">foo</span><spa=
n style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(=
250,250,250)">());</span><span style=3D"font-family:monospace;color:rgb(0,0=
,0);background-color:rgb(250,250,250)"> </span><span style=3D"font-fam=
ily:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">}</sp=
an><span style=3D"color:rgb(102,102,0);font-family:monospace;background-col=
or:rgb(250,250,250)">;</span></div><div dir=3D"ltr"><span style=3D"font-fam=
ily:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> &n=
bsp; </span><span style=3D"font-family:monospace;color:rgb(0,0,136);ba=
ckground-color:rgb(250,250,250)">virtual</span><span style=3D"font-family:m=
onospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> X</span>=
<span style=3D"font-family:monospace;color:rgb(102,102,0);background-color:=
rgb(250,250,250)">&</span><span style=3D"font-family:monospace;color:rg=
b(0,0,0);background-color:rgb(250,250,250)"> __bar</span><span style=
=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250=
,250)">()</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backg=
round-color:rgb(250,250,250)"> </span><span style=3D"font-family:monos=
pace;color:rgb(0,0,136);background-color:rgb(250,250,250)">override { =
</span><span style=3D"font-family:monospace;color:rgb(0,0,136);background-c=
olor:rgb(250,250,250)">return</span><span style=3D"font-family:monospace;co=
lor:rgb(0,0,0);background-color:rgb(250,250,250)"> </span><span style=
=3D"font-family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,2=
50)">static_cast</span><span style=3D"font-family:monospace;color:rgb(102,1=
02,0);background-color:rgb(250,250,250)"><</span><span style=3D"font-fam=
ily:monospace;background-color:rgb(250,250,250)"><font color=3D"#000000">X<=
/font></span><span style=3D"font-family:monospace;color:rgb(102,102,0);back=
ground-color:rgb(250,250,250)">&>(</span><span style=3D"font-family:=
monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">this</span>=
<span style=3D"font-family:monospace;color:rgb(102,102,0);background-color:=
rgb(250,250,250)">-<wbr>></span><span style=3D"font-family:monospace;col=
or:rgb(0,0,0);background-color:rgb(250,250,250)">bar</span><span style=3D"f=
ont-family:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)=
">());</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgrou=
nd-color:rgb(250,250,250)"> </span><span style=3D"font-family:monospac=
e;color:rgb(102,102,0);background-color:rgb(250,250,250)">}</span><span sty=
le=3D"color:rgb(102,102,0);font-family:monospace;background-color:rgb(250,2=
50,250)">;</span></div><span style=3D"font-family:monospace;color:rgb(102,1=
02,0);background-color:rgb(250,250,250)"></span><div dir=3D"ltr"><span styl=
e=3D"font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,25=
0)"> </span><span style=3D"font-family:monospace;color:rg=
b(0,0,136);background-color:rgb(250,250,250)">virtual</span><span style=3D"=
font-family:monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)">&=
nbsp;X</span><span style=3D"font-family:monospace;color:rgb(0,0,0);backgrou=
nd-color:rgb(250,250,250)"> __</span><span style=3D"color:rgb(0,0,0);f=
ont-family:monospace;background-color:rgb(250,250,250)">proposal</span><spa=
n style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(=
250,250,250)">()</span><span style=3D"font-family:monospace;color:rgb(0,0,0=
);background-color:rgb(250,250,250)"> </span><span style=3D"font-famil=
y:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">overr<wbr=
>ide { </span><span style=3D"font-family:monospace;color:rgb(0,0,136);=
background-color:rgb(250,250,250)">return</span><span style=3D"font-family:=
monospace;color:rgb(0,0,0);background-color:rgb(250,250,250)"> </span>=
<span style=3D"font-family:monospace;color:rgb(0,0,136);background-color:rg=
b(250,250,250)">static_cast</span><span style=3D"font-family:monospace;colo=
r:rgb(102,102,0);background-color:rgb(250,250,250)"><</span><span style=
=3D"font-family:monospace;background-color:rgb(250,250,250)"><font color=3D=
"#000000">X</font></span><span style=3D"font-family:monospace;color:rgb(102=
,102,0);background-color:rgb(250,250,250)">>(</span><span style=3D"font-=
family:monospace;color:rgb(0,0,136);background-color:rgb(250,250,250)">this=
</span><span style=3D"font-family:monospace;color:rgb(102,102,0);background=
-color:rgb(250,250,250)">-></span><span style=3D"color:rgb(0,0,0);font-f=
amily:monospace;background-color:rgb(250,250,250)"><wbr>proposal</span><spa=
n style=3D"font-family:monospace;color:rgb(102,102,0);background-color:rgb(=
250,250,250)">());</span><span style=3D"font-family:monospace;color:rgb(0,0=
,0);background-color:rgb(250,250,250)"> </span><span style=3D"font-fam=
ily:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)">}</sp=
an><span style=3D"color:rgb(102,102,0);font-family:monospace;background-col=
or:rgb(250,250,250)">;</span></div><span style=3D"font-family:monospace;col=
or:rgb(102,102,0);background-color:rgb(250,250,250)"></span><div dir=3D"ltr=
"><span style=3D"color:rgb(102,102,0);font-family:monospace;background-colo=
r:rgb(250,250,250)">};</span><br></div><div dir=3D"ltr"><br></div></div></d=
iv></div></div></blockquote><div><br></div><div>That doesn't work if there =
is a C inheriting from B which override foo as well. This is fixable and as=
alluded by David, that could be a mean to implement the current proposal, =
at the cost of adding virtual functions at each level were covariant return=
is used.</div><div><br></div><div>struct R1 {};</div><div>struct R2: R1 {}=
;</div><div>struct R3: R2 {};</div><div><br></div><div>struct C1 {</div><di=
v> virtual R1* foo();</div><div>};</div><div><br></div><div>str=
uct C2: C1 {</div><div> virtual R1* foo() { return static_cast&=
lt;R1*>(foo__1()); }; // final descendant overrides instead foo__1</div>=
<div> virtual R2* foo__1();</div><div>};</div><div><br></div><d=
iv>struct C3: C2 {</div><div> virtual R2* foo__1() { return sta=
tic_cast<R2*>(foo__2()); }; // final, descendant overrides instead fo=
o__2</div><div> virtual R3* foo__2();</div><div>};</div><div><b=
r></div><div><br></div><div>Yours</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4240_2091050164.1419352082268--
------=_Part_4239_600274989.1419352082268--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 23 Dec 2014 19:13:04 +0200
Raw View
On 23 December 2014 at 18:28, Jean-Marc Bourguet <jm.bourguet@gmail.com> wrote:
>> struct B : A
>> {
>> Y* foo() ;
>> Y& bar() ;
>> Y proposal() ;
>> //implement virtual:
>> virtual X* __foo() override { return static_cast<X*>(this->foo()); };
>> virtual X& __bar() override { return static_cast<X&>(this->bar()); };
>> virtual X __proposal() override { return
>> static_cast<X>(this->proposal()); };
>> };
>>
>
> That doesn't work if there is a C inheriting from B which override foo as
> well. This is fixable and as alluded by David, that could be a mean to
> implement the current proposal, at the cost of adding virtual functions at
> each level were covariant return is used.
>
> struct R1 {};
> struct R2: R1 {};
> struct R3: R2 {};
>
> struct C1 {
> virtual R1* foo();
> };
>
> struct C2: C1 {
> virtual R1* foo() { return static_cast<R1*>(foo__1()); }; // final
> descendant overrides instead foo__1
> virtual R2* foo__1();
> };
>
> struct C3: C2 {
> virtual R2* foo__1() { return static_cast<R2*>(foo__2()); }; // final,
> descendant overrides instead foo__2
> virtual R3* foo__2();
> };
Pointer conversions are fairly easy business. Converting from a value of
derived type to a value of base type isn't, nor is converting from unique_ptr<D>
to unique_ptr<B> or vector<D*> to vector<B*>. There may be ABI complications
involved, so this proposal should be looked at by an implementation vendor.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 09:22:32 -0800 (PST)
Raw View
------=_Part_4165_1042853410.1419355352578
Content-Type: multipart/alternative;
boundary="----=_Part_4166_1951973480.1419355352584"
------=_Part_4166_1951973480.1419355352584
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 6:13:05 PM UTC+1, Ville Voutilainen wrote:
>
> On 23 December 2014 at 18:28, Jean-Marc Bourguet <jm.bo...@gmail.com
> <javascript:>> wrote:
>
> Pointer conversions are fairly easy business. Converting from a value of
> derived type to a value of base type isn't, nor is converting from
> unique_ptr<D>
> to unique_ptr<B> or vector<D*> to vector<B*>. There may be ABI
> complications
> involved, so this proposal should be looked at by an implementation
> vendor.
>
Thank you for your feedback Ville. Just as a note, I am not proposing to
allow converting a vector<D*> into a vector<B*>. Such a conversion
currently does not exist, and it seems to me that whether it should exist
or not is independent from the context of covariant return types.
The (user-defined) conversion from unique_ptr<D> to unique_ptr<B>, on the
other hand, exists, and I wish covariant return types took user-defined
conversions into account.
I am not sufficiently experienced to understand the implications in terms
of ABI, and there is no formal proposal yet. Do you have suggestions on
whom I can contact for feedback on feasibility? Or should I just write a
proposal and let it be discussed?
Thank you in advance,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4166_1951973480.1419355352584
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 6:13:05 PM UTC+1, Ville Vout=
ilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 23 December 2=
014 at 18:28, Jean-Marc Bourguet <<a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"abcI3mNCjhgJ" onmousedown=3D"this.href=3D'java=
script:';return true;" onclick=3D"this.href=3D'javascript:';return true;">j=
m.bo...@gmail.com</a>> wrote:
<br><br>Pointer conversions are fairly easy business. Converting from a val=
ue of
<br>derived type to a value of base type isn't, nor is converting from uniq=
ue_ptr<D>
<br>to unique_ptr<B> or vector<D*> to vector<B*>. There m=
ay be ABI complications
<br>involved, so this proposal should be looked at by an implementation ven=
dor.
<br></blockquote><div><br>Thank you for your feedback Ville. Just as a note=
, I am not proposing to allow converting a vector<D*> into a vector&l=
t;B*>. Such a conversion currently does not exist, and it seems to me th=
at whether it should exist or not is independent from the context of covari=
ant return types.<br><br></div><div>The (user-defined) conversion from uniq=
ue_ptr<D> to unique_ptr<B>, on the other hand, exists, and I wi=
sh covariant return types took user-defined conversions into account.<br><b=
r>I am not sufficiently experienced to understand the implications in terms=
of ABI, and there is no formal proposal yet. Do you have suggestions on wh=
om I <span style=3D"font-size: 13.3333330154419px;">can</span><span st=
yle=3D"font-size: 13.3333330154419px;"> </span><span style=3D"font-siz=
e: 13px;">contact for feedback on feasibility? Or should I just write a pro=
posal and let it be discussed?<br><br>Thank you in advance,<br><br>Andy</sp=
an></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4166_1951973480.1419355352584--
------=_Part_4165_1042853410.1419355352578--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 16:32:20 -0200
Raw View
On Tuesday 23 December 2014 05:31:06 Andy Prowl wrote:
> Currently, covariant return types are allowed under the restrictions placed
> by [class.virtual]/7. I think these restrictions are unnecessarily severe.
>
> For instance, the following is legal:
>
> struct X { };
> struct Y : X { };
>
> struct A
> {
> virtual void X* foo();
> virtual void X& bar();
> };
>
> struct B : A
> {
> virtual void Y* foo() override;
> virtual void Y& bar() override;
> };
>
> However, replacing raw pointers by unique_ptr or shared_ptr is not allowed.
> This makes little sense to me.
>
> Given that B derives from A, I think that a function "T B::foo()" should be
> allowed to override a function "U A::foo()" if and only if T is implicitly
> convertible to U. Derived-to-base conversion would be just one particular
> case of this rule.
>
> What do you think?
I think you based your request on the simplest example possible. Yes, it would
work for your example, but not for anything a little more complex.
struct X {};
struct Spacing { char buffer[100]; }
struct Y: Spacing, X {};
Now the covariant returns are permitted, but require a pointer-adjustment
thunk because the value of an X* differs from an Y* if they point to the same
object.
With that in mind, your request implies:
- alll smart pointers must be able to handle deleting of derived classes if
they delete, which isn't the case (example: std::unique_ptr with default
deleter)
- all smart pointers must be able to handle copying from a derived class
pointer or object containing the derived class
- the compiler must know how to copy
The first and last requirements are a non-starter.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 11:12:38 -0800 (PST)
Raw View
------=_Part_578_990395600.1419361959061
Content-Type: multipart/alternative;
boundary="----=_Part_579_433101303.1419361959061"
------=_Part_579_433101303.1419361959061
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 7:32:26 PM UTC+1, Thiago Macieira wrote:
>
>
> I think you based your request on the simplest example possible. Yes, it
> would
> work for your example, but not for anything a little more complex.
>
> struct X {};
> struct Spacing { char buffer[100]; }
> struct Y: Spacing, X {};
>
> Now the covariant returns are permitted, but require a pointer-adjustment
> thunk because the value of an X* differs from an Y* if they point to the
> same
> object.
>
> With that in mind, your request implies:
> - alll smart pointers must be able to handle deleting of derived classes
> if
> they delete, which isn't the case (example: std::unique_ptr with
> default
> deleter)
> - all smart pointers must be able to handle copying from a derived class
> pointer or object containing the derived class
> - the compiler must know how to copy
>
> The first and last requirements are a non-starter.
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
> PGP/GPG: 0x6EF45358; fingerprint:
> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
>
If I understand your first point correctly, then no, I don't think all
smart pointers should be able to handle deleting of derived classes. I
think it's a user's responsibility to make sure that the base class X has a
virtual destructor if they plan to delete objects of type Y polymorphically
(e.g. through a unique_ptr<X>). After all, even today, nothing prevents the
user (with reference to your example) from deleting a pointer of type X*
which is pointing to an object of type Y obtained by invoking an overriding
virtual function - since Y* is covariant with X*, a function returning Y*
can override a function returning X*. In my view, allowing a conversion
from unique_ptr<Y> to unique_ptr<X> does not change anything here. That
conversion exists and deletion of an object of type Y through a
unique_ptr<X> can bite the user in several other contexts. I don't see why
special concerns should be raised for this use case.
I am not sure I understand points 2. and 3. - in particular, I don't
understand if they follow from point 1., and whether the answer above
indirectly addresses those as well. What do you mean by "the compiler must
know how to copy"? What is to be copied?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_579_433101303.1419361959061
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 7:32:26 PM UTC+1, Thiago Mac=
ieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>I think you ba=
sed your request on the simplest example possible. Yes, it would=20
<br>work for your example, but not for anything a little more complex.
<br>
<br>struct X {};
<br>struct Spacing { char buffer[100]; }
<br>struct Y: Spacing, X {};
<br>
<br>Now the covariant returns are permitted, but require a pointer-adjustme=
nt=20
<br>thunk because the value of an X* differs from an Y* if they point to th=
e same=20
<br>object.
<br>
<br>With that in mind, your request implies:
<br> - alll smart pointers must be able to handle deleting of derived =
classes if=20
<br> they delete, which isn't the case (example: std::unique_pt=
r with default=20
<br> deleter)
<br> - all smart pointers must be able to handle copying from a derive=
d class=20
<br> pointer or object containing the derived class
<br> - the compiler must know how to copy
<br>
<br>The first and last requirements are a non-starter.
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%=
3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhq=
Ln_62FW8ag';return true;" onclick=3D"this.href=3D'http://www.google.com/url=
?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNC=
Nanbu7euhqLn_62FW8ag';return true;">macieira.info</a> - thiago (AT) <a href=
=3D"http://kde.org" target=3D"_blank" onmousedown=3D"this.href=3D'http://ww=
w.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AFQj=
CNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;" onclick=3D"this.href=3D'http:=
//www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75=
AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;">kde.org</a>
<br> Software Architect - Intel Open Source Technology Center
<br> PGP/GPG: 0x6EF45358; fingerprint:
<br> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4=
5358
<br></blockquote><div><br>If I understand your first point correctly, then =
no, I don't think all smart pointers should be able to handle deleting of d=
erived classes. I think it's a user's responsibility to make sure that the =
base class X has a virtual destructor if they plan to delete objects of typ=
e Y polymorphically (e.g. through a unique_ptr<X>). After all, even t=
oday, nothing prevents the user (with reference to your example) from delet=
ing a pointer of type X* which is pointing to an object of type Y obtained =
by invoking an overriding virtual function - since Y* is covariant with X*,=
a function returning Y* can override a function returning X*. In my view, =
allowing a conversion from unique_ptr<Y> to unique_ptr<X> does =
not change anything here. That conversion exists and deletion of an object =
of type Y through a unique_ptr<X> can bite the user in several other =
contexts. I don't see why special concerns should be raised for this use ca=
se.<br><br>I am not sure I understand points 2. and 3. - in particular, I d=
on't understand if they follow from point 1., and whether the answer above =
indirectly addresses those as well. What do you mean by "the compiler must =
know how to copy"? What is to be copied?<br><br>Kind regards,<br><br>Andy</=
div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_579_433101303.1419361959061--
------=_Part_578_990395600.1419361959061--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 17:22:12 -0200
Raw View
On Tuesday 23 December 2014 11:12:38 Andy Prowl wrote:
> I am not sure I understand points 2. and 3. - in particular, I don't
> understand if they follow from point 1., and whether the answer above
> indirectly addresses those as well. What do you mean by "the compiler must
> know how to copy"? What is to be copied?
Suppose what you asked for were allowed:
struct X {};
struct Spacing { char buffer[100]; }
struct Y: Spacing, X {};
struct A
{
virtual std::shared_ptr<X> foo();
};
struct B : A
{
virtual std::shared_ptr<Y> foo() override;
};
void f(A *a)
{
a->foo();
}
The call to foo() must be placed virtually, since the compiler doesn't know
what the real tyoe of A is. If it's actually B, then that means it needs to
call, somehow, B::foo(), which returns std::shared_ptr<Y>, then somehow
copy/move that returned value into a std::shared_ptr<X>.
Of course that the compiler can't know how to do that. It needs to call a
helper function, probably the template move assignment operator or template
move constructor from std::shared_ptr.
If that is permitted, what's stopping one from writing:
struct A
{
virtual Foo foo();
};
struct B : A
{
virtual Bar foo() override;
};
for two unrelated types Foo and Bar, provided that
Bar b{Foo()};
compiles?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 11:31:58 -0800 (PST)
Raw View
------=_Part_706_2013043360.1419363118972
Content-Type: multipart/alternative;
boundary="----=_Part_707_1762376682.1419363118972"
------=_Part_707_1762376682.1419363118972
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 8:22:22 PM UTC+1, Thiago Macieira wrote:
>
>
> If that is permitted, what's stopping one from writing:
>
> struct A
> {
> virtual Foo foo();
> };
>
> struct B : A
> {
> virtual Bar foo() override;
> };
>
> for two unrelated types Foo and Bar, provided that
>
> Bar b{Foo()};
>
> compiles?
>
Nothing. What I'm proposing is to take into consideration *any* viable
implicit conversions, including user-defined ones; the conversions from
unique_ptr<D> to unique_ptr<B>, from shared_ptr<D> to shared_ptr<B>, from
D* to B*, from D& to B&, etc. would be just particular cases of the general
rule.
I can't find a good reason why your example above should not compile. If
"Bar b{Foo()};" (or rather, "Bar b = Foo();") compiles, this means a Foo
can be provided wherever a Bar is expected: in that case, why should we
prevent an overriding function to return a Foo when the caller of the
overridden function is expecting a Bar?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_707_1762376682.1419363118972
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 8:22:22 PM UTC+1, Thiago Mac=
ieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>If that is per=
mitted, what's stopping one from writing:
<br>
<br>struct A
<br>{
<br> virtual Foo foo();
<br>};
<br>
<br>struct B : A
<br>{
<br> virtual Bar foo() override;
<br>};
<br>
<br>for two unrelated types Foo and Bar, provided that
<br>
<br> Bar b{Foo()};
<br>
<br>compiles?
<br></blockquote><div><br>Nothing. What I'm proposing is to take into consi=
deration *any* viable implicit conversions, including user-defined ones; th=
e conversions from unique_ptr<D> to unique_ptr<B>, from shared_=
ptr<D> to shared_ptr<B>, from D* to B*, from D& to B&, =
etc. would be just particular cases of the general rule.<br><br>I can't fin=
d a good reason why your example above should not compile. If "Bar b{Foo()}=
;" (or rather, "Bar b =3D Foo();") compiles, this means a Foo can be provid=
ed wherever a Bar is expected: in that case, why should we prevent an overr=
iding function to return a Foo when the caller of the overridden function i=
s expecting a Bar?<br><br>Kind regards,<br><br>Andy</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_707_1762376682.1419363118972--
------=_Part_706_2013043360.1419363118972--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 17:54:26 -0200
Raw View
On Tuesday 23 December 2014 11:31:58 Andy Prowl wrote:
> Nothing. What I'm proposing is to take into consideration *any* viable
> implicit conversions, including user-defined ones; the conversions from
> unique_ptr<D> to unique_ptr<B>, from shared_ptr<D> to shared_ptr<B>, from
> D* to B*, from D& to B&, etc. would be just particular cases of the general
> rule.
Why do a covariant override at all?
In my experience, most covariant overrides can be replaced by a non-covariant
override returning the original type and adjust the caller code to up-cast as
needed.
> I can't find a good reason why your example above should not compile. If
> "Bar b{Foo()};" (or rather, "Bar b = Foo();") compiles, this means a Foo
> can be provided wherever a Bar is expected: in that case, why should we
> prevent an overriding function to return a Foo when the caller of the
> overridden function is expecting a Bar?
Data loss. Foo and Bar may be copyable, but may not be supersets of one
another.
Given that same rule, then:
struct A
{
virtual unsigned foo();
};
struct B : A
{
unsigned long long x;
virtual unsigned long long foo() override
{ return x; }
};
The above also compiles and you can virtually call foo() on A, getting a
truncated value without any warnings.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 12:24:39 -0800 (PST)
Raw View
------=_Part_4579_1403649467.1419366279675
Content-Type: multipart/alternative;
boundary="----=_Part_4580_1028729574.1419366279675"
------=_Part_4580_1028729574.1419366279675
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 8:54:31 PM UTC+1, Thiago Macieira wrote:
>
> On Tuesday 23 December 2014 11:31:58 Andy Prowl wrote:
> > Nothing. What I'm proposing is to take into consideration *any* viable
> > implicit conversions, including user-defined ones; the conversions from
> > unique_ptr<D> to unique_ptr<B>, from shared_ptr<D> to shared_ptr<B>,
> from
> > D* to B*, from D& to B&, etc. would be just particular cases of the
> general
> > rule.
>
> Why do a covariant override at all?
>
> In my experience, most covariant overrides can be replaced by a
> non-covariant
> override returning the original type and adjust the caller code to up-cast
> as
> needed.
>
I'm not sure what you mean here, unless you meant to write "down-cast"
instead of "up-cast". That's of course possible (and pretty much
unavoidable as of today), but unnecessary IMO. The logic seems sound to me:
if there is an implicit conversion from B to A, then this means I am
allowed to provide a B whenever an A is expected. Since the caller of the
base class's virtual function expects an A, it makes sense to allow the
overriding virtual function to provide a B (which would get implicitly
converted).
> > I can't find a good reason why your example above should not compile. If
> > "Bar b{Foo()};" (or rather, "Bar b = Foo();") compiles, this means a Foo
> > can be provided wherever a Bar is expected: in that case, why should we
> > prevent an overriding function to return a Foo when the caller of the
> > overridden function is expecting a Bar?
>
> Data loss. Foo and Bar may be copyable, but may not be supersets of one
> another.
But then the problem is not specific to this particular use case in which
that lossy conversion would be used. If the user does not want a lossy
conversion from Foo to Bar (or vice versa), then it should simply not use
it (or not define it) - either directly or in the context of covariant
return types. If the user overrides a function returning a Foo by a
function returning a Bar, and the conversion from Bar to Foo is lossy, I
expect the user to know what they are doing.
> Given that same rule, then:
>
> struct A
> {
> virtual unsigned foo();
> };
>
> struct B : A
> {
> unsigned long long x;
> virtual unsigned long long foo() override
> { return x; }
> };
>
> The above also compiles and you can virtually call foo() on A, getting a
> truncated value without any warnings.
>
Why "without any warnings"? When you compile B, the compiler has all the
necessary information for emitting a warning. Again, I don't see how this
differs from:
unsigned long long x = ...;
unsigned y = x;
If I am writing the above, it means I know what I am doing. If the data
loss matters, then I'm doing the wrong thing, yet nobody is stopping me.
Why should we try to stop the user from doing the same in the context of
covariant return types?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4580_1028729574.1419366279675
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 8:54:31 PM UTC+1, Thiago Mac=
ieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday 23 Dece=
mber 2014 11:31:58 Andy Prowl wrote:
<br>> Nothing. What I'm proposing is to take into consideration *any* vi=
able
<br>> implicit conversions, including user-defined ones; the conversions=
from
<br>> unique_ptr<D> to unique_ptr<B>, from shared_ptr<D&g=
t; to shared_ptr<B>, from
<br>> D* to B*, from D& to B&, etc. would be just particular cas=
es of the general
<br>> rule.
<br>
<br>Why do a covariant override at all?
<br>
<br>In my experience, most covariant overrides can be replaced by a non-cov=
ariant=20
<br>override returning the original type and adjust the caller code to up-c=
ast as=20
<br>needed.
<br></blockquote><div><br>I'm not sure what you mean here, unless you meant=
to write "down-cast" instead of "up-cast". That's of course possible (and =
pretty much unavoidable as of today), but unnecessary IMO. The logic seems =
sound to me: if there is an implicit conversion from B to A, then this mean=
s I am allowed to provide a B whenever an A is expected. Since the caller o=
f the base class's virtual function expects an A, it makes sense to allow t=
he overriding virtual function to provide a B (which would get implicitly c=
onverted). <br> </div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;=
">> I can't find a good reason why your example above should not compile=
.. If
<br>> "Bar b{Foo()};" (or rather, "Bar b =3D Foo();") compiles, this mea=
ns a Foo
<br>> can be provided wherever a Bar is expected: in that case, why shou=
ld we
<br>> prevent an overriding function to return a Foo when the caller of =
the
<br>> overridden function is expecting a Bar?
<br>
<br>Data loss. Foo and Bar may be copyable, but may not be supersets of one=
=20
<br>another. </blockquote><div><br>But then the problem is not specifi=
c to this particular use case in which that lossy conversion would be used.=
If the user does not want a lossy conversion from Foo to Bar (or vice vers=
a), then it should simply not use it (or not define it) - either directly o=
r in the context of covariant return types. If the user overrides a functio=
n returning a Foo by a function returning a Bar, and the conversion from Ba=
r to Foo is lossy, I expect the user to know what they are doing.<br> =
</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;">Given that same rule, th=
en:
<br>
<br>struct A
<br>{
<br> virtual unsigned foo();
<br>};
<br>
<br>struct B : A
<br>{
<br> unsigned long long x;
<br> virtual unsigned long long foo() override
<br> { return x; }
<br>};
<br>
<br>The above also compiles and you can virtually call foo() on A, getting =
a=20
<br>truncated value without any warnings.
<br></blockquote><div><br>Why "without any warnings"? When you compile B, t=
he compiler has all the necessary information for emitting a warning. Again=
, I don't see how this differs from:<br><br><div class=3D"prettyprint" styl=
e=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgroun=
d-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"sub=
prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">unsi=
gned</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">long</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">long</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><font color=3D"#006666"><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">...;</span></font><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">unsigned</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> y</span><font color=3D"#666600"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span></font></div></code></div><br>If I am wr=
iting the above, it means I know what I am doing. If the data loss matters,=
then I'm doing the wrong thing, yet nobody is stopping me. Why should we t=
ry to stop the user from doing the same in the context of covariant return =
types?<br><br>Kind regards,<br><br>Andy<br> </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4580_1028729574.1419366279675--
------=_Part_4579_1403649467.1419366279675--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 15:58:32 -0500
Raw View
On 2014-12-23 14:12, Andy Prowl wrote:
> On Tuesday, December 23, 2014 7:32:26 PM UTC+1, Thiago Macieira wrote:
>> - alll smart pointers must be able to handle deleting of derived classes
>> if they delete, which isn't the case (example: std::unique_ptr with
>> default deleter)
>
> If I understand your first point correctly, then no, I don't think all
> smart pointers should be able to handle deleting of derived classes. I
> think it's a user's responsibility to make sure that the base class X has a
> virtual destructor if they plan to delete objects of type Y polymorphically
> (e.g. through a unique_ptr<X>). After all, even today, nothing prevents the
> user (with reference to your example) from deleting a pointer of type X*
> which is pointing to an object of type Y obtained by invoking an overriding
> virtual function - since Y* is covariant with X*, a function returning Y*
> can override a function returning X*.
Of course, the compiler may be able to (and if it can, *ought* to)
diagnose this. I.e. if a covariant return converts from
unique_ptr<Derived> to unique_ptr<Base>, and Base does *not* have a
virtual dtor, that is an error. (In fact, such unique_ptr conversion
should very possible be an error, period. A static_assert in the
conversion operator could probably be used for this...)
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 16:21:10 -0500
Raw View
On 2014-12-23 14:22, Thiago Macieira wrote:
> [...]
> Of course that the compiler can't know how to do that. It needs to call a
> helper function, probably the template move assignment operator or template
> move constructor from std::shared_ptr.
>
> If that is permitted, what's stopping one from writing:
>
> struct A
> {
> virtual Foo foo();
> };
>
> struct B : A
> {
> virtual Bar foo() override;
> };
>
> for two unrelated types Foo and Bar, provided that
>
> Bar b{Foo()};
>
> compiles?
Why does it need to be prevented?
Example internal implementation:
struct A
{
virtual Foo foo() { return A::__foo(); }
private: Foo __foo();
};
struct B
{
virtual Bar foo() { return B::__foo(); } // shadows A::foo!
private:
Bar __foo();
virtual Foo foo() override final
{ return Foo{foo()}; } // calls B's virtual 'Bar foo()'
};
IOW, the virtual dispatch calls a flavor of foo() based on the type of
the pointer via which the method is invoked. Covariant return creates a
hidden thunk which converts from B's return type to A's return type
which supplies A's vtable entry. B makes that override final and hidden,
supplying a *NEW* vtable entry which returns B's return type and can be
overridden in derived classes as usual.
It's not much different from overloading (which can also hide base
virtual members), except the overload is based on the return type
instead of the parameters, with the addition that the hidden virtual
method of the base class has an implicit converting implementation.
On 2014-12-23 14:54, Thiago Macieira wrote:
> Why do a covariant override at all?
>
> In my experience, most covariant overrides can be replaced by a non-covariant
> override returning the original type and adjust the caller code to up-cast as
> needed.
It seems to me that the point would be to avoid this... (Anyway, in case
of return by value, allowing the above means less work or may avoid data
loss.)
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 16:28:31 -0500
Raw View
On 2014-12-23 15:24, Andy Prowl wrote:
> On Tuesday, December 23, 2014 8:54:31 PM UTC+1, Thiago Macieira wrote:
>> Given that same rule, then:
>>
>> struct A
>> {
>> virtual unsigned foo();
>> };
>>
>> struct B : A
>> {
>> unsigned long long x;
>> virtual unsigned long long foo() override
>> { return x; }
>> };
>>
>> The above also compiles and you can virtually call foo() on A, getting a
>> truncated value without any warnings.
>
> Why "without any warnings"? When you compile B, the compiler has all the
> necessary information for emitting a warning. Again, I don't see how this
> differs from:
>
> unsigned long long x = ...;
> unsigned y = x;
Well, -Wconversion is not on by default. I don't think the above warns
by default, either, but I agree both should emit the same warning. (And
also I agree that they aren't conceptually different.)
Although, Thiago's example may or may not be legal depending on whether
the conversion is defined as construction (i.e. brace initialization) or
a static_cast. The former is actually ill-formed for the above and
should error in this case; i.e. covariant returns would require a user
defined conversion operator or constructor.
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 19:35:46 -0200
Raw View
On Tuesday 23 December 2014 12:24:39 Andy Prowl wrote:
> > Given that same rule, then:
> >=20
> > struct A
> > {
> >=20
> > virtual unsigned foo();
> >=20
> > };
> >=20
> > struct B : A
> > {
> >=20
> > unsigned long long x;
> > virtual unsigned long long foo() override
> > { return x; }
> >=20
> > };
> >=20
> > The above also compiles and you can virtually call foo() on A, getting =
a
> > truncated value without any warnings.
>=20
> Why "without any warnings"? When you compile B, the compiler has all the
> necessary information for emitting a warning. Again, I don't see how this
> differs from:
Please tell me where the compiler would print a warning here:
struct A
{
virtual unsigned foo();
}
void f(A *a)
{
a->foo();
}
Because that's all it sees at the call site.
Or are you saying that it should generate a warning on the following, witho=
ut=20
the definition of the function?
struct B: A
{
virtual unsigned long long foo() override;
};
"warning: conversion from `unsigned long long' to `unsigned' may alter its=
=20
value in the return of virtual override of foo()"
> unsigned long long x =3D ...;
> unsigned y =3D x;
>=20
> If I am writing the above, it means I know what I am doing. If the data
> loss matters, then I'm doing the wrong thing, yet nobody is stopping me.
> Why should we try to stop the user from doing the same in the context of
> covariant return types?
Because in the above, there was an explicit assignment of a larger integer =
to=20
a smaller one, even if the cast itself was implicit.
unsigned f(unsigned long long y) { return y; }
=3D> warning: conversion to =E2=80=98unsigned int=E2=80=99 from =E2=80=98l=
ong long unsigned int=E2=80=99 may=20
alter its value [-Wconversion]
But I can silence such a warning with:
unsigned f(unsigned long long y) { return unsigned(y); }'
How do you suggest modifying the definition of B above so the compiler know=
s=20
not to emit a warning?
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 13:38:10 -0800 (PST)
Raw View
------=_Part_2597_1236033476.1419370690344
Content-Type: multipart/alternative;
boundary="----=_Part_2598_1405313701.1419370690344"
------=_Part_2598_1405313701.1419370690344
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 10:28:52 PM UTC+1, Matthew Woehlke wrote:
>
>
>
Although, Thiago's example may or may not be legal depending on whether
> the conversion is defined as construction (i.e. brace initialization) or
> a static_cast. The former is actually ill-formed for the above and
> should error in this case; i.e. covariant returns would require a user
> defined conversion operator or constructor.
>
Assuming that the overridden virtual function has return type T, I think an
overriding function can have return type U if and only if some invented
variable of type T can be copy-initialized from an rvalue of type U.
What do you think?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2598_1405313701.1419370690344
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 10:28:52 PM UTC+1, Matthew W=
oehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><span style=3D"fo=
nt-size: 13px;"> </span><br></blockquote><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;">Although, Thiago's example may or may not be legal dependin=
g on whether
<br>the conversion is defined as construction (i.e. brace initialization) o=
r
<br>a static_cast. The former is actually ill-formed for the above and
<br>should error in this case; i.e. covariant returns would require a user
<br>defined conversion operator or constructor.
<br></blockquote><div><br>Assuming that the overridden virtual function has=
return type T, I think an overriding function can have return type U if an=
d only if some invented variable of type T can be copy-initialized from an =
rvalue of type U.<br><br>What do you think?<br><br>Kind regards,<br><br>And=
y<br> <br><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2598_1405313701.1419370690344--
------=_Part_2597_1236033476.1419370690344--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 19:40:46 -0200
Raw View
On Tuesday 23 December 2014 15:58:32 Matthew Woehlke wrote:
> Of course, the compiler may be able to (and if it can, *ought* to)
> diagnose this. I.e. if a covariant return converts from
> unique_ptr<Derived> to unique_ptr<Base>, and Base does *not* have a
> virtual dtor, that is an error. (In fact, such unique_ptr conversion
> should very possible be an error, period. A static_assert in the
> conversion operator could probably be used for this...)
Unfortunately, this currently compiles:
struct X {};
struct Y : X { ~Y(); };
std::unique_ptr<Y> f();
void g()
{
std::unique_ptr<X> x = f();
}
There are no warnings and the Y destructor is not called.
Whether there is a valid use-case for erroring out on this or not, I can't
say.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 13:59:39 -0800 (PST)
Raw View
------=_Part_4868_1774481621.1419371979808
Content-Type: multipart/alternative;
boundary="----=_Part_4869_1607198258.1419371979808"
------=_Part_4869_1607198258.1419371979808
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Tuesday, December 23, 2014 10:35:52 PM UTC+1, Thiago Macieira wrote:=20
>
>
> Please tell me where the compiler would print a warning here:=20
>
> struct A=20
> {=20
> virtual unsigned foo();=20
> }=20
>
> void f(A *a)=20
> {=20
> a->foo();=20
> }=20
>
> Because that's all it sees at the call site.=20
>
Correct, the compiler cannot generate any warning here, but I do not see=20
this as a problem. The client is only concerned with the contract of=20
A::foo(), and shall assume that any subtype of A is able to fulfill=20
A::foo()'s contract. Now if a subtype of A called B is defined in a way=20
that it fulfills A::foo()'s contract (i.e. returning an unsigned long) by=
=20
truncating a value of type unsigned long long, then this is a something the=
=20
implementer of B has to be warned about, not the client of A. The compiler=
=20
should be able to warn during the compilation of B.
=20
> Or are you saying that it should generate a warning on the following,=20
> without=20
> the definition of the function?=20
>
> struct B: A=20
> {=20
> virtual unsigned long long foo() override;=20
> };=20
>
> "warning: conversion from `unsigned long long' to `unsigned' may alter it=
s=20
> value in the return of virtual override of foo()"=20
>
Yes, this is what I meant.
=20
> > unsigned long long x =3D ...;=20
> > unsigned y =3D x;=20
> >=20
> > If I am writing the above, it means I know what I am doing. If the data=
=20
> > loss matters, then I'm doing the wrong thing, yet nobody is stopping me=
..=20
> > Why should we try to stop the user from doing the same in the context o=
f=20
> > covariant return types?=20
>
> Because in the above, there was an explicit assignment of a larger intege=
r=20
> to=20
> a smaller one, even if the cast itself was implicit.=20
>
> unsigned f(unsigned long long y) { return y; }=20
> =3D> warning: conversion to =E2=80=98unsigned int=E2=80=99 from =E2=80=
=98long long unsigned int=E2=80=99=20
> may=20
> alter its value [-Wconversion]=20
>
> But I can silence such a warning with:=20
> unsigned f(unsigned long long y) { return unsigned(y); }'=20
>
> How do you suggest modifying the definition of B above so the compiler=20
> knows=20
> not to emit a warning?=20
>
Good question. Compiler-specific directives are one possibility, although I=
=20
do understand it is not a very elegant solution.
Kind regards,
Andy
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_4869_1607198258.1419371979808
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 10:35:52 PM UTC+1, Thiago Ma=
cieira wrote:<span style=3D"font-size: 13px;"> </span><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;">
<br>Please tell me where the compiler would print a warning here:
<br>
<br>struct A
<br>{
<br> virtual unsigned foo();
<br>}
<br>
<br>void f(A *a)
<br>{
<br> a->foo();
<br>}
<br>
<br>Because that's all it sees at the call site.
<br></blockquote><div><br></div><div><div>Correct, the compiler cannot gene=
rate any warning here, but I do not see this as a problem. The client is on=
ly concerned with the contract of A::foo(), and shall assume that any subty=
pe of A is able to fulfill A::foo()'s contract. Now if a subtype of A calle=
d B is defined in a way that it fulfills A::foo()'s contract (i.e. returnin=
g an unsigned long) by truncating a value of type unsigned long long, then =
this is a something the implementer of B has to be warned about, not the cl=
ient of A. The compiler should be able to warn during the compilation of B.=
</div></div><div><span style=3D"font-size: 13px;"> </span><br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;">Or are you saying that it should=
generate a warning on the following, without=20
<br>the definition of the function?
<br>
<br>struct B: A
<br>{
<br> virtual unsigned long l=
ong foo() override;
<br>};
<br>
<br>"warning: conversion from `unsigned long long' to `unsigned' may alter =
its=20
<br>value in the return of virtual override of foo()"
<br></blockquote><div><br></div><div><div>Yes, this is what I meant.</div><=
/div><div><span style=3D"font-size: 13px;"> </span><br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left:=
1px #ccc solid;padding-left: 1ex;">> unsigned long long x =3D ...;
<br>> unsigned y =3D x;
<br>>=20
<br>> If I am writing the above, it means I know what I am doing. If the=
data
<br>> loss matters, then I'm doing the wrong thing, yet nobody is stoppi=
ng me.
<br>> Why should we try to stop the user from doing the same in the cont=
ext of
<br>> covariant return types?
<br>
<br>Because in the above, there was an explicit assignment of a larger inte=
ger to=20
<br>a smaller one, even if the cast itself was implicit.
<br>
<br>unsigned f(unsigned long long y) { return y; }
<br> =3D> warning: conversion to =E2=80=98unsigned int=E2=80=99 fro=
m =E2=80=98long long unsigned int=E2=80=99 may=20
<br>alter its value [-Wconversion]
<br>
<br>But I can silence such a warning with:
<br>unsigned f(unsigned long long y) { return unsigned(y); }'
<br>
<br>How do you suggest modifying the definition of B above so the compiler =
knows=20
<br>not to emit a warning?
<br></blockquote><div><br>Good question. Compiler-specific directives are o=
ne possibility, although I do understand it is not a very elegant solution.=
<br><br>Kind regards,<br><br>Andy</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4869_1607198258.1419371979808--
------=_Part_4868_1774481621.1419371979808--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 17:35:09 -0500
Raw View
On 2014-12-23 16:38, Andy Prowl wrote:
> On Tuesday, December 23, 2014 10:28:52 PM UTC+1, Matthew Woehlke wrote:
>> Although, Thiago's example may or may not be legal depending on whether
>> the conversion is defined as construction (i.e. brace initialization) or
>> a static_cast. The former is actually ill-formed for the above and
>> should error in this case; i.e. covariant returns would require a user
>> defined conversion operator or constructor.
>
> Assuming that the overridden virtual function has return type T, I think an
> overriding function can have return type U if and only if some invented
> variable of type T can be copy-initialized from an rvalue of type U.
....or if there exists a conversion operator, e.g. 'U::operator T'. Or,
put differently, if the following is legal:
U&& u = ...;
return T{u};
But basically, yes, that's what I was trying to say. I think we're on
the same page.
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 17:45:21 -0500
Raw View
On 2014-12-23 16:35, Thiago Macieira wrote:
> Please tell me where the compiler would print a warning [...]
> Or are you saying that it should generate a warning on the following, without
> the definition of the function?
>
> struct B: A
> {
> virtual unsigned long long foo() override;
> };
>
> "warning: conversion from `unsigned long long' to `unsigned' may alter its
> value in the return of virtual override of foo()"
Right. In order to satisfy A's vtable, there exists an implementation in
B of 'virtual unsigned foo() override /*final*/'. Wherever that is
compiled, I would expect a warning. (I guess that would be in any TU
that includes the definition of B, since the definition is effectively
inline.)
If we go with the 'as if brace initialized', you'd actually get a
-Wnarrowing warning (or error).
> On Tuesday 23 December 2014 12:24:39 Andy Prowl wrote:
>> unsigned long long x = ...;
>> unsigned y = x;
>>
>> If I am writing the above, it means I know what I am doing. If the data
>> loss matters, then I'm doing the wrong thing, yet nobody is stopping me.
>> Why should we try to stop the user from doing the same in the context of
>> covariant return types?
>
> Because in the above, there was an explicit assignment of a larger integer to
> a smaller one, even if the cast itself was implicit.
....and you still get a -Wconversion warning, which we expect as a
minimum for the covariant return case also (if not -Wnarrowing).
> But I can silence such a warning with:
> unsigned f(unsigned long long y) { return unsigned(y); }'
>
> How do you suggest modifying the definition of B above so the compiler knows
> not to emit a warning?
Either use a pragma, or don't use a covariant return that results in a
warning in the first place :-).
In practice I would expect covariant returns of integral types to be
much less common than of [pointers to] class types.
If we *really* need this, I almost feel like the correct solution is to
allow the user to supply definitions of both the base override and the
flavor with the covariant return type. (Which, yeah, violates the 'no
overload on return type' rule... we'd need a careful exception.)
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 14:52:00 -0800 (PST)
Raw View
------=_Part_2801_704135978.1419375120404
Content-Type: multipart/alternative;
boundary="----=_Part_2802_1778487276.1419375120404"
------=_Part_2802_1778487276.1419375120404
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 11:45:38 PM UTC+1, Matthew Woehlke wrote:
>
>
> Either use a pragma, or don't use a covariant return that results in a
> warning in the first place :-).
>
> In practice I would expect covariant returns of integral types to be
> much less common than of [pointers to] class types.
>
I share your thoughts on this.
> If we *really* need this, I almost feel like the correct solution is to
> allow the user to supply definitions of both the base override and the
> flavor with the covariant return type. (Which, yeah, violates the 'no
> overload on return type' rule... we'd need a careful exception.)
>
Personally, I would not go that far. If the only purpose of this exception
would be to avoid using pragmas for silecing warnings about narrowing
conversions for covariant return types, it is not worth it. That's my
impression at least.
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2802_1778487276.1419375120404
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 11:45:38 PM UTC+1, Matthew W=
oehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>Either use a =
pragma, or don't use a covariant return that results in a
<br>warning in the first place :-).
<br>
<br>In practice I would expect covariant returns of integral types to be
<br>much less common than of [pointers to] class types.
<br></blockquote><div> </div><div>I share your thoughts on this.<br>&n=
bsp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">If we *really* need =
this, I almost feel like the correct solution is to
<br>allow the user to supply definitions of both the base override and the
<br>flavor with the covariant return type. (Which, yeah, violates the 'no
<br>overload on return type' rule... we'd need a careful exception.)
<br></blockquote><div><br>Personally, I would not go that far. If the only =
purpose of this exception would be to avoid using pragmas for silecing warn=
ings about narrowing conversions for covariant return types, it is not wort=
h it. That's my impression at least.<br><br>Kind regards,<br><br>Andy</div>=
</div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2802_1778487276.1419375120404--
------=_Part_2801_704135978.1419375120404--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 17:52:12 -0500
Raw View
On 2014-12-23 16:40, Thiago Macieira wrote:
> On Tuesday 23 December 2014 15:58:32 Matthew Woehlke wrote:
>> Of course, the compiler may be able to (and if it can, *ought* to)
>> diagnose this. I.e. if a covariant return converts from
>> unique_ptr<Derived> to unique_ptr<Base>, and Base does *not* have a
>> virtual dtor, that is an error. (In fact, such unique_ptr conversion
>> should very possible be an error, period. A static_assert in the
>> conversion operator could probably be used for this...)
>
> Unfortunately, this currently compiles:
>
> struct X {};
> struct Y : X { ~Y(); };
>
> std::unique_ptr<Y> f();
> void g()
> {
> std::unique_ptr<X> x = f();
> }
>
> There are no warnings and the Y destructor is not called.
"Unfortunate" is indeed the correct word :-).
As far as the original topic, I don't think we should make the behavior
here different for covariant return types. If you can write such broken
code without covariant returns involved, having it suddenly diagnose
because it's happening via a covariant return seems a little odd. If we
want to diagnose it, we should diagnose it here also.
(I don't think we had the necessary introspection to be *able* to
diagnose this as of C++11, which probably has something to do with why
it isn't being diagnosed... At the very least, this should trip some
warning, e.g. -Wnon-virtual-dtor.)
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 17:59:19 -0500
Raw View
On 2014-12-23 17:52, Matthew Woehlke wrote:
> On 2014-12-23 16:40, Thiago Macieira wrote:
>> Unfortunately, this currently compiles:
>>
>> struct X {};
>> struct Y : X { ~Y(); };
>>
>> std::unique_ptr<Y> f();
>> void g()
>> {
>> std::unique_ptr<X> x = f();
>> }
>>
>> There are no warnings and the Y destructor is not called.
>
> "Unfortunate" is indeed the correct word :-).
>
> (I don't think we had the necessary introspection to be *able* to
> diagnose this as of C++11, which probably has something to do with why
> it isn't being diagnosed... At the very least, this should trip some
> warning, e.g. -Wnon-virtual-dtor.)
Meanwhile I've filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64399
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 15:00:04 -0800 (PST)
Raw View
------=_Part_236_1816886806.1419375604783
Content-Type: multipart/alternative;
boundary="----=_Part_237_1346571749.1419375604783"
------=_Part_237_1346571749.1419375604783
Content-Type: text/plain; charset=UTF-8
On Tuesday, December 23, 2014 11:52:27 PM UTC+1, Matthew Woehlke wrote:
> (I don't think we had the necessary introspection to be *able* to
> diagnose this as of C++11, which probably has something to do with why
> it isn't being diagnosed... At the very least, this should trip some
> warning, e.g. -Wnon-virtual-dtor.)
Actually, C++11 has the std::has_virtual_destructor type trait, so unless
I'm missing something the risky conversions for unique_ptr could have been
ruled out by design library-wise (shared_ptr has a type-erased deleter, so
this discussion does not apply to it). Perhaps allowing those conversions
was a conscious decision?
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_237_1346571749.1419375604783
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, December 23, 2014 11:52:27 PM UTC+1, Matthew W=
oehlke wrote:<div> </div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
(I don't think we had the necessary introspection to be *able* to
<br>diagnose this as of C++11, which probably has something to do with why
<br>it isn't being diagnosed... At the very least, this should trip some
<br>warning, e.g. -Wnon-virtual-dtor.)
</blockquote><div> </div><div>Actually, C++11 has the std::has_virtual=
_destructor type trait, so unless I'm missing something the risky conversio=
ns for unique_ptr could have been ruled out by design library-wise (shared_=
ptr has a type-erased deleter, so this discussion does not apply to it). Pe=
rhaps allowing those conversions was a conscious decision?<br><br>Kind rega=
rds,<br><br>Andy</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_237_1346571749.1419375604783--
------=_Part_236_1816886806.1419375604783--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 23 Dec 2014 18:02:13 -0500
Raw View
On 2014-12-23 17:52, Andy Prowl wrote:
> On Tuesday, December 23, 2014 11:45:38 PM UTC+1, Matthew Woehlke wrote:
>> If we *really* need this, I almost feel like the correct solution is to
>> allow the user to supply definitions of both the base override and the
>> flavor with the covariant return type. (Which, yeah, violates the 'no
>> overload on return type' rule... we'd need a careful exception.)
>
> Personally, I would not go that far. If the only purpose of this exception
> would be to avoid using pragmas for silecing warnings about narrowing
> conversions for covariant return types, it is not worth it. That's my
> impression at least.
Agreed. I would hope that in actual practice this is not an issue and
can be ignored (or at least, is not sufficiently an issue that folks
would take umbrage to using pragmas or the like to work around it).
That's why I emphasized "really" in the above :-).
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 Dec 2014 23:37:24 -0200
Raw View
On Tuesday 23 December 2014 15:00:04 Andy Prowl wrote:
> On Tuesday, December 23, 2014 11:52:27 PM UTC+1, Matthew Woehlke wrote:
> > (I don't think we had the necessary introspection to be *able* to
> > diagnose this as of C++11, which probably has something to do with why
> > it isn't being diagnosed... At the very least, this should trip some
> > warning, e.g. -Wnon-virtual-dtor.)
>
> Actually, C++11 has the std::has_virtual_destructor type trait, so unless
> I'm missing something the risky conversions for unique_ptr could have been
> ruled out by design library-wise (shared_ptr has a type-erased deleter, so
> this discussion does not apply to it). Perhaps allowing those conversions
> was a conscious decision?
You can delete it properly by casting it to the right type before delete or by
moving it to a right-type std::unique_ptr.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.