escaping pointer to scope local array: bug or not?

HOSOKAWA Kenchi hskwk at inter7.jp
Sun Aug 16 10:13:42 PDT 2009


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?
}




More information about the Digitalmars-d mailing list