Valid to assign to field of struct in union?
Johan Engelen via Digitalmars-d
digitalmars-d at puremagic.com
Tue Sep 6 06:00:07 PDT 2016
On Tuesday, 6 September 2016 at 12:56:24 UTC, Johan Engelen wrote:
>
> The compiler allows it, but it leads to a bug with CTFE of this
> code: the assert fails.
Before someone smart tries it, yes the code works with LDC, but
wait... swap the order of `first` and `second` in the union, and
BOOM!
Internally, CTFE of the code leads to a corrupt union initializer
array. LDC and DMD do things a little differently in codegen.
Oversimplified: LDC will use the first member of the union, DMD
the last.
More information about the Digitalmars-d
mailing list