From Jason Turner

[class.union.anon]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpm_3yxqnl/{from.md → to.md} +16 -16
tmp/tmpm_3yxqnl/{from.md → to.md} RENAMED
@@ -5,20 +5,18 @@ A union of the form
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() {
@@ -31,17 +29,17 @@ void f() {
31
  Here `a` and `p` are used like ordinary (non-member) variables, but
32
  since they are union members they have the same address.
33
 
34
  — *end example*]
35
 
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,11 +56,13 @@ The assignment to plain `aa` is ill-formed since the member name is not
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
 
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 member* if it is
11
+ a non-static data member or an *anonymous union variable* otherwise.
12
+ Each *member-declaration* in the *member-specification* of an anonymous
13
+ union shall either define one or more public non-static data members or
14
+ be a *static_assert-declaration*. Nested types, anonymous unions, and
15
  functions shall not be declared within an anonymous union. The names of
16
+ the members of an anonymous union are bound in the scope inhabited by
17
+ the union declaration.
 
 
 
18
 
19
  [*Example 1*:
20
 
21
  ``` cpp
22
  void f() {
 
29
  Here `a` and `p` are used like ordinary (non-member) variables, but
30
  since they are union members they have the same address.
31
 
32
  — *end example*]
33
 
34
+ Anonymous unions declared in the scope of a namespace with external
35
+ linkage shall be declared `static`. Anonymous unions declared at block
36
+ scope shall be declared with any storage class allowed for a block
37
  variable, or with no storage class. A storage class is not allowed in a
38
+ declaration of an anonymous union in a class scope.
39
+
40
+ [*Note 1*:
41
 
42
  A union for which objects, pointers, or references are declared is not
43
  an anonymous union.
44
 
45
  [*Example 2*:
 
56
  visible outside the union, and even if it were visible, it is not
57
  associated with any particular object.
58
 
59
  — *end example*]
60
 
61
+ *end note*]
62
+
63
+ [*Note 2*: 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