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); }
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 ***