<div class="gmail_quote">On Sun, Jul 15, 2012 at 1:41 PM, Benjamin Thaut <span dir="ltr"><<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am 15.07.2012 02:02, schrieb Timon Gehr:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 07/15/2012 12:55 AM, Benjamin Thaut wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am 14.07.2012 19:30, schrieb Gor Gyolchanyan:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, Jul 14, 2012 at 9:23 PM, Benjamin Thaut <<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><br>
<mailto:<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><u></u>>> wrote:<br>
<br>
Am 14.07.2012 19:21, schrieb kenji hara:<br>
<br>
2012/7/15 Benjamin Thaut <<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><br>
<mailto:<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><u></u>>>:<br>
<br>
The only problem about this is:<br>
<br>
class Fruit<br>
{<br>
class Seed {<br>
void SetFruit(Fruit fruit)<br>
{<br>
this.outer = fruit;<br>
<br>
<br>
Setting to pseudo variable 'outer' should be rejected in<br>
compilation.<br>
Please report it to bugzilla.<br>
<br>
}<br>
}<br>
}<br>
<br>
class Apple: Fruit<br>
{<br>
void AppleOnlyMethod(){ ... }<br>
<br>
class AppleSeed: Fruit.Seed {<br>
void DoSomething()<br>
{<br>
AppleOnlyMethod();<br>
}<br>
}<br>
<br>
auto GetNewSeed() { return new AppleSeed(); }<br>
}<br>
<br>
auto apple = new Apple();<br>
auto seed = apple.GetNewSeed();<br>
seed.SetFruit(new Fruit());<br>
seed.DoSomething(); //what happens here?<br>
<br>
Kind Regards<br>
Benjamin Thaut<br>
<br>
<br>
Kenji Hara<br>
<br>
<br>
I will not report this, beacuse it will break my custom new operator<br>
(template) for inner classes ;-)<br>
<br>
Kind Regards<br>
Benjamin Thaut<br>
<br>
<br>
That's most unwise, because if it's not supposed to be like that it will<br>
get fixed anyway, so you better start replacing your custom new<br>
operator.<br>
<br>
--<br>
Bye,<br>
Gor Gyolchanyan.<br>
</blockquote>
<br>
Replacing my custom new operator exactly by what? Overloading the build<br>
in new is deprecated...<br>
<br>
</blockquote>
<br>
class C{<br>
     class D{<br>
<br>
     }<br>
}<br>
void main(){<br>
     auto c = new C;<br>
     auto buf = new void[__traits(<u></u>classInstanceSize, C.D)];<br>
     (cast(byte[])buf)[] = typeid(C.D).init[];<br>
     auto d = cast(C.D)buf.ptr;<br>
     static if(is(typeof(d.__ctor()))) d.__ctor();<br>
     enum offset=d.outer.offsetof;<br>
     static assert(offset%C.sizeof==0);<br>
     (cast(C[])buf)[offset/C.<u></u>sizeof]=c;<br>
     assert(d.outer is c);<br>
}<br>
</blockquote>
<br></div></div>
Yes of course I can assign the reference by computing the address and then using that to assign it. But the point here is, that this is currently the only bug that is hepling me in what I'm doing, and I rather want the 7 other bugs I reported so far to be fixed, rather then the one that helps me.<br>

<br>
Kind Regards<span class="HOEnZb"><font color="#888888"><br>
Benjamin Thaut<br>
<br>
</font></span></blockquote></div><br>Not being able to assign is not about some sort of authoritative forbidding. It's about not breaking a working mechanism. You can't cast a function pointer into a class object not because the type system says so (which it does), but because that'll result in an undefined behavior, which will result in an immediate crash in the best scenario. Go ahead and change the outer via those hacks. But then don't get surprised when your program crashes for no reason (because the compiler assumed it not to change and ended up being wrong).<br clear="all">
<div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>