[Issue 11824] A stack variable escaping problem in CTFE Phobos code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 3 09:27:59 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11824
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |CTFE
--- Comment #4 from monarchdodra at gmail.com 2014-02-03 09:27:55 PST ---
I can work *around* the issue, but there is a CTFE bug in there to begin with.
Here is a reduced test case:
//----
int foo(T)()
{
T[] arr = new T[](1);
T* getAddr(ref T a)
{
return &a;
}
getAddr(arr[0]);
return 5;
}
void main()
{
enum a = foo!int(); //OK!
enum b = foo!(int[])(); //FAILS!
}
//----
main.d(6): Error: returning a pointer to a local stack variable
main.d(8): called from here: getAddr(arr[0])
main.d(15): called from here: foo()
//----
First of all: "foo()" ? What are the template parameters?
Second, I *think* there is a rejects valid: getAddr rejects "return &a" if a is
of type "T[]", but not "T".
To be perfectly pedantic: a happens to be a stack variable, yes, but *not*
inside "getAddr" 's scope. So this should not be rejected during CTFE I think.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list