[RFC] Throwing an exception with null pointers

Derek Fawcus dfawcus+dlang at employees.org
Wed Apr 16 22:50:03 UTC 2025


On Wednesday, 16 April 2025 at 21:12:08 UTC, Walter Bright wrote:
> I'm curious - how does one traverse a binary tree with non-null 
> pointers? How does one create a circular data structure with 
> non-null pointers?

One has nullable and nonnull pointers.  One uses the former for 
the circular data structures.

Now the current ugly bit with clang is this:

```C
int foo(int * arg1, int * NULL_UNSPECIFIED arg2, int * NULLABLE 
arg3) {

         if (arg3 != 0)
                 ptr = arg3;

         return a;
}
```

```
$ clang-14 -Wall -Wnullable-to-nonnull-conversion -c ttt.c
ttt.c:36:9: warning: implicit conversion from nullable pointer 
'int * _Nullable' to non-nullable pointer type 'int * _Nonnull' 
[-Wnullable-to-nonnull-conversion]
                 ptr = arg3;
                       ^
```

i.e. there is no DFA, and one still has to cast the value in the 
assignment.  So the clang support could stand some improvement.


More information about the Digitalmars-d mailing list