From Jason Turner

[class.mem.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpni47whu9/{from.md → to.md} +357 -0
tmp/tmpni47whu9/{from.md → to.md} RENAMED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### General <a id="class.mem.general">[[class.mem.general]]</a>
2
+
3
+ ``` bnf
4
+ member-specification:
5
+ member-declaration member-specificationₒₚₜ
6
+ access-specifier ':' member-specificationₒₚₜ
7
+ ```
8
+
9
+ ``` bnf
10
+ member-declaration:
11
+ attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ member-declarator-listₒₚₜ ';'
12
+ function-definition
13
+ using-declaration
14
+ using-enum-declaration
15
+ static_assert-declaration
16
+ template-declaration
17
+ explicit-specialization
18
+ deduction-guide
19
+ alias-declaration
20
+ opaque-enum-declaration
21
+ empty-declaration
22
+ ```
23
+
24
+ ``` bnf
25
+ member-declarator-list:
26
+ member-declarator
27
+ member-declarator-list ',' member-declarator
28
+ ```
29
+
30
+ ``` bnf
31
+ member-declarator:
32
+ declarator virt-specifier-seqₒₚₜ pure-specifierₒₚₜ
33
+ declarator requires-clause
34
+ declarator brace-or-equal-initializerₒₚₜ
35
+ identifierₒₚₜ attribute-specifier-seqₒₚₜ ':' constant-expression brace-or-equal-initializerₒₚₜ
36
+ ```
37
+
38
+ ``` bnf
39
+ virt-specifier-seq:
40
+ virt-specifier
41
+ virt-specifier-seq virt-specifier
42
+ ```
43
+
44
+ ``` bnf
45
+ virt-specifier:
46
+ override
47
+ final
48
+ ```
49
+
50
+ ``` bnf
51
+ pure-specifier:
52
+ '=' '0'
53
+ ```
54
+
55
+ The *member-specification* in a class definition declares the full set
56
+ of members of the class; no member can be added elsewhere. A
57
+ *direct member* of a class `X` is a member of `X` that was first
58
+ declared within the *member-specification* of `X`, including anonymous
59
+ union members [[class.union.anon]] and direct members thereof. Members
60
+ of a class are data members, member functions [[class.mfct]], nested
61
+ types, enumerators, and member templates [[temp.mem]] and
62
+ specializations thereof.
63
+
64
+ [*Note 1*: A specialization of a static data member template is a
65
+ static data member. A specialization of a member function template is a
66
+ member function. A specialization of a member class template is a nested
67
+ class. — *end note*]
68
+
69
+ A *member-declaration* does not declare new members of the class if it
70
+ is
71
+
72
+ - a friend declaration [[class.friend]],
73
+ - a *deduction-guide* [[temp.deduct.guide]],
74
+ - a *template-declaration* whose *declaration* is one of the above,
75
+ - a *static_assert-declaration*,
76
+ - a *using-declaration* [[namespace.udecl]], or
77
+ - an *empty-declaration*.
78
+
79
+ For any other *member-declaration*, each declared entity that is not an
80
+ unnamed bit-field [[class.bit]] is a member of the class, and each such
81
+ *member-declaration* shall either declare at least one member name of
82
+ the class or declare at least one unnamed bit-field.
83
+
84
+ A *data member* is a non-function member introduced by a
85
+ *member-declarator*. A *member function* is a member that is a function.
86
+ Nested types are classes [[class.name]], [[class.nest]] and enumerations
87
+ [[dcl.enum]] declared in the class and arbitrary types declared as
88
+ members by use of a typedef declaration [[dcl.typedef]] or
89
+ *alias-declaration*. The enumerators of an unscoped enumeration
90
+ [[dcl.enum]] defined in the class are members of the class.
91
+
92
+ A data member or member function may be declared `static` in its
93
+ *member-declaration*, in which case it is a *static member* (see 
94
+ [[class.static]]) (a *static data member* [[class.static.data]] or
95
+ *static member function* [[class.static.mfct]], respectively) of the
96
+ class. Any other data member or member function is a *non-static member*
97
+ (a *non-static data member* or *non-static member function*
98
+ [[class.mfct.non.static]], respectively).
99
+
100
+ [*Note 2*: A non-static data member of non-reference type is a member
101
+ subobject of a class object [[intro.object]]. — *end note*]
102
+
103
+ A member shall not be declared twice in the *member-specification*,
104
+ except that
105
+
106
+ - a nested class or member class template can be declared and then later
107
+ defined, and
108
+ - an enumeration can be introduced with an *opaque-enum-declaration* and
109
+ later redeclared with an *enum-specifier*.
110
+
111
+ [*Note 3*: A single name can denote several member functions provided
112
+ their types are sufficiently different
113
+ [[basic.scope.scope]]. — *end note*]
114
+
115
+ A redeclaration of a class member outside its class definition shall be
116
+ a definition, an explicit specialization, or an explicit instantiation
117
+ [[temp.expl.spec]], [[temp.explicit]]. The member shall not be a
118
+ non-static data member.
119
+
120
+ A *complete-class context* of a class (template) is a
121
+
122
+ - function body [[dcl.fct.def.general]],
123
+ - default argument [[dcl.fct.default]],
124
+ - default template argument [[temp.param]],
125
+ - *noexcept-specifier* [[except.spec]], or
126
+ - default member initializer
127
+
128
+ within the *member-specification* of the class or class template.
129
+
130
+ [*Note 4*: A complete-class context of a nested class is also a
131
+ complete-class context of any enclosing class, if the nested class is
132
+ defined within the *member-specification* of the enclosing
133
+ class. — *end note*]
134
+
135
+ A class is regarded as complete where its definition is reachable and
136
+ within its complete-class contexts; otherwise it is regarded as
137
+ incomplete within its own class *member-specification*.
138
+
139
+ In a *member-declarator*, an `=` immediately following the *declarator*
140
+ is interpreted as introducing a *pure-specifier* if the *declarator-id*
141
+ has function type, otherwise it is interpreted as introducing a
142
+ *brace-or-equal-initializer*.
143
+
144
+ [*Example 1*:
145
+
146
+ ``` cpp
147
+ struct S {
148
+ using T = void();
149
+ T * p = 0; // OK, brace-or-equal-initializer
150
+ virtual T f = 0; // OK, pure-specifier
151
+ };
152
+ ```
153
+
154
+ — *end example*]
155
+
156
+ In a *member-declarator* for a bit-field, the *constant-expression* is
157
+ parsed as the longest sequence of tokens that could syntactically form a
158
+ *constant-expression*.
159
+
160
+ [*Example 2*:
161
+
162
+ ``` cpp
163
+ int a;
164
+ const int b = 0;
165
+ struct S {
166
+ int x1 : 8 = 42; // OK, "= 42" is brace-or-equal-initializer
167
+ int x2 : 8 { 42 }; // OK, "{ 42 \"} is brace-or-equal-initializer
168
+ int y1 : true ? 8 : a = 42; // OK, brace-or-equal-initializer is absent
169
+ int y2 : true ? 8 : b = 42; // error: cannot assign to const int
170
+ int y3 : (true ? 8 : b) = 42; // OK, "= 42" is brace-or-equal-initializer
171
+ int z : 1 || new int { 0 }; // OK, brace-or-equal-initializer is absent
172
+ };
173
+ ```
174
+
175
+ — *end example*]
176
+
177
+ A *brace-or-equal-initializer* shall appear only in the declaration of a
178
+ data member. (For static data members, see  [[class.static.data]]; for
179
+ non-static data members, see  [[class.base.init]] and 
180
+ [[dcl.init.aggr]]). A *brace-or-equal-initializer* for a non-static data
181
+ member specifies a *default member initializer* for the member, and
182
+ shall not directly or indirectly cause the implicit definition of a
183
+ defaulted default constructor for the enclosing class or the exception
184
+ specification of that constructor. An immediate invocation
185
+ [[expr.const]] that is a potentially-evaluated subexpression
186
+ [[intro.execution]] of a default member initializer is neither evaluated
187
+ nor checked for whether it is a constant expression at the point where
188
+ the subexpression appears.
189
+
190
+ A member shall not be declared with the `extern`
191
+ *storage-class-specifier*. Within a class definition, a member shall not
192
+ be declared with the `thread_local` *storage-class-specifier* unless
193
+ also declared `static`.
194
+
195
+ The *decl-specifier-seq* may be omitted in constructor, destructor, and
196
+ conversion function declarations only; when declaring another kind of
197
+ member the *decl-specifier-seq* shall contain a *type-specifier* that is
198
+ not a *cv-qualifier*. The *member-declarator-list* can be omitted only
199
+ after a *class-specifier* or an *enum-specifier* or in a friend
200
+ declaration [[class.friend]]. A *pure-specifier* shall be used only in
201
+ the declaration of a virtual function [[class.virtual]] that is not a
202
+ friend declaration.
203
+
204
+ The optional *attribute-specifier-seq* in a *member-declaration*
205
+ appertains to each of the entities declared by the *member-declarator*s;
206
+ it shall not appear if the optional *member-declarator-list* is omitted.
207
+
208
+ A *virt-specifier-seq* shall contain at most one of each
209
+ *virt-specifier*. A *virt-specifier-seq* shall appear only in the first
210
+ declaration of a virtual member function [[class.virtual]].
211
+
212
+ The type of a non-static data member shall not be an incomplete type
213
+ [[term.incomplete.type]], an abstract class type [[class.abstract]], or
214
+ a (possibly multidimensional) array thereof.
215
+
216
+ [*Note 5*: In particular, a class `C` cannot contain a non-static
217
+ member of class `C`, but it can contain a pointer or reference to an
218
+ object of class `C`. — *end note*]
219
+
220
+ [*Note 6*: See  [[expr.prim.id]] for restrictions on the use of
221
+ non-static data members and non-static member functions. — *end note*]
222
+
223
+ [*Note 7*: The type of a non-static member function is an ordinary
224
+ function type, and the type of a non-static data member is an ordinary
225
+ object type. There are no special member function types or data member
226
+ types. — *end note*]
227
+
228
+ [*Example 3*:
229
+
230
+ A simple example of a class definition is
231
+
232
+ ``` cpp
233
+ struct tnode {
234
+ char tword[20];
235
+ int count;
236
+ tnode* left;
237
+ tnode* right;
238
+ };
239
+ ```
240
+
241
+ which contains an array of twenty characters, an integer, and two
242
+ pointers to objects of the same type. Once this definition has been
243
+ given, the declaration
244
+
245
+ ``` cpp
246
+ tnode s, *sp;
247
+ ```
248
+
249
+ declares `s` to be a `tnode` and `sp` to be a pointer to a `tnode`. With
250
+ these declarations, `sp->count` refers to the `count` member of the
251
+ object to which `sp` points; `s.left` refers to the `left` subtree
252
+ pointer of the object `s`; and `s.right->tword[0]` refers to the initial
253
+ character of the `tword` member of the `right` subtree of `s`.
254
+
255
+ — *end example*]
256
+
257
+ [*Note 8*: Non-variant non-static data members of non-zero size
258
+ [[intro.object]] are allocated so that later members have higher
259
+ addresses within a class object [[expr.rel]]. Implementation alignment
260
+ requirements can cause two adjacent members not to be allocated
261
+ immediately after each other; so can requirements for space for managing
262
+ virtual functions [[class.virtual]] and virtual base classes
263
+ [[class.mi]]. — *end note*]
264
+
265
+ If `T` is the name of a class, then each of the following shall have a
266
+ name different from `T`:
267
+
268
+ - every static data member of class `T`;
269
+ - every member function of class `T`; \[*Note 9*: This restriction does
270
+ not apply to constructors, which do not have names
271
+ [[class.ctor]] — *end note*]
272
+ - every member of class `T` that is itself a type;
273
+ - every member template of class `T`;
274
+ - every enumerator of every member of class `T` that is an unscoped
275
+ enumeration type; and
276
+ - every member of every anonymous union that is a member of class `T`.
277
+
278
+ In addition, if class `T` has a user-declared constructor
279
+ [[class.ctor]], every non-static data member of class `T` shall have a
280
+ name different from `T`.
281
+
282
+ The *common initial sequence* of two standard-layout struct
283
+ [[class.prop]] types is the longest sequence of non-static data members
284
+ and bit-fields in declaration order, starting with the first such entity
285
+ in each of the structs, such that
286
+
287
+ - corresponding entities have layout-compatible types [[basic.types]],
288
+ - corresponding entities have the same alignment requirements
289
+ [[basic.align]],
290
+ - either both entities are declared with the `no_unique_address`
291
+ attribute [[dcl.attr.nouniqueaddr]] or neither is, and
292
+ - either both entities are bit-fields with the same width or neither is
293
+ a bit-field.
294
+
295
+ [*Example 4*:
296
+
297
+ ``` cpp
298
+ struct A { int a; char b; };
299
+ struct B { const int b1; volatile char b2; };
300
+ struct C { int c; unsigned : 0; char b; };
301
+ struct D { int d; char b : 4; };
302
+ struct E { unsigned int e; char b; };
303
+ ```
304
+
305
+ The common initial sequence of `A` and `B` comprises all members of
306
+ either class. The common initial sequence of `A` and `C` and of `A` and
307
+ `D` comprises the first member in each case. The common initial sequence
308
+ of `A` and `E` is empty.
309
+
310
+ — *end example*]
311
+
312
+ Two standard-layout struct [[class.prop]] types are *layout-compatible
313
+ classes* if their common initial sequence comprises all members and
314
+ bit-fields of both classes [[basic.types]].
315
+
316
+ Two standard-layout unions are layout-compatible if they have the same
317
+ number of non-static data members and corresponding non-static data
318
+ members (in any order) have layout-compatible types
319
+ [[term.layout.compatible.type]].
320
+
321
+ In a standard-layout union with an active member [[class.union]] of
322
+ struct type `T1`, it is permitted to read a non-static data member `m`
323
+ of another union member of struct type `T2` provided `m` is part of the
324
+ common initial sequence of `T1` and `T2`; the behavior is as if the
325
+ corresponding member of `T1` were nominated.
326
+
327
+ [*Example 5*:
328
+
329
+ ``` cpp
330
+ struct T1 { int a, b; };
331
+ struct T2 { int c; double d; };
332
+ union U { T1 t1; T2 t2; };
333
+ int f() {
334
+ U u = { { 1, 2 } }; // active member is t1
335
+ return u.t2.c; // OK, as if u.t1.a were nominated
336
+ }
337
+ ```
338
+
339
+ — *end example*]
340
+
341
+ [*Note 10*: Reading a volatile object through a glvalue of non-volatile
342
+ type has undefined behavior [[dcl.type.cv]]. — *end note*]
343
+
344
+ If a standard-layout class object has any non-static data members, its
345
+ address is the same as the address of its first non-static data member
346
+ if that member is not a bit-field. Its address is also the same as the
347
+ address of each of its base class subobjects.
348
+
349
+ [*Note 11*: There can therefore be unnamed padding within a
350
+ standard-layout struct object inserted by an implementation, but not at
351
+ its beginning, as necessary to achieve appropriate
352
+ alignment. — *end note*]
353
+
354
+ [*Note 12*: The object and its first subobject are
355
+ pointer-interconvertible
356
+ [[basic.compound]], [[expr.static.cast]]. — *end note*]
357
+