You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come across a few inconsistencies with aligned fields in structs. Primarily, the following code produces error: struct layout depends on being pointer aligned (pointing to the definition of A):
pubfnmain() !void {
_=struct { a: A }; // Line A_=A; // Line B
}
pubconstA=struct {
b: struct {
a: *align(@alignOf(struct { a: A })) void,
},
a: *A,
c: struct {
a: *align(@alignOf(struct { a: A })) void,
},
d: u128,
};
but if you swap the order of line A and line B, no such error occurs. Furthermore, commenting out line B makes it error once again, but an error is not produced with solely line B.
Finally, if a: *A is moved up as to become the first field, with just line B (so line A is commented out), the error occurs once again.
However, if struct { a: *align(@alignOf(struct { a: A })) void } is extracted to a separate variable (e.g. B) and is referred to by A (b: B, c: B), the error does not occur in any case that I have tested.
My best guess as to why this is occurring is that the alignment of the struct is being retrieved before the alignment has been correctly set (since A depends on the alignment of itself) so the comptime evaluation of the types of fields of A is inconsistently wrong, dependent on the order of how the expressions are evaluated.
Expected Behavior
To my understanding, none of this code should error, but at a minimum, reordering the two lines in main should not change whether or not there is a compile error.
The text was updated successfully, but these errors were encountered:
This doesn't occur on 0.13.0 (as well as 0.12.0, 0.11.0, 0.10.0), and occurs on 0.14.0 and master, so I assume this is a regression and was introduced somewhere between 0.13.0 and 0.14.0. I haven't bisected individual commits though.
Zig Version
0.15.0-dev.149+2b57f6b71
Steps to Reproduce and Observed Behavior
I've come across a few inconsistencies with aligned fields in structs. Primarily, the following code produces
error: struct layout depends on being pointer aligned
(pointing to the definition ofA
):but if you swap the order of line A and line B, no such error occurs. Furthermore, commenting out line B makes it error once again, but an error is not produced with solely line B.
Finally, if
a: *A
is moved up as to become the first field, with just line B (so line A is commented out), the error occurs once again.However, if
struct { a: *align(@alignOf(struct { a: A })) void }
is extracted to a separate variable (e.g.B
) and is referred to by A (b: B
,c: B
), the error does not occur in any case that I have tested.My best guess as to why this is occurring is that the alignment of the struct is being retrieved before the alignment has been correctly set (since
A
depends on the alignment of itself) so the comptime evaluation of the types of fields ofA
is inconsistently wrong, dependent on the order of how the expressions are evaluated.Expected Behavior
To my understanding, none of this code should error, but at a minimum, reordering the two lines in
main
should not change whether or not there is a compile error.The text was updated successfully, but these errors were encountered: