Bug 7087 – Produce compiler diagnostic when escaping slice to local static array
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2011-12-09T15:34:00Z
Last change time
2015-06-09T01:31:23Z
Assigned to
nobody
Creator
acehreli
Comments
Comment #0 by acehreli — 2011-12-09T15:34:52Z
Although both are "escaping reference to local" data, only one of the following functions produces a compilation error.
int * ret_elem_ptr()
{
int[3] a;
return &a[0]; // GOOD: compilation ERROR
}
int[] ret_slice()
{
int[3] a;
return a[]; // BAD: no help
}
void main()
{}
It would be nice to receive a compilation error when returning a slice as well. This would catch bugs, because programmers rely on slices' keeping their data alive in most situation. Unfortunately that's not the case here.
Ali
Comment #1 by yebblies — 2013-07-27T23:41:54Z
*** This issue has been marked as a duplicate of issue 8838 ***