<div class="gmail_extra"><div class="gmail_quote">On 15 December 2012 19:45, H. S. Teoh <span dir="ltr"><<a href="mailto:hsteoh@quickfur.ath.cx" target="_blank">hsteoh@quickfur.ath.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">On Sat, Dec 15, 2012 at 11:31:22AM -0800, Jonathan M Davis wrote:<br>
> On Saturday, December 15, 2012 19:50:34 Iain Buclaw wrote:<br>
> > On Saturday, 15 December 2012 at 18:38:29 UTC, H. S. Teoh wrote:<br>
> > > With latest git dmd:<br>
> > >   auto makeVoldemort(int x) {<br>
> > ><br>
> > >           struct Voldemort {<br>
> > ><br>
> > >                   @property int value() { return x; }<br>
> > ><br>
> > >           }<br>
> > >           return Voldemort();<br>
> > ><br>
> > >   }<br>
> > >   void main() {<br>
> > ><br>
> > >           auto v = makeVoldemort();<br>
> > >           writeln(v.value);<br>
> > ><br>
> > >   }<br>
> > ><br>
> > > Compile error:<br>
> > >   test.d(3): Error: function test.makeVoldemort.Voldemort.value<br>
> > ><br>
> > > cannot access frame of function test.makeVoldemort<br>
> > ><br>
> > > Changing 'struct' to 'class' works. Is this deliberate, or is it a<br>
> > > bug?  It is certainly inconsistent with Walter's article on<br>
> > > Voldemort types, which uses structs as examples.<br>
</div>[...]<br>
<div class="im">> > Pretty certain it's deliberate.  No closure is created for nested<br>
> > structs to access it's parent, complying with it's POD behaviour.<br>
><br>
> static nested structs don't have access to their outer scopes.<br>
> Non-static structs do. This reeks of a bug.<br>
</div>[...]<br>
<br>
Found the reference in TDPL, §7.1.9 (p.263):<br>
<br>
        Nested structs embed the magic "frame pointer" that allows them<br>
        to access outer values such as a and b in the example above.<br>
        [...] If you want to define a nested struct without that<br>
        baggage, just prefix struct with static in the definition of<br>
        Local, which makes Local a regular struct and consequently<br>
        prevents it from accessing a and b.<br>
<br>
Ironically enough, Andrei in the subsequent paragraph discourages the<br>
use of such nested structs, whereas Walter's article promotes the use of<br>
such Voldemort types as a "happy discovery". :)<br>
<br>
Anyway, filed a bug:<br>
<br>
        <a href="http://d.puremagic.com/issues/show_bug.cgi?id=9162" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=9162</a><br>
<span class=""><font color="#888888"><br></font></span></blockquote></div><br>If it is one, it's a bug in FuncDeclaration::getLevel.<br><br clear="all"><br>-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';<br>

</div>