Skip to content

P1008R1 Prohibit aggregates with user-declared constructors #2169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,49 @@
if those entities are only referenced in contexts
that do not result in an odr-use.

\rSec2[diff.cpp17.dcl.decl]{\ref{dcl.decl}: declarators}

\diffref{dcl.init.aggr}
\change A class that has user-declared constructors is never an aggregate.
\rationale Remove potentially error-prone aggregate initialization
which may apply notwithstanding the declared constructors of a class.
\effect Valid \CppXVII{} code that aggregate-initializes
a type with a user-declared constructor
may be ill-formed or have different semantics
in this International Standard.
\begin{codeblock}
struct A { // not an aggregate; previously an aggregate
A() = delete;
};

struct B { // not an aggregate; previously an aggregate
B() = default;
int i = 0;
};

struct C { // not an aggregate; previously an aggregate
C(C&&) = default;
int a, b;
};

A a{}; // ill-formed; previously well-formed
B b = {1}; // ill-formed; previously well-formed
auto* c = new C{2, 3}; // ill-formed; previously well-formed

struct Y;

struct X {
operator Y();
};

struct Y { // not an aggregate; previously an aggregate
Y(const Y&) = default;
X x;
};

Y y{X{}}; // copy constructor call; previously aggregate-initialization
\end{codeblock}

\rSec2[diff.cpp17.special]{\ref{special}: special member functions}

\diffrefs{class.ctor}{class.dtor}
Expand Down
4 changes: 2 additions & 2 deletions source/declarators.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,7 @@
An \defn{aggregate} is an array or a class\iref{class} with
\begin{itemize}
\item
no user-provided, \tcode{explicit}, or inherited constructors\iref{class.ctor},
no user-declared or inherited constructors\iref{class.ctor},
\item
no private or protected non-static data members\iref{class.access},
\item
Expand Down Expand Up @@ -3456,7 +3456,7 @@
\indextext{initialization!array of class objects}%
\begin{note}
An aggregate array or an aggregate class may contain elements of a
class type with a user-provided constructor\iref{class.ctor}.
class type with a user-declared constructor\iref{class.ctor}.
Initialization of these aggregate objects is described in~\ref{class.expl.init}.
\end{note}

Expand Down