Skip to content

Commit b82546b

Browse files
committed
Merge 2016-02 CWG Motion 6
2 parents cf75550 + 934ef3e commit b82546b

File tree

2 files changed

+101
-27
lines changed

2 files changed

+101
-27
lines changed

source/compatibility.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,28 @@
15261526
int x = f(g1, g2); // ill-formed; previously well-formed
15271527
\end{codeblock}
15281528

1529+
\ref{dcl.init.aggr}
1530+
\change Definition of an aggregate is extended
1531+
to apply to user-defined types with base classes.
1532+
\rationale To increase convenience of aggregate initialization.
1533+
\effect
1534+
Valid \CppXIV code may fail to compile or produce different results in this
1535+
International Standard; initialization from an empty initializer list will
1536+
perform aggregate initialization instead of invoking a default constructor
1537+
for the affected types:
1538+
\begin{codeblock}
1539+
struct derived;
1540+
struct base {
1541+
friend struct derived;
1542+
private:
1543+
base();
1544+
};
1545+
struct derived : base {};
1546+
1547+
derived d1{}; // Error. The code was well-formed before.
1548+
derived d2; // still OK
1549+
\end{codeblock}
1550+
15291551
\rSec2[diff.cpp14.depr]{Annex~\ref{depr}: compatibility features}
15301552

15311553
\change

source/declarators.tex

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,19 +2837,47 @@
28372837
\indextext{\idxcode{\{\}}!initializer list}
28382838

28392839
\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
28442846
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}
28472867

28482868
\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
28532881
\enterexample
28542882
\begin{codeblock}
28552883
struct A {
@@ -2860,14 +2888,38 @@
28602888
} b;
28612889
} a = { 1, { 2, 3 } };
28622890
\end{codeblock}
2863-
28642891
initializes
28652892
\tcode{a.x}
28662893
with 1,
28672894
\tcode{a.b.i}
28682895
with 2,
28692896
\tcode{a.b.j}
28702897
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.
28712923
\exitexample
28722924

28732925
\pnum
@@ -2943,7 +2995,7 @@
29432995

29442996
\pnum
29452997
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
29472999
shall be initialized from its default member initializer~(\ref{class.mem}) or,
29483000
if there is no default member initializer, from an empty
29493001
initializer list~(\ref{dcl.init.list}).
@@ -2992,12 +3044,12 @@
29923044
\exitexample
29933045

29943046
\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
29983050
omitted from an \grammarterm{initializer-list} for an object of type
29993051
\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.
30013053
\enterexample
30023054

30033055
\begin{codeblock}
@@ -3072,20 +3124,20 @@
30723124
begins with a left brace,
30733125
then the succeeding comma-separated list of
30743126
\grammarterm{initializer-clause}{s}
3075-
initializes the members of a subaggregate;
3127+
initializes the elements of a subaggregate;
30763128
it is erroneous for there to be more
30773129
\grammarterm{initializer-clause}{s}
3078-
than members.
3130+
than elements.
30793131
If, however, the
30803132
\grammarterm{initializer-list}
30813133
for a subaggregate does not begin with a left brace,
30823134
then only enough
30833135
\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;
30853137
any remaining
30863138
\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.
30893141
\enterexample
30903142

30913143
\begin{codeblock}
@@ -3144,16 +3196,16 @@
31443196

31453197
\pnum
31463198
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}.
31483200
If the
31493201
\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,
31523204
brace elision is assumed and the
31533205
\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.
31553207
\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
31573209
\grammarterm{initializer-clause} for the entire subobject is
31583210
required.\exitnote
31593211

@@ -3190,7 +3242,7 @@
31903242
\pnum
31913243
\indextext{initialization!array~of class~objects}%
31923244
\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
31943246
class type with a user-provided constructor (\ref{class.ctor}).
31953247
Initialization of these aggregate objects is described in~\ref{class.expl.init}.
31963248
\exitnote

0 commit comments

Comments
 (0)