Bug 18407 – debug should escape nothrow

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-02-09T06:50:55Z
Last change time
2020-09-02T18:25:56Z
Keywords
preapproved, spec
Assigned to
No Owner
Creator
Timothee Cour

Comments

Comment #0 by timothee.cour2 — 2018-02-09T06:50:55Z
``` void fun_nogc()@nogc{ debug{ auto a1=new int(1); // Error: cannot use 'new' in @nogc function 'main.fun' } } void fun_nothrow() nothrow{ debug{ static int a; import std.exception; enforce(a==0); // Error: function std.exception.enforce!(Exception, bool).enforce is not nothrow } } static int temp(){ static int a=0; a++; return a; } int fun_pure() pure{ int ret; debug{ ret+=temp; // ok this works static int a2=0; a2++; ret+=a2; } return ret; } void fun_safe() @safe{ debug{ int []a=[1]; if(false) a.ptr[0]++; // Error: a.ptr cannot be used in @safe code, use &a[0] instead } } void main(){ fun_nogc; fun_nothrow; fun_pure; fun_safe; } ```
Comment #1 by timothee.cour2 — 2018-02-09T06:56:40Z
related forum threads: * option -ignore_pure for temporary debugging (or how to wrap an unpure function inside a pure one)? * Should debug{} allow GC? * Debug prints in @nogc
Comment #2 by timothee.cour2 — 2018-02-09T07:00:56Z
workaround suggested here by Adam Ruppe: https://forum.dlang.org/post/[email protected] ``` void foo() {} @trusted nothrow @nogc void da(scope void delegate() a) { auto hack = cast(void delegate() @nogc) a; try hack(); catch(Exception e) assert(0, e.msg); } @safe nothrow @nogc pure void main() { debug da({foo();}); } ```
Comment #3 by greensunny12 — 2018-02-09T09:13:08Z
Comment #4 by greensunny12 — 2018-02-09T09:14:11Z
Potential duplicate: 16492
Comment #5 by greensunny12 — 2018-02-14T19:52:01Z
This has been approved by Walter and is already in master for @nogc: https://github.com/dlang/dmd/pull/7882
Comment #6 by timothee.cour2 — 2018-02-14T23:21:07Z
> This has been approved by Walter including for remaining ones? (nothrow safe)
Comment #7 by bugzilla — 2018-02-15T04:41:37Z
Comment #8 by greeenify — 2018-07-03T23:30:01Z
Comment #9 by greeenify — 2018-07-03T23:47:54Z
I split this issue in two. This one is now only about `nothrow`, whereas https://issues.dlang.org/show_bug.cgi?id=19053 is about @safe.
Comment #10 by dlang-bot — 2019-02-28T10:11:45Z
@wilzbach updated dlang/dmd pull request #8449 "Issue 18407 - debug should escape nothrow" mentioning this issue: - Issue 18407 - debug should escape nothrow https://github.com/dlang/dmd/pull/8449
Comment #11 by dlang-bot — 2020-07-03T01:45:33Z
dlang/dmd pull request #8449 "Issue 18407 - debug should escape nothrow" was merged into master: - ef38f24a2d8bde1e4bc9d7c8224f336a0c0ed56e by Sebastian Wilzbach: Issue 18407 - debug should escape nothrow https://github.com/dlang/dmd/pull/8449