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: [email protected]
Reporter: [email protected]
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.
--