The most trivial example of this is a check that a caller has provided non-null inputs ( hence allowing 'safe' unchecked access in most cases)
Perhaps for a more familiar case where contracts allow greater memory safety: constexpr T& operator[](size_t i) const pre(i < size()); constexpr T& front() const pre(!empty());
or even more commonly: void register_handler(std::unique_ptr<Handler> h) pre(h != nullptr);
int x = 1;
foo(x);
// What values has x?
In C the answer is obvious, in C++ due to the existence of references and the poor way they are designed, it is not anymore.Considering that every other "C family" language community gets by just fine with call sites that look like using references, I think calling this element of references "poorly designed" is quite a stretch.
Amusingly, the Chromium folks found this out firsthand when working on Rust bindings - all of the unnecessary pointer arguments due to the GSG complicated the process.
I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.
Except this isn't true, and it's at best an unfounded belief that relies on hand waving and wishful thinking to connect how an optional debugging tool that affects memory allocation and is able to throw exceptions will save anyone from things such as use-after-free.