D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19742 - The compiler suggests annotating parameters with `return`, even if they are marked as `return` or `return scope` already
Summary: The compiler suggests annotating parameters with `return`, even if they are m...
Status: RESOLVED DUPLICATE of issue 19210
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-16 05:46 UTC by Meta
Modified: 2020-09-03 02:32 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Meta 2019-03-16 05:46:21 UTC
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);
}
Comment 1 Mathias LANG 2020-09-03 02:32:34 UTC
Duplicate of 19210, which is fixed in master and will be part of DMD v2.094.0.

*** This issue has been marked as a duplicate of issue 19210 ***