Bug 9020 – This pointer is not the same in constructor as it is in invariant
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-13T17:29:00Z
Last change time
2012-11-13T18:00:28Z
Assigned to
nobody
Creator
malteskarupke
Comments
Comment #0 by malteskarupke — 2012-11-13T17:29:42Z
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
Comment #1 by andrej.mitrovich — 2012-11-13T17:35:26Z
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
Comment #2 by malteskarupke — 2012-11-13T17:56:23Z
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
Comment #3 by malteskarupke — 2012-11-13T18:00:28Z
(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...