Skip to content

Commit a672a04

Browse files
committed
[2025-02 CWG Motion 8] P2786R13 Trivial Relocation]
Added freestanding to the lib feature-test macro, as all new parts are marked as freestanding. Picked the most appropriate location within the type traits spec for each of the three new traits.
1 parent 458b16a commit a672a04

File tree

10 files changed

+347
-26
lines changed

10 files changed

+347
-26
lines changed

source/basic.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,15 +4956,28 @@
49564956
cv-qualified\iref{basic.type.qualifier} versions of these
49574957
types are collectively called
49584958
\defnadjx{scalar}{types}{type}.
4959+
49594960
\label{term.trivially.copyable.type}%
49604961
Scalar types, trivially copyable class types\iref{class.prop},
49614962
arrays of such types, and cv-qualified versions of these
49624963
types are collectively called \defnadjx{trivially copyable}{types}{type}.
4964+
4965+
\label{term.trivially.relocatable.type}%
4966+
Scalar types, trivially relocatable class types\iref{class.prop},
4967+
arrays of such types, and cv-qualified versions of these
4968+
types are collectively called \defnadjx{trivially relocatable}{types}{type}.
4969+
4970+
\label{term.replaceable.type}%
4971+
Cv-unqualified scalar types, replaceable class types\iref{class.prop}, and
4972+
arrays of such types are collectively called
4973+
\defnadjx{replaceable}{types}{type}.
4974+
49634975
\label{term.standard.layout.type}%
49644976
Scalar types, standard-layout class
49654977
types\iref{class.prop}, arrays of such types, and
49664978
cv-qualified versions of these types
49674979
are collectively called \defnadjx{standard-layout}{types}{type}.
4980+
49684981
\label{term.implicit.lifetime.type}%
49694982
Scalar types, implicit-lifetime class types\iref{class.prop},
49704983
array types, and cv-qualified versions of these types

source/classes.tex

Lines changed: 109 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
\begin{bnf}
3838
\nontermdef{class-head}\br
39-
class-key \opt{attribute-specifier-seq} class-head-name \opt{class-virt-specifier} \opt{base-clause}\br
39+
class-key \opt{attribute-specifier-seq} class-head-name \opt{class-property-specifier-seq} \opt{base-clause}\br
4040
class-key \opt{attribute-specifier-seq} \opt{base-clause}
4141
\end{bnf}
4242

@@ -46,8 +46,15 @@
4646
\end{bnf}
4747

4848
\begin{bnf}
49-
\nontermdef{class-virt-specifier}\br
50-
\keyword{final}
49+
\nontermdef{class-property-specifier-seq}\br
50+
class-property-specifier \opt{class-property-specifier-seq}
51+
\end{bnf}
52+
53+
\begin{bnf}
54+
\nontermdef{class-property-specifier}\br
55+
\keyword{final}\br
56+
\keyword{trivially_relocatable_if_eligible}\br
57+
\keyword{replaceable_if_eligible}
5158
\end{bnf}
5259

5360
\begin{bnf}
@@ -120,12 +127,15 @@
120127
\end{note}
121128

122129
\pnum
123-
If a class is marked with the \grammarterm{class-virt-specifier} \tcode{final} and it appears
124-
as a \grammarterm{class-or-decltype} in a \grammarterm{base-clause}\iref{class.derived},
125-
the program is ill-formed. Whenever a
126-
\grammarterm{class-key} is followed by a \grammarterm{class-head-name}, the
127-
\grammarterm{identifier} \tcode{final}, and a colon or left brace, \tcode{final} is
128-
interpreted as a \grammarterm{class-virt-specifier}.
130+
Each \grammarterm{class-property-specifier} shall appear at most once within
131+
a single \grammarterm{class-property-specifier-seq}.
132+
133+
Whenever a \grammarterm{class-key} is followed by a \grammarterm{class-head-name},
134+
the identifier \tcode{final}, \tcode{trivially_relocatable_if_eligible}, or
135+
\tcode{replaceable_if_eligible}, and a colon or left brace,
136+
the identifier is interpreted as a \grammarterm{class-property-specifier}.
137+
138+
129139
\begin{example}
130140
\begin{codeblock}
131141
struct A;
@@ -134,12 +144,19 @@
134144

135145
struct X {
136146
struct C { constexpr operator int() { return 5; } };
137-
struct B final : C{}; // OK, definition of nested class \tcode{B},
138-
// not declaration of a bit-field member \tcode{final}
147+
struct B trivially_relocatable_if_eligible : C{};
148+
// OK, definition of nested class \tcode{B},
149+
// not declaration of a bit-field member
150+
// \tcode{trivially_relocatable_if_eligible}
139151
};
140152
\end{codeblock}
141153
\end{example}
142154

