[Issue 6438] [CTFE] wrong error "value used before set" when slicing =void array
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 5 23:43:36 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6438
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |clugdbug at yahoo.com.au
--- Comment #1 from Don <clugdbug at yahoo.com.au> 2011-08-05 23:43:35 PDT ---
That's difficult. Implementing this would be a major feature, since assignment
from void has a high risk of undefined behaviour.
The f() function is passing a reference to an uninitialized value, to another
function. In this particular case, it does initialize every member without
reading from any of them, but that's difficult to determine.
I guess it could be implemented by introducing an 'uninitialized expression',
but then there are problems with this:
void fillWithZero(T)(T[] arr)
{
auto q = arr[0]; // consider this line
foreach(ref x; arr)
x = 0;
}
T[4] f(T)()
{
T[4] stackSpace = void;
fillWithZero(stackSpace[]);
return stackSpace;
}
static assert(f!int() == [0,0,0,0]);
The assignment to q should generate a 'variable used before set' error. But to
be comprehensible, it should also refer to the line where stackSpace was
initialized.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list