Bug 18024 – checkedint.Abort and checkedint.Warn should be @safe

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-01T08:09:59Z
Last change time
2021-03-24T22:12:12Z
Keywords
pull
Assigned to
No Owner
Creator
Seb
Blocks
18110, 21169

Comments

Comment #0 by greensunny12 — 2017-12-01T08:09:59Z
void main(string[] args) @safe @nogc nothrow pure { import std.experimental.checkedint : checked; auto f = (2.checked + 3).get; } foo.d(4): Error: pure function 'D main' cannot call impure function 'std.experimental.checkedint.Checked!(int, Abort).Checked.opBinary!("+", int).opBinary' foo.d(4): Error: @safe function 'D main' cannot call @system function 'std.experimental.checkedint.Checked!(int, Abort).Checked.opBinary!("+", int).opBinary' foo.d(4): Error: @nogc function 'D main' cannot call non-@nogc function 'std.experimental.checkedint.Checked!(int, Abort).Checked.opBinary!("+", int).opBinary' foo.d(4): Error: function std.experimental.checkedint.Checked!(int, Abort).Checked.opBinary!("+", int).opBinary is not nothrow
Comment #1 by jack — 2017-12-15T13:48:51Z
Isn't this just a matter of using a custom hook? Or are you saying the default behavior should be different?
Comment #2 by greensunny12 — 2017-12-15T14:33:58Z
> Isn't this just a matter of using a custom hook? Or are you saying the default behavior should be different? Well, the default hook Abort just SEGFAULTs / assert(0)s will fullfils all the attributes given.
Comment #3 by jack — 2017-12-15T14:40:01Z
(In reply to Seb from comment #2) > > Isn't this just a matter of using a custom hook? Or are you saying the default behavior should be different? > > Well, the default hook Abort just SEGFAULTs / assert(0)s will fullfils all > the attributes given. Don't forget it also prints to stderr, which is why it's @system impure gc and throws
Comment #4 by jack — 2017-12-15T14:56:06Z
The problem with trying to make Warn @safe is File is still unsafe and will be for the foreseeable future. IMO, Abort should be modified to not use Warn, and a new Hook called debug should give the same behavior as Abort has now. That way, by default checked is @nogc @safe nothrow pure
Comment #5 by greensunny12 — 2017-12-15T14:58:05Z
> Don't forget it also prints to stderr, which is why it's @system impure gc and throws Yeah I did forget about this when I opened the issue (didn't had time to dive into this then). Anyhow it `Warn` can easily be made @safe: PR https://github.com/dlang/phobos/pull/5928
Comment #6 by greensunny12 — 2017-12-15T14:59:45Z
> The problem with trying to make Warn @safe is File is still unsafe and will be for the foreseeable future. Well, but we can use the same "trick" / "workaround" as used for stdout? > IMO, Abort should be modified to not use Warn, and a new Hook called debug should give the same behavior as Abort has now. That way, by default checked is @nogc @safe nothrow pure That sounds very reasonable!
Comment #7 by greensunny12 — 2018-06-06T16:35:59Z
See also https://github.com/dlang/phobos/pull/6550 for yet another PR on this problem
Comment #8 by dlang-bot — 2021-03-24T14:03:05Z
@n8sh created dlang/phobos pull request #7909 "checkedint.Abort and checkedint.Warn should be `@safe`" fixing this issue: - Fix Issue 18024 - checkedint.Abort and checkedint.Warn should be `@safe` https://github.com/dlang/phobos/pull/7909
Comment #9 by dlang-bot — 2021-03-24T22:12:12Z
dlang/phobos pull request #7909 "checkedint.Abort and checkedint.Warn should be `@safe`" was merged into master: - 7580f74c9af0afd266f730d8ab3a37c61e06e35c by Nathan Sashihara: Fix Issue 18024 - checkedint.Abort and checkedint.Warn should be `@safe` https://github.com/dlang/phobos/pull/7909