Thread overview
[Issue 11645] struct with union considered unsafe only in second struct literal
Jul 04, 2020
Basile-z
Jul 04, 2020
Rainer Schuetze
Dec 17, 2022
Iain Buclaw
July 04, 2020
https://issues.dlang.org/show_bug.cgi?id=11645

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #1 from Basile-z <b2.temp@gmx.com> ---
Now safe is infered for foo and the test always compiles. Should this be closed ?

--
July 04, 2020
https://issues.dlang.org/show_bug.cgi?id=11645

--- Comment #2 from Rainer Schuetze <r.sagitario@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

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=11645

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--