Checking if a type is void

Paul Backus snarwin at gmail.com
Sat May 28 15:05:05 UTC 2022


On Saturday, 28 May 2022 at 14:47:00 UTC, Stefan Koch wrote:
> It open up the question of whether it should actually be an 
> error.
> Having every time which is not `void` or `typeof(assert(0))` to 
> evaluate to a false boolean doesn't seem to be too bad to me.

It should be an error because the compilier is lying to you that 
(e.g.) `*T` is a valid expression, when it really isn't.

For example, you may write code like the following:

```d
void doSomethingWith(int n) {}

void example(alias foo)()
{
     static if (is(typeof(*foo) == int))
         doSomethingWith(*foo);
}

void main()
{
     example!(int*)();
}
```

Due to the behavior discussed in this thread, the `static if` 
condition evaluates to `true`, but compilation fails on the 
following line:

```
Error: type `int*` is not an expression
```


More information about the Digitalmars-d mailing list