[Issue 19742] New: The compiler suggests annotating parameters with `return`, even if they are marked as `return` or `return scope` already

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 16 05:46:21 UTC 2019


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

          Issue ID: 19742
           Summary: The compiler suggests annotating parameters with
                    `return`, even if they are marked as `return` or
                    `return scope` already
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: monkeyworks12 at hotmail.com

Needle* find(Haystack, Needle)(return Haystack haystack, scope Needle needle)
@safe
{
    size_t index = -1;
    foreach (i, ref val; haystack)
    {
        if (val == needle)
        {
            index = i;
        }
    }

    if (index != -1)
        return &haystack[index]; //Error: returning &haystack[index] escapes a
reference to parameter haystack, perhaps annotate with return
    else
        return null;
}

void main() @safe
{
    int[9] haystack = [0, 10, 5, 6, 2, 3, 9, 4, 5];
    int* foundVal = haystack.find(3);
}

--


More information about the Digitalmars-d-bugs mailing list