www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20658] New: can modify overlapped storage classes in safe

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

          Issue ID: 20658
           Summary: can modify overlapped storage classes in  safe enum
                    function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

This is correctly rejected:

----
union U
{
    int m;
    immutable int i;
}
U u;

void main()  safe
{
    ()  safe { u.m = 13; } ();
}
----

But factor the function literal out into an enum and DMD wrongly accepts it:

----
union U
{
    int m;
    immutable int i;
}
U u;

enum e = ()  safe { u.m = 13; }; /* Should be the same error. */
void main()  safe
{
     e();
}
----

--
Mar 09 2020