Should we warn if we detect null derefernces or void value uses ?
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Wed Dec 7 03:52:43 PST 2016
On Wednesday, 7 December 2016 at 10:25:56 UTC, Walter Bright
wrote:
> On 12/4/2016 8:41 PM, Stefan Koch wrote:
>> What is your opinion, should we warn if we unambiguously
>> detect something that
>> is clearly unwanted ?
> It's an old idea, and comes up regularly.
>
> This all sounds like a great idea, and I've tried it.
> Unfortunately, it runs afoul of code like this:
>
> int i;
> int* p = null;
> if (c)
> p = &i;
> ...code...
> if (c)
> *p = 3; // Warning Will Robinson! p could be null!
That is why I said unambiguously.
We will neither warn or error in the above case, because p could
have been assigned to.
Only if we directly read from something uninitialized will we
error.
More information about the Digitalmars-d
mailing list