On Monday, 3 February 2014 at 22:18:35 UTC, Jonathan M Davis wrote:
For it to know, it would have to examine the body of foo (which it doesn't necessarily have the code for under C's compilation model - which D uses), and
even if it did that wouldn't be enough e.g.

int* foo()
{
    return "/etc/foo".exists ? new int : null;
}

The compiler could flag that as _possibly_ returning null and therefore the previous code _possibly_ dereferencing null, but it can't know for sure.

If null is an invalid value to assign to a pointer, then there's no issue.

int* foo()
{
    //Error: cannot implicitly convert typeof(null) to type int*
    return "/etc/foo".exists ? new int : null;
}

Reply via email to