Thread overview
[Issue 23587] cast(void) doesn't work for noreturn
Dec 30, 2022
Iain Buclaw
Dec 30, 2022
Dlang Bot
Dec 30, 2022
Iain Buclaw
Dec 30, 2022
RazvanN
Dec 30, 2022
Iain Buclaw
Dec 30, 2022
Iain Buclaw
Dec 30, 2022
artha@samerion.com
Dec 30, 2022
Iain Buclaw
Dec 31, 2022
Dlang Bot
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #1 from Iain Buclaw <ibuclaw@gdcproject.org> ---
I suspect introduced by https://github.com/dlang/dmd/pull/14494

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@ibuclaw updated dlang/dmd pull request #14758 "Revert "Fix Issues 23331, 23379 - fix casts involving noreturn"" fixing this issue:

- fix Issue 23587 - cast(void) doesn't work for noreturn

https://github.com/dlang/dmd/pull/14758

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Why does it matter? The call to fun will never return so casting to void (or any other value) it actually a no-op.

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

--- Comment #4 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to RazvanN from comment #3)
> Why does it matter? The call to fun will never return so casting to void (or any other value) it actually a no-op.
The devils in the detail of the change, not the example code in this bug report.  By blowing a hole in the type system has opened up the flood gates to even worse abominations being accepted.

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=23591

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

--- Comment #5 from artha@samerion.com ---
(In reply to RazvanN from comment #3)
> Why does it matter? The call to fun will never return so casting to void (or any other value) it actually a no-op.

In this case it makes the compiler issue an unwanted warning. The cast is supposed to tell the compiler I'm purposefully discarding the return value.

As a workaround, I could've done this:

```
fun();
static if (!is(typeof(stuff()) == void)) {
    writeln("never written");
}
```

But it's a mess, and I don't want to do that every time I call a template delegate.

--
December 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

--- Comment #6 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to artha from comment #5)
> (In reply to RazvanN from comment #3)
> > Why does it matter? The call to fun will never return so casting to void (or any other value) it actually a no-op.
> 
> In this case it makes the compiler issue an unwanted warning. The cast is supposed to tell the compiler I'm purposefully discarding the return value.
> 

You're not wrong. cast(void) bottom is completely valid and the result should
be void.

--
December 31, 2022
https://issues.dlang.org/show_bug.cgi?id=23587

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14758 "Revert "Fix Issues 23331, 23379 - fix casts involving noreturn"" was merged into master:

- 8bf1c8dab73adb9b990be334cdde1a068cb0a71e by Iain Buclaw:
  fix Issue 23587 - cast(void) doesn't work for noreturn

https://github.com/dlang/dmd/pull/14758

--