Topic: Interchangeable syntax for type forward declarations
Author: Igor Baidiuk <target.san@gmail.com>
Date: Wed, 3 Jan 2018 10:29:14 -0800 (PST)
Raw View
------=_Part_38211_1459819583.1515004154882
Content-Type: multipart/alternative;
boundary="----=_Part_38212_1349986979.1515004154883"
------=_Part_38212_1349986979.1515004154883
Content-Type: text/plain; charset="UTF-8"
There's one strange inconvenience in C++, which is forward declaring
certain type. Strange because it's really simple to fix IMO.
1. If you forward declare some type with struct/class/union, you're
required to use the same keyword when you define its body
2. No way to forward-declare type alias.
Proposal is very simple:
1. Make struct/class interchangeable when forward-declaring anything.
Possibly, allow "typename" to be used in the same context
2. Allow to forward-declare type aliases the same way as normal types
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/848201ee-7402-4c4d-8a16-af610f945944%40isocpp.org.
------=_Part_38212_1349986979.1515004154883
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">There's one strange inconvenience in C++, which is for=
ward declaring certain type. Strange because it's really simple to fix =
IMO.<br><br>1. If you forward declare some type with struct/class/union, yo=
u're required to use the same keyword when you define its body<br>2. No=
way to forward-declare type alias.<br><br>Proposal is very simple:<br>1. M=
ake struct/class interchangeable when forward-declaring anything. Possibly,=
allow "typename" to be used in the same context<br>2. Allow to f=
orward-declare type aliases the same way as normal types<br><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/848201ee-7402-4c4d-8a16-af610f945944%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/848201ee-7402-4c4d-8a16-af610f945944=
%40isocpp.org</a>.<br />
------=_Part_38212_1349986979.1515004154883--
------=_Part_38211_1459819583.1515004154882--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 3 Jan 2018 20:59:29 +0200
Raw View
On 3 January 2018 at 20:29, Igor Baidiuk <target.san@gmail.com> wrote:
> There's one strange inconvenience in C++, which is forward declaring certain
> type. Strange because it's really simple to fix IMO.
>
> 1. If you forward declare some type with struct/class/union, you're required
> to use the same keyword when you define its body
> 2. No way to forward-declare type alias.
>
> Proposal is very simple:
> 1. Make struct/class interchangeable when forward-declaring anything.
> Possibly, allow "typename" to be used in the same context
> 2. Allow to forward-declare type aliases the same way as normal types
The standard already allows forward-declaring with struct and defining
with class and vice versa. If you have problems with that,
a) complain to Microsoft so that they stop the madness of their
implementation refusing to conform
b) complain to clang developers so that they stop the madness of
warning about such uses in an attempt to be helpful to
people that might compile their code on MSVC.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUbVrj0KouLO0CyLMNrNj803Zjq6P391YMX6GReNBkN-zA%40mail.gmail.com.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 03 Jan 2018 17:35:13 -0200
Raw View
On Wednesday, 3 January 2018 16:29:14 -02 Igor Baidiuk wrote:
> There's one strange inconvenience in C++, which is forward declaring
> certain type. Strange because it's really simple to fix IMO.
>
> 1. If you forward declare some type with struct/class/union, you're
> required to use the same keyword when you define its body
True for union, not true for struct or class. A union is quite a different
beast from a struct/class.
> 2. No way to forward-declare type alias.
>
> Proposal is very simple:
> 1. Make struct/class interchangeable when forward-declaring anything.
> Possibly, allow "typename" to be used in the same context
Struct and class already ARE interchangeable.
> 2. Allow to forward-declare type aliases the same way as normal types
This I'd like to see.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2830355.7vpS7njdV0%40tjmaciei-mobl1.
.
Author: Brian Bi <bbi5291@gmail.com>
Date: Wed, 3 Jan 2018 12:44:44 -0800
Raw View
--001a113cd88c0bc9650561e549d4
Content-Type: text/plain; charset="UTF-8"
There is a previous thread on this topic here
<https://groups.google.com/a/isocpp.org/d/msg/std-proposals/fm-ThgXXjF4/ELRdkOwzWmkJ>.
Richard Smith wrote:
Such a proposal would need to be accompanied by an explanation of how to
> make it work with existing name-matching linker technology, or an
> explanation of why the feature is so valuable that it would be reasonable
> to require new linker technology to link C++ code (other C++ features have
> required this, but it's a very high bar). Without that, I expect you'll
> find a lot of opposition.
>
This is regarding what you call proposal #1.
I can't think of any case where the ability to forward-declare a type as
"struct" or "class" and then later define it as "union", or vice versa,
would be especially useful.
Proposal #2 is tricky---I can see how it would be useful to be able to
forward-declare typedefs, but it is not that easy. In current C++, a
forward declaration of a class, like so:
class T;
tells the compiler that T is a class type which is *distinct from any other
class defined before or since*. If we could forward-declare T to be a
typedef (I don't know what syntax we would use) then we would be telling
the compiler that T is a type which *may be any type whatsoever, which
might or might not be identical to any type declared at any point before we
finally find out which type T really is*.
This would require some careful thought and a lot of standardese, and it
seems likely to cause ODR violations.
On Wed, Jan 3, 2018 at 11:35 AM, Thiago Macieira <thiago@macieira.org>
wrote:
> On Wednesday, 3 January 2018 16:29:14 -02 Igor Baidiuk wrote:
> > There's one strange inconvenience in C++, which is forward declaring
> > certain type. Strange because it's really simple to fix IMO.
> >
> > 1. If you forward declare some type with struct/class/union, you're
> > required to use the same keyword when you define its body
>
> True for union, not true for struct or class. A union is quite a different
> beast from a struct/class.
>
> > 2. No way to forward-declare type alias.
> >
> > Proposal is very simple:
> > 1. Make struct/class interchangeable when forward-declaring anything.
> > Possibly, allow "typename" to be used in the same context
>
> Struct and class already ARE interchangeable.
>
> > 2. Allow to forward-declare type aliases the same way as normal types
>
> This I'd like to see.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/2830355.7vpS7njdV0%40tjmaciei-mobl1.
>
--
*Brian Bi*
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjbOSjLxFKK%3DgvhX2Z%3Dms2sEBA%2Bi%2BCT3iqwo%2B-U-XO9E8pg%40mail.gmail.com.
--001a113cd88c0bc9650561e549d4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>There is a previous thread on this topic <a href=3D"h=
ttps://groups.google.com/a/isocpp.org/d/msg/std-proposals/fm-ThgXXjF4/ELRdk=
OwzWmkJ">here</a>. Richard Smith wrote:<br></div><div><br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px so=
lid rgb(204,204,204);padding-left:1ex"><div><div>Such a proposal would need=
to be accompanied by an explanation of=20
how to make it work with existing name-matching linker technology, or an
explanation of why the feature is so valuable that it would be=20
reasonable to require new linker technology to link C++ code (other C++=20
features have required this, but it's a very high bar). Without that, I=
=20
expect you'll find a lot of opposition.</div></div></blockquote><div><b=
r></div><div>This is regarding what you call proposal #1.</div><div><br></d=
iv><div>I can't think of any case where the ability to forward-declare =
a type as "struct" or "class" and then later define it =
as "union", or vice versa, would be especially useful.<br></div><=
div><br></div><div>Proposal #2 is tricky---I can see how it would be useful=
to be able to forward-declare typedefs, but it is not that easy. In curren=
t C++, a forward declaration of a class, like so:</div><div><br></div><div>=
=C2=A0=C2=A0=C2=A0 class T;</div><div><br></div><div>tells the compiler tha=
t T is a class type which is <i>distinct from any other class defined befor=
e or since</i>. If we could forward-declare T to be a typedef (I don't =
know what syntax we would use) then we would be telling the compiler that T=
is a type which <i>may be any type whatsoever, which might or might not be=
identical to any type declared at any point before we finally find out whi=
ch type T really is</i>.</div><div><br></div><div>This would require some c=
areful thought and a lot of standardese, and it seems likely to cause ODR v=
iolations.<br></div></div><div class=3D"gmail_extra"><br><div class=3D"gmai=
l_quote">On Wed, Jan 3, 2018 at 11:35 AM, Thiago Macieira <span dir=3D"ltr"=
><<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@maciei=
ra.org</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=
=3D"">On Wednesday, 3 January 2018 16:29:14 -02 Igor Baidiuk wrote:<br>
> There's one strange inconvenience in C++, which is forward declari=
ng<br>
> certain type. Strange because it's really simple to fix IMO.<br>
><br>
> 1. If you forward declare some type with struct/class/union, you'r=
e<br>
> required to use the same keyword when you define its body<br>
<br>
</span>True for union, not true for struct or class. A union is quite a dif=
ferent<br>
beast from a struct/class.<br>
<span class=3D""><br>
> 2. No way to forward-declare type alias.<br>
><br>
> Proposal is very simple:<br>
> 1. Make struct/class interchangeable when forward-declaring anything.<=
br>
> Possibly, allow "typename" to be used in the same context<br=
>
<br>
</span>Struct and class already ARE interchangeable.<br>
<span class=3D""><br>
> 2. Allow to forward-declare type aliases the same way as normal types<=
br>
<br>
</span>This I'd like to see.<br>
<br>
--<br>
Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"noref=
errer" target=3D"_blank">macieira.info</a> - thiago (AT) <a href=3D"http://=
kde.org" rel=3D"noreferrer" target=3D"_blank">kde.org</a><br>
=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center<br>
<span class=3D""><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%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/2830355.7vpS7njdV0%40tjmaciei-=
mobl1" rel=3D"noreferrer" target=3D"_blank">https://groups.google.com/a/<wb=
r>isocpp.org/d/msgid/std-<wbr>proposals/2830355.7vpS7njdV0%<wbr>40tjmaciei-=
mobl1</a>.<br>
</blockquote></div><br><br clear=3D"all"><br>-- <br><div class=3D"gmail_sig=
nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=
=3D"ltr"><font color=3D"#c0c0c0"><i>Brian Bi</i></font><br><div></div><div>=
</div><div></div></div></div></div></div>
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAMmfjbOSjLxFKK%3DgvhX2Z%3Dms2sEBA%2B=
i%2BCT3iqwo%2B-U-XO9E8pg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjb=
OSjLxFKK%3DgvhX2Z%3Dms2sEBA%2Bi%2BCT3iqwo%2B-U-XO9E8pg%40mail.gmail.com</a>=
..<br />
--001a113cd88c0bc9650561e549d4--
.
Author: Bo Persson <bop@gmb.dk>
Date: Thu, 4 Jan 2018 00:38:15 +0100
Raw View
On 2018-01-03 21:44, Brian Bi wrote:
> There is a previous thread on this topic here=20
> <https://groups.google.com/a/isocpp.org/d/msg/std-proposals/fm-ThgXXjF4/E=
LRdkOwzWmkJ>.=20
> Richard Smith wrote:
>=20
> Such a proposal would need to be accompanied by an explanation of
> how to make it work with existing name-matching linker technology,
> or an explanation of why the feature is so valuable that it would be
> reasonable to require new linker technology to link C++ code (other
> C++ features have required this, but it's a very high bar). Without
> that, I expect you'll find a lot of opposition.
>=20
>=20
> This is regarding what you call proposal #1.
>=20
> I can't think of any case where the ability to forward-declare a type as=
=20
> "struct" or "class" and then later define it as "union", or vice versa,=
=20
> would be especially useful.
>=20
> Proposal #2 is tricky---I can see how it would be useful to be able to=20
> forward-declare typedefs, but it is not that easy. In current C++, a=20
> forward declaration of a class, like so:
>=20
> =C2=A0=C2=A0=C2=A0 class T;
>=20
> tells the compiler that T is a class type which is /distinct from any=20
> other class defined before or since/. If we could forward-declare T to=20
> be a typedef (I don't know what syntax we would use) then we would be=20
> telling the compiler that T is a type which /may be any type whatsoever,=
=20
> which might or might not be identical to any type declared at any point=
=20
> before we finally find out which type T really is/.
>=20
> This would require some careful thought and a lot of standardese, and it=
=20
> seems likely to cause ODR violations.
>=20
There is an additional problem in that pointers to the built-in types do=20
not all have to be of the same size. For example, a char* might be=20
larger than an int* on word-addresses machines.
So if we do a typedef x; (or however we forward declare a typedef) we=20
still don't know the size of an x*.
On the other hand, the fact that we CAN forward declare class T; is an=20
implicit requirement that all pointers to class objects must be of the=20
same size, even if that is not spelled out.
Bo Persson
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/p2jpdd%24thj%241%40blaine.gmane.org.
.
Author: mihailnajdenov@gmail.com
Date: Thu, 4 Jan 2018 12:15:18 -0800 (PST)
Raw View
------=_Part_3532_1087643766.1515096918862
Content-Type: multipart/alternative;
boundary="----=_Part_3533_275132421.1515096918862"
------=_Part_3533_275132421.1515096918862
Content-Type: text/plain; charset="UTF-8"
While we are at it, can we have a new magical way to forward declare
templates without spelling out every argument (considering some might be an
impl. detail)?
Right now that is the killing blow to using fwd dcl "everywhere".
Of course having fwd dcl to aliases will alleviate the problem a great deal.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0cd63791-f86c-46f6-b429-78ec0e96e9a1%40isocpp.org.
------=_Part_3533_275132421.1515096918862
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>While we are at it, can we have a new magical way to =
forward declare templates without spelling out every argument (considering =
some might be an impl. detail)?</div><div><br></div><div>Right now that is =
the killing blow to using fwd dcl "everywhere".</div><div><br></d=
iv><div>Of course having fwd dcl to aliases will alleviate the problem a gr=
eat deal.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0cd63791-f86c-46f6-b429-78ec0e96e9a1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0cd63791-f86c-46f6-b429-78ec0e96e9a1=
%40isocpp.org</a>.<br />
------=_Part_3533_275132421.1515096918862--
------=_Part_3532_1087643766.1515096918862--
.
Author: Igor Baidiuk <target.san@gmail.com>
Date: Thu, 4 Jan 2018 13:06:15 -0800 (PST)
Raw View
------=_Part_3638_1627997012.1515099975661
Content-Type: multipart/alternative;
boundary="----=_Part_3639_1252434616.1515099975661"
------=_Part_3639_1252434616.1515099975661
Content-Type: text/plain; charset="UTF-8"
I humbly hope that we'll get modules at least for C++20. At least in the
form proposed by GDR. At which point forward declarations should become
much less needed. Though, modules were first proposed in 2003. And SG2
looks completely abandoned.
On Thursday, January 4, 2018 at 10:15:18 PM UTC+2, mihailn...@gmail.com
wrote:
>
> While we are at it, can we have a new magical way to forward declare
> templates without spelling out every argument (considering some might be an
> impl. detail)?
>
> Right now that is the killing blow to using fwd dcl "everywhere".
>
> Of course having fwd dcl to aliases will alleviate the problem a great
> deal.
>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/57ea4918-e0e2-4287-a018-c393dd588196%40isocpp.org.
------=_Part_3639_1252434616.1515099975661
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I humbly hope that we'll get modules at least for C++2=
0. At least in the form proposed by GDR. At which point forward declaration=
s should become much less needed. Though, modules were first proposed in 20=
03. And SG2 looks completely abandoned.<br><br>On Thursday, January 4, 2018=
at 10:15:18 PM UTC+2, mihailn...@gmail.com wrote:<blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr"><div>While we are at it, can we have a=
new magical way to forward declare templates without spelling out every ar=
gument (considering some might be an impl. detail)?</div><div><br></div><di=
v>Right now that is the killing blow to using fwd dcl "everywhere"=
;.</div><div><br></div><div>Of course having fwd dcl to aliases will allevi=
ate the problem a great deal.<br></div></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/57ea4918-e0e2-4287-a018-c393dd588196%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/57ea4918-e0e2-4287-a018-c393dd588196=
%40isocpp.org</a>.<br />
------=_Part_3639_1252434616.1515099975661--
------=_Part_3638_1627997012.1515099975661--
.