tmp/tmpueqpd1_w/{from.md → to.md}
RENAMED
|
@@ -1,23 +1,24 @@
|
|
| 1 |
### Anonymous unions <a id="class.union.anon">[[class.union.anon]]</a>
|
| 2 |
|
| 3 |
A union of the form
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
is called an *anonymous union*; it defines an unnamed type and an
|
| 6 |
unnamed object of that type called an *anonymous union object*. Each
|
| 7 |
*member-declaration* in the *member-specification* of an anonymous union
|
| 8 |
shall either define a non-static data member or be a
|
| 9 |
-
*static_assert-declaration*.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
is declared. For the purpose of name lookup, after the anonymous union
|
| 17 |
-
definition, the members of the anonymous union are considered to have
|
| 18 |
-
been defined in the scope in which the anonymous union is declared.
|
| 19 |
|
| 20 |
[*Example 1*:
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
void f() {
|
|
@@ -35,12 +36,12 @@ since they are union members they have the same address.
|
|
| 35 |
Anonymous unions declared in a named namespace or in the global
|
| 36 |
namespace shall be declared `static`. Anonymous unions declared at block
|
| 37 |
scope shall be declared with any storage class allowed for a block-scope
|
| 38 |
variable, or with no storage class. A storage class is not allowed in a
|
| 39 |
declaration of an anonymous union in a class scope. An anonymous union
|
| 40 |
-
shall not have
|
| 41 |
-
|
| 42 |
|
| 43 |
A union for which objects, pointers, or references are declared is not
|
| 44 |
an anonymous union.
|
| 45 |
|
| 46 |
[*Example 2*:
|
|
@@ -57,11 +58,11 @@ The assignment to plain `aa` is ill-formed since the member name is not
|
|
| 57 |
visible outside the union, and even if it were visible, it is not
|
| 58 |
associated with any particular object.
|
| 59 |
|
| 60 |
— *end example*]
|
| 61 |
|
| 62 |
-
[*Note
|
| 63 |
is described in [[dcl.init.aggr]]. — *end note*]
|
| 64 |
|
| 65 |
A *union-like class* is a union or a class that has an anonymous union
|
| 66 |
as a direct member. A union-like class `X` has a set of *variant
|
| 67 |
members*. If `X` is a union, a non-static data member of `X` that is not
|
|
|
|
| 1 |
### Anonymous unions <a id="class.union.anon">[[class.union.anon]]</a>
|
| 2 |
|
| 3 |
A union of the form
|
| 4 |
|
| 5 |
+
``` bnf
|
| 6 |
+
union '{' member-specification '}' ';'
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
is called an *anonymous union*; it defines an unnamed type and an
|
| 10 |
unnamed object of that type called an *anonymous union object*. Each
|
| 11 |
*member-declaration* in the *member-specification* of an anonymous union
|
| 12 |
shall either define a non-static data member or be a
|
| 13 |
+
*static_assert-declaration*. Nested types, anonymous unions, and
|
| 14 |
+
functions shall not be declared within an anonymous union. The names of
|
| 15 |
+
the members of an anonymous union shall be distinct from the names of
|
| 16 |
+
any other entity in the scope in which the anonymous union is declared.
|
| 17 |
+
For the purpose of name lookup, after the anonymous union definition,
|
| 18 |
+
the members of the anonymous union are considered to have been defined
|
| 19 |
+
in the scope in which the anonymous union is declared.
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
[*Example 1*:
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
void f() {
|
|
|
|
| 36 |
Anonymous unions declared in a named namespace or in the global
|
| 37 |
namespace shall be declared `static`. Anonymous unions declared at block
|
| 38 |
scope shall be declared with any storage class allowed for a block-scope
|
| 39 |
variable, or with no storage class. A storage class is not allowed in a
|
| 40 |
declaration of an anonymous union in a class scope. An anonymous union
|
| 41 |
+
shall not have private or protected members [[class.access]]. An
|
| 42 |
+
anonymous union shall not have member functions.
|
| 43 |
|
| 44 |
A union for which objects, pointers, or references are declared is not
|
| 45 |
an anonymous union.
|
| 46 |
|
| 47 |
[*Example 2*:
|
|
|
|
| 58 |
visible outside the union, and even if it were visible, it is not
|
| 59 |
associated with any particular object.
|
| 60 |
|
| 61 |
— *end example*]
|
| 62 |
|
| 63 |
+
[*Note 1*: Initialization of unions with no user-declared constructors
|
| 64 |
is described in [[dcl.init.aggr]]. — *end note*]
|
| 65 |
|
| 66 |
A *union-like class* is a union or a class that has an anonymous union
|
| 67 |
as a direct member. A union-like class `X` has a set of *variant
|
| 68 |
members*. If `X` is a union, a non-static data member of `X` that is not
|