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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 30 01:44:48 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11645

           Summary: struct with union considered unsafe only in second
                    struct literal
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: r.sagitario at gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario at gmx.de> 2013-11-30 01:44:46 PST ---
Compiling:

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

void foo()()
{
    S s1 = S();
    S s2 = S(); // line 19: compiles without this line
}

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

yields:

test2.d(19): Error: safe function 'D main' cannot call system function
'test2.foo!().foo'

Please note, that the error does not happen with only s1 being declared.

std.regex makes use of the buggy behaviour, otherwise std.regex.replace would
not infer as @safe because struct Captures contains a similar union.

Note: https://github.com/D-Programming-Language/dmd/pull/2480 contains a fix
for this, but causes the unittests of std.regex to fail.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list