Topic: General anonymous class proposal


Author: Daryle Walker <darylew@gmail.com>
Date: Mon, 3 Feb 2014 17:59:36 -0800 (PST)
Raw View
------=_Part_1843_11093930.1391479176359
Content-Type: text/plain; charset=UTF-8

I got a proposal for anonymous classes<http://htmlpreview.github.io/?https://raw.github.com/CTMacUser/multiarray-iso-proposal/master/anonymous-class-proposal.html>uploaded on my GitHub pages. It generalizes the C++ anonymous union feature
in a way that should be compatible with the C11 anonymous structure & union
feature. I'm looking if I missed something in the sections I proposed to
change, and if I need to change more sections.

Handling of anonymous unions in the C++ way has been (mostly) changed to
the C11 way:

struct A {
  int a; union { int b; /*...*/ };
} x = { 1, { 2 } }, y = { 3, 4 };


In current C++, the second initializer term in x is the proper way to
initialize the anonymous union, and the version in y is the slack version
in that braces are elided. In C11, the official-ness is reversed: the
second initializer term in y is the proper way to initialize the b member
(Named members of anonymous composites are spewed to their enclosing scope,
recursively if needed.) and the version in x is the slack version with a
gratuitous pair of braces. My proposal goes the C11 way, which is a
"breaking" change with no effect (I hope).

Due to arbitrary nesting and that an anonymous struct may be a member of a
union, the variant branches of a union may have multiple co-variants
instead of always exactly one co-variant per variant branch. I added the
terms "conflicting members" and "non-conflicting members" to replace the
idea that a class's variants are always distinct and mutually-exclusive.

I call considering the members of an anonymous class to be part of the
encloser's scope to be their "elevated scope." Members nested in at least
two anonymous classes bubble up to use the outermost's class's enclosing
scope.

When an anonymous class member is empty, the member is considered part of
the enclosing class. This is the C++ way of handling empty classes, instead
of the C11 way of never considering anonymous class subobjects as
themselves. This shouldn't break anything because empty composites are
illegal in C(11)! (C requires structs and unions to have at least one
member; they can't be empty. Please notify me if I got this wrong.)

Daryle W.

--

---
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_1843_11093930.1391479176359
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I got a <a href=3D"http://htmlpreview.github.io/?http=
s://raw.github.com/CTMacUser/multiarray-iso-proposal/master/anonymous-class=
-proposal.html">proposal for anonymous classes</a> uploaded on my GitHub pa=
ges. It generalizes the C++ anonymous union feature in a way that should be=
 compatible with the C11 anonymous structure &amp; union feature. I'm looki=
ng if I missed something in the sections I proposed to change, and if I nee=
d to change more sections.</div><div><br></div><div>Handling of anonymous u=
nions in the C++ way has been (mostly) changed to the C11 way:</div><div><b=
r></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187,=
 187); border-image: none; -ms-word-wrap: break-word; background-color: rgb=
(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><font color=3D"#000088"><span class=3D"styled-by-prettify" style=3D"color:=
 rgb(0, 0, 136);">struct</span></font><span class=3D"styled-by-prettify" st=
yle=3D"color: rgb(0, 0, 0);"> A </span><span class=3D"styled-by-prettify" s=
tyle=3D"color: rgb(102, 102, 0);">{</span><span class=3D"styled-by-prettify=
" style=3D"color: rgb(0, 0, 0);"><br>&nbsp; </span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(0, 0, 136);">int</span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(0, 0, 0);"> a</span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(102, 102, 0);">;</span><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(0, 0, 136);">union</span><span class=3D=
"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"=
styled-by-prettify" style=3D"color: rgb(102, 102, 0);">{</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">int</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> b</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">;</span><span=
 class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(136, 0, 0);">/*...*/</span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span>=
<span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">};</s=
pan><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br><=
/span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);"=
>}</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=
 x </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, =
0);">=3D</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0,=
 0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 1=
02, 0);">{</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, =
0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 1=
02, 102);">1</span><span class=3D"styled-by-prettify" style=3D"color: rgb(1=
02, 102, 0);">,</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb=
(102, 102, 0);">{</span><span class=3D"styled-by-prettify" style=3D"color: =
rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"color: r=
gb(0, 102, 102);">2</span><span class=3D"styled-by-prettify" style=3D"color=
: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"color:=
 rgb(102, 102, 0);">}</span><span class=3D"styled-by-prettify" style=3D"col=
or: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"colo=
r: rgb(102, 102, 0);">},</span><span class=3D"styled-by-prettify" style=3D"=
color: rgb(0, 0, 0);"> y </span><span class=3D"styled-by-prettify" style=3D=
"color: rgb(102, 102, 0);">=3D</span><span class=3D"styled-by-prettify" sty=
le=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" styl=
e=3D"color: rgb(102, 102, 0);">{</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" st=
yle=3D"color: rgb(0, 102, 102);">3</span><span class=3D"styled-by-prettify"=
 style=3D"color: rgb(102, 102, 0);">,</span><span class=3D"styled-by-pretti=
fy" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettif=
y" style=3D"color: rgb(0, 102, 102);">4</span><span class=3D"styled-by-pret=
tify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prett=
ify" style=3D"color: rgb(102, 102, 0);">};</span><span class=3D"styled-by-p=
rettify" style=3D"color: rgb(0, 0, 0);"><br></span></div></code></div><p><b=
r></p><div>In current C++, the second initializer term in <font face=3D"cou=
rier new,monospace">x</font> is the proper way to initialize the anonymous =
union, and the version in <font face=3D"courier new,monospace">y</font> is =
the slack version in that braces are elided. In C11, the official-ness is r=
eversed: the second initializer term in <font face=3D"courier new,monospace=
">y</font> is the proper way to initialize the <font face=3D"courier new,mo=
nospace">b</font> member (Named members of anonymous composites are spewed =
to their enclosing scope, recursively if needed.) and the version in <font =
face=3D"courier new,monospace">x</font> is the slack version with a gratuit=
ous pair of braces. My proposal goes the C11 way, which&nbsp;is a "breaking=
" change with no effect (I hope).</div><div><br></div><div>Due to arbitrary=
 nesting and that an anonymous struct may be a member of a union, the varia=
nt branches of a union may have multiple co-variants instead of always exac=
tly one co-variant per variant branch. I added the terms "conflicting membe=
rs" and "non-conflicting members" to replace the idea that a class's varian=
ts are always distinct and mutually-exclusive.</div><div><br></div><div>I c=
all considering the members of an anonymous class to be part of the enclose=
r's scope to be their "elevated scope." Members nested in at least two anon=
ymous classes bubble up to use the outermost's class's enclosing scope.</di=
v><div><br></div><div>When an anonymous class member is empty, the member i=
s considered part of the enclosing class. This is the C++ way of handling e=
mpty classes, instead of the C11 way of never considering anonymous class s=
ubobjects as themselves. This shouldn't break anything because empty compos=
ites are illegal in C(11)! (C requires structs and unions to have at least =
one member; they can't be empty. Please notify me if I got this wrong.)</di=
v><div><br></div><div>Daryle W.</div><div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_1843_11093930.1391479176359--

.