|
36 | 36 |
|
37 | 37 | \begin{bnf} |
38 | 38 | \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 |
40 | 40 | class-key \opt{attribute-specifier-seq} \opt{base-clause} |
41 | 41 | \end{bnf} |
42 | 42 |
|
|
46 | 46 | \end{bnf} |
47 | 47 |
|
48 | 48 | \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} |
51 | 58 | \end{bnf} |
52 | 59 |
|
53 | 60 | \begin{bnf} |
|
120 | 127 | \end{note} |
121 | 128 |
|
122 | 129 | \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 | + |
129 | 139 | \begin{example} |
130 | 140 | \begin{codeblock} |
131 | 141 | struct A; |
|
134 | 144 |
|
135 | 145 | struct X { |
136 | 146 | 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} |
139 | 151 | }; |
140 | 152 | \end{codeblock} |
141 | 153 | \end{example} |
142 | 154 |
|
| 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 | + |
143 | 160 | \pnum |
144 | 161 | \begin{note} |
145 | 162 | Complete objects of class type have nonzero size. |
|
172 | 189 | \item that has a trivial, non-deleted destructor\iref{class.dtor}. |
173 | 190 | \end{itemize} |
174 | 191 |
|
| 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 | + |
175 | 273 | \pnum |
176 | 274 | A class \tcode{S} is a \defnadj{standard-layout}{class} if it: |
177 | 275 | \begin{itemize} |
|
185 | 283 | for all non-static data members, |
186 | 284 |
|
187 | 285 | \item has no non-standard-layout base classes, |
188 | | - |
189 | 286 | \item has at most one base class subobject of any given type, |
190 | | - |
191 | 287 | \item has all non-static data members and bit-fields in the class and |
192 | 288 | its base classes first declared in the same class, and |
193 | 289 |
|
|
0 commit comments