Skip to content

Commit 3095e14

Browse files
authored
Merge 2025-02 CWG Motion 3
P3074R7 trivial `unions` (was `std::uninitialized<T>`)
2 parents 22729b6 + 184b90f commit 3095e14

File tree

4 files changed

+63
-48
lines changed

4 files changed

+63
-48
lines changed

source/classes.tex

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,59 +1220,64 @@
12201220
\item any non-static data member with no default member initializer\iref{class.mem} is
12211221
of reference type,
12221222

1223-
\item any non-variant non-static data member of const-qualified type
1223+
\item \tcode{X} is a non-union class and
1224+
any non-variant non-static data member of const-qualified type
12241225
(or possibly multidimensional array thereof)
12251226
with no \grammarterm{brace-or-equal-initializer}
12261227
is not const-default-constructible\iref{dcl.init},
12271228

1228-
\item \tcode{X} is a union and all of its variant members are of const-qualified
1229-
type (or possibly multidimensional array thereof),
1230-
1231-
\item \tcode{X} is a non-union class and all members of any anonymous union member are
1232-
of const-qualified type (or possibly multidimensional array thereof),
1233-
1234-
\item any potentially constructed subobject, except for a non-static data member
1235-
with a \grammarterm{brace-or-equal-initializer}
1236-
or a variant member of a union where another non-static data member
1237-
has a \grammarterm{brace-or-equal-initializer},
1229+
\item any non-variant potentially constructed subobject, except for a non-static data member
1230+
with a \grammarterm{brace-or-equal-initializer},
12381231
has class type \tcode{M} (or possibly multidimensional array thereof)
12391232
and overload resolution\iref{over.match}
12401233
as applied to find \tcode{M}'s corresponding constructor
1241-
either does not result in a usable candidate\iref{over.match.general}
1242-
or, in the case of a variant member, selects a non-trivial function, or
1234+
does not result in a usable candidate\iref{over.match.general}, or
12431235

1244-
\item any potentially constructed subobject has
1245-
class type \tcode{M} (or possibly multidimensional array thereof) and
1236+
\item any potentially constructed subobject $S$ has
1237+
class type \tcode{M} (or possibly multidimensional array thereof),
12461238
\tcode{M} has
12471239
a destructor that is deleted or inaccessible from the defaulted default
1248-
constructor.
1240+
constructor, and
1241+
either $S$ is non-variant or $S$ has a default member initializer.
12491242
\end{itemize}
12501243

12511244
\pnum
1252-
A default constructor is
1245+
A default constructor for a class \tcode{X} is
12531246
\defnx{trivial}{constructor!default!trivial}
12541247
if it is not user-provided and if
12551248
\begin{itemize}
12561249
\item
1257-
its class has no virtual functions\iref{class.virtual} and no virtual base
1250+
\tcode{X} has no virtual functions\iref{class.virtual} and no virtual base
12581251
classes\iref{class.mi}, and
12591252

1260-
\item no non-static data member of its class has
1253+
\item no non-static data member of \tcode{X} has
12611254
a default member initializer\iref{class.mem}, and
12621255

12631256
\item
1264-
all the direct base classes of its class have trivial default constructors, and
1257+
all the direct base classes of \tcode{X} have trivial default constructors, and
12651258

12661259
\item
1267-
for all the non-static data members of its class that are of class
1260+
either \tcode{X} is a union or
1261+
for all the non-variant non-static data members of \tcode{X} that are of class
12681262
type (or array thereof), each such class has a trivial default constructor.
12691263
\end{itemize}
12701264

12711265
Otherwise, the default constructor is
12721266
\defnx{non-trivial}{constructor!default!non-trivial}.
12731267

12741268
\pnum
1275-
An implicitly-defined\iref{dcl.fct.def.default} default constructor performs the set of
1269+
If a default constructor of a union-like class \tcode{X} is trivial,
1270+
then for each union \tcode{U}
1271+
that is either \tcode{X} or an anonymous union member of \tcode{X},
1272+
if the first variant member, if any, of \tcode{U}
1273+
has implicit-lifetime type\iref{basic.types.general},
1274+
the default constructor of \tcode{X} begins the lifetime of that member
1275+
if it is not the active member of its union.
1276+
\begin{note}
1277+
It is already the active member if \tcode{U} was value-initialized.
1278+
\end{note}
1279+
Otherwise,
1280+
an implicitly-defined\iref{dcl.fct.def.default} default constructor performs the set of
12761281
initializations of the class that would be performed by a user-written default
12771282
constructor for that class with no
12781283
\grammarterm{ctor-initializer}\iref{class.base.init} and an empty
@@ -2022,25 +2027,40 @@
20222027
A defaulted destructor for a class
20232028
\tcode{X} is defined as deleted if
20242029
\begin{itemize}
2025-
\item any potentially constructed subobject has class type
2026-
\tcode{M} (or possibly multidimensional array thereof) and
2030+
\item \tcode{X} is a non-union class and
2031+
any non-variant potentially constructed subobject has class type
2032+
\tcode{M} (or possibly multidimensional array thereof) where
20272033
\tcode{M} has a destructor that is deleted or
2028-
is inaccessible from the defaulted destructor or,
2029-
in the case of a variant member, is non-trivial,
2034+
is inaccessible from the defaulted destructor,
20302035

