We all get nullability wrong sometimes

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Jul 13 16:45:16 UTC 2026


On 10/07/2026 11:09 AM, Walter Bright wrote:
> A simpler version of that is:
> 
> ```d
> void foo(int* p)
> {
>      if (p == null)
>          *p = 3;
> }
> ```
> which I keep thinking I should implement in the optimizer.

That's an easy case.

```d
void checkViaObjNullDeref(char cond, int** ptrArg)
{
     int* var;
     int** ptr = cond ? &var : ptrArg;
     **ptr = 2;
}
```

Try that one, its taken me 4 days to get that to work.

Clang can catch this, gcc can't.



More information about the Digitalmars-d mailing list