TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #25818 5
(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
Compiler-Explorer Compiler Explorer - C++ (x86-64 clang (trunk)) /* Implementation */ template<class T> class MutableBorrow; template<class T> class ImmutableBorrow; template <class T> struct Taken { T impl; T* operator->() { return &impl; } }; template <class T> class [[clang::consumable(unconsumed)]] Rust {…
More from @r_cpp
  1. Oct 8, 2026Henrik Fransson: From Prompt to Probe - Closing the Agentic AI Loop on Bare Metal https://…
  2. Oct 7, 2026Escaping `CreateProcess()` arguments on Windows https://holyblackcat.github.io/blog/2026/0…
  3. Oct 7, 2026flat_map internals https://quantdev.blog/posts/flat-map-internals/index.html https://redd.…
  4. Oct 7, 2026New C++ Conference Videos Released This Month - September 2026 C++Now 2026-08-31 - 2026-09…
  5. Oct 7, 2026Jean Frantz René: C++ Memory safety for safety-critical and non-safety critical applicatio…
  6. Oct 7, 2026Full Meeting C++ 2026 program released https://meetingcpp.com/mcpp/schedule/#2026 https://…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →