www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9020] New: This pointer is not the same in constructor as it is in methods

reply d-bugmail puremagic.com writes:
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



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: -------
Nov 13 2012
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Nov 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9020




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: -------
Nov 13 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9020


Malte Skarupke <malteskarupke web.de> changed:

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



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
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: -------
Nov 13 2012