Bug 22113 – Allow `noreturn` as a type for main function
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-08T22:27:47Z
Last change time
2021-12-25T11:28:26Z
Keywords
pull
Assigned to
No Owner
Creator
Bolpat
Comments
Comment #0 by qs.il.paperinik — 2021-07-08T22:27:47Z
Using `noreturn main(..)` makes sense for some programs, but isn't currently allowed.
Comment #1 by pro.mathias.lang — 2021-07-13T03:59:55Z
Does it make sense ? What advantage can one derive from it over `void` ?
Comment #2 by dkorpel — 2021-07-13T09:53:06Z
(In reply to Mathias LANG from comment #1)
> Does it make sense ?
Based on covariance of noreturn functions, I think so. `noreturn function(...)` converts to `T function(...)` in general.
> What advantage can one derive from it over `void` ?
Smaller codegen, statically knowing the endless loop doesn't have any breaks. Could be useful for embedded applications that are supposed to run forever until the power is cut off.
Comment #3 by dlang-bot — 2021-10-07T18:36:14Z
@MoonlightSentinel created dlang/dmd pull request #13138 "Fix 22113 - Allow `noreturn` as a type for main function" fixing this issue:
- Fix 22113 - Allow `noreturn` as a type for main function
`noreturn` is a valid because it's a subtype of `int`/`void` and also
guarantees that the function will never actually return to the caller.
The motivation as stated on bugzilla:
>> What advantage can one derive from it over `void` ?
>
> Smaller codegen, statically knowing the endless loop doesn't have any
> breaks. Could be useful for embedded applications that are supposed to
> run forever until the power is cut off.
https://github.com/dlang/dmd/pull/13138
Comment #4 by dlang-bot — 2021-10-08T06:11:50Z
dlang/dmd pull request #13138 "Fix 22113 - Allow `noreturn` as a type for main function" was merged into master:
- 3bd54c000197c5d50809d8a6269c84aa2612e08b by MoonlightSentinel:
Fix 22113 - Allow `noreturn` as a type for main function
`noreturn` is a valid because it's a subtype of `int`/`void` and also
guarantees that the function will never actually return to the caller.
The motivation as stated on bugzilla:
>> What advantage can one derive from it over `void` ?
>
> Smaller codegen, statically knowing the endless loop doesn't have any
> breaks. Could be useful for embedded applications that are supposed to
> run forever until the power is cut off.
https://github.com/dlang/dmd/pull/13138