|
3694 | 3694 | the address of an unspecified byte of storage |
3695 | 3695 | occupied by the complete object of that subobject. |
3696 | 3696 |
|
| 3697 | +\pnum |
| 3698 | +A \defnadj{union elemental}{subobject} |
| 3699 | +\indextext{union!elemental subobject|see{subobject, union elemental}} |
| 3700 | +is a direct member of a union or |
| 3701 | +an element of an array that is a union elemental subobject. |
| 3702 | +An \defnx{inactive union elemental subobject}{subobject!union elemental!inactive} |
| 3703 | +\indextext{inactive union elemental subobject|see{subobject, union elemental, inactive}} |
| 3704 | +\indextext{union!inactive elemental subobject|see{subobject, union elemental, inactive}} |
| 3705 | +is a union elemental subobject that is not within its lifetime. |
| 3706 | + |
3697 | 3707 | \pnum |
3698 | 3708 | The \defnx{constituent values}{constituent value} of an object $o$ are |
3699 | 3709 | \begin{itemize} |
3700 | 3710 | \item |
3701 | 3711 | if $o$ has scalar type, the value of $o$; |
3702 | 3712 | \item |
3703 | 3713 | otherwise, the constituent values of any direct subobjects of $o$ |
3704 | | -other than inactive union members. |
| 3714 | +other than inactive union elemental subobjects. |
3705 | 3715 | \end{itemize} |
3706 | 3716 | The \defnx{constituent references}{constituent reference} of an object $o$ are |
3707 | 3717 | \begin{itemize} |
3708 | 3718 | \item |
3709 | 3719 | any direct members of $o$ that have reference type, and |
3710 | 3720 | \item |
3711 | 3721 | the constituent references of any direct subobjects of $o$ |
3712 | | -other than inactive union members. |
| 3722 | +other than inactive union elemental subobjects. |
3713 | 3723 | \end{itemize} |
| 3724 | +\begin{example} |
| 3725 | +\begin{codeblock} |
| 3726 | +struct A { |
| 3727 | + struct X { |
| 3728 | + int i; |
| 3729 | + int j; |
| 3730 | + }; |
| 3731 | + |
| 3732 | + struct Y { |
| 3733 | + X x1; |
| 3734 | + X x2; |
| 3735 | + }; |
| 3736 | + |
| 3737 | + union { |
| 3738 | + int i; |
| 3739 | + int arr[4]; |
| 3740 | + Y y; |
| 3741 | + }; |
| 3742 | +}; |
| 3743 | + |
| 3744 | +constexpr A v1; // OK, no constituent values |
| 3745 | +constexpr A v2{.i=1}; // OK, the constituent values are \tcode{\{v2.i\}} |
| 3746 | +constexpr A v3 = []{ |
| 3747 | + A a; |
| 3748 | + std::start_lifetime(a.arr); // OK, arr is now the active element of the union |
| 3749 | + new (&a.arr[1]) int(1); |
| 3750 | + a.arr[2] = 2; |
| 3751 | + return a; |
| 3752 | +}(); // OK, the constituent values are \tcode{\{v3.arr[1], v3.arr[2]\}} |
| 3753 | +constexpr A v4 = []{ |
| 3754 | + A a; |
| 3755 | + a.y.x1.i = 1; |
| 3756 | + a.y.x2.j = 2; |
| 3757 | + return a; |
| 3758 | +}(); // error: the constituent values include \tcode{v4.y.x1.j} and \tcode{v4.y.x2.i} |
| 3759 | + // which have erroneous value |
| 3760 | +\end{codeblock} |
| 3761 | +\end{example} |
3714 | 3762 |
|
3715 | 3763 | \pnum |
3716 | 3764 | Some operations are described as |
|
0 commit comments