Here is another example where neither opAssign nor the dtor are called for an assignment (unless a postblit is added too):

---
uint dtorCount;

struct S {
  uint x;
  void opAssign(const ref S rhs) { assert(false, "Not called"); }
  ~this() { ++dtorCount; }
}

void main() {
  S[] a;
  a.length = 1;
  a[0].x = 42; // Some random non-init value

  a[] = S.init;

  assert(a[0].x == 0); // As expected, the value has been reset
  assert(dtorCount == 0); // Passes?!?
}
---


Again, am I missing something obvious here? I can't quite believe that struct lifetime would have been quite as broken for so long.

 – David

Reply via email to