|
2837 | 2837 | \indextext{\idxcode{\{\}}!initializer list}
|
2838 | 2838 |
|
2839 | 2839 | \pnum
|
2840 |
| -An |
2841 |
| -\term{aggregate} |
2842 |
| -is an array or a class (Clause~\ref{class}) with no |
2843 |
| -user-provided constructors (\ref{class.ctor}), |
| 2840 | +An \defn{aggregate} is an array or a class (Clause~\ref{class}) with |
| 2841 | +\begin{itemize} |
| 2842 | +\item |
| 2843 | +no user-provided constructors~(\ref{class.ctor}) |
| 2844 | +(including those inherited~(\ref{namespace.udecl}) from a base class), |
| 2845 | +\item |
2844 | 2846 | no private or protected non-static data members (Clause~\ref{class.access}),
|
2845 |
| -no base classes (Clause~\ref{class.derived}), |
2846 |
| -and no virtual functions (\ref{class.virtual}). |
| 2847 | +\item |
| 2848 | +no virtual functions~(\ref{class.virtual}), and |
| 2849 | +\item |
| 2850 | +no virtual, private, or protected base classes~(\ref{class.mi}). |
| 2851 | +\end{itemize} |
| 2852 | +\enternote |
| 2853 | +Aggregate initialization does not allow accessing |
| 2854 | +protected and private base class' members or constructors. |
| 2855 | +\exitnote |
| 2856 | + |
| 2857 | +\pnum |
| 2858 | +\indextext{aggregate!elements}% |
| 2859 | +The \term{elements} of an aggregate are: |
| 2860 | +\begin{itemize} |
| 2861 | +\item |
| 2862 | +for an array, the array elements in increasing subscript order, or |
| 2863 | +\item |
| 2864 | +for a class, the direct base classes in declaration order |
| 2865 | +followed by the direct members in declaration order. |
| 2866 | +\end{itemize} |
2847 | 2867 |
|
2848 | 2868 | \pnum
|
2849 |
| -When an aggregate is initialized by an initializer list, as specified in~\ref{dcl.init.list}, the elements of the initializer list are taken as initializers |
2850 |
| -for the members of the aggregate, |
2851 |
| -in increasing subscript or member order. |
2852 |
| -Each member is copy-initialized from the corresponding \grammarterm{initializer-clause}. If the \grammarterm{initializer-clause} is an expression and a narrowing conversion~(\ref{dcl.init.list}) is required to convert the expression, the program is ill-formed. \enternote If an \grammarterm{initializer-clause} is itself an initializer list, the member is list-initialized, which will result in a recursive application of the rules in this section if the member is an aggregate. \exitnote |
| 2869 | +When an aggregate is initialized by an initializer list |
| 2870 | +as specified in~\ref{dcl.init.list}, |
| 2871 | +the elements of the initializer list are taken as initializers |
| 2872 | +for the elements of the aggregate, in order. |
| 2873 | +Each element is copy-initialized |
| 2874 | +from the corresponding \grammarterm{initializer-clause}. |
| 2875 | +If the \grammarterm{initializer-clause} is an expression and |
| 2876 | +a narrowing conversion~(\ref{dcl.init.list}) is required |
| 2877 | +to convert the expression, the program is ill-formed. |
| 2878 | +\enternote If an \grammarterm{initializer-clause} is itself an initializer list, |
| 2879 | +the element is list-initialized, which will result in a recursive application |
| 2880 | +of the rules in this section if the element is an aggregate. \exitnote |
2853 | 2881 | \enterexample
|
2854 | 2882 | \begin{codeblock}
|
2855 | 2883 | struct A {
|
|
2860 | 2888 | } b;
|
2861 | 2889 | } a = { 1, { 2, 3 } };
|
2862 | 2890 | \end{codeblock}
|
2863 |
| - |
2864 | 2891 | initializes
|
2865 | 2892 | \tcode{a.x}
|
2866 | 2893 | with 1,
|
2867 | 2894 | \tcode{a.b.i}
|
2868 | 2895 | with 2,
|
2869 | 2896 | \tcode{a.b.j}
|
2870 | 2897 | with 3.
|
| 2898 | + |
| 2899 | +\begin{codeblock} |
| 2900 | +struct base1 { int b1, b2 = 42; }; |
| 2901 | +struct base2 { |
| 2902 | + B() { |
| 2903 | + b3 = 42; |
| 2904 | + } |
| 2905 | + int b3; |
| 2906 | +}; |
| 2907 | +struct derived : base1, base2 { |
| 2908 | + int d; |
| 2909 | +}; |
| 2910 | + |
| 2911 | +derived d1{{1, 2}, {}, 4}; |
| 2912 | +derived d2{{}, {}, 4}; |
| 2913 | +\end{codeblock} |
| 2914 | +initializes |
| 2915 | +\tcode{d1.b1} with 1, |
| 2916 | +\tcode{d1.b2} with 2, |
| 2917 | +\tcode{d1.b3} with 42, |
| 2918 | +\tcode{d1.d} with 4, and |
| 2919 | +\tcode{d2.b1} with 0, |
| 2920 | +\tcode{d2.b2} with 42, |
| 2921 | +\tcode{d2.b3} with 42, |
| 2922 | +\tcode{d2.d} with 4. |
2871 | 2923 | \exitexample
|
2872 | 2924 |
|
2873 | 2925 | \pnum
|
|
2943 | 2995 |
|
2944 | 2996 | \pnum
|
2945 | 2997 | If there are fewer \grammarterm{initializer-clause}{s} in the list than there
|
2946 |
| -are members in the aggregate, then each member not explicitly initialized |
| 2998 | +are elements in the aggregate, then each element not explicitly initialized |
2947 | 2999 | shall be initialized from its default member initializer~(\ref{class.mem}) or,
|
2948 | 3000 | if there is no default member initializer, from an empty
|
2949 | 3001 | initializer list~(\ref{dcl.init.list}).
|
|
2992 | 3044 | \exitexample
|
2993 | 3045 |
|
2994 | 3046 | \pnum
|
2995 |
| -If an aggregate class \tcode{C} contains a subaggregate member |
2996 |
| -\tcode{m} that has no members for purposes of aggregate initialization, |
2997 |
| -the \grammarterm{initializer-clause} for \tcode{m} shall not be |
| 3047 | +If an aggregate class \tcode{C} contains a subaggregate element |
| 3048 | +\tcode{e} that has no elements for purposes of aggregate initialization, |
| 3049 | +the \grammarterm{initializer-clause} for \tcode{e} shall not be |
2998 | 3050 | omitted from an \grammarterm{initializer-list} for an object of type
|
2999 | 3051 | \tcode{C} unless the \grammarterm{initializer-clause}{s} for all
|
3000 |
| -members of \tcode{C} following \tcode{m} are also omitted. |
| 3052 | +elements of \tcode{C} following \tcode{e} are also omitted. |
3001 | 3053 | \enterexample
|
3002 | 3054 |
|
3003 | 3055 | \begin{codeblock}
|
|
3072 | 3124 | begins with a left brace,
|
3073 | 3125 | then the succeeding comma-separated list of
|
3074 | 3126 | \grammarterm{initializer-clause}{s}
|
3075 |
| -initializes the members of a subaggregate; |
| 3127 | +initializes the elements of a subaggregate; |
3076 | 3128 | it is erroneous for there to be more
|
3077 | 3129 | \grammarterm{initializer-clause}{s}
|
3078 |
| -than members. |
| 3130 | +than elements. |
3079 | 3131 | If, however, the
|
3080 | 3132 | \grammarterm{initializer-list}
|
3081 | 3133 | for a subaggregate does not begin with a left brace,
|
3082 | 3134 | then only enough
|
3083 | 3135 | \grammarterm{initializer-clause}{s}
|
3084 |
| -from the list are taken to initialize the members of the subaggregate; |
| 3136 | +from the list are taken to initialize the elements of the subaggregate; |
3085 | 3137 | any remaining
|
3086 | 3138 | \grammarterm{initializer-clause}{s}
|
3087 |
| -are left to initialize the next member of the aggregate |
3088 |
| -of which the current subaggregate is a member. |
| 3139 | +are left to initialize the next element of the aggregate |
| 3140 | +of which the current subaggregate is an element. |
3089 | 3141 | \enterexample
|
3090 | 3142 |
|
3091 | 3143 | \begin{codeblock}
|
|
3144 | 3196 |
|
3145 | 3197 | \pnum
|
3146 | 3198 | All implicit type conversions (Clause~\ref{conv}) are considered when
|
3147 |
| -initializing the aggregate member with an \grammarterm{assignment-expression}. |
| 3199 | +initializing the element with an \grammarterm{assignment-expression}. |
3148 | 3200 | If the
|
3149 | 3201 | \grammarterm{assignment-expression}
|
3150 |
| -can initialize a member, the member is initialized. |
3151 |
| -Otherwise, if the member is itself a subaggregate, |
| 3202 | +can initialize an element, the element is initialized. |
| 3203 | +Otherwise, if the element is itself a subaggregate, |
3152 | 3204 | brace elision is assumed and the
|
3153 | 3205 | \grammarterm{assignment-expression}
|
3154 |
| -is considered for the initialization of the first member of the subaggregate. |
| 3206 | +is considered for the initialization of the first element of the subaggregate. |
3155 | 3207 | \enternote As specified above, brace elision cannot apply to
|
3156 |
| -subaggregates with no members for purposes of aggregate initialization; an |
| 3208 | +subaggregates with no elements for purposes of aggregate initialization; an |
3157 | 3209 | \grammarterm{initializer-clause} for the entire subobject is
|
3158 | 3210 | required.\exitnote
|
3159 | 3211 |
|
|
3190 | 3242 | \pnum
|
3191 | 3243 | \indextext{initialization!array~of class~objects}%
|
3192 | 3244 | \enternote
|
3193 |
| -An aggregate array or an aggregate class may contain members of a |
| 3245 | +An aggregate array or an aggregate class may contain elements of a |
3194 | 3246 | class type with a user-provided constructor (\ref{class.ctor}).
|
3195 | 3247 | Initialization of these aggregate objects is described in~\ref{class.expl.init}.
|
3196 | 3248 | \exitnote
|
|
0 commit comments