Advertisement
tinyevil

Untitled

Jul 29th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. I found that "x = y" invoking custom code brings serious consequences.
  2.  
  3. Jellyfish treats `x = y` as destruction of x, followed by a copy ctor.
  4.  
  5. For a brief moment of time, `x` is in an indeterminate state. This is not
  6. a problem for memcpy, as no other part of the program can observe this brief
  7. inconsistency. But if we allow custom operator=, then this incosistency may
  8. become visible to the rest of the program if = does some funny stuff.
  9.  
  10. Consider
  11.  
  12. struct Foo{
  13. field bar:Bar;
  14. }
  15.  
  16. function f(x:ref Foo){
  17. x->bar = make_bar();
  18. }
  19.  
  20. In this case, the `Bar` destructor is invoked first. So `x->bar` becomes
  21. uninitialized. Then it invokes a copy ctor, but if there are more references to
  22. `x`, and this copy ctor uses one of them to access it, then they'll see `Foo`
  23. in an incosistent state.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement