Thread overview
[Issue 9020] New: This pointer is not the same in constructor as it is in methods
Nov 14, 2012
Malte Skarupke
[Issue 9020] This pointer is not the same in constructor as it is in invariant
Nov 14, 2012
Andrej Mitrovic
Nov 14, 2012
Malte Skarupke
Nov 14, 2012
Malte Skarupke
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9020

           Summary: This pointer is not the same in constructor as it is
                    in methods
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: malteskarupke@web.de


--- Comment #0 from Malte Skarupke <malteskarupke@web.de> 2012-11-13 17:29:42 PST ---
Following test:

int main()
{
    class C
    {
        this()
        {
            this_pointer = &this;
        }
        invariant()
        {
            assert(this_pointer == &this);
        }

        C * this_pointer;
    }
    C c = new C;
    return 0;
}

That assert fires on DMD 2.060

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9020


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com
            Summary|This pointer is not the     |This pointer is not the
                   |same in constructor as it   |same in constructor as it
                   |is in methods               |is in invariant


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-13 17:35:26 PST ---
This seems to only happen in the invariant, not in methods:

import std.stdio;

void main()
{
    class C
    {
        this()
        {
            this_pointer = &this;
            writefln("ptr: %X", this_pointer);
            writefln("ths: %X", &this);
        }

        void test()
        {
            writefln("ptr: %X", this_pointer);
            writefln("ths: %X", &this);
        }

        C* this_pointer;
    }

    C c = new C;
    c.test();
}

Log:
ptr: 12FE44
ths: 12FE44
ptr: 12FE44
ths: 12FE44

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9020



--- Comment #2 from Malte Skarupke <malteskarupke@web.de> 2012-11-13 17:56:23 PST ---
Seems kinda random actually:

import std.stdio;

void main()
{
    class C
    {
        this(int a)
        {
            this_pointer = &this;
            writefln("ptr: %X", this_pointer);
            writefln("ths: %X", &this);
        }

        void test()
        {
            writefln("ptr: %X", this_pointer);
            writefln("ths: %X", &this);
        }

        C* this_pointer;
    }

    C c = new C(5);
    c.test();
}

ptr: 7FFFF8A0B0A0
ths: 7FFFF8A0B0A0
ptr: 7FFFF8A0B0A0
ths: 7FFFF8A0B0A8

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9020


Malte Skarupke <malteskarupke@web.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #3 from Malte Skarupke <malteskarupke@web.de> 2012-11-13 18:00:28 PST ---
(In reply to comment #2)
> Seems kinda random actually:
> 
> import std.stdio;
> 
> void main()
> {
>     class C
>     {
>         this(int a)
>         {
>             this_pointer = &this;
>             writefln("ptr: %X", this_pointer);
>             writefln("ths: %X", &this);
>         }
> 
>         void test()
>         {
>             writefln("ptr: %X", this_pointer);
>             writefln("ths: %X", &this);
>         }
> 
>         C* this_pointer;
>     }
> 
>     C c = new C(5);
>     c.test();
> }
> 
> ptr: 7FFFF8A0B0A0
> ths: 7FFFF8A0B0A0
> ptr: 7FFFF8A0B0A0
> ths: 7FFFF8A0B0A8

Nevermind, it was explained to me that I am comparing addresses to the pointer to the class on the stack...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------