155+
\pnum
156+
If a class is marked with the \grammarterm{class-property-specifier}
157+
\tcode{final} and that class appears as a \grammarterm{class-or-decltype}
158+
in a \grammarterm{base-clause}\iref{class.derived}, the program is ill-formed.
159+
143160
\pnum
144161
\begin{note}
145162
Complete objects of class type have nonzero size.
@@ -172,6 +189,87 @@
172189
\item that has a trivial, non-deleted destructor\iref{class.dtor}.
173190
\end{itemize}
174191

192+
\pnum
193+
A class \tcode{C} is \defn{default-movable} if
194+
195+
\begin{itemize}
196+
\item overload resolution for direct-initializing an object of type \tcode{C}
197+
from an xvalue of type \tcode{C} selects a constructor that is a direct member
198+
of \tcode{C} and is neither user-provided nor deleted,
199+
200+
\item overload resolution for assigning to an lvalue of type \tcode{C} from an
201+
xvalue of type \tcode{C} selects an assignment operator function that is a
202+
direct member of \tcode{C} and is neither user-provided nor deleted, and
203+
204+
\item \tcode{C} has a destructor that is neither user-provided nor deleted.
205+
\end{itemize}
206+
207+
\pnum
208+
A class is \defn{eligible for trivial relocation} unless it
209+
\begin{itemize}
210+
\item has any virtual base classes,
211+
\item has a base class that is not a trivially relocatable class,
212+
\item has a non-static data member of an object type that is not of a
213+
trivially relocatable type, or
214+
215+
\item has a deleted destructor,
216+
\end{itemize}
217+
except that it is \impldef{whether an otherwise-eligible union having one or
218+
more subobjects of polymorphic class type is eligible for trivial relocation}
219+
whether an otherwise-eligible union having one or more subobjects of
220+
polymorphic class type is eligible for trivial relocation.
221+
222+
\pnum
223+
A class \tcode{C} is a \defnadj{trivially relocatable}{class}
224+
if it is eligible for trivial relocation and
225+
\begin{itemize}
226+
\item has the \tcode{trivially_relocatable_if_eligible} \grammarterm{class-property-specifier},
227+
\item is a union with no user-declared special member functions, or
228+
\item is default-movable.
229+
\end{itemize}
230+
231+
\pnum
232+
\begin{note}
233+
A class with const-qualified or reference non-static data members can be
234+
trivially relocatable.
235+
\end{note}
236+
237+
\pnum
238+
A class \tcode{C} is \defn{eligible for replacement} unless
239+
\begin{itemize}
240+
\item it has a base class that is not a replaceable class,
241+
\item it has a non-static data member that is not of a replaceable type,
242+
\item overload resolution fails or selects a deleted constructor when
243+
direct-initializing an object of type \tcode{C} from an xvalue of type
244+
\tcode{C}\iref{dcl.init.general},
245+
246+
\item overload resolution fails or selects a deleted assignment operator
247+
function when assigning to an lvalue of type \tcode{C} from an xvalue of type
248+
\tcode{C} \iref{expr.assign,over.assign}), or
249+
250+
\item it has a deleted destructor.
251+
\end{itemize}
252+
253+
\pnum
254+
A class \tcode{C} is a \defnadj{replaceable}{class} if it is
255+
eligible for replacement and
256+
\begin{itemize}
257+
\item has the \tcode{replaceable_if_eligible} \grammarterm{class-property-specifier},
258+
\item is a union with no user-declared special member functions, or
259+
\item is default-movable.
260+
\end{itemize}
261+
262+
\pnum
263+
\begin{note}
264+
Accessibility of the special member functions is not considered when
265+
establishing trivial relocatability or replaceability.
266+
\end{note}
267+
268+
\pnum
269+
\begin{note}
270+
Not all trivially copyable classes are trivially relocatable or replaceable.
271+
\end{note}
272+
175273
\pnum
176274
A class \tcode{S} is a \defnadj{standard-layout}{class} if it:
177275
\begin{itemize}
@@ -185,9 +283,7 @@
185283
for all non-static data members,
186284

187285
\item has no non-standard-layout base classes,
188-
189286
\item has at most one base class subobject of any given type,
190-
191287
\item has all non-static data members and bit-fields in the class and
192288
its base classes first declared in the same class, and
193289

source/compatibility.tex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@
7474

7575
\rSec2[diff.cpp23.dcl.dcl]{\ref{dcl}: declarations}
7676

