Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Borrow Checker, Lifetimes, and Destructor Arguments in C++ (2024)

https://a10nw01f.github.io/post/advanced_compile_time_valida...



The lifetimes it implements is the now unused lexical lifetimes of early Rust. Modern rust uses non-lexical lifetimes which accepts a larger amount of valid programs and the work on Polonius will further allow more legal programs that lexical lifetimes and non lexical lifetimes can’t allow. Additionally, the “borrow checker” they implement is RefCell which isn’t the Rust borrow checker at all but an escape hatch to do limited single-threaded borrow checking at runtime (which the library won’t notice if you use in multiple threads but Rust won’t let you).

Given how the committee works and the direction they insist on taking, C++ will never ever become a safe language.


Oh and to add on, in c++ there’s no borrow checker and no language guarantees that exploit UB in the way Rust does with ownership. What does it matter if two parts of a single threaded program have simultaneous mutable references to something - it’s not a safety or correctness issue as there’s no risk of triggering UB and there’s no ill formed program that could be generated that way. IMHO a RefCell equivalent in C++ is utterly pointless.


> Stateful Metaprogeamming

Bit of a fun fact, but as one of the linked articles states the C++ committee doesn't seem to be a fan of stateful metaprogramming so its status is somewhat unclear. From Core Working Group issue 2118:

> Defining a friend function in a template, then referencing that function later provides a means of capturing and retrieving metaprogramming state. This technique is arcane and should be made ill-formed.

> Notes from the May, 2015 meeting:

> CWG agreed that such techniques should be ill-formed, although the mechanism for prohibiting them is as yet undetermined.

[0]: https://cplusplus.github.io/CWG/issues/2118.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: