On Sun, 16 Aug 2009 10:13:42 -0700, HOSOKAWA Kenchi <hs...@inter7.jp>
wrote:
It seems dmd 2.031 forgets scope attribute for array.ptr in some cases,
so that it allows escaping a pointer to scope local array.
I'm not sure this is a bug or a kind of "dangerous-but-valid".
int[] a()
{
scope auto a = new int[1];
return a; // error; escaping reference to scope local array
}
int* ap()
{
scope auto a = new int[1];
return a.ptr; // no error; this is the problem
}
int* i()
{
int i;
return &i; // error; escaping reference to local variable
}
int* ip()
{
scope int* p = new int;
return p; // no error; only is "int* p" local, "new int" not scope
local?
}
I'd recommend checking to see if p* was allocated on the stack or on the
heap, as the difference represents two very different bugs.