Skip to content

Commit e3aed68

Browse files
kinkeGeod24
authored andcommitted
Fix spec wrt. the align attribute
The semantics were changed with dlang/dmd#6754.
1 parent c731a9f commit e3aed68

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

spec/attribute.dd

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ struct S
227227
int b; // placed at offset 4
228228
long c; // placed at offset 8
229229
}
230-
auto sz = S.sizeof; // 16
230+
static assert(S.alignof == 8);
231+
static assert(S.sizeof == 16);
231232
--------
232233

233234
$(P $(I AssignExpression) specifies the alignment
@@ -247,12 +248,13 @@ struct S
247248
int b; // placed at offset 1
248249
long c; // placed at offset 5
249250
}
250-
auto sz = S.sizeof; // 16
251+
static assert(S.alignof == 1);
252+
static assert(S.sizeof == 13);
251253
--------
252254

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.)
256258

257259
--------
258260
align (2) struct S
@@ -262,7 +264,8 @@ align (2) struct S
262264
int b; // placed at offset 1
263265
long c; // placed at offset 5
264266
}
265-
auto sz = S.sizeof; // 14
267+
static assert(S.alignof == 2);
268+
static assert(S.sizeof == 14);
266269
--------
267270

268271
$(P Setting the alignment of a field aligns it to that power of 2, regardless
@@ -271,12 +274,12 @@ auto sz = S.sizeof; // 14
271274
--------
272275
struct S
273276
{
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
278280
}
279-
auto sz = S.sizeof; // 12
281+
static assert(S.alignof == 16);
282+
static assert(S.sizeof == 32);
280283
--------
281284

282285

0 commit comments

Comments
 (0)