[Issue 23114] New: Can't use noreturn operand in arithmetic expression
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 16 14:46:32 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23114
Issue ID: 23114
Summary: Can't use noreturn operand in arithmetic expression
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
As of DMD 2.100.0, the following program fails to compile
---
void main()
{
auto _ = 2 + throw new Exception("");
}
---
The error message is:
---
bug.d(3): Error: incompatible types for `(2) + (throw new Exception("",
"bug.d", 3LU, null))`: `int` and `noreturn`
---
Changing the right-hand operand of the + operator to `cast(int) throw new
Exception("")` causes the program to compile successfully and throw an
exception at runtime, as expected.
Since noreturn implicitly converts to every type, including int, this program
should compile without an explicit cast.
--
More information about the Digitalmars-d-bugs
mailing list