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();});
}
```
@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