logoalt Hacker News

sprocketztoday at 1:06 PM2 repliesview on HN

And the most important idea: destructive moves. Since C++ doesn't track lifetimes it has to leave the object in a "valid state" after a move and the destructor still runs which has to have a check if it should do something or not.


Replies

porneltoday at 2:46 PM

BTW, Rust's lifetime annotations for borrowed references are a mostly orthogonal feature.

Liveness of objects for move/drop semantics is tracked differently, without any syntax and with implicit runtime drop flags where necessary.

C++ could probably add the same deinitialized/moved-from state tracking (with an opt-in for back compat sake) purely to avoid dtor bloat, without having to add safety of borrow checking.

show 1 reply
jandrewrogerstoday at 4:48 PM

While not the common case, C++ move semantics match the situation in systems code where correctness requires decoupling logical object lifetimes and destructors. The object is logically dead but the destructor may be deferred indefinitely for safety reasons.

Most code doesn't have the shared memory setups where deferred destruction is necessary.