<div class="gmail_quote">On Sun, Jul 15, 2012 at 3:35 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 13:24, schrieb Gor Gyolchanyan:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, Jul 15, 2012 at 1:41 PM, Benjamin Thaut <<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><div class="im"><br>
<mailto:<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><u></u>>> wrote:<br>
<br>
    Am 15.07.2012 02:02, schrieb Timon Gehr:<br>
<br>
        On 07/15/2012 12:55 AM, Benjamin Thaut wrote:<br>
<br>
            Am 14.07.2012 19:30, schrieb Gor Gyolchanyan:<br>
<br>
                On Sat, Jul 14, 2012 at 9:23 PM, Benjamin Thaut<br>
                <<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a> <mailto:<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><u></u>><br></div>
                <mailto:<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a><div class="im"><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></div>
                <mailto:<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>>__>>:<div><div class="h5"><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<br>
                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<br>
                like that it will<br>
                get fixed anyway, so you better start replacing your<br>
                custom new<br>
                operator.<br>
<br>
                --<br>
                Bye,<br>
                Gor Gyolchanyan.<br>
<br>
<br>
            Replacing my custom new operator exactly by what?<br>
            Overloading the build<br>
            in new is deprecated...<br>
<br>
<br>
        class C{<br>
              class D{<br>
<br>
              }<br>
        }<br>
        void main(){<br>
              auto c = new C;<br></div></div>
              auto buf = new void[__traits(__<u></u>classInstanceSize, C.D)];<div class="im"><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></div>
              (cast(C[])buf)[offset/C.__<u></u>sizeof]=c;<div class="im"><br>
              assert(d.outer is c);<br>
        }<br>
<br>
<br>
    Yes of course I can assign the reference by computing the address<br>
    and then using that to assign it. But the point here is, that this<br>
    is currently the only bug that is hepling me in what I'm doing, and<br>
    I rather want the 7 other bugs I reported so far to be fixed, rather<br>
    then the one that helps me.<br>
<br>
    Kind Regards<br>
    Benjamin Thaut<br>
<br>
<br></div><div class="im">
Not being able to assign is not about some sort of authoritative<br>
forbidding. It's about not breaking a working mechanism. You can't cast<br>
a function pointer into a class object not because the type system says<br>
so (which it does), but because that'll result in an undefined behavior,<br>
which will result in an immediate crash in the best scenario. Go ahead<br>
and change the outer via those hacks. But then don't get surprised when<br>
your program crashes for no reason (because the compiler assumed it not<br>
to change and ended up being wrong).<br>
<br>
--<br>
Bye,<br>
Gor Gyolchanyan.<br>
</div></blockquote>
<br>
Before your change suggestion it was absolutley save to assign to outer. Thats the whole point why I posted this here. I very well know that the bug will get fixed some time. But before your change suggestion it was not even a bug.<br>

<br>
Kind Regards<span class="HOEnZb"><font color="#888888"><br>
Benjamin Thaut<br>
<br>
</font></span></blockquote></div><br>A bug remains a bug whether it was discovered or not. If it wasn't - it would never get discovered. Even if the bug didn't get discovered for a long time, making designs around bugs is a very bad idea precisely for this reason. But it's not entirely your fault, because there's no reliable reference to D at the moment, so it's very hard to determine what is and is not supposed to work. That's one of the problems, that drive new commers away: lack of a reference material.<br clear="all">
<div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>