Bug 8464 – debug too strict from function attributes
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-29T13:30:35Z
Last change time
2019-10-10T11:36:15Z
Assigned to
No Owner
Creator
Era Scarecrow
Comments
Comment #0 by rtcvb32 — 2012-07-29T13:30:35Z
If a function is @safe then the debug {} calls all remain required to also follow that requirement as well.
void pureSafe() @safe pure {
debug {
writeln("Debugging info!");
}
}
Error: safe function 'pureSafe' cannot call system function 'writeln'
Marking the function as @trusted (although works) when the non-debug code is provably @safe seems like a bad approach just for debugging. Debug scope should break constraints and limitations for debugging purposes.
Comment #1 by bugzilla — 2012-07-29T13:59:30Z
Not a bad idea, but it's an enhancement.
Comment #2 by monarchdodra — 2013-08-20T08:48:31Z
*** Issue 10854 has been marked as a duplicate of this issue. ***
Comment #3 by monarchdodra — 2013-08-20T08:50:00Z
(In reply to comment #2)
> *** Issue 10854 has been marked as a duplicate of this issue. ***
I also think that @safe can call anything in a debug clause.
Consider also making debug callable in a nothrow scope, even if the debug code can throw.
Comment #4 by bearophile_hugs — 2014-07-20T05:46:00Z
(In reply to Era Scarecrow from comment #0)
> If a function is @safe then the debug {} calls all remain required to also
> follow that requirement as well.
>
> void pureSafe() @safe pure {
> debug {
> writeln("Debugging info!");
> }
> }
> Error: safe function 'pureSafe' cannot call system function 'writeln'
>
> Marking the function as @trusted (although works) when the non-debug code
> is provably @safe seems like a bad approach just for debugging. Debug scope
> should break constraints and limitations for debugging purposes.
What other unsafe functions do you want to call (beside writeln) in a debug{}?
Comment #5 by hsteoh — 2014-07-20T14:27:17Z
This came up in a recent PR, where assumeUTF has a `debug validate(s)` line to run a validation check on the input ubyte[]/short[]/int[] in order to catch user error when passing in invalid data. Since validate() is an expensive operation, we only do it during -debug. It also makes the function throwing, etc., which would make it stop compiling if called from pure/nothrow/etc. code.
Comment #6 by razvan.nitu1305 — 2019-10-10T11:36:15Z
This has been fixed in git master. Closing as fixed.