Bug 1979 – Anonymous class with confused context pointer

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-04-08T13:09:00Z
Last change time
2014-02-24T15:33:52Z
Assigned to
nobody
Creator
benoit

Comments

Comment #0 by benoit — 2008-04-08T13:09:50Z
The following snippet shows an inner anonymous class, that uses the constructor to copy local values to member var. This is to make a closure behaviour. When the inner class later tries to access the outer class, a segmentation fault happens. The compiler should either given an error or it should work. void main(){ auto o = new Outer; o.run(5); } interface Intf { void doIt(); } class Outer { int i; void inc( int v ){ i += v ; } void run( int v2 ){ auto i = new class Intf { int v2_; this(){ v2_ = v2; } void doIt(){ inc( v2_ ); // (1) segmentation fault } }; i.doIt(); } }
Comment #1 by clugdbug — 2009-04-18T03:43:02Z
This doesn't segfault for me in DMD1.042. Has it been fixed?
Comment #2 by clugdbug — 2009-09-16T02:39:16Z
This was fixed in either 1.029 or 1.030. Works now.