option -ignore_pure for temporary debugging (or how to wrap an unpure function inside a pure one)?

Adam D. Ruppe destructionator at gmail.com
Thu Feb 8 03:37:24 UTC 2018


On Thursday, 8 February 2018 at 03:29:54 UTC, Timothee Cour wrote:
> How about adding flags ` -ignore_pure` (and perhaps 
> -ignore_safe -ignore_nothrow) to allow code to compile ignoring 
> safe, pure, nothrow mismatches?

We already have that for pure. Just write `debug your_function` 
and it will work.

void foo() {}

pure void main() {
         debug foo();
}

Note you must use the -debug switch to dmd to compile such 
statements in, but they are exempt from the pure check.

Then for safe and nothrow, a @trusted wrapper that catches 
Exceptions and rethrows them as Errors will handle that, like you 
are basically already doing.

@nogc is the exception... I think you can cast. So this:

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


cheats the system entirely.


More information about the Digitalmars-d mailing list