P3790R2 — Pointer lifetime-end zap proposed solutions: Bag-of-bits pointer class
LEWGLWG
The C++ standard currently specifies that all pointers to an object become invalid at the end of its lifetime [basic.life]. Although this permits additional diagnostics and optimizations which might be of some value, it is not consistent with long-standing usage, especially for a range of concurrent and sequential algorithms that rely on loads, stores, equality comparisons, and even dereferencing of such pointers. Similar issues result from object-lifetime aspects of C *pointer* *provenance.* **We propose (1) the addition to the C++ standard library of the function launder_ptr_bits() that takes a pointer** **argument and returns a prospective pointer value corresponding to its argument; and (2) the addition to the** **C++ standard library of the class template std::ptr_bits<T> that is a pointer-like type that is still usable after the** **pointed-to object’s lifetime has ended.** Please note that this paper does not propose adding bag-of-bits pointer semantics to the standard. However, in the service of legacy code, it is hoped that implementers provide such semantics, perhaps via some facility such as a command-line option that causes all pointers to be exempt from lifetime-end po