|
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 |
| 131 | +withina single \grammarterm{class-property-specifier-seq}. |
| 132 | +Whenever a \grammarterm{class-key} is followed |
| 133 | +by a \grammarterm{class-head-name}, |
| 134 | +the identifier \tcode{final}, \tcode{trivially_relocatable_if_eligible}, |
| 135 | +or \tcode{replaceable_if_eligible}, and a colon or left brace, |
| 136 | +the identifier is interpreted as a \grammarterm{class-property-specifier}. |
129 | 137 | \begin{example}
|
130 | 138 | \begin{codeblock}
|
131 | 139 | struct A;
|
|
134 | 142 |
|
135 | 143 | struct X {
|
136 | 144 | 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} |
| 145 | + struct B trivially_relocatable_if_eligible : C{}; |
| 146 | + // OK, definition of nested class \tcode{B}, |
| 147 | + // not declaration of a bit-field member |
| 148 | + // \tcode{trivially_relocatable_if_eligible} |
139 | 149 | };
|
140 | 150 | \end{codeblock}
|
141 | 151 | \end{example}
|
142 | 152 |
|
| 153 | +\pnum |
| 154 | +If a class is marked with the \grammarterm{class-property-specifier} |
| 155 | +\tcode{final} and that class appears as a \grammarterm{class-or-decltype} |
| 156 | +in a \grammarterm{base-clause}\iref{class.derived}, the program is ill-formed. |
| 157 | + |
143 | 158 | \pnum
|
144 | 159 | \begin{note}
|
145 | 160 | Complete objects of class type have nonzero size.
|
|
172 | 187 | \item that has a trivial, non-deleted destructor\iref{class.dtor}.
|
173 | 188 | \end{itemize}
|
174 | 189 |
|
| 190 | +\pnum |
| 191 | +A class \tcode{C} is \defn{default-movable} if |
| 192 | + |
| 193 | +\begin{itemize} |
| 194 | +\item overload resolution for direct-initializing an object of type \tcode{C} |
| 195 | +from an xvalue of type \tcode{C} selects a constructor that is a direct member |
| 196 | +of \tcode{C} and is neither user-provided nor deleted, |
| 197 | + |
| 198 | +\item overload resolution for assigning to an lvalue of type \tcode{C} from an |
| 199 | +xvalue of type \tcode{C} selects an assignment operator function that is a |
| 200 | +direct member of \tcode{C} and is neither user-provided nor deleted, and |
| 201 | + |
| 202 | +\item \tcode{C} has a destructor that is neither user-provided nor deleted. |
| 203 | +\end{itemize} |
| 204 | + |
| 205 | +\pnum |
| 206 | +A class is \defn{eligible for trivial relocation} unless it |
| 207 | +\begin{itemize} |
| 208 | +\item has any virtual base classes, |
| 209 | +\item has a base class that is not a trivially relocatable class, |
| 210 | +\item has a non-static data member of an object type that is not of a |
| 211 | +trivially relocatable type, or |
| 212 | + |
| 213 | +\item has a deleted destructor, |
| 214 | +\end{itemize} |
| 215 | +except that it is \impldef{whether an otherwise-eligible union having one or |
| 216 | +more subobjects of polymorphic class type is eligible for trivial relocation} |
| 217 | +whether an otherwise-eligible union having one or more subobjects of |
| 218 | +polymorphic class type is eligible for trivial relocation. |
| 219 | + |
| 220 | +\pnum |
| 221 | +A class \tcode{C} is a \defnadj{trivially relocatable}{class} |
| 222 | +if it is eligible for trivial relocation and |
| 223 | +\begin{itemize} |
| 224 | +\item has the \tcode{trivially_relocatable_if_eligible} \grammarterm{class-property-specifier}, |
| 225 | +\item is a union with no user-declared special member functions, or |
| 226 | +\item is default-movable. |
| 227 | +\end{itemize} |
| 228 | + |
| 229 | +\pnum |
| 230 | +\begin{note} |
| 231 | +A class with const-qualified or reference non-static data members can be |
| 232 | +trivially relocatable. |
| 233 | +\end{note} |
| 234 | + |
| 235 | +\pnum |
| 236 | +A class \tcode{C} is \defn{eligible for replacement} unless |
| 237 | +\begin{itemize} |
| 238 | +\item it has a base class that is not a replaceable class, |
| 239 | +\item it has a non-static data member that is not of a replaceable type, |
| 240 | +\item overload resolution fails or selects a deleted constructor when |
| 241 | +direct-initializing an object of type \tcode{C} from an xvalue of type |
| 242 | +\tcode{C}\iref{dcl.init.general}, |
| 243 | + |
| 244 | +\item overload resolution fails or selects a deleted assignment operator |
| 245 | +function when assigning to an lvalue of type \tcode{C} from an xvalue of type |
| 246 | +\tcode{C} \iref{expr.assign,over.assign}), or |
| 247 | + |
| 248 | +\item it has a deleted destructor. |
| 249 | +\end{itemize} |
| 250 | + |
| 251 | +\pnum |
| 252 | +A class \tcode{C} is a \defnadj{replaceable}{class} if it is |
| 253 | +eligible for replacement and |
| 254 | +\begin{itemize} |
| 255 | +\item has the \tcode{replaceable_if_eligible} \grammarterm{class-property-specifier}, |
| 256 | +\item is a union with no user-declared special member functions, or |
| 257 | +\item is default-movable. |
| 258 | +\end{itemize} |
| 259 | + |
| 260 | +\pnum |
| 261 | +\begin{note} |
| 262 | +Accessibility of the special member functions is not considered when |
| 263 | +establishing trivial relocatability or replaceability. |
| 264 | +\end{note} |
| 265 | + |
| 266 | +\pnum |
| 267 | +\begin{note} |
| 268 | +Not all trivially copyable classes are trivially relocatable or replaceable. |
| 269 | +\end{note} |
| 270 | + |
175 | 271 | \pnum
|
176 | 272 | A class \tcode{S} is a \defnadj{standard-layout}{class} if it:
|
177 | 273 | \begin{itemize}
|
|
0 commit comments