logoalt Hacker News

zarzavat • last Sunday at 11:01 PM • 2 replies • view on HN

While I don't doubt this makes C++ safer, it really has nothing to do with memory safety which is usually understood as a language-level guarantee, either through the type system (as in Rust), or through execution in a managed environment.


Replies

horseloverthin • last Sunday at 11:26 PM

I think some increase in memory-safe outputs is a part of the 'memory safety story' of C++ regardless of whether this comes from type-level changes or improved constructs for memory safety.

Perhaps, a good way to describe the difference here is to clarify that contracts do not innately make C++ as a language more memory safe, but have plenty to do with the memory safety of C++ applications.

btown • last Sunday at 11:13 PM

Agreed that it’s not memory safety in the language-guarantee sense. But it lets a library make a spatial-safety guarantee that holds regardless of how it’s compiled.

If I call safe_library::some_low_level_op(some_offset), the library can guarantee a bad offset terminates the program before any out-of-bounds access, and no build flag on my end can drop that check. That’s the same “safe API over unsafe internals, enforced at runtime” pattern Rust’s own standard library relies on for bounds.

What C++ still can’t do is stop me from bypassing that API with a raw pointer, or help at all with lifetimes. But it's useful in practice, not just in theory.