77+
\diffref{dcl.decl.general}
78+
\change
79+
Introduction of \tcode{trivially_relocatable_if_eligible} and
80+
\tcode{replaceable_if_eligible} as identifiers with special meaning\iref{lex.name}.
81+
\rationale
82+
Support declaration of trivially relocatable and replaceable types\iref{class.prop}.
83+
\effect
84+
Valid \CppXXIII{} code can become ill-formed.
85+
86+
\begin{example}
87+
\begin{codeblock}
88+
struct C {};
89+
struct C replaceable_if_eligible {}; // was well-formed (new variable \tcode{replaceable_if_eligible})
90+
// now ill-formed (redefines \tcode{C})
91+
\end{codeblock}
92+
\end{example}
93+
7794
\diffref{dcl.init.list}
7895
\change
7996
Pointer comparisons between \tcode{initializer_list} objects' backing arrays
@@ -194,6 +211,17 @@
194211
Valid \CppXXIII{} code that \tcode{\#include}{s} headers with these names may be
195212
invalid in this revision of \Cpp{}.
196213

214+
\diffref{res.on.macro.definitions}
215+
\change
216+
Additional restrictions on macro names.
217+
\rationale
218+
Avoid hard to diagnose or non-portable constructs.
219+
\effect
220+
Names of special identifiers may not be used as macro names.
221+
Valid \CppXXIII{} code that defines \tcode{replaceable_if_eligible} or
222+
\tcode{trivially_relocatable_if_eligible} as macros is invalid
223+
in this revision of \Cpp{}.
224+
197225
\rSec2[diff.cpp23.strings]{\ref{strings}: strings library}
198226

199227
\diffref{string.conversions}

source/expressions.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,9 +1963,9 @@
19631963
other than by changing:
19641964
\begin{itemize}
19651965
\item the size and/or alignment of the closure type,
1966-
1967-
\item whether the closure type is trivially copyable\iref{class.prop}, or
1968-
1966+
\item whether the closure type is trivially copyable\iref{class.prop},
1967+
\item whether the closure type is trivially relocatable\iref{class.prop},
1968+
\item whether the closure type is replaceable\iref{class.prop}, or
19691969
\item whether the closure type is a standard-layout class\iref{class.prop}.
19701970
\end{itemize}
19711971

source/lex.tex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@
907907
\indextext{\idxcode{final}}%
908908
\indextext{\idxcode{module}}%
909909
\indextext{\idxcode{override}}%
910+
\indextext{\idxcode{replaceable_if_eligible}}%
911+
\indextext{\idxcode{trivially_relocatable_if_eligible}}%
910912
The identifiers in \tref{lex.name.special} have a special meaning when
911913
appearing in a certain context. When referred to in the grammar, these identifiers
912914
are used explicitly rather than using the \grammarterm{identifier} grammar production.
@@ -915,14 +917,15 @@
915917
token as a regular \grammarterm{identifier}.
916918

917919
\begin{multicolfloattable}{Identifiers with special meaning}{lex.name.special}
918-
{llll}
919-
\keyword{final} \\
920-
\columnbreak
921-
\keyword{import} \\
920+
{lll}
921+
\keyword{final} \\
922+
\keyword{import} \\
922923
\columnbreak
923-
\keyword{module} \\
924+
\keyword{module} \\
925+
\keyword{override} \\
924926
\columnbreak
925-
\keyword{override} \\
927+
\keyword{replaceable_if_eligible} \\
928+
\keyword{trivially_relocatable_if_eligible} \\
926929
\end{multicolfloattable}
927930

928931
\pnum

source/lib-intro.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,6 +3826,25 @@
38263826
side effects.
38273827
\end{note}
38283828

3829+
\rSec3[library.class.props]{Properties of library classes}
3830+
3831+
\pnum
3832+
Unless specifically stated, it is unspecified whether any class described in
3833+
\ref{\firstlibchapter} through \ref{\lastlibchapter} and \ref{depr} is a
3834+
trivially copyable class, a standard-layout class, or
3835+
an implicit-lifetime class\iref{class.prop}.
3836+
3837+
\pnum
3838+
Unless specifically stated, it is unspecified whether any class for which
3839+
trivial relocation (i.e., the effects of \tcode{trivially_relocate}) would be
3840+
semantically equivalent to move-construction of the destination object followed
3841+
by destruction of the source object is trivially relocatable.
3842+
3843+
\pnum
3844+
Unless specifically stated, it is unspecified whether any class for which move
3845+
assignment is semantically equivalent to destroying the assigned-to object,
3846+
then move-constructing from the source object in its place is replaceable.
3847+
38293848
\rSec3[protection.within.classes]{Protection within classes}
38303849

38313850
\pnum

0 commit comments

Comments
 (0)