|
2849 | 2849 | \indextext{\idxcode{\{\}}!initializer list}
|
2850 | 2850 |
|
2851 | 2851 | \pnum
|
2852 |
| -An |
2853 |
| -\term{aggregate} |
2854 |
| -is an array or a class (Clause~\ref{class}) with no |
2855 |
| -user-provided constructors (\ref{class.ctor}), |
| 2852 | +An \defn{aggregate} is an array or a class (Clause~\ref{class}) with |
| 2853 | +\begin{itemize} |
| 2854 | +\item |
| 2855 | +no user-provided constructors~(\ref{class.ctor}) |
| 2856 | +(including those inherited~(\ref{namespace.udecl}) from a base class), |
| 2857 | +\item |
2856 | 2858 | no private or protected non-static data members (Clause~\ref{class.access}),
|
2857 |
| -no base classes (Clause~\ref{class.derived}), |
2858 |
| -and no virtual functions (\ref{class.virtual}). |
| 2859 | +\item |
| 2860 | +no virtual functions~(\ref{class.virtual}), and |
| 2861 | +\item |
| 2862 | +no virtual, private, or protected base classes~(\ref{class.mi}). |
| 2863 | +\end{itemize} |
| 2864 | +\enternote |
| 2865 | +Aggregate initialization does not allow accessing |
| 2866 | +protected and private base class' members or constructors. |
| 2867 | +\exitnote |
| 2868 | + |
| 2869 | +\pnum |
| 2870 | +\indextext{aggregate!elements}% |
| 2871 | +The \term{elements} of an aggregate are: |
| 2872 | +\begin{itemize} |
| 2873 | +\item |
| 2874 | +for an array, the array elements in increasing subscript order, or |
| 2875 | +\item |
| 2876 | +for a class, the direct base classes in declaration order |
| 2877 | +followed by the direct members in declaration order. |
| 2878 | +\end{itemize} |
2859 | 2879 |
|
2860 | 2880 | \pnum
|
2861 |
| -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 |
2862 |
| -for the members of the aggregate, |
2863 |
| -in increasing subscript or member order. |
2864 |
| -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 |
| 2881 | +When an aggregate is initialized by an initializer list |
| 2882 | +as specified in~\ref{dcl.init.list}, |
| 2883 | +the elements of the initializer list are taken as initializers |
| 2884 | +for the elements of the aggregate, in order. |
| 2885 | +Each element is copy-initialized |
| 2886 | +from the corresponding \grammarterm{initializer-clause}. |
| 2887 | +If the \grammarterm{initializer-clause} is an expression and |
| 2888 | +a narrowing conversion~(\ref{dcl.init.list}) is required |
| 2889 | +to convert the expression, the program is ill-formed. |
| 2890 | +\enternote If an \grammarterm{initializer-clause} is itself an initializer list, |
| 2891 | +the element is list-initialized, which will result in a recursive application |
| 2892 | +of the rules in this section if the element is an aggregate. \exitnote |
2865 | 2893 | \enterexample
|
2866 | 2894 | \begin{codeblock}
|
2867 | 2895 | struct A {
|
|
2872 | 2900 | } b;
|
2873 | 2901 | } a = { 1, { 2, 3 } };
|
2874 | 2902 | \end{codeblock}
|
2875 |
| - |
2876 | 2903 | initializes
|
2877 | 2904 | \tcode{a.x}
|
2878 | 2905 | with 1,
|
2879 | 2906 | \tcode{a.b.i}
|
2880 | 2907 | with 2,
|
2881 | 2908 | \tcode{a.b.j}
|
2882 | 2909 | with 3.
|
| 2910 | + |
| 2911 | +\begin{codeblock} |
| 2912 | +struct base1 { int b1, b2 = 42; }; |
| 2913 | +struct base2 { |
| 2914 | + B() { |
| 2915 | + b3 = 42; |
| 2916 | + } |
| 2917 | + int b3; |
| 2918 | +}; |
| 2919 | +struct derived : base1, base2 { |
| 2920 | + int d; |
| 2921 | +}; |
| 2922 | + |
| 2923 | +derived d1{{1, 2}, {}, 4}; |
| 2924 | +derived d2{{}, {}, 4}; |
| 2925 | +\end{codeblock} |
| 2926 | +initializes |
| 2927 | +\tcode{d1.b1} with 1, |
| 2928 | +\tcode{d1.b2} with 2, |
| 2929 | +\tcode{d1.b3} with 42, |
| 2930 | +\tcode{d1.d} with 4, and |
| 2931 | +\tcode{d2.b1} with 0, |
| 2932 | +\tcode{d2.b2} with 42, |
| 2933 | +\tcode{d2.b3} with 42, |
| 2934 | +\tcode{d2.d} with 4. |
2883 | 2935 | \exitexample
|
2884 | 2936 |
|
2885 | 2937 | \pnum
|
|
2955 | 3007 |
|
2956 | 3008 | \pnum
|
2957 | 3009 | If there are fewer \grammarterm{initializer-clause}{s} in the list than there
|
2958 |
| -are members in the aggregate, then each member not explicitly initialized |
| 3010 | +are elements in the aggregate, then each element not explicitly initialized |
2959 | 3011 | shall be initialized from its default member initializer~(\ref{class.mem}) or,
|
2960 | 3012 | if there is no default member initializer, from an empty
|
2961 | 3013 | initializer list~(\ref{dcl.init.list}).
|
|
3004 | 3056 | \exitexample
|
3005 | 3057 |
|
3006 | 3058 | \pnum
|
3007 |
| -If an aggregate class \tcode{C} contains a subaggregate member |
3008 |
| -\tcode{m} that has no members for purposes of aggregate initialization, |
3009 |
| -the \grammarterm{initializer-clause} for \tcode{m} shall not be |
| 3059 | +If an aggregate class \tcode{C} contains a subaggregate element |
| 3060 | +\tcode{e} that has no elements for purposes of aggregate initialization, |
| 3061 | +the \grammarterm{initializer-clause} for \tcode{e} shall not be |
3010 | 3062 | omitted from an \grammarterm{initializer-list} for an object of type
|
3011 | 3063 | \tcode{C} unless the \grammarterm{initializer-clause}{s} for all
|
3012 |
| -members of \tcode{C} following \tcode{m} are also omitted. |
| 3064 | +elements of \tcode{C} following \tcode{e} are also omitted. |
3013 | 3065 | \enterexample
|
3014 | 3066 |
|
3015 | 3067 | \begin{codeblock}
|
|
3084 | 3136 | begins with a left brace,
|
3085 | 3137 | then the succeeding comma-separated list of
|
3086 | 3138 | \grammarterm{initializer-clause}{s}
|
3087 |
| -initializes the members of a subaggregate; |
| 3139 | +initializes the elements of a subaggregate; |
3088 | 3140 | it is erroneous for there to be more
|
3089 | 3141 | \grammarterm{initializer-clause}{s}
|
3090 |
| -than members. |
| 3142 | +than elements. |
3091 | 3143 | If, however, the
|
3092 | 3144 | \grammarterm{initializer-list}
|
3093 | 3145 | for a subaggregate does not begin with a left brace,
|
3094 | 3146 | then only enough
|
3095 | 3147 | \grammarterm{initializer-clause}{s}
|
3096 |
| -from the list are taken to initialize the members of the subaggregate; |
| 3148 | +from the list are taken to initialize the elements of the subaggregate; |
3097 | 3149 | any remaining
|
3098 | 3150 | \grammarterm{initializer-clause}{s}
|
3099 |
| -are left to initialize the next member of the aggregate |
3100 |
| -of which the current subaggregate is a member. |
| 3151 | +are left to initialize the next element of the aggregate |
| 3152 | +of which the current subaggregate is an element. |
3101 | 3153 | \enterexample
|
3102 | 3154 |
|
3103 | 3155 | \begin{codeblock}
|
|
3156 | 3208 |
|
3157 | 3209 | \pnum
|
3158 | 3210 | All implicit type conversions (Clause~\ref{conv}) are considered when
|
3159 |
| -initializing the aggregate member with an \grammarterm{assignment-expression}. |
| 3211 | +initializing the element with an \grammarterm{assignment-expression}. |
3160 | 3212 | If the
|
3161 | 3213 | \grammarterm{assignment-expression}
|
3162 |
| -can initialize a member, the member is initialized. |
3163 |
| -Otherwise, if the member is itself a subaggregate, |
| 3214 | +can initialize an element, the element is initialized. |
| 3215 | +Otherwise, if the element is itself a subaggregate, |
3164 | 3216 | brace elision is assumed and the
|
3165 | 3217 | \grammarterm{assignment-expression}
|
3166 |
| -is considered for the initialization of the first member of the subaggregate. |
| 3218 | +is considered for the initialization of the first element of the subaggregate. |
3167 | 3219 | \enternote As specified above, brace elision cannot apply to
|
3168 |
| -subaggregates with no members for purposes of aggregate initialization; an |
| 3220 | +subaggregates with no elements for purposes of aggregate initialization; an |
3169 | 3221 | \grammarterm{initializer-clause} for the entire subobject is
|
3170 | 3222 | required.\exitnote
|
3171 | 3223 |
|
|
3202 | 3254 | \pnum
|
3203 | 3255 | \indextext{initialization!array~of class~objects}%
|
3204 | 3256 | \enternote
|
3205 |
| -An aggregate array or an aggregate class may contain members of a |
| 3257 | +An aggregate array or an aggregate class may contain elements of a |
3206 | 3258 | class type with a user-provided constructor (\ref{class.ctor}).
|
3207 | 3259 | Initialization of these aggregate objects is described in~\ref{class.expl.init}.
|
3208 | 3260 | \exitnote
|
|
0 commit comments