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

           Summary: std.container.Array.opIndex returns by value,
                    resulting in perfect storm
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Andrei Alexandrescu <[email protected]> 2014-01-10 00:20:37 
PST ---
Per
http://forum.dlang.org/thread/[email protected]:

void main()
{
    import std.container;
    struct S
    {
      int i;
    }
    Array!S array = [ S(0) ];
    array[0].i = 1;
    assert(array[0].i == 1);
}

This fails because opIndex returns by value and then the lax rules of accessing
members for rvalues masquerade the member as a lvalue, which can be
subsequently assigned to.

Current stance of D is that ref results cannot be escaped (not enforced yet
statically but it will) so it's safe to return a ref.

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

Reply via email to