struct Foo
{
union {
int a;
int b;
}
}
struct Bar
{
__gshared union { // also fails if __gshared -> static
int a;
int b;
}
}
void main (string[] args)
{
Foo x; Bar y;
assert (cast(uint)(&x.a) == cast(uint)(&x.b)); // PASS
assert (cast(uint)(&y.a) == cast(uint)(&y.b)); // FAIL
}
Comment #1 by nick — 2024-09-21T19:53:42Z
Still happens with 2.109. Also:
pragma(msg, Foo.b.offsetof); // 0
pragma(msg, Bar.b.offsetof); // Error: no property `offsetof` for `b` of type `int`
Comment #2 by robert.schadek — 2024-12-13T18:38:34Z