Bug 24117 – noreturn can be used as expression

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-27T08:15:39Z
Last change time
2023-08-31T09:39:38Z
Keywords
accepts-invalid, pull
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2023-08-27T08:15:39Z
Example 1, in an AddExpression: ```d int v(e)() { return e + 0; } int main() { return v!(noreturn)(); } ``` Example 2, as EnumMember initializer: ```d enum E {e1 = 1, e2 = 2, illegal = noreturn} void main() { E e; e = E.illegal; } ```
Comment #1 by nick — 2023-08-28T10:05:00Z
This code: auto e = noreturn + 1; Gets lowered to: int e = 1; Also, `cast(int) E.illegal` is 0.
Comment #2 by dlang-bot — 2023-08-28T12:39:10Z
@ntrel created dlang/dmd pull request #15561 "Fix Issue 24117 - noreturn can be used as expression" fixing this issue: - Fix Issue 24117 - noreturn can be used as expression https://github.com/dlang/dmd/pull/15561
Comment #3 by b2.temp — 2023-08-28T13:48:01Z
Example 2 was about the member initializer Also if it's set to 0, then this becomes a problem because it's not expected to have two members of the same value, e.g ```d enum E {e0 = 0, e1 = 1, illegal = noreturn} ``` Otherwise I have a 3rd example: ```d void main() { foreach (const i; 0 .. noreturn){} } ```
Comment #4 by dlang-bot — 2023-08-30T11:34:03Z
@ntrel created dlang/dmd pull request #15562 "Fix Issue 24117 - noreturn can be used as expression" fixing this issue: - Fix Issue 24117 - noreturn can be used as expression https://github.com/dlang/dmd/pull/15562
Comment #5 by nick — 2023-08-30T11:38:18Z
> enum E {e0 = 0, e1 = 1, illegal = noreturn} > foreach (const i; 0 .. noreturn){} I made a new fix that is more precise which does reject the 2 above and should cover all cases.
Comment #6 by dlang-bot — 2023-08-31T09:39:38Z
dlang/dmd pull request #15562 "Fix Issue 24117 - noreturn can be used as expression" was merged into master: - 46f1225eaeaf4332f5769ce5b1e3853d88ede527 by Nick Treleaven: Fix Issue 24117 - noreturn can be used as expression https://github.com/dlang/dmd/pull/15562