Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 20743 - Checked!(int, Abort) does not abort but raise SIGFPE #7454

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion std/experimental/checkedint.d
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,10 @@ static:
{
stderr.writefln("Overflow on binary operator: %s(%s) %s %s(%s)",
Lhs.stringof, lhs, x, Rhs.stringof, rhs);
return mixin("lhs" ~ x ~ "rhs");
static if (x == "/") // Issue 20743: mixin below would cause SIGFPE on POSIX
return typeof(lhs / rhs).min; // or EXCEPTION_INT_OVERFLOW on Windows
else
return mixin("lhs" ~ x ~ "rhs");
}
}

Expand All @@ -1622,6 +1625,23 @@ static:
short y1 = cast(const byte) y;
}

@system unittest
{
auto a = checked!Warn(int.min);
auto b = checked!Warn(-1);
assert(a / b == a * b);
}

@system unittest
{
import std.exception : assertThrown;
import core.exception : AssertError;

auto a = checked!Abort(int.min);
auto b = checked!Abort(-1);
assertThrown!AssertError(a / b);
}

// ProperCompare
/**

Expand Down