Bug 22419 – Allow return type inference for main

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-10-18T14:02:02Z
Last change time
2021-12-25T11:28:46Z
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2021-10-18T14:02:02Z
`auto main()` is currently rejected by the compiler even if the right return type (int/void/noreturn) can be inferred from the function body. But return type inference allows for more flexibility and potentially better codegen for `void` vs. `noreturn`.
Comment #1 by dlang-bot — 2021-10-19T09:33:22Z
dlang/dmd pull request #13195 "Fix 22419 - Allow inferred return type for main" was merged into master: - 8db36eadfcd72a30e4968f1d068f423cc96c190d by MoonlightSentinel: Fix 22419 - Allow inferred return type for main `auto main()` is fine iff return type inference resolves `auto` to one of the allowed return types (`void`, `int`, `noreturn`). Deferring the check after the return type inference removes this arbitrary limitation and allows for more flexible code. E.g. to use the upcoming `noreturn` inference and the associated codegen improvements. https://github.com/dlang/dmd/pull/13195
Comment #2 by nick — 2021-12-25T11:28:46Z
I have documented the change in this pull: https://github.com/dlang/dlang.org/pull/3149