www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20581] New: DIP1000 wrongly flags hidden ref temporary

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

          Issue ID: 20581
           Summary: DIP1000 wrongly flags hidden ref temporary
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

Compiling phobos unittests with -checkaction=context causes DIP1000 to raise an
error about a hidden temporary outliving the referenced content.

Reduced example:

void main()  safe
{
    int[5] a = [ 1, 2, 3, 4, 5 ];
    assert(retro(a[]).source is a[]); // => Hidden temporary __assertOp4
}

auto retro(return scope int[] s)  safe
{
    static struct R
    {
        int[] source;
    }
    return R(s);
}


safe.d(6): Error: address of variable a assigned to __assertOp4 with longer
lifetime

--
Feb 14