Thinking about nothing: Solving the weirdness of the `void` type

Basile B. b2.temp at gmx.com
Fri Jul 14 15:10:47 UTC 2023


On Thursday, 13 July 2023 at 18:56:06 UTC, Timon Gehr wrote:
> On 7/13/23 19:58, Quirin Schroll wrote:
>> **Key idea: Make `void` an alias to `typeof(null)` when used 
>> as a return type, with the goal of deprecating `void` return 
>> types altogether.**
>>
> 3. `typeof(null)` is not a canonical unit type. It has a 
> subtyping relationship with class references and pointers. This 
> means you would sometimes actually need to reserve a full

That's correct but `typeof(null)` is actually more simply the 
type of the `null` expression [1].

Then by implicit conversion it indeed converts to all reference 
tpyes and pointers types.

That implicit cast happens **99.99%** of the time, but not always 
e.g:

```d
void* v()
{
     auto error() // the internal type null
     {
         things();
         return null;
     }
     if (auto s = stuff())
         return s;
     return error(); // cast(void*) error()
}
```

So the proposed change cannot work.

[1]: https://dlang.org/spec/expression.html#null



More information about the Digitalmars-d mailing list