tmp/tmpxog1kmpb/{from.md → to.md}
RENAMED
|
@@ -12,13 +12,13 @@ non-static data members can be stored in a union at any time.
|
|
| 12 |
|
| 13 |
[*Note 1*: One special guarantee is made in order to simplify the use
|
| 14 |
of unions: If a standard-layout union contains several standard-layout
|
| 15 |
structs that share a common initial sequence [[class.mem]], and if a
|
| 16 |
non-static data member of an object of this standard-layout union type
|
| 17 |
-
is active and is one of the standard-layout structs,
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
The size of a union is sufficient to contain the largest of its
|
| 22 |
non-static data members. Each non-static data member is allocated as if
|
| 23 |
it were the sole member of a non-union class.
|
| 24 |
|
|
@@ -28,22 +28,20 @@ consequence, all non-static data members of a union object have the same
|
|
| 28 |
address. — *end note*]
|
| 29 |
|
| 30 |
A union can have member functions (including constructors and
|
| 31 |
destructors), but it shall not have virtual [[class.virtual]] functions.
|
| 32 |
A union shall not have base classes. A union shall not be used as a base
|
| 33 |
-
class. If a union contains a non-static data member of reference type
|
| 34 |
the program is ill-formed.
|
| 35 |
|
| 36 |
[*Note 3*:
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
[[class.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
member function of the union must be user-provided or it will be
|
| 44 |
-
implicitly deleted [[dcl.fct.def.delete]] for the union.
|
| 45 |
|
| 46 |
[*Example 1*:
|
| 47 |
|
| 48 |
Consider the following union:
|
| 49 |
|
|
@@ -55,13 +53,14 @@ union U {
|
|
| 55 |
};
|
| 56 |
```
|
| 57 |
|
| 58 |
Since `std::string` [[string.classes]] declares non-trivial versions of
|
| 59 |
all of the special member functions, `U` will have an implicitly deleted
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
— *end example*]
|
| 65 |
|
| 66 |
— *end note*]
|
| 67 |
|
|
@@ -78,17 +77,19 @@ lifetime of that union member, as described below. For an expression
|
|
| 78 |
subscripting operator, S(E) is S(A) if `A` is of array type, S(B) if
|
| 79 |
`B` is of array type, and empty otherwise.
|
| 80 |
- Otherwise, S(E) is empty.
|
| 81 |
|
| 82 |
In an assignment expression of the form `E1 = E2` that uses either the
|
| 83 |
-
built-in assignment operator [[expr.
|
| 84 |
-
operator [[class.copy.assign]], for each element `X` of S(`E1`)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
|
| 91 |
[*Note 4*: This ends the lifetime of the previously-active member of
|
| 92 |
the union, if any [[basic.life]]. — *end note*]
|
| 93 |
|
| 94 |
[*Example 2*:
|
|
@@ -169,15 +170,16 @@ void f() {
|
|
| 169 |
Here `a` and `p` are used like ordinary (non-member) variables, but
|
| 170 |
since they are union members they have the same address.
|
| 171 |
|
| 172 |
— *end example*]
|
| 173 |
|
| 174 |
-
|
| 175 |
-
linkage shall
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
|
| 180 |
[*Note 1*:
|
| 181 |
|
| 182 |
A union for which objects, pointers, or references are declared is not
|
| 183 |
an anonymous union.
|
|
|
|
| 12 |
|
| 13 |
[*Note 1*: One special guarantee is made in order to simplify the use
|
| 14 |
of unions: If a standard-layout union contains several standard-layout
|
| 15 |
structs that share a common initial sequence [[class.mem]], and if a
|
| 16 |
non-static data member of an object of this standard-layout union type
|
| 17 |
+
is active and is one of the standard-layout structs, the common initial
|
| 18 |
+
sequence of any of the standard-layout struct members can be inspected;
|
| 19 |
+
see [[class.mem]]. — *end note*]
|
| 20 |
|
| 21 |
The size of a union is sufficient to contain the largest of its
|
| 22 |
non-static data members. Each non-static data member is allocated as if
|
| 23 |
it were the sole member of a non-union class.
|
| 24 |
|
|
|
|
| 28 |
address. — *end note*]
|
| 29 |
|
| 30 |
A union can have member functions (including constructors and
|
| 31 |
destructors), but it shall not have virtual [[class.virtual]] functions.
|
| 32 |
A union shall not have base classes. A union shall not be used as a base
|
| 33 |
+
class. If a union contains a non-static data member of reference type,
|
| 34 |
the program is ill-formed.
|
| 35 |
|
| 36 |
[*Note 3*:
|
| 37 |
|
| 38 |
+
If any non-static data member of a union has a non-trivial copy
|
| 39 |
+
constructor, move constructor [[class.copy.ctor]], copy assignment
|
| 40 |
+
operator, or move assignment operator [[class.copy.assign]], the
|
| 41 |
+
corresponding member function of the union must be user-provided or it
|
| 42 |
+
will be implicitly deleted [[dcl.fct.def.delete]] for the union.
|
|
|
|
|
|
|
| 43 |
|
| 44 |
[*Example 1*:
|
| 45 |
|
| 46 |
Consider the following union:
|
| 47 |
|
|
|
|
| 53 |
};
|
| 54 |
```
|
| 55 |
|
| 56 |
Since `std::string` [[string.classes]] declares non-trivial versions of
|
| 57 |
all of the special member functions, `U` will have an implicitly deleted
|
| 58 |
+
copy/move constructor and copy/move assignment operator. The default
|
| 59 |
+
constructor and destructor of `U` are both trivial even though
|
| 60 |
+
`std::string` has a non-trivial default constructor and a non-trivial
|
| 61 |
+
destructor.
|
| 62 |
|
| 63 |
— *end example*]
|
| 64 |
|
| 65 |
— *end note*]
|
| 66 |
|
|
|
|
| 77 |
subscripting operator, S(E) is S(A) if `A` is of array type, S(B) if
|
| 78 |
`B` is of array type, and empty otherwise.
|
| 79 |
- Otherwise, S(E) is empty.
|
| 80 |
|
| 81 |
In an assignment expression of the form `E1 = E2` that uses either the
|
| 82 |
+
built-in assignment operator [[expr.assign]] or a trivial assignment
|
| 83 |
+
operator [[class.copy.assign]], for each element `X` of S(`E1`) and each
|
| 84 |
+
anonymous union member `X` [[class.union.anon]] that is a member of a
|
| 85 |
+
union and has such an element as an immediate subobject (recursively),
|
| 86 |
+
if modification of `X` would have undefined behavior under
|
| 87 |
+
[[basic.life]], an object of the type of `X` is implicitly created in
|
| 88 |
+
the nominated storage; no initialization is performed and the beginning
|
| 89 |
+
of its lifetime is sequenced after the value computation of the left and
|
| 90 |
+
right operands and before the assignment.
|
| 91 |
|
| 92 |
[*Note 4*: This ends the lifetime of the previously-active member of
|
| 93 |
the union, if any [[basic.life]]. — *end note*]
|
| 94 |
|
| 95 |
[*Example 2*:
|
|
|
|
| 170 |
Here `a` and `p` are used like ordinary (non-member) variables, but
|
| 171 |
since they are union members they have the same address.
|
| 172 |
|
| 173 |
— *end example*]
|
| 174 |
|
| 175 |
+
An anonymous union declared in the scope of a namespace with external
|
| 176 |
+
linkage shall use the *storage-class-specifier* `static`. Anonymous
|
| 177 |
+
unions declared at block scope shall not use a *storage-class-specifier*
|
| 178 |
+
that is not permitted in the declaration of a block variable. An
|
| 179 |
+
anonymous union declaration at class scope shall not have a
|
| 180 |
+
*storage-class-specifier*.
|
| 181 |
|
| 182 |
[*Note 1*:
|
| 183 |
|
| 184 |
A union for which objects, pointers, or references are declared is not
|
| 185 |
an anonymous union.
|