Surprise destructor call...

Manu turkeyman at gmail.com
Wed Aug 14 09:19:55 UTC 2024


Can anyone illuminate me as to where this destructor call is coming from?

struct Thing
{
  static int x;
  this(typeof(null)) pure {} // <-- comment this line and the error goes
away
  ~this() { ++x; }
}

Thing fun() pure
{
   return Thing(null);
}

error : `pure` function `urt.string.string.fun` cannot call impure
destructor `urt.string.string.Thing.~this`

Shouldn't NVRO construct the result in place and elide the copy/move? I
would not expect any call to the destructor in fun()...
Also surprisingly, if I comment out the constructor, the compile error
about the destructor goes away. I can't see why the constructor's existence
affects the destruction semantics in fun()?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240814/349e2e82/attachment-0001.htm>


More information about the Digitalmars-d mailing list