[Issue 11889] New: std.container.Array.opIndex returns by value, resulting in perfect storm

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 10 00:20:40 PST 2014


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: nobody at puremagic.com
        ReportedBy: andrei at erdani.com


--- Comment #0 from Andrei Alexandrescu <andrei at erdani.com> 2014-01-10 00:20:37 PST ---
Per
http://forum.dlang.org/thread/mailman.281.1389340467.15871.digitalmars-d@puremagic.com:

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: -------


More information about the Digitalmars-d-bugs mailing list