Bug 6319 – debug's relaxed purity does not apply to nested scopes
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-14T17:14:00Z
Last change time
2013-01-17T17:23:40Z
Keywords
pull, rejects-valid
Assigned to
yebblies
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2011-07-14T17:14:15Z
A D2 program:
import core.stdc.stdio;
void foo() pure {
debug {
if(true)
printf("********");
}
}
void main() {
foo();
}
If I compile it with -debug I DMD 2.054 it shows:
test.d(5): Error: pure function 'foo' cannot call impure function 'printf'
If I remove the if(true) line the program compiles and runs correctly:
import core.stdc.stdio;
void foo() pure {
debug {
printf("********");
}
}
void main() {
foo();
}
Comment #1 by bearophile_hugs — 2011-07-14T17:52:52Z
Until this bug gets fixed, a simple workaround is to just put the if() outside the debug{}:
import core.stdc.stdio;
void foo() pure {
if(true)
debug {
printf("********");
}
}
void main() {
foo();
}
Comment #2 by changlon — 2011-07-14T18:10:31Z
Starting program: /web/www/tmp/jade/jade2test
[Thread debugging using libthread_db enabled]
f = 0x4fc4b0,32, t = 0x713030,32, size = 1
f = 0x4fed20,176, t = 0x7ffff7ed5f00,176, size = 1
f = 0x4ff200,72, t = 0x71f490,72, size = 1
f = 0x4f8c10,64, t = 0x7ffff7ed8fc0,64, size = 1
f = 0x4f8d00,64, t = 0x7ffff7ed8f80,64, size = 1
f = 0x4f0880,12, t = 0x7ffff7ed9ff0,12, size = 1
f = 0x4f3920,56, t = 0x7ffff7ed8f00,56, size = 1
f = 0x4f3920,56, t = 0x7ffff7ed8ec0,56, size = 1
1 times use time = 1ms
Program received signal SIGSEGV, Segmentation fault.
0x00000000004cda08 in rt.lifetime.rt_finalize (p=0x7ffff729d000, det=false)
at src/rt/lifetime.d:1154
1154 ClassInfo c = **pc;
(gdb) bt
#0 0x00000000004cda08 in rt.lifetime.rt_finalize (p=0x7ffff729d000, det=false)
at src/rt/lifetime.d:1154
#1 0x00000000004cb1de in gc.gcx.Gcx.fullcollect (this=0x713060,
stackTop=0x7fffffffe260) at src/gc/gcx.d:2631
#2 0x00000000004caaf3 in gc.gcx.Gcx.fullcollectshell (this=0x713060)
at src/gc/gcx.d:2391
#3 0x00000000004c902b in gc.gcx.GC.fullCollectNoStack (this=0x713030)
at src/gc/gcx.d:1329
#4 0x00000000004c721d in gc.gc.gc_term () at src/gc/gc.d:133
#5 0x00000000004abc4d in rt.dmain2.main.runAll (this=0x7fffffffe4a0)
at src/rt/dmain2.d:515
#6 0x00000000004ab6f5 in rt.dmain2.main.tryExec (this=0x7fffffffe4a0,
dg=0x00000000004abbdc00007fffffffe4a0) at src/rt/dmain2.d:471
#7 0x00000000004ab684 in rt.dmain2.main (argc=1, argv=0x7fffffffe588)
at src/rt/dmain2.d:518
Comment #3 by changlon — 2011-07-14T18:11:45Z
(In reply to comment #2)
> Starting program: /web/www/tmp/jade/jade2test
> [Thread debugging using libthread_db enabled]
> f = 0x4fc4b0,32, t = 0x713030,32, size = 1
> f = 0x4fed20,176, t = 0x7ffff7ed5f00,176, size = 1
> f = 0x4ff200,72, t = 0x71f490,72, size = 1
> f = 0x4f8c10,64, t = 0x7ffff7ed8fc0,64, size = 1
> f = 0x4f8d00,64, t = 0x7ffff7ed8f80,64, size = 1
> f = 0x4f0880,12, t = 0x7ffff7ed9ff0,12, size = 1
> f = 0x4f3920,56, t = 0x7ffff7ed8f00,56, size = 1
> f = 0x4f3920,56, t = 0x7ffff7ed8ec0,56, size = 1
> 1 times use time = 1ms
>
>
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00000000004cda08 in rt.lifetime.rt_finalize (p=0x7ffff729d000, det=false)
> at src/rt/lifetime.d:1154
> 1154 ClassInfo c = **pc;
> (gdb) bt
> #0 0x00000000004cda08 in rt.lifetime.rt_finalize (p=0x7ffff729d000, det=false)
> at src/rt/lifetime.d:1154
> #1 0x00000000004cb1de in gc.gcx.Gcx.fullcollect (this=0x713060,
> stackTop=0x7fffffffe260) at src/gc/gcx.d:2631
> #2 0x00000000004caaf3 in gc.gcx.Gcx.fullcollectshell (this=0x713060)
> at src/gc/gcx.d:2391
> #3 0x00000000004c902b in gc.gcx.GC.fullCollectNoStack (this=0x713030)
> at src/gc/gcx.d:1329
> #4 0x00000000004c721d in gc.gc.gc_term () at src/gc/gc.d:133
> #5 0x00000000004abc4d in rt.dmain2.main.runAll (this=0x7fffffffe4a0)
> at src/rt/dmain2.d:515
> #6 0x00000000004ab6f5 in rt.dmain2.main.tryExec (this=0x7fffffffe4a0,
> dg=0x00000000004abbdc00007fffffffe4a0) at src/rt/dmain2.d:471
> #7 0x00000000004ab684 in rt.dmain2.main (argc=1, argv=0x7fffffffe588)
> at src/rt/dmain2.d:518
sorry for my mistake, this is for bug 6014
Comment #4 by yebblies — 2013-01-16T05:27:22Z
Reduced:
int x;
void main() pure
{
debug
{
{
x = 0;
}
}
}