http://d.puremagic.com/issues/show_bug.cgi?id=6438


Don <clugd...@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugd...@yahoo.com.au


--- Comment #1 from Don <clugd...@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: -------

Reply via email to