(Imperfect) Emulation of Rust's borrow checker in C++23 with Clang Extensions
https://compiler-explorer.com/z/4nennEooe
Clang has had a somewhat abandoned extension 'Consumed Annotation Checking' for some time now. Surprisingly I've not seen many people talk about it, despite the potential it has.
It is a little buggy and has some limitations, but I believe a more fleshed out implementation could be very useful in catching lifetime bugs.
I've linked a toy example of how powerful this feature is. Don't expect me to defend any of the practices in it (namely the operator& overloads).
https://redd.it/1x09wv5
@r_cpp
Post #25818
5