[Issue 11645] struct with union considered unsafe only in second struct literal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 4 18:00:49 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=11645

--- Comment #2 from Rainer Schuetze <r.sagitario at gmx.de> ---
(In reply to Basile-z from comment #1)
> Now safe is infered for foo and the test always compiles.

Hmm, that's pretty bad. This compiles and runs but produces a memory
corruption:

struct S
{
        union
        {
                int[] a;
                long[] b;
        }
}

void foo()()
{
        S s1 = S();
        s1.a = [1];
        s1.b[0] = 1;
}

void main() @safe
{
        foo();
}

Broken since 2.072 according to run.dlang.io

--


More information about the Digitalmars-d-bugs mailing list