@@ -227,7 +227,8 @@ struct S
227
227
int b; // placed at offset 4
228
228
long c; // placed at offset 8
229
229
}
230
- auto sz = S.sizeof; // 16
230
+ static assert(S.alignof == 8);
231
+ static assert(S.sizeof == 16);
231
232
--------
232
233
233
234
$(P $(I AssignExpression) specifies the alignment
@@ -247,12 +248,13 @@ struct S
247
248
int b; // placed at offset 1
248
249
long c; // placed at offset 5
249
250
}
250
- auto sz = S.sizeof; // 16
251
+ static assert(S.alignof == 1);
252
+ static assert(S.sizeof == 13);
251
253
--------
252
254
253
- $(P The alignment for the fields of an aggregate does not affect the alignment
254
- of the aggregate itself - that is affected by the alignment setting outside
255
- of the aggregate.)
255
+ $(P The natural alignment of an aggregate is the maximum alignment of its
256
+ fields. It can be overridden by setting the alignment outside of the
257
+ aggregate.)
256
258
257
259
--------
258
260
align (2) struct S
@@ -262,7 +264,8 @@ align (2) struct S
262
264
int b; // placed at offset 1
263
265
long c; // placed at offset 5
264
266
}
265
- auto sz = S.sizeof; // 14
267
+ static assert(S.alignof == 2);
268
+ static assert(S.sizeof == 14);
266
269
--------
267
270
268
271
$(P Setting the alignment of a field aligns it to that power of 2, regardless
@@ -271,12 +274,12 @@ auto sz = S.sizeof; // 14
271
274
--------
272
275
struct S
273
276
{
274
- align (4):
275
- byte a; // placed at offset 0
276
- byte b; // placed at offset 4
277
- short c; // placed at offset 8
277
+ byte a; // placed at offset 0
278
+ align (4) byte b; // placed at offset 4
279
+ align (16) short c; // placed at offset 16
278
280
}
279
- auto sz = S.sizeof; // 12
281
+ static assert(S.alignof == 16);
282
+ static assert(S.sizeof == 32);
280
283
--------
281
284
282
285
0 commit comments