www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23114] New: Can't use noreturn operand in arithmetic expression


          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 puremagic.com
          Reporter: snarwin+bugzilla 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.

May 16 2022