2031-
\item or, for a virtual destructor, lookup of the non-array deallocation
2036+
\item
2037+
\tcode{X} is a union and
2038+
\begin{itemize}
2039+
\item
2040+
overload resolution to select a constructor to
2041+
default-initialize an object of type \tcode{X} either fails or
2042+
selects a constructor that is either deleted or not trivial, or
2043+
\item
2044+
\tcode{X} has a variant member \tcode{V} of
2045+
class type \tcode{M} (or possibly multi-dimensional array thereof)
2046+
where \tcode{V} has a default member initializer and
2047+
\tcode{M} has a destructor that is non-trivial, or,
2048+
\end{itemize}
2049+
2050+
\item for a virtual destructor, lookup of the non-array deallocation
20322051
function results in an ambiguity or in a function that is deleted or
20332052
inaccessible from the defaulted destructor.
20342053
\end{itemize}
20352054

20362055
\pnum
2037-
A destructor is trivial if it is not user-provided and if
2056+
A destructor for a class \tcode{X} is trivial if it is not user-provided and if
20382057
\begin{itemize}
20392058
\item the destructor is not virtual,
20402059

2041-
\item all of the direct base classes of its class have trivial destructors, and
2060+
\item all of the direct base classes of \tcode{X} have trivial destructors, and
20422061

2043-
\item for all of the non-static data members of its class that are of class
2062+
\item either \tcode{X} is a union or
2063+
for all of the non-variant non-static data members of \tcode{X} that are of class
20442064
type (or array thereof), each such class has a trivial destructor.
20452065
\end{itemize}
20462066

@@ -3054,12 +3074,12 @@
30543074
If a union contains a non-static data member of
30553075
reference type, the program is ill-formed.
30563076
\begin{note}
3057-
Absent default member initializers\iref{class.mem},
3058-
if any non-static data member of a union has a non-trivial
3059-
default constructor\iref{class.default.ctor},
3060-
copy constructor, move constructor\iref{class.copy.ctor},
3061-
copy assignment operator, move assignment operator\iref{class.copy.assign},
3062-
or destructor\iref{class.dtor}, the corresponding member function
3077+
If any non-static data member of a union has a non-trivial
3078+
copy constructor,
3079+
move constructor\iref{class.copy.ctor},
3080+
copy assignment operator, or
3081+
move assignment operator\iref{class.copy.assign},
3082+
the corresponding member function
30633083
of the union must be user-provided or it will
30643084
be implicitly deleted\iref{dcl.fct.def.delete} for the union.
30653085
\begin{example}
@@ -3072,11 +3092,11 @@
30723092
};
30733093
\end{codeblock}
30743094
Since \tcode{std::string}\iref{string.classes} declares non-trivial versions of all of the special
3075-
member functions, \tcode{U} will have an implicitly deleted default constructor,
3076-
copy/move constructor,
3077-
copy/move assignment operator, and destructor.
3078-
To use \tcode{U}, some or all of these member functions
3079-
must be user-provided.
3095+
member functions, \tcode{U} will have an implicitly deleted
3096+
copy/move constructor and copy/move assignment operator.
3097+
The default constructor and destructor of \tcode{U} are both trivial
3098+
even though \tcode{std::string} has
3099+
a non-trivial default constructor and a non-trivial destructor.
30803100
\end{example}
30813101
\end{note}
30823102

source/containers.tex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9534,13 +9534,6 @@
95349534
\tcode{inplace_vector<T, N>::const_iterator}
95359535
meet the constexpr iterator requirements.
95369536

9537-
\pnum
9538-
For any $\tcode{N} > 0$,
9539-
if \tcode{T} is not trivially copyable or
9540-
\tcode{is_trivially_default_constructible_v<T>} is \tcode{false},
9541-
then no \tcode{inplace_vector<T, N>} member functions
9542-
are usable in constant expressions.
9543-
95449537
\pnum
95459538
Any member function of \tcode{inplace_vector<T, N>} that
95469539
would cause the size to exceed \tcode{N}

source/preprocessor.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,7 @@
19081908
\defnxname{cpp_structured_bindings} & \tcode{202411L} \\ \rowsep
19091909
\defnxname{cpp_template_template_args} & \tcode{201611L} \\ \rowsep
19101910
\defnxname{cpp_threadsafe_static_init} & \tcode{200806L} \\ \rowsep
1911+
\defnxname{cpp_trivial_union} & \tcode{202502L} \\ \rowsep
19111912
\defnxname{cpp_unicode_characters} & \tcode{200704L} \\ \rowsep
19121913
\defnxname{cpp_unicode_literals} & \tcode{200710L} \\ \rowsep
19131914
\defnxname{cpp_user_defined_literals} & \tcode{200809L} \\ \rowsep

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@
612612
#define @\defnlibxname{cpp_lib_constexpr_dynamic_alloc}@ 201907L // also in \libheader{memory}
613613
#define @\defnlibxname{cpp_lib_constexpr_exceptions}@ 202411L // also in \libheader{exception}
614614
#define @\defnlibxname{cpp_lib_constexpr_functional}@ 201907L // freestanding, also in \libheader{functional}
615+
#define @\defnlibxname{cpp_lib_constexpr_inplace_vector}@ 202502L // also in \libheader{inplace_vector}
615616
#define @\defnlibxname{cpp_lib_constexpr_iterator}@ 201811L // freestanding, also in \libheader{iterator}
616617
#define @\defnlibxname{cpp_lib_constexpr_memory}@ 202202L // freestanding, also in \libheader{memory}
617618
#define @\defnlibxname{cpp_lib_constexpr_new}@ 202406L // freestanding, also in \libheader{new}

0 commit comments

Comments
 (0)