Relocatable objects and internal pointers

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 17:18:33 PST 2016


On 01/29/2016 05:07 PM, Matt Elkins wrote:

 >      this(/* arguments to populate stuff */)
 >      {
 >          m_this = &this;
 >          /* ... populate stuff ... */
 >      }

 > a section in TDPL which said internal pointers are
 > verboten because objects must be relocatable. Does this mean my example
 > is invalid

Yes, D explicitly bans internal pointers.

 > does that mean there are circumstances under which the
 > post-blit constructor can be elided when performing a copy or copy-like
 > operation (such as a move)?

Definitely so. Rvalues are moved around all the time. The following 
program has two rvalue moves without calling post-blits or destructors.

struct Foo {
     this(this) {
         assert(false);    // not expected to be called in this program
     }
}

Foo makeFoo() {
     return Foo();
}

void takesFoo(Foo foo) {
}

void main() {
     Foo foo;
     foo = makeFoo();    // post-blit not called
     takesFoo(Foo());    // post-blit not called
}

Ali



More information about the Digitalmars-d-learn mailing list