www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20743] New: Checked!(int, Abort) does not abort but raise

https://issues.dlang.org/show_bug.cgi?id=20743

          Issue ID: 20743
           Summary: Checked!(int, Abort) does not abort but raise SIGFPE
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kdevel vogtner.de

```
import std.experimental.checkedint;
alias cint = Checked!(int, Abort);

void works_okay ()
{
   cint a = cint.max;
   cint b = 1;
   cint c = a + b; 
}

void raises_sigfpe_instead ()
{
   cint a = cint.min;
   cint b = -1;
   cint c = a / b; 
}

void main ()
{
   import std.stdio;
   foreach (f; [&works_okay, &raises_sigfpe_instead])
      try f ();
      catch (Throwable e)
         writefln ("caught Throwable <%s>", e.msg);
}
```

Application output

Overflow on binary operator: int(2147483647) + const(int)(1)
caught Throwable <Assertion failure>
Overflow on binary operator: int(-2147483648) / const(int)(-1)
Error: program killed by signal 8

--
Apr 16 2020