Checking if a type is void

Boris Carvajal boris2.9 at gmail.com
Sun May 29 16:12:01 UTC 2022


On Sunday, 29 May 2022 at 13:26:55 UTC, Nick Treleaven wrote:
> On Saturday, 28 May 2022 at 14:37:42 UTC, Stefan Koch wrote:
>> static assert(is(U == void));
>
> I'm going to go off on a tangent just to vent:
> Seeing `typeof(x) == void` doesn't even mean x is a (runtime) 
> expression, because x can be a template:
>
> template t {}
> static assert(is(typeof(t) == void));
>
> This was only recently documented in February. Apparently 
> Walter and Andrei had previously said it should be removed:
> https://issues.dlang.org/show_bug.cgi?id=15437#c6
> https://github.com/dlang/dlang.org/pull/3218
>
> I don't think it makes any sense.

There was some code depending on this behavior that I even had to 
make `typeof(T.t) == void`  for consistency 
[(#12294)](https://github.com/dlang/dmd/pull/12294).

Quoting myself from 
[#12897](https://github.com/dlang/dmd/pull/12897#issuecomment-883798530)
```
there is an overuse of `void` in the compiler internals, there 
are many objects whose type is `void` when it could be something 
else like an `unresolved` or `none` type, having this distinction 
should help in general.
```

I agree it should be changed, now there are many `traits` to 
replace its usage.
We only need a deprecation period.


More information about the Digitalmars-d mailing list